<cftransaction isolation="serializable">
<cfquery name="qryInsertInvoice">
insert into Invoices (Ref,Amy) values ('12345-123',150.23)
</cfquery>
<cfquery name="qryGetID">
select Max(InvoiceID) as NewID from Invoices
</cfquery>
</cftransaction>
<cfset pvtNewID = qryGetID.NewID>
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/7a60174e-5521-4cd9-9fc9-848c6f4788d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/5e1e84db-f019-4362-9950-f05420ba503c%40googlegroups.com.
You can also use the result attribute to get this info
Micha
Am Mittwoch, 4. März 2015 schrieb Joe Matte :
I've experienced the same situation on MS SQL and MySQL using various "get the recently inserted row id" techniques.--
What I do that seems to have worked 100% of the time. I know it's nowhere near the most efficient method and I cringe at having to use a serializable isolation, but the syntax works for me across different SQL engines so I don't have to modify my code depending on engine.
Assuming table Invoices has an Auto-Increment field called InvoiceID
<cftransaction isolation="serializable">
<cfquery name="qryInsertInvoice">
insert into Invoices (Ref,Amy) values ('12345-123',150.23)
</cfquery>
<cfquery name="qryGetID">
select Max(InvoiceID) as NewID from Invoices
</cfquery>
</cftransaction>
<cfset pvtNewID = qryGetID.NewID>
The extra query's performance is usually trivial, if you tend to have "artificial" primary keys - in the above example InvoiceID would not only be auto-increment, but also the only field in your Primary Key or at least the first field in your Primary Key field list.
Joe
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.