Re: Get last inserted ID

2006-01-12 Thread alexander sicular
dont know about mysql, but this is how i do it in mssql2k : cfquery name=getMaxObject datasource=#dsn# SET NOCOUNT ON INSERT INTO Objects (EmployeeID, patientID, ObjectTypeID) VALUES (cfqueryparam cfsqltype=CF_SQL_INTEGER value=#session.whoami#, cfqueryparam cfsqltype=CF_SQL_INTEGER

Re: Get last inserted ID

2006-01-12 Thread Robert Munn
If you are only inserting into the address table in this bit of code, you could also serialize the whole thing by using cflock around the transaction, but I don't like using application-level locking where I should be using database-level locking. Is this the best way to do this:

Re: Get last inserted ID

2006-01-12 Thread James Holmes
Assuming there's only one CF server (not a cluster) and no other method of accessing the DB is used (no other server platforms, developers etc). On 1/13/06, Robert Munn [EMAIL PROTECTED] wrote: If you are only inserting into the address table in this bit of code, you could also serialize the

Re: Get last inserted ID

2006-01-09 Thread Ryan Guill
ORDERS... It's much easier to tell your colleague to look into OrderID: 155000 rather than OrderID: hagfhdvklchjcvadj... -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Sunday, January 08, 2006 10:32 PM To: CF-Talk Subject: RE: Get last inserted ID This should

RE: Get last inserted ID

2006-01-09 Thread Bobby Hartsfield
What version of MySQL was this? ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Baz [mailto:[EMAIL PROTECTED] Sent: Monday, January 09, 2006 1:00 AM To: CF-Talk Subject: RE: Get last inserted ID Thanks for the info guys

RE: Get last inserted ID

2006-01-09 Thread Baz
inserted ID What version of MySQL was this? ...:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Baz [mailto:[EMAIL PROTECTED] Sent: Monday, January 09, 2006 1:00 AM To: CF-Talk Subject: RE: Get last inserted ID Thanks for the info

RE: Get last inserted ID

2006-01-09 Thread Bobby Hartsfield
for last_insert_id() but who knows. ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Baz [mailto:[EMAIL PROTECTED] Sent: Monday, January 09, 2006 9:32 AM To: CF-Talk Subject: RE: Get last inserted ID MySQL5... someone mentioned to append

RE: Get last inserted ID

2006-01-09 Thread Andy Matthews
] Sent: Sunday, January 08, 2006 6:24 PM To: CF-Talk Subject: Get last inserted ID Is this the best way to do this: cftransaction cfquery name=InsertAddress datasource=#DSN# INSERT INTO Address (City) VALUES (cfqueryparam value=#City# cfsqltype=cf_sql_integer /) /cfquery cfquery name

RE: Get last inserted ID

2006-01-09 Thread Bobby Hartsfield
-Original Message- From: Andy Matthews [mailto:[EMAIL PROTECTED] Sent: Monday, January 09, 2006 10:42 AM To: CF-Talk Subject: RE: Get last inserted ID mySQL has the LAST_INSERT_ID() function. I do this: SELECT LAST_INSERT_ID() as id FROM yourTableName !//-- andy

Get last inserted ID

2006-01-08 Thread Baz
Is this the best way to do this: cftransaction cfquery name=InsertAddress datasource=#DSN# INSERT INTO Address (City) VALUES (cfqueryparam value=#City# cfsqltype=cf_sql_integer /) /cfquery cfquery name=getInsertedID datasource=#DSN# SELECT MAX(AddressID) as MaxID

Re: Get last inserted ID

2006-01-08 Thread James Holmes
It's only 100% reliable if you use a serializable transaction, as far as I remember. This is certainly the case with Oracle. There is an extensive thread on this in the archives somewhere. On 1/9/06, Baz [EMAIL PROTECTED] wrote: Is this the best way to do this: cftransaction cfquery

Re: Get last inserted ID

2006-01-08 Thread Ryan Guill
What I usually do is have a column that just holds a specific timestamp or uuid of some sorts. I create a variable to hold the timestamp or uuid right before the insert query, then I select against the table looking for that timestamp or uuid. If you are using a db that stores a pretty detailed

RE: Get last inserted ID

2006-01-08 Thread Baz
, January 08, 2006 8:08 PM To: CF-Talk Subject: Re: Get last inserted ID What I usually do is have a column that just holds a specific timestamp or uuid of some sorts. I create a variable to hold the timestamp or uuid right before the insert query, then I select against the table looking

Re: Get last inserted ID

2006-01-08 Thread Mike Soultanian
What if someone were to insert another city just before the SELECT statement executed? Mike Baz wrote: James, in which cases is it not 100% reliable? Are the CF-Talk archives searchable? On 1/9/06, Baz [EMAIL PROTECTED] wrote: Is this the best way to do this: cftransaction cfquery

Re: Get last inserted ID

2006-01-08 Thread James Holmes
(This is based on Oracle defaults; ymmv with MySql). It's essentially what Mike said, but only if the other insert is committed first. It's like this: 1) My transaction is started 2) My INSERT is done 3) Someone else's transaction starts 4) Their INSERT is done 5) Their SELECT is done 6) Their

