Possible Info, if a Index belongs to a def. Database ?

Possible Info, if a Index belongs to a def. Database ?

Postby ukoenig » Fri Feb 08, 2008 4:20 pm

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
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Postby StefanHaupt » Mon Feb 11, 2008 8:27 am

Uwe,

You can use BEGIN SEQUENCE... END SEQUENCE construction to handle the error internally.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby nageswaragunupudi » Mon Feb 11, 2008 8:38 am

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby nageswaragunupudi » Mon Feb 11, 2008 8:50 am

NTX header
I think this may be useful to read the index expression

Code: Select all  Expand view
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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby nageswaragunupudi » Mon Feb 11, 2008 4:29 pm

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  Expand view
#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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 53 guests