Multiple UPDATE or INSERT in a Single cfquery block

I would normally expect that any cfquery that errors in a transaction will force all other previous cfquery blocks in the same transaction to rollback. But I noticed that if one cfquery block has multiple DML statements, it behaves differently between Lucee and Coldfusion.

On ColdFusion, if any one of the statements in the cfquery block fails, then it will error.
On Lucee, if the first statement succeeds, then any failure in the subsequent statements will be silent.

        <cfquery name="insertIntoMultipleTables">
            INSERT INTO [A] VALUES('a', 'b')

            INSERT INTO [B] VALUES('a', 'b')

            INSERT INTO [C] VALUES('a', 'b')
        <cftransaction action="commit" />
                <cftransaction action="rollback" />

If we posit that object [B] doesn’t exist in the database, then on Lucee, the server does not raise an exception and the insertion into [A] will not rollback whereas on ColdFusion, the server raises an exception and everything in the transaction is rolled back.

Are there any settings on Lucee that changes this behavior or is it just how Lucee’s cfquery works and I just need to avoid having multiple statements in a single cfquery?

OS: Windows 10
Tomcat Version: Tomcat 9
Lucee Version:
Database: MS SQL Server 2019

Thank you.

@mpark This is already a known issue ([LDEV-3127] - Lucee). Also the issue is fixed in Lucee version But due to some issues with other drivers the changes were reverted to

You can use the changes made for LDEV-3127 using any of the options below. Can you please check with this and report here back?

System property: lucee.datasource.mssql.modern=true (OR)
Environment variable: LUCEE_DATASOURCE_MSSQL_MODERN=true

See this related ticket which explains a bit better IMO, not only the loss of exceptions, but Lucee’s failure to preserve ALL exceptions when there are multiple statements in the query. This is the source of these downstream issues where errors get ignored.

Hello @cfmitrah. I am reporting back.
I tried the system property and env variable and it seems to be working. When a statement other than the first statement in a cfquery block fails, Lucee now raises an exception, which can be caught and rollback the transaction.

1 Like