You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Giuseppe Di Pierri <pi...@arpage.ch> on 2002/03/01 15:34:57 UTC
using MSQL's LAST_INSERT_ID() with DatabaseAddAction
Hi there,
I have a problem using the DatabaseAddAction in MySQL.
I would do two table insertions, one after an other like the following
example:
INSERT INTO base (id,...) VALUES(NULL,...);
# id is defined as INT NOT NULL AUTO_INCREMENT
INSERT INTO derived (id,....) VALUES(LAST_INSERT_ID(),....);
<employee>
<connection>personnel</connection>
<table name="base">
<keys>
<key param="id" dbcol="id" type="int" mode="manual"/>
</keys>
<values>
<value param="myparam" dbcol="...." type="string" />
</values>
</table>
<table name="derived">
<keys>
<!-- how can I use the mysql LAST_INSERT_ID() here,
in order to insert the previous inserted auto_increment value
?-->
<key param="id" dbcol="id" type="int"/>
</keys>
<values>
<value param="..." dbcol="..." type="string" />
</values>
</table>
</employee>
Is there someone that has an idea how to solve this?
Thank you in advance for your answer
Regards,
pino
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: using MSQL's LAST_INSERT_ID() with DatabaseAddAction
Posted by Giuseppe Di Pierri <pi...@arpage.ch>.
----- Original Message -----
From: "Christian Haul" <ha...@dvs1.informatik.tu-darmstadt.de>
To: <co...@xml.apache.org>
Sent: Friday, March 01, 2002 3:38 PM
Subject: Re: using MSQL's LAST_INSERT_ID() with DatabaseAddAction
> On 01.Mar.2002 -- 03:34 PM, Giuseppe Di Pierri wrote:
> > Hi there,
> >
> > I have a problem using the DatabaseAddAction in MySQL.
> >
> > I would do two table insertions, one after an other like the following
> > example:
>
> The value is written to a request attribute (table.column) that you
> can use if you were using the manual method of determining the id
> (looks up current max value +1).
>
>
> I was about to check in new database actions to scratchpad (atually,
> new versions of the ones already there) but since I encountered
> problems with datasources with today's CVS I cannot verify that they
> still work. Those do understand mysql's autoincrement columns. But
> they use a slightly different database.xml syntax *and* their name
> and their configuration sitemap-wise will change with my checkin.
>
> If you'd like to stay tuned.... should be only a matter of days
> now.
>
> > INSERT INTO base (id,...) VALUES(NULL,...);
> > # id is defined as INT NOT NULL AUTO_INCREMENT
> >
> > INSERT INTO derived (id,....) VALUES(LAST_INSERT_ID(),....);
> >
> > <employee>
> > <connection>personnel</connection>
> > <table name="base">
> > <keys>
> > <key param="id" dbcol="id" type="int" mode="manual"/>
> > </keys>
> > <values>
> > <value param="myparam" dbcol="...." type="string" />
> > </values>
> > </table>
> > <table name="derived">
> > <keys>
> > <!-- how can I use the mysql LAST_INSERT_ID() here,
> > in order to insert the previous inserted auto_increment value
> > <key param="id" dbcol="id" type="int"/>
> > ?-->
> <key param="base.id" dbcol="id" type="int"/>
Christian, you gave me the trigger to look at the source:
Is this also correct ?
<key param="key:base:id" dbcol="id" type="int"/>
bye
pino
> > </keys>
> > <values>
> > <value param="..." dbcol="..." type="string" />
> > </values>
> > </table>
> > </employee>
>
> Chris.
>
> --
> C h r i s t i a n H a u l
> haul@informatik.tu-darmstadt.de
> fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>
>
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: using MSQL's LAST_INSERT_ID() with DatabaseAddAction
Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 01.Mar.2002 -- 03:34 PM, Giuseppe Di Pierri wrote:
> Hi there,
>
> I have a problem using the DatabaseAddAction in MySQL.
>
> I would do two table insertions, one after an other like the following
> example:
The value is written to a request attribute (table.column) that you
can use if you were using the manual method of determining the id
(looks up current max value +1).
I was about to check in new database actions to scratchpad (atually,
new versions of the ones already there) but since I encountered
problems with datasources with today's CVS I cannot verify that they
still work. Those do understand mysql's autoincrement columns. But
they use a slightly different database.xml syntax *and* their name
and their configuration sitemap-wise will change with my checkin.
If you'd like to stay tuned.... should be only a matter of days
now.
> INSERT INTO base (id,...) VALUES(NULL,...);
> # id is defined as INT NOT NULL AUTO_INCREMENT
>
> INSERT INTO derived (id,....) VALUES(LAST_INSERT_ID(),....);
>
> <employee>
> <connection>personnel</connection>
> <table name="base">
> <keys>
> <key param="id" dbcol="id" type="int" mode="manual"/>
> </keys>
> <values>
> <value param="myparam" dbcol="...." type="string" />
> </values>
> </table>
> <table name="derived">
> <keys>
> <!-- how can I use the mysql LAST_INSERT_ID() here,
> in order to insert the previous inserted auto_increment value
> <key param="id" dbcol="id" type="int"/>
> ?-->
<key param="base.id" dbcol="id" type="int"/>
> </keys>
> <values>
> <value param="..." dbcol="..." type="string" />
> </values>
> </table>
> </employee>
Chris.
--
C h r i s t i a n H a u l
haul@informatik.tu-darmstadt.de
fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>