[ic] Return auto_increment value from [query] INSERT

Mike Heins interchange-users@icdevgroup.org
Tue May 6 22:00:01 2003


Quoting Paul Jordan (paul@gishnetwork.com):
> 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]

This is one that is best done in embedded Perl.

[perl messages] 
	my $db = $Db{messages};
	my %hash = (
		call_id => $Scratch->{callid},
		direction => 2,
		message_source => 'SeeBase',
		to_email => '',
		subject => $Values->{resub},
		status => '4',
	);
	$Scratch->{new_id} = $db->set_slice(undef, \%hash);
	return;
[/perl]

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Nature, to be commanded, must be obeyed. -- Francis Bacon