CFQUERY broken?

Hi Folks,

I am confused! That code in a cfm:

UPDATE tabelle SET feld1 = 120, feld2 = 'Hallo' WHERE (id = 1)

results in a error:

variable [MEINQUERY] doesn’t exist

OS: Windows 2019
Lucee Version: 6.0.0.585

Any ideas?

Merry Christmas!
Allan

Please, post your complete code. With [cfquery] tag/script too.

An other try to paste that code…

<cfquery name="MeinQuery" datasource="mySQLDB">
UPDATE tabelle SET feld1 = 120, feld2 = 'Hallo' WHERE (id = 1)
</cfquery>
<cfdump var="#MeinQuery#">

The result of this is an error:
variable [MEINQUERY] doesn’t exist

I’m a bit confused because I’ve never had problems dumping update queries before.

If you are expecting an result from a pure sql update, try the attribute name result.

<cfquery result="MeinQuery" datasource="mySQLDB">
UPDATE tabelle SET feld1 = 120, feld2 = 'Hallo' WHERE (id = 1)
</cfquery>
<cfdump var="#MeinQuery#">
2 Likes

Ok, I will try that.

In ColdFusion I usually get back the executed query and the execution time. This seems to be a small incompatibility. In this case, I can also use the query without the name attribute.

I just tried. cf10 works like lucee.

1 Like

I think those cfml engine versions that returned such stuff in a variable defined by the name attribute were pretty old legacy engines.

In tag format, use the attribute “name” vs result.

ie

<cfquery name="MeinQuery" datasource="mySQLDB">

The application started with cf4.5 up to cf9 where I switched to lucee. In cf9 he still gave me a return on the name attribute…

You never stop learning…

And another task on the to-do list to change this to the “result” attribute.

Thanks all for the hints!

2 Likes

No, do not follow that advice. It is incorrect. Your query is valid and “name” is correct “result” is NOT.
The problem is you do not have any output from your query. An update query will not return any data unless you specify an OUTPUT clause for example (sql server)

Ok, I think there is some misunderstanding here.

If you follow the docs, the attribute “name” is used to retrieve a recordset. It will populate the variable specified in the attribute name with that recordset (that is a query object). A pure SQL UPDATE doesn’t retrieve a recordset at all, it’s an UPDATE. A SQL SELECT does retrieve a recordset, but we are talking here about an UPDATE statement. If you want to deal with additional information about any SQL statement (like some SQL query metadata) then use the attribute “result”. Result is NOT a 1:1 alternative for the attribute “name’ (name returns a query, result returns a struct), just changing the attibute won’t suffice. It will just give you a struct of additional information about your query that you might be expecting within the variable you specified in the 'name” attribute. Most important for us to know is: what are you expecting to get back from that SQL UPDATE exactly?

3 Likes