Fixed
Details
Assignee
UnassignedUnassignedReporter
Nicholas TunneyNicholas TunneyPriority
NewLabels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
Affects versions
Details
Details
Assignee
Unassigned
UnassignedReporter
Nicholas Tunney
Nicholas TunneyPriority
Labels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
Affects versions
Created 29 April 2016 at 17:42
Updated 18 May 2021 at 18:58
Resolved 11 May 2016 at 06:49
I was attempting to grab a new ID from an MS SQL database server (2008) when I came across this.
<cfquery name="q"> DECLARE @id UNIQUEIDENTIFIER; SET @id = NEWID(); INSERT INTO MYTABLE (id) VALUES (@id); SELECT @id as id; </cfquery>
At the end of the statement q is a string (not a Query object), and ID does not exist. Now if I place the SELECT statement before the INSERT it works:
<cfquery name="q"> DECLARE @id UNIQUEIDENTIFIER; SET @id = NEWID(); SELECT @id as id; INSERT INTO MYTABLE (id) VALUES (@id); </cfquery>
I can get the ID at q.id, and the INSERT successfully completes as well. Here is where it got very weird. If an error is thrown in the INSERT statement in the last example where the INSERT is the second query run, the program continued to run and a db error was never thrown (and the record was of course not inserted since an error was thrown). I found this only when the ID written in this query was not available in an FK constraint a few method calls later.