Skip to content

Commit

Permalink
Merge pull request #2186 from zspitzer/LDEV-4645
Browse files Browse the repository at this point in the history
LDEV-4645 bugfix for cfprocparam and empty char strings
  • Loading branch information
zspitzer authored Jul 20, 2023
2 parents e04e251 + b84eff1 commit 02dcf81
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/lucee/runtime/tag/ProcParamBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public Object getValueForCF() throws PageException {
@Override
public boolean isNulls() {
return getValue() == null
|| (sqlType != Types.VARCHAR && sqlType != Types.LONGVARCHAR && sqlType != Types.NVARCHAR && getValue() instanceof String && StringUtil.isEmpty(getValue()));
|| (sqlType != Types.VARCHAR && sqlType != Types.LONGVARCHAR && sqlType != Types.NVARCHAR
&& sqlType != Types.NCHAR && sqlType != Types.CHAR
&& getValue() instanceof String && StringUtil.isEmpty(getValue()));
}

@Override
Expand Down
42 changes: 40 additions & 2 deletions test/tickets/LDEV1917.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,48 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="mysql" {
}
function run( testResults , testBox ) {
if(!hasCredentials()) return;
describe( "test suite for LDEV-1917()", function() {
describe( "test suite for LDEV-1917", function() {
it(title = "cfprocparam passes null instead of empty strings with NVARCHAR cfsqltype", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm"
template:"#variables.uri#/test.cfm",
form: {
datatype: "nvarchar"
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});

it(title = "cfprocparam passes null instead of empty strings with CHAR cfsqltype", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "char"
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});
});

describe( "test suite for LDEV-4645", function() {

it(title = "cfprocparam passes null instead of empty strings with NVARCHAR cfsqltype, col not null", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "nvarchar",
notNull: true
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});

it(title = "cfprocparam passes null instead of empty strings with CHAR cfsqltype, col not null", body = function( currentSpec ) {
local.result = _InternalRequest(
template:"#variables.uri#/test.cfm",
form: {
datatype: "char",
notNull: true
}
);
expect(local.result.filecontent.trim()).toBeTrue();
});
Expand Down
17 changes: 12 additions & 5 deletions test/tickets/LDEV1917/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
component {
this.name = "ac";
this.name = "ldev-1917";

param name="form.datatype";
param name="form.notNull" default="false";


if (form.datatype neq "char" and form.datatype neq "nvarchar")
throw "bad datatype [#form.datatype#]";

mySQL = getCredentials();
if(mySQL.count()!=0){
Expand All @@ -8,21 +15,21 @@ component {

public function onRequestStart() {
setting requesttimeout=10;
}

public function onApplicationStart() {
var extra= form.notNull ? " NOT NULL" : "";

query {
echo("DROP PROCEDURE IF EXISTS `LDEV1917SP`");
}
query {
echo("DROP TABLE IF EXISTS `LDEV1917`");
}
query {
echo("CREATE TABLE LDEV1917 (null_Value nvarchar(10))");
echo("CREATE TABLE LDEV1917 (null_Value #form.datatype#(10) #extra# )");
}
query {
echo("
CREATE PROCEDURE `LDEV1917SP`(IN null_Value nvarchar(10))
CREATE PROCEDURE `LDEV1917SP`(IN null_Value #form.datatype#(10))
BEGIN
INSERT INTO LDEV1917 VALUE(null_Value);
END
Expand Down
2 changes: 1 addition & 1 deletion test/tickets/LDEV1917/test.cfm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<cfstoredproc procedure="LDEV1917SP">
<cfprocparam type = "IN" CFSQLType = "NVARCHAR" value = "" null=false>
<cfprocparam type = "IN" CFSQLType = "#form.datatype#" value = "" null=false>
</cfstoredproc>
<cfquery name="test1917">
select * from LDEV1917
Expand Down

0 comments on commit 02dcf81

Please sign in to comment.