[ic] return value of autonumber or code at time of INSERT

Mike Heins mike at perusion.com
Mon Aug 22 16:56:43 EDT 2005


Quoting maillists (lists at gmnet.net):
> On Mon, 2005-08-22 at 12:17 -0500, Mike Heins wrote:
> > Quoting maillists (lists at gmnet.net):
> > > HI,
> > > 
> > > I have searched the docs and mail list and I have not found the answer
> > > to this. I need to be able to get the value of the primary key made by
> > > autonumber or auto_increment at the time it is created.
> > > 
> > > Here is my scenario:
> > > 
> > > * user creates an account or logs in.
> > > 
> > > * user can insert a new record in a table via a form. call it tableA
> > > 
> > > * When the user inserts this record, into tableA, 2 things happen.
> > > 
> > >   1) user gets an email with the new record ID or code in the email. 
> > >   2) I update the value of a field in another table say tableB with the
> > > value of the ID or code from the new inserted record in tableA.
> > > 
> > > I know how to do all the inserts, email, and everything. I just can't
> > > figure out how to return the value code of tableA at the time it is
> > > created.
> > > 
> > 
> > Depends how you are creating the record.
> > 
> > If it is with embedded Perl, it is returned from set_slice:
> > 
> > 	$Scratch->{new_key} = $db->set_slice(undef, \%record);
> > 
> > If it is with [table-editor] or mv_action=set, you should find [cgi
> > the_key] set to the new key value upon return from writing. You can
> > control where that value goes with mv_data_return_key, meaning if you
> > do in the table-editor:
> > 
> > 	hidden.mv_data_return_key=foo
> > 
> > then [cgi foo] will contain the new key value.
> > 
> 
> Thanks Mike,
> 
> I'm still not getting a value returned.
> I hope this email is not too long...
> 
> I guess my problem is the "way" that I am inserting the data.
> My form is based on the "contact us" web form in the foundation catalog,
> where is sends an email.  My database "tableA" is a mysql table with
> code set to type=INT(20) and auto_increment. 

If you are using [query ...], which was not intended by me to do database
updates, then all bets are off. I don't know how to get the key off the top
of my head and I ain't looking.

I suggest you replace it with an embedded Perl call that does the same thing,
and get it back from $db->set_slice(). There are lots of examples in the
admin pages and elsewhere if you search for set_slice.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry


More information about the interchange-users mailing list