Re: Get last inserted ID

2006-01-08 Thread Mike Soultanian
I'm going to be using SQL Server and I wanted something like Oracle's sequences. I found this: http://jamesthornton.com/software/coldfusion/nextval.html Mike James Holmes wrote: (This is based on Oracle defaults; ymmv with MySql). It's essentially what Mike said, but only if the other

Re: Get last inserted ID

2006-01-08 Thread Douglas Knudsen
yes, this topic has been beaten to death. All posts here have links at the bottom, one of which is to the archives http://www.houseoffusion.com/cf_lists/threads.cfm/4 With Oracle all you need is a sequence defined and use it. No trans is needed, the sequence always gives a unique value. other

Re: Get last inserted ID

2006-01-08 Thread Ryan Guill
-Original Message- From: Ryan Guill [mailto:[EMAIL PROTECTED] Sent: Sunday, January 08, 2006 8:08 PM To: CF-Talk Subject: Re: Get last inserted ID What I usually do is have a column that just holds a specific timestamp or uuid of some sorts. I create a variable to hold the timestamp or uuid

RE: Get last inserted ID

2006-01-08 Thread Bobby Hartsfield
own defined IDs over autoincrementing ones. ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Baz [mailto:[EMAIL PROTECTED] Sent: Sunday, January 08, 2006 7:24 PM To: CF-Talk Subject: Get last inserted ID Is this the best way

RE: Get last inserted ID

2006-01-08 Thread Baz
James, CFTransaction doesn't take care of that? Baz -Original Message- From: James Holmes [mailto:[EMAIL PROTECTED] Sent: Sunday, January 08, 2006 8:39 PM To: CF-Talk Subject: Re: Get last inserted ID (This is based on Oracle defaults; ymmv with MySql). It's essentially what Mike

Re: Get last inserted ID

2006-01-08 Thread James Holmes
Not without the serializable isolation level, no. On 1/9/06, Baz [EMAIL PROTECTED] wrote: James, CFTransaction doesn't take care of that? -- CFAJAX docs and other useful articles: http://jr-holmes.coldfusionjournal.com/ ~|

RE: Get last inserted ID

2006-01-08 Thread Baz
:19 PM To: CF-Talk Subject: Re: Get last inserted ID Not without the serializable isolation level, no. On 1/9/06, Baz [EMAIL PROTECTED] wrote: James, CFTransaction doesn't take care of that? -- CFAJAX docs and other useful articles: http://jr-holmes.coldfusionjournal.com

RE: Get last inserted ID

2006-01-08 Thread Baz
: Sunday, January 08, 2006 10:32 PM To: CF-Talk Subject: RE: Get last inserted ID This should insert your record and return the new primary key as 'newid' cfquery NAME='myqry' Insert into address (city) Values (cfqueryparam value=#City# cfsqltype=cf_sql_integer /); Select LAST_INSERT_ID() as newid

RE: Get last inserted ID

2006-01-08 Thread Dave Watts
What does cftransaction do then? The livedocs say that it can be used to group multiple queries that use CFQUERY into one business event. How do other events occur in between one event? Transactions are a bit complicated, and can be used to achieve different sorts of results. One thing

Re: Get last inserted ID

2006-01-08 Thread James Holmes
It happens because Oracle and most other DBs do not default to serializable transactions; Oracle, for example, defaults to read committed, which means that your transaction can read other committed data even if it happened during your transaction (although in Oracle this level does provide

RE: Get last inserted ID

2006-01-08 Thread Baz
PROTECTED] Sent: Monday, January 09, 2006 12:45 AM To: CF-Talk Subject: Re: Get last inserted ID It happens because Oracle and most other DBs do not default to serializable transactions; Oracle, for example, defaults to read committed, which means that your transaction can read other committed data even

Re: Get last inserted ID

2006-01-08 Thread James Holmes
You can just modify your cftransaction tags to use the serializable isolation level if you want, but do some load testing first because there will be locks-a-plenty if you do... On 1/9/06, Baz [EMAIL PROTECTED] wrote: Thanks for the info guys - all this makes me really sad... I remember

RE: Get last inserted ID

2006-01-08 Thread Baz
: Monday, January 09, 2006 1:14 AM To: CF-Talk Subject: Re: Get last inserted ID You can just modify your cftransaction tags to use the serializable isolation level if you want, but do some load testing first because there will be locks-a-plenty if you do... On 1/9/06, Baz [EMAIL PROTECTED] wrote