5

I’ve inherited a big application which is running on CF 9.01.
I’m in the process to port it to Lucee 5.3.3.62, but have some problems with and I know that I should replace it with , but this application has ~1000 source files (!!), and replacing all those tags is currently not obvious for timing reasons.
Lucee is throwing errors like:

“An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as “” or are not allowed. Change the alias to a valid name.”

At first, I thought there were problems with date field, because Lucee is handling them differently than CF 9.01, but this is not the case. So, I created a test table (on MS-SQL Server 2008R2):

CREATE TABLE [dbo].[LuceeTest01](   
  [Field1] [nvarchar](50) NULL,
  [Field2] [nvarchar](50) NULL ) ON [PRIMARY]

In Lucee, I’m using as datasource: Microsoft SQL Server (Vendor Microsoft), called “one”

This is my test application:

<cfset Form.Field1 = "Field1">
<cfset Form.Field2 = "Field2">
<cfoutput>
    <cfinsert datasource="one"
        tablename="LuceeTest01"
        formfields="Field1, Field2">
</cfoutput>

When I run this, I get the same error. Any idea why? Full trace here: https://justpaste.it/6k0hw

Thanks!

EDIT1:
Curious. I tried using “jTDS Type 4 JDBC Driver for MS SQL Server and Sybase” as datasource driver, and now the error is:

The database name component of the object qualifier must be the name of the current database.

This traces back to this statement:

{call []..sp_columns 'LuceeTest01', '', '', 'null', 3}

When I try this in the Microsoft SQL Server Management Studio, I get the same error. However, when I specify the database name (‘one’ as third argument), no error in MS SQL SMS.

EXEC sp_columns 'LuceeTest01', '', 'one', 'null', 3

Shouldn’t Lucee take this argument from the datasource configuration or something?

EDIT2:

As suggested by @Redtopia, when "tableowner" and "tablequalifier" are specified, it works for the jTDS driver. Will use this as workaround. Updated sample code:

<cfset Form.Field1 = "Field1">
<cfset Form.Field2 = "Field2">
<cfinsert datasource="onecfc"
    tableowner="dbo"
    tablename="LuceeTest01"
    tablequalifier="one"
    formfields="Field1,Field2">

EDIT3:

Bug filed here: https://luceeserver.atlassian.net/browse/LDEV-2566

GunterO
  • 389
  • 2
  • 13
  • Did try a cfquery with this datasource? There could be a chance that you have a faulty connection setup. I think this [thread](https://blog.sqlauthority.com/2017/10/13/sql-server-msg-1038-object-column-name-missing-empty-select-statements-verify-column-name/) should make some sense. – rrk Nov 08 '19 at 14:58
  • 2
    Try getting rid of the space in your formfields variable. BTW, I've done two ports on large legacy codebases from ACF9 to Lucee 5 and depending on your code it can be quite a lot of work. I have never used cfinsert or cfupdate, so if it's not caused from the extra space, I would try testing the equivalent using cfquery (or better yet do it in cfscript and use queryExecute(). – Redtopia Nov 08 '19 at 15:13
  • Your tags got stripped out when saving your question. Could you please add them back and wrap them in backticks so they don't get removed? – Sebastian Zartner Nov 08 '19 at 22:09
  • @RRK Yes, cfquery is working fine with this datasource. – GunterO Nov 08 '19 at 23:25
  • @Redtopia Yes, tried without the extra space, same problem. – GunterO Nov 08 '19 at 23:26
  • @Redtopia And yes, if I replace the cfinsert tag with cfquery and INSERT INTO ... it works (using the same datasource), but like I said, I wish to find a solution for the cfinsert/cfupdate problem, considering the amount of code to alter ... – GunterO Nov 08 '19 at 23:36
  • @Redtopia Can you check my "EDIT1:" please? Any ideas / insights? Thanks! – GunterO Nov 11 '19 at 13:07
  • 2
    Maybe try specifying a tablequalifier attribute https://docs.lucee.org/reference/tags/insert.html – Redtopia Nov 11 '19 at 14:28
  • 1
    I tried the suggestion from @Redtopia - tablequalifier did not work for me with either DB driver. Using both `tablequalifier="dbname"` and `tableowner="dbo"` still didn't work for me for with the MS SQL Server driver, but does seem to work for the jTDS driver, so a possible workaround but ideally the Lucee guys will be able to fix the bug from their end or identify which Java update broke it if Lucee itself didn't. – Sev Roberts Nov 11 '19 at 15:12
  • You can submit a bug report here https://luceeserver.atlassian.net/ – Redtopia Nov 11 '19 at 15:22
  • 1
    @Redtopia Yes, this works for the jTDS driver. Added an "Edit2". Thanks! – GunterO Nov 11 '19 at 16:45
  • @Redtopia The bug is filed here: https://luceeserver.atlassian.net/browse/LDEV-2566 – GunterO Nov 12 '19 at 11:18
  • @GunterO make sure you follow up and provide additional info as needed. I see there’s been some activity on that bug report. – Redtopia Nov 12 '19 at 19:05

3 Answers3

4

I personally would refactor CFINSERT into queryExecute and write a plain InsertInto SQL statement. I wish we would completely remove support for cfinsert.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
splls
  • 59
  • 2
1

Consider using

<cfscript>
 Form.Field1 = "Field1";
 Form.Field2 = "Field2";

 // Don't forget to setup datasource in application.cfc
 QueryExecute("
    INSERT INTO LuceeTest01 (Field1, Field2)
    VALUES (?, ?)
    ",
    [form.field1, form.field2]
    );
</cfscript>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Yes, I know, but the application is too big to alter all those statements, that's why I want to have this cfupdate / cfinsert fixed, for now. – GunterO Nov 08 '19 at 23:24
0

I am 99% confident that this is a Lucee / JDK / JDBC Driver bug and not a fault in your config.

Source:

I initially suspected some low-hanging fruit such as your leading whitespace in ' Field2'. Then I saw your comment showing that you had tried with that trimmed and your Edit1 with the different error when using a different DB Driver. So I set to work trying to reproduce your issue.

On Lucee 5.2.4.37 and MS SQL Server 2016, armed with your sample code and two new datasources - one each for jTDS (MSQL and Sybase) driver and Microsoft SQL Server (JDBC4 - Vendor Microsoft) on SQL, I was unable to reproduce either issue on either driver. Even when selectively taking away various DB permissions and changing default DB for the SQL user, I was still only able to force different (expected) errors, not your error.

As soon as I hit the admin update to Lucee 5.3.3.62 and re-ran the tests, boom I hit both of your errors with the respective datasources, with no other change in DB permissions, datasource config or sample code.

Good luck convincing the Lucee guys that this anecdotal evidence is proof of a bug, but give me a shout if you need an extra voice. Whilst I don't use cfinsert/cfupdate in my own code, I have in the recent past been in the position of supporting a legacy CF application of similar sounding size and nature and empathise with the logistical challenges surrounding refactoring or modernising it!

error with jTDS driver enter image description here

Edit: I tried the tablequalifier suggestion from @Redtopia in a comment above. Adding just the tablequalifier attribute did not work for me with either DB driver.

Using both tablequalifier="dbname" and tableowner="dbo" still didn't work for me with the MS SQL Server driver, but does seem to work for the jTDS driver, so it's a possible workaround meaning changing every occurrence of the tag, so ideally the Lucee guys will be able to fix the bug from their end or identify which Java update broke it if Lucee itself didn't.

Sev Roberts
  • 1,295
  • 6
  • 7
  • Thanks for taking the time to look into this. Much appreciated! I will accept this as a solution. – GunterO Nov 11 '19 at 16:03