Page 1 of 1
APPEND FROM not working when CDX file exist
Posted: Tue Aug 14, 2007 8:48 pm
by CharlesPratt
I am not able to append from a dbf file when it has a .CDX file associated with it. The only way I can do it is to delete the cdx file first, then do an "INDEX ON..." to rebuild it after I append from it. Is this a limitation of xHarbour or is it a bug?
Charles
Re: APPEND FROM not working when CDX file exist
Posted: Tue Aug 14, 2007 9:39 pm
by Enrico Maria Giordano
Can you show a reduced sample of the problem?
EMG
Posted: Thu Aug 16, 2007 11:33 am
by CharlesPratt
Enrico -
You can download a sample that shows the problem from
http://www.softraksystems.com/download/append.zip Run the exe file and look at the prg file. I also included the error.log which appears in the app directory after it overwrites the first one that you see when the error occurs. The one you see says "alias not found", but is overwritten by the one that says "hb_cdxIndexFree: Index file still locked."
The problem appears to be that dbCloseArea() does not release the lock on the CDX file that has been previously opened with the dbf file as EXCLUSIVE.
Thanks for your help.
Charles
Posted: Thu Aug 16, 2007 2:02 pm
by Enrico Maria Giordano
Page not found. Please paste here the PRG showing the problem.
EMG
Posted: Thu Aug 16, 2007 2:45 pm
by CharlesPratt
Enrico -
Now the download link works. Sorry I didn't test it before.
Charles
Posted: Thu Aug 16, 2007 4:10 pm
by Enrico Maria Giordano
The following sample works fine here:
Code: Select all
REQUEST DBFCDX
FUNCTION MAIN()
RDDSETDEFAULT( "DBFCDX" )
DBCREATE( "ERRTEST", { { "TEST", "C", 35, 0 } } )
USE ERRTEST
INDEX ON FIELD -> test TO ERRTEST
APPEND BLANK
REPLACE FIELD -> test WITH "Test"
DBCREATE( "ERRTEST2", { { "TEST", "C", 35, 0 } } )
USE ERRTEST2
APPEND FROM ERRTEST
RETURN NIL
Please add the minimal amount of code needed to replicate the problem.
EMG
Posted: Fri Aug 17, 2007 12:24 am
by driessen
Enrico,
It has been some time since I used "Append".
But if I remember well, the file from which you append, must be closed.
Could that solve your problem ?
Good luck.
Posted: Fri Aug 17, 2007 6:46 am
by Enrico Maria Giordano
Yes, you are right, as COPY TO opens the destination file in exclusive mode.
EMG
Posted: Fri Aug 17, 2007 2:25 pm
by CharlesPratt
Enrico -
The following code is very simple, and causses the error to occur. Rather than using dbcreate as you did, I am using the customer.dbf from the FWH samples folder. The first time you run this, un-comment the COPY TO CUST line to produce the tcust.dbf.
REQUEST DBFCDX
RDDSETDEFAULT("DBFCDX")
USE CUSTOMER NEW EXCLUSIVE
INDEX ON CUSTOMER->LAST TAG LAST
INDEX ON CUSTOMER->SALARY TAG SALARY
DBGOTOP()
*COPY TO TCUST
CUSTOMER->(DBCLOSEAREA())
USE TCUST
ZAP
APPEND FROM CUSTOMER
RETURN NIL
Regards,
Charles
Posted: Fri Aug 17, 2007 3:15 pm
by Enrico Maria Giordano
Same error with Clipper. The reason is that you can't use aliases inside the index key. Change as follows:
Code: Select all
INDEX ON FIELD->LAST TAG LAST
INDEX ON FIELD->SALARY TAG SALARY
EMG
Posted: Fri Aug 17, 2007 5:37 pm
by CharlesPratt
That fixes it. Many thanks, Enrico. I have some code to change in some of my apps.
Charles