Page 1 of 1

Serious problem with .NTX created with "index on"

PostPosted: Thu Sep 11, 2008 9:44 am
by max
I have problems with the "index on" command.
I create my index from inside my procedure with:

Code: Select all  Expand view
USE mydbf
INDEX ON mydbf->lastname INDEX myntx

If i open the .dbf and .ntx with:
USE mydbf INDEX myntx

all works ok (apparently, but i have problems moving record from my browses, etc.), but if i open the same files with the alias clause:
Code: Select all  Expand view
USE mydbf INDEX myntx ALIAS myalias

i receive a runtime error "Error base 1002/ ALIAS mydbf DOES NOT EXIST" (!?) .
I receive the same error (on the 2nd row) if i try to open the .ntx file with:
Code: Select all  Expand view
USE mydbf ALIAS myalias
SET INDEX TO myntx

If i create the same .ntx file with DBU utility of clipper 5.2, all works ok!

Please help me! There is a bug with the "INDEX ON" command?
Or something wrong or incomplete in my code?
Thank you.
max

FWH 8.04 - XHARBOUR 1.1.0

PostPosted: Thu Sep 11, 2008 10:19 am
by Marc Vanzegbroeck
You have to use
Code: Select all  Expand view
INDEX ON lastname INDEX myntx

instead of mydbf->lastname
if you want to open the file with
Code: Select all  Expand view
USE mydbf INDEX myntx ALIAS myalias

because the alias 'mydbf' does't exist if you open it with ALIAS myalias

Marc

PostPosted: Thu Sep 11, 2008 10:30 am
by max
Thank you Marc, but i use the switch /w compiling my .prg, so i can't delete the alias ref. because the harbour compiler stop with "ambigous reference" error in "lastname" variable.
However, if i delete the switch /w and recompiling my .prg, all is right, so your suggest is ok.

A few seconds ago i find the solution for manteining the switch /w and solving the problem.
Reading some .prg in \FWH\SAMPLES directory, i found that i can use the alias "field", like this:

INDEX ON field->lastname to myntx

In this mode, all is ok and (finally!) my xbrowses work fine!
Thank you.
Bye.

PostPosted: Thu Sep 11, 2008 12:03 pm
by nageswaragunupudi
>
INDEX ON field->lastname to myntx
>

It is always better not to use alias in index expressions. INDEX ON LASTNAME TO MYNTX is the best and recommended way.

It is desirable that the database understands the expression independant of our program. Even field-> is not necessary and desirable to have just the name of the fields

PostPosted: Thu Sep 11, 2008 12:23 pm
by Euclides
Max,
The good old Clipper, behaves the same manner... :-))
Regards,
Euclides

PostPosted: Thu Sep 11, 2008 3:09 pm
by James Bott
Max,

>A few seconds ago i find the solution for manteining the switch /w and solving the problem.
>Reading some .prg in \FWH\SAMPLES directory, i found that i can use the alias "field", like this:

You can (and should) also declare all your fieldnames using the FIELD statement like this:

field lastname
...
index on lastname to myntx

Regards,
James