On Wed, 31 Mar 2010, Heinz V. Bergen wrote:

Hi,

> Harbour compiled program is corrupting Cl*pper NTX  Indexes.
> Discovered cause was with Indexes containing STR(RECNO()) in its key.
> Clipper will return a string length of 7, while Harbour returns a length of 
> 10.
> Checked the Harbour Docs and it indicates that Str(Recno())
> should also return a string length of 7.
> Using latest SVN with MINGW32  Am I missing something?

This is Harbour src/rdd/dbf1.c code which control this:

   #ifdef HB_CLP_STRICT
      /* this is for strict Clipper compatibility but IMHO Clipper should not
         do that and always set fixed size independent to the record number */
      if( ulRecNo < 10000000 )
      {
         hb_itemPutNLLen( pRecNo, ulRecNo, 7 );
      }
      else
      {
         hb_itemPutNLLen( pRecNo, ulRecNo, 10 );
      }
   #else
      hb_itemPutNInt( pRecNo, ulRecNo );
   #endif

As you can see in Clipper the default number of formatting digits depends
on record number. Such behavior causes serious problems in some cases, i.e.
in index like yours it reduces maximum table size to 9999999 records (over
this limit last 3 digits from index key are lost) so I decided to "fix" it
and left above note in source code.

> As it is I do have access the Cl*pper Index keys, they are stored in a DBF
> file which is used to recreate the indexes and I will change all references
> of Str(Recno()) to Str(Recno(),7,0) or will Str(Recno(),7) suffice?

Yes. It's enough to set explicitly number of digits though I suggest to
use 10 instead of 7 if you do not want to introduce some limits for
maximum number of records.

BTW if you do not need to access the indexes by Clipper then you can
reach the same effect much easier.
   rddInfo( RDDI_SORTRECNO, .t., "DBFNTX" )
enables Harbour extension which causes that in newly created indexes
RECNO() is calculate as hidden trailing part of the key just like in
CDX or NSX so it gives effectively the same without adding any STR(RECNO())
to index key and without increasing the index size. It also eliminates
potentially big performance problem caused by linear scan in NTX indexes
using a lot of non unique keys when they have to be positioned after
GOTO or for update.
You can also use:
   rddInfo( RDDI_MULTITAG, .t., "DBFNTX" )
to enable support for multitag NTX indexes - many indexes (tags) in
single file like in CDX or NSX formats.

> I will then recreate all indexes to solve my corruption problem.
> But if I didn't have access to change the Cl*pper NTX keys this would
> be an issue when a Harbour program accesses and updates.

Yes it is and user should remember about it.
BTW many clipper/xbase compatible languages use different number of
default digits in recno item so you should always try to use explicit
size of in str(recno()) expression if you want to share indexes or
use some RDBMS for DBFs.

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to