Skip to main content
Inspiring
October 20, 2023
Question

CFQUERY Result.GENERATEDKEY Failing After Applying Update 11

We have been using the result structure from CFQUERY for years to retrieve an inserted ID, but it started to fail after applying update 2021/11 recently. It would appear that we now need to pull the inserted ID out of another structure entirely. I created a simple test scenario below and dumped out both the query and result structures - note that GENERATEDKEY is no longer in the result structure:

 

<cfquery name="myquery" datasource="#ds#" result="myresult">
    insert into ejtest(testfield) values('test')
</cfquery>
 

 

The test table has both an identity field and PK set on that field. It produces the same result whether I have a PK set or not, however.

 

The CF documentation for CFQUERY also does not mention this:

 

cfquery (adobe.com)

 

Thoughts?

 

Thanks,

Eric

 

Server Details
Server Product ColdFusion 2021
Version 2021,0,11,330247
Edition Standard
Operating System Windows Server 2019
OS Version 10.0
Update Level [CF Path]/cfusion/lib/updates/hf202100-4212383.jar
Adobe Driver Version 5.1.4 (Build 0001)
Tomcat Version 9.0.78.0

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

ej401Author
Inspiring
October 20, 2023

I think I see what's going on here now - if I parameterize the input (which we should be doing anyway), the generatedkey attribute is returned:

 

<cfquery name="myquery" datasource="#request.cfg_db_to_use#" result="insert_org_result">
    insert into ejtest(testfield) values(<cfqueryparam cfsqltype="cf_sql_varchar" value="test">)
</cfquery>
 

 

It is strange that update 11 created this anamoly, though.

 

-Eric

 

Translate
BKBK
Community Expert
Community Expert
October 20, 2023

Strange indeed. The result structure in the second test misses a 'columnList' key. I wonder what would happen if you ran the following code in both tests:

<cfoutput>
resultStruct.columnList:#resultStruct.columnList#<br>
resultStruct.generated_key:#resultStruct.generated_key#<br>
resultStruct.generated_keys:#resultStruct.generated_keys#<br>
</cfoutput>

 

Translate
BKBK
Community Expert
Community Expert
October 20, 2023

On second thoughts, report a bug anyway.

Translate