Page 1 of 1
Possible Info, if a Index belongs to a def. Database ?
Posted: Fri Feb 08, 2008 4:20 pm
by ukoenig
Im still busy with the new DB-Tool.
A little problem :
When the user opens a database,
as well he can select any index.
As long you know the Index, that fits the database,
it is ok. When you try to use a wrong index,
you will get a error-message : unknown fields.
In the Index-header, there is no information
about the database to be used together with the index.
I think, it can be solved only with a error-function.
Is there maybe another way to handle this ?
Regards
Uwe
Re: Possible Info, if a Index belongs to a def. Database ?
Posted: Fri Feb 08, 2008 5:08 pm
by Enrico Maria Giordano
No, as far as I know.
EMG
Posted: Mon Feb 11, 2008 8:27 am
by StefanHaupt
Uwe,
You can use BEGIN SEQUENCE... END SEQUENCE construction to handle the error internally.
Posted: Mon Feb 11, 2008 8:38 am
by nageswaragunupudi
We can find the index expression from the NTX headers and check if the field names used in the expression match the dbf. We also get the number of index entries from the header. We can match with the number of records in the dbf. That gives us some level of confidence that the NTX is very likely to belong to this DBF.
Not a 100% sure method, but fairly dependable, if you take the trouble. It was long long time back I was using header informations for various purposes. Now it is years since I touched NTX.
Posted: Mon Feb 11, 2008 8:50 am
by nageswaragunupudi
NTX header
I think this may be useful to read the index expression
Code: Select all
Type Size Field Name Description
xbShort 2 Signature Byte The Clipper signature byte. 0x003h indicates Clipper 87. 0x006h indicates Clipper 5.x
xbShort 2 Indexing Version Number Documented as the "Compiler Version" but I have observed an increasing number. Incremented whenever the index is changed.
xbLong 4 First Node Offset The offset to the first node.
xbLong 4 First Unused Page Offset The offset to the first unused node.
xbShort 2 Key Size + 8 The Key Size plus 8 bytes.
xbShort 2 Key Size The size (length) of the key.
xbShort 2 Number of Decimals Number of decimal places in key.
xbShort 2 Max Items Per Node The maximum number of key per node.
xbShort 2 1/2 The Max Items Per Node Half the maximum number of key per node. Important in a B-tree system, as this is the minimum number of keys that must be on a page.
char 256 KeyExpression Key expression string
char 1 Unique Unique indicator
00 - Not Unique - XB_NON_UNIQUE
01 - Unique - XB_UNIQUE
char 745 Unused Unused
1024
Seems 24th byte onwards we get the key expression.
Posted: Mon Feb 11, 2008 4:29 pm
by nageswaragunupudi
Mr Ukoenig
Here is a small program. This can tell if an NTX file does not belong to a DBF or it most probably can belong. If you like, please try and I hope we can improve on it's functionality.
Code: Select all
#include "fivewin.ch"
function main()
local cdbf, cntx, cIndexExpr, cType
if ! Empty( cdbf := cGetFile( "Select DataBase (*.DBF) |*.dbf|", CURDIR() ) )
use (cdbf) new alias dbff
do while ! Empty( cNtx := cGetFile( "Select Index (*.NTX) |*.ntx|", cFilePath( cdbf ) ) )
cIndexExpr := GetIndexExpr( cNtx )
if ! Empty( cIndexExpr )
msginfo( cIndexExpr, cNtx )
cType := Type( cIndexExpr )
if ( cType = "U" )
MsgInfo( cNtx + CRLF + "DOES NOT MATCH" + CRLF + cDbf, "NO MATCH" )
else
MsgInfo( cNtx + CRLF + "Possible Index of" + CRLF + cDbf, "POSSIBLE" )
endif
else
msginfo( "Can not read index experession" )
endif
enddo
endif
return nil
static function GetIndexExpr( cNtx )
local hFile
local cBuf := replicate( chr(0), 300 )
hFile := fopen( cNtx )
if ferror() == 0
if fread( hFile, @cBuf, 300 ) == 300
return trim( substr( cBuf, 23, 256 ) )
endif
fclose( hFile )
endif
return ""
I have tested on some very old NTX files and I am satisfied with the performance. I would be glad if you can give me your opinion.