Page 1 of 1
strange execution of Index
Posted: Mon Jan 14, 2019 1:00 am
by Silvio.Falconi
I have a dbf and made 3 index
USE SERVIZI ALIAS SERVIZI
INDEX ON SERVIZI->ID TAG ID TO SERVIZI FOR !deleted()
INDEX ON UPPER(SERVIZI->NAME) TAG NAME TO SERVIZI FOR !deleted()
INDEX ON SERVIZI->ORDINE TAG ORDINE TO SERVIZI FOR !deleted()
Now I wish see the dbf index on Ordine field
If I made
SERVIZI->( DbSetOrder(3 ) ) //ORDINESERVIZI->( DBGOTOP() )
XBROWSE()
then I see this
check the last column if I made SERVIZI->( DbSetOrder("ordine" ) ) //ORDINE SERVIZI->( DBGOTOP() )
XBROWSE()
then I see this
why ?
Re: strange execution of Index
Posted: Mon Jan 14, 2019 8:08 am
by James Bott
What did you expect to see?
We can't see the Ordine column so we can't tell if it is correct.
Re: strange execution of Index
Posted: Mon Jan 14, 2019 8:25 am
by AntoninoP
I think the problem for Silvio is that the index "order" is not the number 3.
may be you can use
IndexOrd to see what number it is.
or get informations by this piece of code (untested):
Code: Select all | Expand
cMsg := ""
for j = 1 to OrdCount()
if !Empty( IndexKey( j ) )
OrdSetFocus( j )
cMsg += Str(j) " OrdName:" + OrdName( j )
cMsg += " Key: " + IndexKey(j) + CRLF
endif
next
MsgInfo(cMsg)
SetClipboardData( 1 /* CF_TEXT */, cMsg )
Re: strange execution of Index
Posted: Mon Jan 14, 2019 10:26 am
by Marc Venken
Silvio,
Mr. Rao told that there can be a issue when building indexes like this :
INDEX ON SERVIZI->ID TAG ID TO SERVIZI FOR !deleted()
See :
viewtopic.php?f=3&t=33776&hilit=fieldMaybe this wil help your problem.
Re: strange execution of Index
Posted: Mon Jan 14, 2019 5:06 pm
by Silvio.Falconi
I have ID as Character sample "0001", name as Character , Ordine as Number
the problem is on ordine field if I use dbsetorder(3) instead of dbsetorder("ordine") is the tag
Re: strange execution of Index
Posted: Mon Jan 14, 2019 6:13 pm
by James Bott
Silvio,
You can't use aliases in an index.
Re: strange execution of Index
Posted: Mon Jan 14, 2019 6:26 pm
by James Bott
Silvio,
This code is working fine here.
Code: Select all | Expand
#include "fivewin.ch"
Function Main()
REQUEST DBFCDX
rddsetdefault( "DBFCDX" )
SET EXCLUSIVE OFF
SET(_SET_AUTOPEN, .T. )
USE SERVIZI ALIAS SERVIZI
INDEX ON ID TAG ID TO SERVIZI FOR !deleted()
INDEX ON UPPER(NAME) TAG NAME TO SERVIZI FOR !deleted()
INDEX ON ORDINE TAG ORDINE TO SERVIZI FOR !deleted()
Set order to "name"
go top
browse()
set order to "ordine"
go top
browse()
set order to 3
go top
browse()
Return nil
Re: strange execution of Index
Posted: Mon Jan 14, 2019 7:19 pm
by FranciscoA
Silvio,
DbSetOrder( <nIndexPos> ) --> NIL
Arguments
<nIndexPos>
This is the numeric ordinal position of the index to activate as the controlling index. Indexes are numbered in the sequence they are opened with OrdListAdd(),
try this way:
Re: strange execution of Index
Posted: Mon Jan 14, 2019 7:40 pm
by Silvio.Falconi
I made allways servizi->(dbsetorder(number_of_index))
why now I must make servizi->(dbsetorder(tagname))
Incredible!!!!
Re: strange execution of Index
Posted: Mon Jan 14, 2019 7:46 pm
by James Bott
Silvio,
I noticed that the file was already in ORDINE order, so I changed a couple of them. Then when I ran it they were not indexed properly.
Then I realized I had forgotten to delete the existing index before building the indexes. I did that and now it is working.
Code: Select all | Expand
Function Main()
REQUEST DBFCDX
rddsetdefault( "DBFCDX" )
SET EXCLUSIVE OFF
SET(_SET_AUTOPEN, .T. )
ferase("servizi.cdx")
USE SERVIZI ALIAS SERVIZI
INDEX ON ID TAG ID TO SERVIZI FOR !deleted()
INDEX ON UPPER(NAME) TAG NAME TO SERVIZI FOR !deleted()
INDEX ON ORDINE TAG ORDINE TO SERVIZI FOR !deleted()
Set order to "name"
go top
browse()
set order to "ordine"
go top
browse()
//set order to 3
SERVIZI->( DbSetOrder(3 ) )
go top
browse()
Return nil
Re: strange execution of Index
Posted: Mon Jan 14, 2019 8:03 pm
by Silvio.Falconi
Perhaps
Re: strange execution of Index
Posted: Thu Jan 17, 2019 8:02 am
by Silvio.Falconi
First I never had this error because when I opened the application I went to check if the dbf files were in the specific folder (cDbfpath) and if I did not there I created them and also created the indexes by deleting them first.
Obviously, I first opened the archives in exclusive mode. Now with the opening in the new share mode I can not create the indexes because it requires the exclusive way and consequently I can not make the packs.
So now I have not understood well when I can make indexes and packs to the database.
If a user opens the program from another location on the network, the application can not perform the above check because the files are already opened by another user in another location.
It seems an absurdity and at the same time it seems to me absurd to be able to make a voice alert to all connected users "you have to close because I have to make the indexes to the archives ..!" and then run the indexes and the packs.
1) Can you explain to me when I can make the indexes and the packs
2) when I deliver the application to the client I also have to deliver the indexes?
3)how to check if the archives are open and create indexes?
Re: strange execution of Index
Posted: Thu Jan 17, 2019 3:51 pm
by James Bott
Silvio,
1) Can you explain to me when I can make the indexes and the packs
I have been trying to tell you this. You cannot build indexes unless you have the files open in exclusive use.
And you should not be building indexes everytime the program is run--there is no need.
If the program has just been installed, then it should check to see if the databases exist, and if not create them. Then it should open them in exclusive use mode, and build the indexes. Then close the files. Files should then be opened shared whenever they are opened.
From then on, when the program is run and does the check for the databases, it will find them and thus just skip that step.
Do you have a lot of deleted records? If so, why? Most times you can avoid doing packs by reusing deleted records. If you don't reuse them, then an Admin will have to have exclusive use of the files needing to be packed.
2) when I deliver the application to the client I also have to deliver the indexes?
No, see explaination above.
3)how to check if the archives are open and create indexes?
If you can't get exclusive use of the files, then they are open by someone else. And you need to get exclusive use of ALL the files BEFORE you delete the indexes and rebuild them.
Also, you seem to think that the indexes need to be created each time the program is run. Not so. Generally, the only time they need to be created is when they don't exist or when they are corrupted.