8

This does not crash in ColdFusion 11, but does crash in ColdFusion 2016

SELECT  *
FROM    dbo.Roles WITH (NOLOCK)
WHERE   Code IS NOT NULL
AND     Active = 1
AND     RoleID IN (SELECT RoleID FROM dbo.Emp WITH (NOLOCK)) -- It's ok to look at termed employees

enter image description here

This works OK in both

SELECT  *
FROM    dbo.Roles WITH (NOLOCK)
WHERE   Code IS NOT NULL
AND     Active = 1
AND     RoleID IN (SELECT RoleID FROM dbo.Emp WITH (NOLOCK)) 

Is there a setting to restore the orginal behavior?

UPDATE

I thought I had a minimal example of the issue, but I didn't. Here is the complete query

    SELECT '<ul>' + STUFF (
        (
        SELECT  MIN(Role) AS "li/code", Code AS "li/span/b", 'Unsorted' AS "li/span/var"
        FROM    dbo.Roles WITH (NOLOCK)
        WHERE   Code IS NOT NULL
        AND     Active = 1
        AND     RoleID IN (SELECT RoleID FROM dbo.Emp WITH (NOLOCK)) -- It's ok to look at termed employees
        GROUP BY Code
        FOR XML PATH ('')
        ),
        1,0,''

    ) + '</ul>' AS xmlRole

When I turn on DB debugging: I get:

spy(http-nio-8500-exec-5)(2016/02/17 10:21:13.807)>> OK

spy(http-nio-8500-exec-5)(2016/02/17 10:21:13.807)>> Statement[4].execute(String sql, int autoGeneratedKeys)
spy(http-nio-8500-exec-5)(2016/02/17 10:21:13.807)>> sql = SELECT '<ul>' + STUFF ( ( SELECT MIN(Role) AS "li/code", Code AS "li/span/b", 'Unsorted' AS "li/span/var" FROM dbo.Roles WITH (NOLOCK) WHERE Code IS NOT NULL AND Active = 1 AND RoleID IN (SELECT RoleID FROM dbo.Emp WITH (NOLOCK)) -- It's ok to look at termed employees GROUP BY Code FOR XML PATH ('') ), 1,0,'' ) + '</ul>' AS xmlRole
spy(http-nio-8500-exec-5)(2016/02/17 10:21:13.807)>> autoGeneratedKeys = 1
spy(http-nio-8500-exec-5)(2016/02/17 10:21:13.807)>>    
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near ')'. ErrorCode=102 SQLState=HY000
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near ')'.
    at macromedia.jdbc.sqlserverbase.ddcw.b(Unknown Source)
    at macromedia.jdbc.sqlserverbase.ddcw.a(Unknown Source)

Note that the SQL String is on a single line. When the comment starts, it does not end. Everything after the -- remains as a commented out.

White space management is turned on. Turning it off does not change the behavior. The generated SQL is the same

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 4
    One of my least favourite things about ColdFusion - when you upgrade, things that used to work start to break. – Dan Bracuk Feb 17 '16 at 02:57
  • *ColdFusoin 10.5 * ColdFusion 10.5.1 – Scott Stroz Feb 17 '16 at 03:43
  • Im sure there was an issue like this when upgrading to CF9 from CF8. Resolving this involved turning off white space management in the admin. Does this change anything if you turn white space management off? Either way, defo a bug. – haxtbh Feb 17 '16 at 09:06
  • Actually you pasted the same code twice. Consider changing SQL to use query of queries. – PatNowak Feb 17 '16 at 10:18
  • @PatNowak I think that was intentional. The issue is with the -- comment in the first query. The same query without the comment works fine. – haxtbh Feb 17 '16 at 11:41
  • Maybe CF has a problem with parsing this comment, since proper comment is tag syntax is – PatNowak Feb 17 '16 at 12:03
  • There was definitely an [issue with comments back in CF8/9](http://www.mischefamily.com/nathan/index.cfm/2008/1/29/Problems-with-CF-8s-Generated-Keys-Feature). Any change if you move the comment to somewhere other than the end of the SQL? – Leigh Feb 17 '16 at 13:38
  • @PatNowak - No, CF's job is just evaluate any *CFML* and pass the generated sql string on to the database for execution. So it will ignore the " --". The database should ignore it too, and treat it as a valid sql comment. – Leigh Feb 17 '16 at 13:40
  • @PatNowak The sql is different. The first has an SQL comment in it – James A Mohler Feb 17 '16 at 15:45
  • @Leigh It is broken no matter where the tsql comment is – James A Mohler Feb 17 '16 at 15:46
  • 1
    @JamesAMohler - a) Can you enable debugging in the DSN and check the log file to see the actual sql string being passed to the db? Also, b) check with SQL Profiler to see what statement SQL Server is actually trying to execute and c) Did you check the whitespace management settings Scott mentioned? Because what you posted looks valid to me too, suggesting maybe it is being changed somehow before it hits the db (?) and if so logging/Profiler might help pinpoint what that change is. – Leigh Feb 17 '16 at 16:44
  • 1
    *Note that the SQL String is on a single line*. Hmm... well that would sort of explain the syntax error. As a single line, it is no longer a valid sql statement with the comment breaking it up in the middle. I do not recall if the spy log formats the sql string in any way. Check the SQL Profiler. Is that statement really being executed a single line, or is that just how it appears in the spy log? – Leigh Feb 17 '16 at 20:20
  • (Edit) FWIW, just copied and pasted your exact query above and ran it with CF11. The generated spy log sql is NOT all one line. Not definitive, but ... that does suggest CF might be mucking with it on the way to the db. (Assuming the cfquery really contains new lines and none of your other code is altering it pre-execution that is). SQL Profiler should confirm/disprove. Unfortunately I am not running 2016, so that is about all I can say about the "why" or "where". – Leigh Feb 17 '16 at 21:16
  • 1
    I submitted a bug: https://bugbase.adobe.com/index.cfm?event=bug&id=4118874 – James A Mohler Feb 17 '16 at 22:31
  • 1
    Bug #4118874 - Subtitle: *Keep your grubby mitts off the SQL* ;-) – Leigh Feb 17 '16 at 22:52
  • @JamesAMohler - Since the answer is "it is a bug", can you promote your comment to an answer so it is more visible to [folks experiencing the same issue](http://stackoverflow.com/questions/37062966/coldfusion-2016-strips-newlines-and-executes-queries-on-a-single-line-breaking)? – Leigh May 06 '16 at 02:51

1 Answers1

1

According to Adobe, adding Update 1 will address this issue

List of issues patched in Update 1: https://helpx.adobe.com/coldfusion/kb/bugs-fixed-coldfusion-2016-update-1.html#main-pars_minitoc

Details of Update 1: https://helpx.adobe.com/coldfusion/kb/coldfusion-2016-update-1.html

James A Mohler
  • 11,060
  • 15
  • 46
  • 72