queryParam attribute maxlength being ignored in script

The ‘maxlegnth’ attribute is not being applied when used with cfscript:
Not sure if I’m doing something wrong or this is a bug. Here is an example:

// mysql80
// CREATE TABLE maxlenbug (
//   `ID` int unsigned PRIMARY KEY AUTO_INCREMENT,
//   `TheString` varchar(20)
// );


// this will not throw error...
  sql     = "INSERT INTO maxlenbug (`TheString`) VALUES (:THESTRING)",
  params  = { 'TheString': { value:TheString, sqltype: "VARCHAR", maxlength: 20 } },
  options = { datasource: "timesheets_main" }

<!--- this will throw error --->
<cfquery name="qTest" datasource="timesheets_main">
  INSERT INTO maxlenbug (`TheString`) VALUES (
    <cfqueryparam sqltype="VARCHAR" maxlength="20" value="#TheString#">

The script version falls through to a database error stating the field will be truncated.
The tag version throws the following error as expected:

value [MORE THAN TWENTY CHARACTERS IN THIS LONG STRING] is too large, defined maxlength is [20] but length of value is [47]

I’ve tried all combinations of the param struct including assignment and declaration:

{ 'TheString': { value:TheString, sqltype: "VARCHAR", maxlength: 20 } },
{ 'TheString'+ { value=TheString, sqltype="VARCHAR", maxlength=20 } },
{ 'TheString'= { value="#TheString", sqltype="VARCHAR", maxlength="20" } },

None of it makes a difference. If you omit the ‘value’ attribute though you get this:

The key [value] does not exist, only the following keys are available: [maxlength,sqltype] .

Which tells me the maxlength attributes is making it to the query param validation,
its just being ignored.

We’ve got an app in development with hundreds of params defined with maxlength attributes and just
discovered none of them actually work.

This is lucee@5.3.6+61 on ColdBox 6.2.2 and CommandBox 5.2.0+00280

Yes @timesheetsDev, this is a bug. Already we have a ticket for this LDEV-3010 and it was fixed from the lucee version

1 Like

Ah, thank you very much. I knew it had to be a bug. I just missed it searching issues for whatever reason. Thanks again!