Ask a Jedi: CFQueryParam and MaxLength

Brian had an interesting question about the cfqueryparam tag:

Question about the cfqueryparam maxlength attribute. I understand that it is (psuedo-)required for string types, but is it used for numerics, integers, or dates? Or does ColdFusion ignore it for non-string datatypes?

For those who aren’t familiar with cfqueryparam, stop everything and go straight to the docs for it. The maxlength attribute is typically used for a string. So for example, if you were inserting a name and the size of the column in the database was 50, your tag could look like so:

<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.name#" maxlength="50">

So while this makes sense, what does maxlength do for non-string based column types? Believe it or not, it still gets checked. For example, if you try to pass a number, 999, and the maxlength is 2, ColdFusion will throw an error since the string length (3) is greater than 2.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments