DbServer.Append() is working for some DBF tables only in VO but not in X#

This forum is meant for questions and discussions about the X# language and tools
Post Reply
hilberg.it
Posts: 75
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by hilberg.it »

Hi,
again another issue with my DBF files.
Does anyone have a clue, why this piece of code is only working in VO?
I don't think that is useful code :dry: but it prints out the last 3 records.

In X# on the other hand _oDbArtikel:Append() returns false
and the DO WHILE !_oDbArtikel:eof results in an infinity loop with empty entries. :(

Any ideas why this is happening? It happens only on 2 DBF files. All others work as expected.

Code: Select all

RDDSETDEFAULT("DBFCDX")
...

LOCAL _oDbArtikel as bDBServer
_oDbArtikel = bDBServer{"dArtikel"}

IF _oDbArtikel:Append()
   _oDbArtikel:FIELDPUT(#Arname, "Test123")
   _oDbArtikel:Skip(0)
ELSE 
   ? "Append returned false"
ENDIF
   
_oDbArtikel:GoBottom()
_oDbArtikel:Skip(-2)
DO WHILE !_oDbArtikel:eof
   ? "Arname: "
   ?? _oDbArtikel:FIELDGET(#Arname)
   _oDbArtikel:Skip(1)
ENDDO
_oDbArtikel:Close()
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by Chris »

Maybe it's a problem with the dbf, maybe a problem with the index, or a problem in the X# RDD, very difficult to say without having the data files.

Some things to try in order to narrow down the problem:
- Can you please try using DBServer instead of dDBServer, does the problem still exist?
- What happens if you reindex the data?
- If this still fails, please zap the data and try again, does it still happen?

Also is it possible to send the data files so that we can have a look?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by ic2 »

Hello,

What happens if you end your appends with

_oDbArtikel:Commit()
_oDbArtikel:Unlock()

We have seen (in VO) multiple situations where, directly after appending info, especially in loops, one ore more values were empty. Since then we always add these lines ate the end of a loop or single addition.

Dick
hilberg.it
Posts: 75
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by hilberg.it »

Thanks to you two.

ic2 wrote:What happens if you end your appends with

_oDbArtikel:Commit()
_oDbArtikel:Unlock()
-> Unfortunately that did not do the trick.

Chris wrote:Also is it possible to send the data files so that we can have a look?
-> I sent you a copy.


I think that the DBF files are quite old and that there might be some corruption. So far I tried to recreate the DBF/FPT Headers using XSharp RDD with this code snippet Gist
inspired by Roberts idea in this Thread.

The idea was, using X# RDD to create a new DBF file and paste in the old content. Besides that I used this code snippet to filter for corruptions Link.
Apparently that solved not all of my problems in the file.

If you see some errors or room for improvement in the Code please let me know!

Thx
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by Chris »

Hi Moritz,

Thanks for the files! I think I have good news, I tried your code with this data and it seems to work fine in our current build, see attachment below.
So most likely it's an old bug in the X# runtime which must be fixed now. In a few days there should be a new X# build released, please try again with this one.
hilberg.png
hilberg.png (30.34 KiB) Viewed 748 times
.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
hilberg.it
Posts: 75
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by hilberg.it »

That is very good news!
Correct me if I am wrong, but shouldn't the output state the appended entry as the last entry? In this case "AuNummer: 123"?!
hilberg.it
Posts: 75
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by hilberg.it »

Ok. Just noticed something really strange. If I delete the CDX file, it works and shows the appended entry. Any ideas on this behavior?
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by Chris »

No, because there's an active index on that field, and the value "123" is not one that would put the record logically last. If I change the value written to the field from "123" to "ZZZ", then indeed the last value shown is this one now.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
hilberg.it
Posts: 75
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by hilberg.it »

Wow! Thanks. That solves it! :)
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

DbServer.Append() is working for some DBF tables only in VO but not in X#

Post by Karl-Heinz »

Hi Moritz,

When your append fails it would be interesting to know the content of the error object. What´s e.g. the content of the "Description" property ?

Code: Select all

IF _oDbAuftrag:Append()
   _oDbAuftrag:FIELDPUT(#AUNUMMER, "123")
   _oDbAuftrag:Skip(0)
ELSE 


    if _oDBAuftrag:ErrInfo != NULL_OBJECT
	    ?  _oDBAuftrag:ErrInfo:Description 
    else
           ? "no Error object"  
    endif

ENDIF
regards
Karl-Heinz
Post Reply