fdbozzo / foxbin2prg

Visual FoxPro 9 Binary to Text and Text to Binary converter. Replacement for SCCText(X) and TwoFox that is bi-directional (Text is editable)
https://vfpx.codeplex.com/wikipage?title=FoxBin2Prg
MIT License
59 stars 35 forks source link

Text To Bin with Fieldcaption = "NULL" #106

Closed griessbach14943 closed 6 months ago

griessbach14943 commented 7 months ago

ℹ Computer information

📝 Provide detailed reproduction steps (if any)

  1. I have been using XCASE from Resolution for years to create and maintain databases. For some time now, I have also been versioning the respective models together with my projects. I have noticed that field contents are not restored if the field was named "NULL".

  2. TEST: CREATE Table tblMyTest ( MyName c(10), MyField l, Null l) INSERT INTO tblMyTest Values( "Row 1", .T., .T. ) INSERT INTO tblMyTest Values( "Row 2", .F., .F. ) INSERT INTO tblMyTest Values( "Row 3", .T., .T. ) INSERT INTO tblMyTest Values( "Row 4", .F., .F. )

  3. Table original image

  4. After Restore via Text to Bin image

Best Regards Ulf Neugebauer

griessbach14943 commented 6 months ago

Referencing the field name alone will of course fail, but via table alias e.g. tblMytest.NULL actually returns the correct content. But I have searched a little further, the error already appears when creating the *.db2 file, If I correct the file, the restore works.

Best Regards Ulf Neugebauer

lscheffler commented 6 months ago

@griessbach14943

Ooops. Somehow I missed the issue. There was a lot of noise in GoFish spamming me, so I fear I ignored the VFPX section.
I will look at the problem later this week. Would you mind to send me an example dbf?

It's always a problem to use internal designators as user defined designators. Not that VFP give a good example. Anyway, I like to discourage everybody.

The special handler needed sadly will slow down FoxBin2Prg.

griessbach14943 commented 6 months ago

TableTest.zip

lscheffler commented 6 months ago

@griessbach14943 Thank you. Is closing this issue intended?

lscheffler commented 6 months ago

@griessbach14943 I recommend that you always use the latest version of FoxBin2Prg. Best via Thor. Anyway, the problem exist in recent version 1.21.02

Analysing the problem: Basically, the problem is on how VFP looks up fields, variables and build in literals. One must understand, that NULL is identical to .NULL. (with dots). To determine the value of a field to store with the db2 file, FoxBin2Prg uses:

luValue = Evaluate(lcField)

this is for your table like

lcField = "NULL"
luValue = Evaluate(lcField) 

and luValue is null after this.
So VFP first looks up the build in literal, then the field, then the variable.

To completely understand, try the following:

use tblMyTest.dbf alias tblMyTest
NULL = 'A'
?NULL
?m.NULL
?tblMyTest.NULL
?!NULL

SELECT null FROM tblMyTest

Again, this is a problem of using Reserved Words (see help for Reserved Words in VFP help). So, be not surprised if your field returns unexpected results.

The problem for FoxBin2Prg is simple enough to solve by just adding the alias.

lscheffler commented 6 months ago

@griessbach14943 Sorry, but just to be picky:

The problem is not on a fields caption (this is a fields property for a DBC bound table), its about a fields name.

lscheffler commented 6 months ago

@griessbach14943 New version is available here and via Thor.

griessbach14943 commented 6 months ago

Super Job, jetzt klappt es auch mit xCase, ich denke das was DIE Ausnahme von der Regel! Danke!

lscheffler commented 6 months ago

Immer gerne.
NULL ist halt der eine Bezeichner, der in VFP auch als Konstante geht. Zum Glück war es weiter kein lauf-zeitlicher Aufwand, das zu flicken.