Welcome, Guest. Please login or register.
Did you miss your activation email?
Feb. 09, 2010, 03:35:41 PM
52593 Posts in 11677 Topics by 7491 Members
Latest Member: peerjee
News: Class documentation is handy to learn about component properties, events and methods.
 
The PRADO Community » Prado v3.x » General Discussion » Database » sqlmap insert into multiple tables at once « previous next »
Pages: [1] Print
Author Topic: sqlmap insert into multiple tables at once  (Read 4335 times)
ghesil
Junior Member
**

Karma: 1
Offline Offline

Posts: 6


View Profile
« on: Jun. 08, 2007, 10:56:12 AM »

i need to insert data into multiple tables from a single <insert> in an sqlMap. is there any way to do that?

the closest i got is something like

<insert id="insertData" parameterClass="Application.database.Data">
INSERT INTO
T1 (id,c1,c2)
VALUES (nextval('t1_id_seq'),#c1#,#c2#);

INSERT INTO
T2(id,t1id,c3,c4)
VALUES (nextval('cust_account_id_seq'),__what_here?__,#c3#,#c4#)
</insert>

but i don't know how to put the new generated key from t1 into t2 (where __what_here?__ is)

seleckKey was an option but couldn't make it work as expected Sad

thank you very much
Logged
DaMule
Senior Member
***

Karma: 11
Offline Offline

Posts: 245


Sam Hennessy


View Profile WWW
« Reply #1 on: Jun. 08, 2007, 03:22:21 PM »

You could try user defined variables

It may look somthing like this

Code:
<insert id="insertData" parameterClass="Application.database.Data">
INSERT INTO
T1 (id,c1,c2)
VALUES (nextval('t1_id_seq'),#c1#,#c2#);

SET @last_id = SELECT LAST_INSERT_ID();

INSERT INTO
T2(id,t1id,c3,c4)
VALUES (nextval('cust_account_id_seq'),@last_id,#c3#,#c4#)
</insert>

I've not test this or anything, just a guess.
Logged

ghesil
Junior Member
**

Karma: 1
Offline Offline

Posts: 6


View Profile
« Reply #2 on: Jun. 08, 2007, 04:35:54 PM »

the ideea is nice, but i'm using postgress and it doesn't seem to work there (or i don't know the sintax)
thanks for the ideea anyway, i'll dig it more along this line
Logged
ghesil
Junior Member
**

Karma: 1
Offline Offline

Posts: 6


View Profile
« Reply #3 on: Jun. 08, 2007, 09:47:17 PM »

found a nice way of doing it in postgress, as it doesn't seem to have user defined variables Smiley

it looks like

INSERT INTO
T1 (id,c1,c2)
VALUES (nextval('t1_id_seq'),#c1#,#c2#);


INSERT INTO
T2(id,t1id,c3,c4)
VALUES (nextval('cust_account_id_seq'),currval('t1_id_seq'),#c3#,#c4#);

thank you fir your answer DaMule Wink
Logged
bobgherasim
Newbie
*

Karma: 0
Offline Offline

Posts: 4



View Profile
« Reply #4 on: Jun. 09, 2007, 09:32:28 AM »

Great stuff ghesil. Nice Wink
Logged

Do one thing and do it right
Ben
Senior Member
***

Karma: 3
Offline Offline

Posts: 69


View Profile
« Reply #5 on: Jul. 24, 2007, 11:24:58 AM »

Will there be something like the select-attribute in resultMap but for inserting data?
I mean anything that helps inserting complex properties and collections into DB in a similar way.

Maybe it can already be done using the typeHandler attribute, not sure about that...

But I think an additional insert attribute within the parameterMap would be more straight foreward.
Logged
Pages: [1] Print 
« previous next »
Jump to: