Search code examples
sqlcoldfusionrailocfml

Is using cfsqltype good practice?


When coding a cfqueryparam or cfprocparam, cfsqltype is optional. However, I've usually seen it coded. Are there any benefits to specifying cfsqltype?


Solution

  • The main benefit is an additional level of sanity checking for your query inputs, prior to passing it into your query. Also, in the case of date time values, I believe CF will properly translate datetime strings into the proper database format, if the cfsqltype="CF_SQL_DATE" or ="CF_SQL_TIMESTAMP" is specified.

    In addition, I think it makes it more clear for future developers to see the types excepted when they read your code.