I have two different CF11 applications with two different datasources each with its own back-end schema on the same Oracle 12g database. In one datasource dsA, when I use CFQUERY to insert a new record, the result structure contains a GENERATEDKEY value. In datasource dsB, when I run exactly the same code, there is no GENERATEDKEY value in the result structure.
This is the test code I'm running...
<cftry>
<cfset ds = "dsA"/>
<cfquery name="insertTest" datasource="#ds#" result="testResult">
INSERT INTO categories(cat_name)
VALUES ('testing')
</cfquery>
<cfdump var="#testResult#" label="#ds#">
<cfcatch>
<cfdump var="#cfcatch#" label="#ds#"><cfabort>
</cfcatch>
</cftry>
When I set the datasource to dsA, I get this output. Notice both the GENERATEDKEY and the ROWID values.
When I set the datasource to dsB, I get this output, with no GENERATEDKEY and no ROWID.
As far as I can tell, both Oracle schemas are set up the same way, and both datasources are configured identically. Does anyone have any idea what could cause one query to return the GENERATEDKEY and the other not to? I'm pulling my hair out trying to find a cause for this.
Thanks in advance for any advice.
INSERT
, you can useSELECT scope_identity() as NEW_ID
to return the new ID of the inserted row. That's whatGENERATEDKEY
is trying to do, but instead of relying on that, find out how to do it in Oracle and just update your query to natively return the new ID after theINSERT
. – DotterelSELECT scope_identity() as NEW_ID
statement be in the same cfquery tag as theINSERT
statement? Or would that have to be in another cfquery tag? As much as I want to fix the actual problem, this might be a short-term work-around. – SanctuaryINSERT
andSELECT
in the same query. – Dotterelscope_identity()
is only for MS SQL Server and won't work with my Oracle database. I can't seem to find an Oracle substitute that works. – Sanctuary