xsharp.eu • Problems with reindexing with NTX; record pointer at wrong record
Page 1 of 1

Problems with reindexing with NTX; record pointer at wrong record

Posted: Thu May 19, 2022 12:07 pm
by ThomasWYale
There's no relevant changes to my code, or the DBF tables and associated NTX files they're indexed with, but a few changes to my environment. Within the last few months I used Acronis True Image to copy the contents of my old drive to my new one, as well as install XIDE and VS. At no point during that time did I need to reindex a DBF file.

When I did reindex one DBF last night, I ran my code as usual, but the record pointer kept going to the wrong record. I even hard-coded what I wanted it to find at that point, DbSeek("m*an"), and it kept going to either the record with the field "sitter*" or "*eat" (those asterisks in the words are necessary to indicate to my application at which point to inflect English words with associated codes, e.g. "eat" -> "ate", "man" -> "men").

By process of elimination, certainly one of the changes in the environment had affected my app's ability to create NTX files, especially if nothing about the tables, indices or relevant code to search for records have changed. Is there any way I can attempt to repair this, perhaps through ODBC? Has anyone else had this problem?

Problems with reindexing with NTX; record pointer at wrong record

Posted: Thu May 19, 2022 10:20 pm
by Chris
Hi Thomas,

Can you post the dbf and ntx files, together with the code you use to reindex them, so we can have a look?

.

Problems with reindexing with NTX; record pointer at wrong record

Posted: Thu May 19, 2022 11:35 pm
by ThomasWYale
The dbf and ntx file are attached, and the only lines of code used to index are:

DBUSEAREA(FALSE,"DBFNTX","c:DiscoveryOLDdbfsROOT.dbf")
DBCREATEINDEX("c:DiscoveryOLDdbfsroot1","Literal")

Problems with reindexing with NTX; record pointer at wrong record

Posted: Thu May 19, 2022 11:37 pm
by ThomasWYale
The files didn't go through. Trying it again.

Problems with reindexing with NTX; record pointer at wrong record

Posted: Thu May 19, 2022 11:40 pm
by ThomasWYale
Still didn't go through. I attached the files themselves, and when that didn't work, put them in a zip file and included that. Not sure how to send them to you. Trying it again.
ROOT.zip
(2.6 MiB) Downloaded 138 times

Problems with reindexing with NTX; record pointer at wrong record

Posted: Fri May 20, 2022 7:08 am
by Chris
Hi Thomas,

Thanks! And can you also post some code that reproduces the problem with seek?

I tried here this simple code and this seems to work fine (without recreating the index, just using the one you posted), so there must be something different in your code:

Code: Select all

FUNCTION Start() AS VOID
LOCAL cFolder AS STRING
cFolder := "C:.......ROOT"
? DbUseArea(,"DBFNTX",cFolder + "ROOT")
? DbSetIndex(cFolder + "ROOT1.NTX")
? DbSeek("m*an") // true
? FieldGet(1) // "m*an"
? DbCloseArea()
.

Problems with reindexing with NTX; record pointer at wrong record

Posted: Fri May 20, 2022 11:58 am
by ThomasWYale
But I changed nothing in the code. The problem occurred when I edited a field in one record and reindexed, and nothing else was affected. That's why I figured that something changed in my PC environment, more likely my upgrade from Windows 7 to 10, less likely the disk imaging from my old hard drive to my current one. Anyway, here's the code for opening the table:

Code: Select all

DBUSEAREA(TRUE,"DBFNTX","c:DiscoveryOLDdbfsROOT.dbf")
DbSetIndex("c:DiscoveryOLDdbfsroot1")
Searching for a value:

Code: Select all

 FOR y:=0 UPTO SLen(ocWord:cLiteral)
  DbSeek(Left(ocWord:cLiteral,SLen(ocWord:cLiteral)-y)+"*")
  IF!Left(ocWord:cLiteral,SLen(ocWord:cLiteral)-y)+"*"==Left(literal,SLen(ocWord:cLiteral)-y+1)
   LOOP
  ENDIF
  WHILE Left(ocWord:cLiteral,SLen(ocWord:cLiteral)-y)+"*"==Left(literal,SLen(ocWord:cLiteral)-y+1)
   DbSelectArea("WRDNFLCT")
   DbGoto(Integer(Root->(wrdnflct)))
   SELF:rootFound(ocWord)
   DbSelectArea("ROOT")
   DBSKIP()
  ENDDO
  IF lExit
   EXIT
  ENDIF
 NEXT
The code for this literally hasn't changed for decades. A good indication of this is that I downloaded DBF Manager, which enables me to create and reindex an NTX file for a DBF. When I reindex from my application, it fails. When I reindex using DBF Manager, there's no problem. That definitely suggests something in the environment.

Problems with reindexing with NTX; record pointer at wrong record

Posted: Fri May 20, 2022 12:08 pm
by robert
Thomas,
If your code uses SetCollation(#Windows) then a change in the OS might cause the problem.
Especially if you change from a US version to a German version or vice versa.
If you want to be independent on the OS cultural settings, then use SetAppLocaleID() to set the locale to use when sorting:

// To use the standard German Language in Phone Book sorting mode:

Code: Select all

SetAppLocaleId(MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), ;
       SORT_GERMAN_PHONE_BOOK))


// To use the Swiss German Language in Default sorting mode

Code: Select all

SetAppLocaleId(MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS),;
 SORT_DEFAULT))


// To use the Norwegian Bokmal language, default sorting mode

Code: Select all

SetAppLocaleId(MAKELCID(MAKELANGID(LANG_NORWEGIAN,SUBLANG_NORWEGIAN_BOKMAL),;
 SORT_DEFAULT))


// To use language independent sorting

Code: Select all

SetAppLocaleId(MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL), ;
 SORT_DEFAULT))
Robert

Problems with reindexing with NTX; record pointer at wrong record

Posted: Fri May 20, 2022 10:46 pm
by ThomasWYale
Robert,
I think you may be on to something. My app doesn't use SetCollocation(#WINDOWS) but it does use SetCollocation(#CLIPPER). Perhaps it would be possible that using #CLIPPER as the argument would change the behavior after an OS update. I'll follow up on this and alternate between settings using SetAppLocaleId() to see whether this resolves the problem. Thank you for your prompt reply!

Problems with reindexing with NTX; record pointer at wrong record

Posted: Sat May 21, 2022 8:53 am
by ThomasWYale
Robert, thanks to you, I found the reason for the problem! I had SetCollocation(#CLIPPER) only after my dialog I use to reindex the DBF's I use in my app. In that case, the NTX was created with #WINDOWS, which is the default. When I inserted SetCollocation(#CLIPPER) before that dialog comes up, it solved the problem! Thank you, sir!