FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour strange execution of Index
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
strange execution of Index
Posted: Mon Jan 14, 2019 01:00 AM
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 ) ) //ORDINE
SERVIZI->( 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 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 08:08 AM

What did you expect to see?

We can't see the Ordine column so we can't tell if it is correct.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 08:25 AM
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 (fw): Select all Collapse
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 )
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 10:26 AM

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=3t=33776hilit=field

Maybe this wil help your problem.

&&

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 05:06 PM

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

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 06:13 PM

Silvio,

You can't use aliases in an index.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 06:26 PM
Silvio,

This code is working fine here.

Code (fw): Select all Collapse
#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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 07:19 PM
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:
Code (fw): Select all Collapse
SERVIZI->( OrdSetFocus("ORDINE" ) )
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 07:40 PM

I made allways servizi->(dbsetorder(number_of_index))
why now I must make servizi->(dbsetorder(tagname))
Incredible!!!!

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 07:46 PM
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 (fw): Select all Collapse
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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange execution of Index
Posted: Mon Jan 14, 2019 08:03 PM

Perhaps

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: strange execution of Index
Posted: Thu Jan 17, 2019 08:02 AM
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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: strange execution of Index
Posted: Thu Jan 17, 2019 03:51 PM
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.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion