` Printed Icetips Article

Icetips Article



SQL Related Articles: Retrieving autonumbered MySQL record
2005-11-28 -- Bjarne Havnen - Aditech As
 
Newsgroups: softvelocity.clarion.databasedrivers

> Anybody with experience of using auto_increment
> keys with MySQL?
> The problem is that Clarion auto_number returns
> the next value by reading the biggest value from
> the table and MySQL gives the value from an internal
> field-value when physically adding the record. And
> these are not necessary the same.
>
> I need to know the auto_incremented value because
> the same procedure updates two other related tables.
>
> I can handle this by hand-coding (re-reading the added
> record) but if anybody has figured out how to handle the
> auto_increment -values, please give information.

Sample code from my filemanager used with mysql
Add the record, retrive the last_insert_id() and then fetch the record to
retrive the entire recordbuffer.
I have derived the PrimeAutoInc method to support this. Other choose to do
similar things in a form, others override the Savebutton to first add the
record and then retrieve it before enabling child inserts. I prefer my way
in all cases where I work with files where I will be adding records manually


 Add(Self.File)
  If Errorcode()
     Message(FileError())
     ReturnVAlue = Level:Fatal
     Exit
 End
 Self.File{Prop:Sql}='Select Last_Insert_Id()'
 Next(Self.File)
 Self.Fetch(AutoKey)



Printed November 23, 2024, 3:26 am
This article has been viewed/printed 35224 times.
Google search has resulted in 10 hits on this article since January 25, 2004.