Skip to content

Commit

Permalink
Merge pull request #2187 from zspitzer/LDEV-4645-v54
Browse files Browse the repository at this point in the history
LDEV-4645 bugfix for cfprocparam and empty char strings (5.4)
  • Loading branch information
zspitzer authored Jul 20, 2023
2 parents 0af71b7 + b8ca824 commit df04313
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 46 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
45 changes: 41 additions & 4 deletions test/tickets/LDEV1917.cfc
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{
component extends="org.lucee.cfml.test.LuceeTestCase" labels="mysql" {
function beforeAll(){
variables.uri = createURI("LDEV1917");
}
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 All @@ -18,7 +56,6 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
return baseURI&""&calledName;
}


private boolean function hasCredentials() {
return (structCount(server.getDatasource("mysql")) gt 0);
}
Expand Down
57 changes: 17 additions & 40 deletions test/tickets/LDEV1917/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,65 +1,42 @@
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){
this.datasource="#{
class: 'com.mysql.cj.jdbc.Driver'
, bundleName:'com.mysql.cj'
, bundleVersion:'8.0.15'
, connectionString: 'jdbc:mysql://'&mySQL.server&':'&mySQL.port&'/'&mySQL.database&'?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=true'
, username: mySQL.username
, password: mySQL.password
}#";
this.datasource=mySQL;
}

public function onRequestStart() {
setting requesttimeout=10;

var extra= form.notNull ? " NOT NULL" : "";

public function onApplicationStart() {
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
");
}
}
private struct function getCredentials() {
// getting the credentials from the enviroment variables
var mySQL={};
if(
!isNull(server.system.environment.MYSQL_SERVER) &&
!isNull(server.system.environment.MYSQL_USERNAME) &&
!isNull(server.system.environment.MYSQL_PASSWORD) &&
!isNull(server.system.environment.MYSQL_PORT) &&
!isNull(server.system.environment.MYSQL_DATABASE)) {
mySQL.server=server.system.environment.MYSQL_SERVER;
mySQL.username=server.system.environment.MYSQL_USERNAME;
mySQL.password=server.system.environment.MYSQL_PASSWORD;
mySQL.port=server.system.environment.MYSQL_PORT;
mySQL.database=server.system.environment.MYSQL_DATABASE;
}
// getting the credentials from the system variables
else if(
!isNull(server.system.properties.MYSQL_SERVER) &&
!isNull(server.system.properties.MYSQL_USERNAME) &&
!isNull(server.system.properties.MYSQL_PASSWORD) &&
!isNull(server.system.properties.MYSQL_PORT) &&
!isNull(server.system.properties.MYSQL_DATABASE)) {
mySQL.server=server.system.properties.MYSQL_SERVER;
mySQL.username=server.system.properties.MYSQL_USERNAME;
mySQL.password=server.system.properties.MYSQL_PASSWORD;
mySQL.port=server.system.properties.MYSQL_PORT;
mySQL.database=server.system.properties.MYSQL_DATABASE;
}
return mysql;
return server.getDatasource("mysql");
}
}
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 df04313

Please sign in to comment.