Forum > Databases

[SOLVED] TDBf Primary Fields

(1/1)

1HuntnMan:
Has anyone questioned why when adding the first record to a Dbf table containing a AutoInc-primary field, that field's value is assigned 0 instead of 1?  This was a question I was asked by one of my users who is testing this new app? I'm relatively new to programming. So, I went into the system and in every table with a primary AutoInc primary field I added a new record first, copied it to a new record and then deleted the 0 record.  Now the 3 people testing this new app are happier because there are no 0 records  ::)!

Zvoni:
What's wrong with 0 for a (Primary Key?) Auto-Inc-Field?
It's a value you (and anyone else) shouldn't be interested in at all

korba812:

--- Quote from: Zvoni on February 06, 2024, 08:33:23 am ---What's wrong with 0 for a (Primary Key?) Auto-Inc-Field?
It's a value you (and anyone else) shouldn't be interested in at all

--- End quote ---
In the case of DBF, this is important because standard numeric fields do not know NULL value and the zero (0) value is used instead. Most Auto-Inc implementations in DBF number from 1.

Zvoni:

--- Quote from: korba812 on February 06, 2024, 12:41:26 pm ---In the case of DBF, this is important because standard numeric fields do not know NULL value and the zero (0) value is used instead. Most Auto-Inc implementations in DBF number from 1.

--- End quote ---
OK. Accepted.
Didn't know that, since the last time i was in "contact" with dBase was 1996 in economic school

EDIT: Found something in "...\source\packages\fcl-db\src\dbase\dbf_dbffile.pas"
Line 854 (FPC3.2.2 - 32Bit)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // Update our field list      with FFieldDefs.AddFieldDef do      begin        Assign(lFieldDef);        Offset := lFieldOffset;        AutoInc := 0;      end;There.
AutoInc:=0;

and looking further through the file, any mention of "AutoInc" that has a direct assignment, assigns "0", even "local" variables containing "AutoInc" in its name

https://www.freepascal.org/daily/packages/fcl-db/dbf_fields/tdbffielddef.html
As far as i understand it: If you create everything from FPC-Code, you should be able to set AutoInc to whatever Startvalue you want (Don't forget AutoIncStep) when you create the FieldDefs.

1HuntnMan:
I totally agree and understand that a Primary/AutoInc field starts with 0. But, the users could give a flip. They just don't like a 0 Appointment ID. They want the Appointment No. to be a 1 and increment from there. I guess I should have given them a true Appointment No./ID field instead of using the Primary key. Would be easy to change... Thanks

Navigation

[0] Message Index

Go to full version