>>>>> "Matthias" == Matthias Pigulla <mp@stripped> writes:
Matthias> Benjamin Pflugmann wrote:
>> Without looking at the source, it sounds to me as if the server
>> sends/updates the value of mysql_insert_id() only if it was changed on
>> the server.
Matthias> I don't really understand your point. If I see things right, the last
Matthias> insert id is stored in the MYSQL struct. Every time the server generates
Matthias> a new id, it "tells" the client the value. The client saves the value in
Matthias> the struct. It should not get lost?
Matthias> I can't imagine that LAST_INSERT_ID() is intended to return the ID and
Matthias> then set it to zero - and as Paul already noticed, it doesn't.
Matthias> So where and why is the value in the MYSQL struct getting lost?
Matthias> w e b f a c t o r y | matthias pigulla
Matthias> www.webfactory.de mp@stripped
The current behaveour is actually the intended behaveour; This makes
it very easy for some general clients to check if the last query was
an insert statement that did update an auto_increment column.
For example, you can have a general client print in a information
wiget: 'The inserted row got id: #', just by checking if
'mysql_insert_id()' returns something else than 0.
Benjamin mailed the following to me:
Benjamin> A short opinion on the above topic: I feel that LAST_INSERT_ID and
Benjamin> mysql_insert_id should behave the same (i.e. the result should be the
Benjamin> same), whatever the behaviour ought be.
The problem with this is that I would in this case have to change the
server/client protocol and this would break all old clients :(
On the other hand; One should normally use mysql_insert_id() as this
is faster. If you have access to the mysql_insert_id() call, you are
probably using a general language and in this case you can easily
store it away and it's probably safer that it's reset between each query.
On the other hand; If you are using some high level interface
(ODBC?), you can't easily access mysql_insert_id() and you may not
even have variables available to store the result of
mysql_insert_id(). In this case it's very nice that the server
doesn't clear the value between queries!
I agree that this isn't perfect, but I think this is good enough for
now (at least until we next time change the client/server protocol)