ColdFusion 9.01 -> Lucee 5.3.3.62 and <cfinsert> / <cfupdate> - sql-server

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

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

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>

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!
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.

Related

Replace is not working for weird character

I use UPDATE a SET GR_P = REPLACE(GR_P,'','') FROM mytable a to replace things.
But replace function is not working for below charter:
In Query analyzer it works but when I used SSIS Execute SQL task or OLEDB Source then it is giving me error:
No Connection manager is specified.
In Toad against Oracle (since that's one of your tags), I issued this (pressing ALT-12 to get the female symbol) and got 191 as a result. note selecting it back using CHR(191) shows an upside-down question mark though.
select ascii('♀') from dual;
Given that, this worked but it's Oracle syntax, your mileage may vary.
UPDATE mytable SET GR_P = REPLACE(GR_P, CHR(191));
Note if it does not work, that symbol could be for another control character. You may need to use a regular expression to eliminate all characters not in a-zA-Z0-9, etc. I suspect you'll need to update your tags to get a more accurate answer.
Maybe this info will help anyway. Please post back what you find out.

SQL Server Query SELECT Error (now trying LIMIT)

I am working on what should be a super simple query for SQL Server 2014. All I want to do is check that our systems can interface with SQL Server after updates, etc. So I need to just verify that it makes the connection correctly and finds a table within the Server.
Attempt 1:
SELECT TOP (1) *
From [X].[dbo].[Y]
WITH (NOLOCK);
But apparently 'top' is not a supported option with SQL Server 2014.
To add some more, here is the exact error I get when trying to run that: Syntax error. The token 'Top' is invalid. Please check the case of your operators (eg 'or' versus 'OR') and check that your functions use brackets after the function name eg Now(), eg Len("abc").
Attempt 2:
SELECT *
From [X].[dbo].[Y]
WITH (NOLOCK)
LIMIT (1);
That one tells me that I need to put data items between [], text between "", and functions as FunctionName(). However...I don't see where I missed any of those.
Can anybody possibly shed some light on why my query isn't going through? Any help would be appreciated.
The first attempt should work just fine:
SELECT TOP (1) *
From [dbo].[Y]
WITH (NOLOCK);
See example
If it doesn't work, you should include the error message.

PDO ODBC, one of several result sets causes php to crash

-Running PHP 5.6 on IIS 8.5 (Windows Server 2012 R2)
-Connecting to SQL Server 2008 R2 remotely via PDO, ODBC
-Issue isolated to one query, other queries function normally with expected results.
I am calling a stored procedure that returns eight result sets. I write each result set to a CSV. When I get to the third result set, php-cgi.exe crashes and I get a 500 error.
I have isolated the issue to this particular result set because if I skip the result set altogether using $stmt->nextRowset() everything works as expected.
//execute sp, bind parameters year and period-defined above
$StmtText = "{CALL PROCESS_PR (?, ?) }";
$Stmt = $dbh->prepare($QueryText);
$Stmt->bindParam(1, $PayYear, PDO::PARAM_INT);
$Stmt->bindParam(2, $PayPeriod, PDO::PARAM_INT);
$Stmt->execute();
$file_out = fopen('c:\windows\temp\tmp_1.csv, 'w');
$Result = $Stmt->fetchAll(PDO::FETCH_NUM);
foreach($Result as $row) { fputcsv($file_out,$row); }
fclose($file_out);
$Stmt->nextRowset();
//this happens 8 times, fails on the third
I am not throwing any PHP errors, and advanced IIS logging doesn't suggest a whole lot. I am struggling to determine what is crashing PHP. I executed the stored procedure directly via SSMS and it executes successfully, and looking at the problematic result set, can't see anything out of the ordinary- no special characters, no long strings, etc.
I have also been down the road of confirming PHP memory limits are set appropriately, checking timeouts on both FastCGI and in php.ini, and verifying MVC++ 2012 is installed, both 32bit and 64bit.
Looking for any thoughts on how to track down php crashing on this one particular result set. Thanks much.
UPDATE: Laughing Vergil's answer below solved the issue. The problematic result set had two fields with datatype varchar(max). changing one of them to varchar(255) solved the problem.

SELECT DAY('2007-04-30T01:01:01.1234567 -07:00') does not work?

This sql statement:
SELECT DAY('2007-04-30T01:01:01.1234567 -07:00');
is copied from the SQL Server 2012 documentation and tested in my SQL Server 2012 express edition environment. But there was an error saying
Conversion failed when converting date and/or time from character string.
I understand that the character type argument passed in DAY() is unable to be converted to a datetime type value, meaning it has the wrong format (incompatible with some current settings related to SET DATEFORMAT or any settings I don't know). So that's what I would like to know about. Could you explain why that sample statement (not of mine) does not work in my environment. My SQL Server instance was installed with default settings, I've not changed anything after installing it.
By modifying the input string a little, it works:
SELECT DAY('2007-04-30T01:01:01.123'); -- Works!
But these don't (saying the same error I posted at first):
SELECT DAY('2007-04-30T01:01:01.1234'); -- just add 4
SELECT DAY('2007-04-30T01:01:01.123 -07:00'); -- just add -07:00
Looks like there is some settings related to this problem, please tell me what it might be and how to fix this issue (I don't want to change the input string as I tried to make it work).
Thanks for your time solving my problem!
UPDATE:
Also done as some suggestions, like this:
SELECT DAY('2007-04-30T01:01:01.1234567-07:00');
SELECT DAY('2007-04-30T01:01:01.123-07:00');
but it still does not work.
Well, I found the problem. In fact the statement itself (as some ones suggested) should work, but that's just one side of the problem. The other side is the compatibility level of the current datatbase. In my case it's just 90 (which is SQL Server 2005), so explicit casting is required. By changing the compatibility level to 110 (SQL Server 2012) or explicitly casting, it works expectedly.

MATLab - Database Handle is Empty

I have the following problem. At work we have personal computers running windows7 with MATLab (including the database toolbox), Oracle and so on. I got a new process I should take care about which involves a MATLab script which connects to the oracle database. The scripts works fine on any computer of the department except of mine. Sadly the IT told me that every PC is configured the same and I have to find the misstake for my one.
So i started "debugging" by checking the connection struct MATLab creates when it connects via
conn = database(instance,username,password)
It appears that the content of the structure is equal to every one else, except that the handle is empty:
val =
Instance: '***'
UserName: '*'
Driver: []
URL: []
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: [1x128 char]
Handle: 0
TimeOut: 0
AutoCommit: 'off'
Type: 'Database Object'
on all other systems the handle is set to:
sun.jdbc.odbc.JdbcOdbcConnection
So my question is: Do I have to configure MATLab or is the driver for the JDBC/ODBC is missing? I already checked systems preferences/adminstration/ODBC sources but it seems to by the same as everywhere else.
Do someone might know how I can track down the source of this issue? Any help or hint is highly apprechiated.
Thanks and best regards
stephan
after some research here is the way one can figure it out. It is actually very easy, but I did not try the obvious...
first, if the
connection = database(...)
can not be created, type
connection.message
in the MATLab console. This message will give you additional feedback on the error. In my case the DNS entries for the oracle Databases where empty. After adding them through system preferences it worked as expected.

Resources