Hello All,
I have a form where I need to know the ID field value that is a Autoincrement value on the database, that before the register is being inserted. Is this posible? how?
Hello All,
I have a form where I need to know the ID field value that is a Autoincrement value on the database, that before the register is being inserted. Is this posible? how?
Re: Autoincrement value
The ID is created by the database ??
Then put your code in OnAfterInsert Event. It depends on the database how to get the last value of
autoincrement field. For example in mysql it’s
$Last_ID = mysql_insert_id();
Hope this helps
Best regards
Uwe
Re: Autoincrement value
If you want to show the value in the form even before the insert statement is fired to the database, then you should not use auto_increment. You should use a function in the form to get the next id.
This function could just get the max(id) + 1 using a query, but then you might get in trouble with multiple concurrent users. The function could also insert a record in a table that holds just the id’s. In this table insert record, auto_increment will generate new id, and retrieve this new id from table.
Re: Autoincrement value
There are basically no solution. Why?
Autoincrement fields simply counting forward. Thus, the RedordID be generated. So in the ideal case 1,2,3, …
Now do you delete records, create gaps in the numbering. So 1,3,4,7. If we add to this list to a record, creating 1,3,4,7,8. The stands autorincrementwert to 8 and the next record would be 9th Deletes one now 8, gets the next record anyway 9
?bersetzung von Deutsch nach Englisch
SELECT max (id) from table provides only 7
SELECT max (id) +1 from table 8 provides
Insert a reocrd creates an ID 9
Goes to work with DBMS in which the sequences better. Eg. Oracle
SELECT FROM nextValue sequencename
returns the next value of the sequence. Here you can get the sequence even to use the gaps in the numbering to fill again. (I think). This model has the disadvantage that you need for each table to determine the onBEforeInsert-trigger to calculate the RecordId and set. In MySQL, you need not do.
What I still care about is, Why do you want to know before you insert the ID? I can not imagine a case where you might need it.
Re: Autoincrement value
@Chopper64: Oracle sequences cannot be used to fill gaps, they always pick the max + 1.
Re: Autoincrement value
Can it be this is so. My latest Oracle database is three years ago. I seem to remember that your sequence does not get the maximum value of the table. K?nnenSie not, because they have no connection to the table but simply include autonomous.
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
INCREMENT BY value also shows that
INCREMENT BY 100
steps may be numbered in 100.
SELECT seq.nextval from dual
returns the next value. Dabi economic incremented the sequence.
SELECT currvalue From Dual
returns the current value of the sequence.
For MYSQL:
In order to get the next auto index value, you should run the following query:
view source print?
1.
SHOW TABLE STATUS LIKE `tablename`
MySQL returned (of course with existing table with that name) is a line with many values, among other things, collation, coding, date of last change and other includes. What we have read here is the value in the column Auto_increment, which includes our value.