Recent

Author Topic: The current value of AutoInc fields in a TDbf table  (Read 10232 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
The current value of AutoInc fields in a TDbf table
« on: October 27, 2021, 01:56:41 pm »
Yet another TDbf question.

I am importing lots of data into a bunch of DBF files. AutoInc fields are set to the required value (it's complicated). When that is done, I have to set the value of the AutoInc fields to the correct maximum value. The current TDbf (trunk) supports AutoInc fields according to the wiki, but I cannot find where they are set or that max value is extracted from the DBF file. Does anyone knows?

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: The current value of AutoInc fields in a TDbf table
« Reply #1 on: October 27, 2021, 02:13:30 pm »
When that is done, I have to set the value of the AutoInc fields to the correct maximum value.
I'm not even going to pretend to understand this.
Do you want to prevent the User to add new records to this table?
Since an AutoInc-Field is usually an Integer --> Max(UInt64)?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #2 on: October 27, 2021, 02:57:46 pm »
Although the wiki says that TDbf supports AutoInc fields, it really doesn't. I have to fill them myself. And the app that is going to use that database expects specific values across multiple tables (in the code the AutoInc fields are changed to Integer, so they can be inserted).

So, I make a counter and fill them with the correct value. But the current AutoInc value is stored in the table and has to be changed to the correct maximum value, so the next record is inserted with the correct number.

It's just a bunch of (mostly text) files. It's not a database server where referential integrity and AutoInc values are automagically enforced.

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: The current value of AutoInc fields in a TDbf table
« Reply #3 on: October 27, 2021, 03:38:10 pm »
If those fields must have specific values, then AutoInc is the wrong mechanism.
I have no experience with dbase (last contact being some 25 years ago), but does DBF (and a Query-Object?) support SQL?
Then it would be a simple SELECT MAX(MyAutoIncField)+1 FROM MyTable
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #4 on: October 27, 2021, 05:32:51 pm »
I'm doing the conversion for an existing application. And, AFAIK there is no SQL. Just a directory full of files (tables, indexes, memo's, etc). It's more like MyStringList.LoadFromFile(ThisTable); MyStringList.Separator := Chr(0);.

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: The current value of AutoInc fields in a TDbf table
« Reply #5 on: October 28, 2021, 08:27:48 am »
Maybe wp will find this Thread.
AFAIK he's the Maintainer for MyDBFStudio (or whatever its name) --> Look in third party-forum for this

EDIT: Found it:
https://forum.lazarus.freepascal.org/index.php/topic,8954.45.html
« Last Edit: October 28, 2021, 11:00:48 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #6 on: October 28, 2021, 11:54:57 am »
Thanks! I'll check the code.

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: The current value of AutoInc fields in a TDbf table
« Reply #7 on: October 28, 2021, 05:40:59 pm »
It seems that the autoinc fields do not work in TDbf when creating dbf files compatible with Visual Fox Pro (TableLevel = 30) - ftAutoInc fields are constructed as simple integer fields. I will look at this problem.

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: The current value of AutoInc fields in a TDbf table
« Reply #8 on: October 28, 2021, 11:03:57 pm »
Frank, could you please upload sample dbf file produced by VisualFoxPro containing autoinc field and some data records? TDbf writes autoinc field values as big endian, but I'm not sure this is correct.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #9 on: October 29, 2021, 09:06:00 am »
Yes, MyDBFStudio also doesn't see them as AutoInc fields and treats them as integers.

I have attached the example DBF (the first field is AutoInc).

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: The current value of AutoInc fields in a TDbf table
« Reply #10 on: October 29, 2021, 12:20:59 pm »
Thanks, but could you please upload dbf file with some data? Two rows of data are enough. I need to check how the autoinc field data is written (big-endian or little-endian and what is written in header).

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: The current value of AutoInc fields in a TDbf table
« Reply #11 on: October 29, 2021, 07:30:51 pm »
I'm sending the patch. Please test especially if dbf files created by TDbf work properly in VFP application.
« Last Edit: October 29, 2021, 07:34:27 pm by korba812 »

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: The current value of AutoInc fields in a TDbf table
« Reply #12 on: October 29, 2021, 08:36:38 pm »
I found another problem. I'm sending another patch.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #13 on: October 29, 2021, 09:11:11 pm »
Thanks! I'll look at them tomorrow. And I'll make a filled table as well.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: The current value of AutoInc fields in a TDbf table
« Reply #14 on: October 30, 2021, 02:02:41 pm »
Here is the table.

 

TinyPortal © 2005-2018