[ic] Return auto_increment value from [query] INSERT

Stefan Hornburg interchange-users@icdevgroup.org
Tue May 6 21:50:00 2003


On Tue, 6 May 2003 18:29:14 -0700
"Paul Jordan" <paul@gishnetwork.com> wrote:

> Hi guys      IC 4.9.7   MYSQL 3.2XXXXX
> 
> I have a [query] INSERT statement, and the table it is on has an
> auto_increment primary key. A little birdie told me that it was
> possible to do an INSERT and also be able to grab the auto_incremented
> value...
> 
> [query
>     st=sql
>     table="messages"
>     type=list
>     sql=|
>         INSERT  messages
>         SET     message_id = '',
>                 call_id = '[scratch callid]',
>                 direction = '2',
>                 message_source = 'SeeBase',
>    [snip "code"]
>                 to_email = '',
>                 subject = '[value resub]',
>                 status = '4'
>         |][seti new_id][sql-pos 0][/seti][/query]
> 

Give this piece of code a shot:

[perl table="messages"]
$Scratch->{new_id} = $Db{messages}->set_slice('',
	['message_id','call_id','direction','message_source','to_email','subject','status'],
	['',$Scratch->{callid},2,'SeeBase','',$Values->{resub},4]);
return;
[perl]

Bye
	Racke

-- 
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team