🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.kylix.database.sqlservers
Article #136

Re: Getting auto increment PK value

#136
From: Suddn
Date: Mon, 24 Feb 2003 21:53
55 lines
3301 bytes
Arrrrrgggghhhhh!!

This is a SHOW STOPPER!!!


On Mon, 24 Feb 2003 01:04:50 -0800, BoBo wrote:

> Hi,
> 
> Unfortunately this problem is still not solved since the middle of 2001
> in DBExpress. In MySQL theoretically(!) you could use the 
> LAST_INSERT_ID() function after an INSERT statement. However, because of
> a bug in DBExpress which exists since a looooong time this will not
> work. DBExpress opens a NEW connection to the MySQL database for
> each end every SQL statement and you cannot execute two SQL
> instructions at once.
> The only way is to read back the record you just inserted somehow and
> get the auto increment field value from there.
> 
> Also, be careful because the
> "select ... from ... order by ... limit ..." type SQL statements will
> not work either (can be fixed though by editing DBCommon.pas) because
> DBExpress tries to process the "LIMIT ..." part as a field list in the
> "ORDER BY" part.
> 
> Also, you cannot specify other ports than 3306 for MySQL connections.
> 
> These are the 3 bugs I encountered so far. There are some reports about
> memory leaks too if you check these newsgroups...
> 
> 
> 
> Suddn wrote:
>> I'm not sure which news group would be the best one for this question but 
>> here it is:
>> 
>> When I add a record to a database that uses an auto increment primary key, 
>> how do I get the value of the primary key to the record I just added.
>> 
>> For example, let's say I have the table CUSTOMER it has three fields: id, 
>> fname, lname.
>> 
>> The id field is the PK and is auto incremented.  So I add the record 
>> fname="John", lname="Smith".  I don't accually add the value of the PK 
>> because it is incremented automaticaly.  Now say that I need to Use the 
>> primary key to the John Smith's record to associate this record with 
>> something else.  I don't have the PK and I can't reliably search for John 
>> and Smith as that could return multiple records.  I can't just get the MAX
>> value because in a multi user environment more records may have been added
>> right after I created my record.
>>  
>> I'm using Mandrake 9.1 rc1, MySQL and the dbexpress TClientDataSet component from Kylix 3.
>> 
>> Thanks.
>>
Technical Details
Message-ID: <pan.2003.02.24.21.53.23.975569@NoSpam.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeeds.sol.net!skynet.be!skynet.be!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <pan.2003.02.24.02.50.09.189804@NoSpam.com> <3e59e089$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fa73d,1610dbb07280dd00
X-Google-Attributes: gidfa73d,public
X-Google-ArrivalTime: 2003-02-24 14:09:41 PST
From: "Suddn" <Bogus@NoSpam.com>
Subject: Re: Getting auto increment PK value
Date: Mon, 24 Feb 2003 13:53:29 -0800
User-Agent: Pan/0.13.3.93 (My Bloody Valentine)
Message-ID: <pan.2003.02.24.21.53.23.975569@NoSpam.com>
Newsgroups: borland.public.kylix.database.sqlservers
References: <pan.2003.02.24.02.50.09.189804@NoSpam.com> <3e59e089$1@newsgroups.borland.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 12.228.243.202
X-Trace: newsgroups.borland.com 1046123608 12.228.243.202 (24 Feb 2003 13:53:28 -0800)
Lines: 56
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeeds.sol.net!skynet.be!skynet.be!newsfeed.icl.net!newsfeed.fjserv.net!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail