CFQueryParam problems after you change a query

  • Post author:
  • Post category:Uncategorized

On CF-Talk today, an interesting comment about CFQueryParam was made by Adam Howitt. He mentioned that sometimes you will run into database errors because of using cfqueryparam. He wasn’t saying not to use it, I want to get that out up front. However, when you use cfqueryparam, ColdFusion creates a prepared statement (precompiled) to send back to the database. This makes things faster. However, sometimes CF will keep these prepared SQL statements in memory, even after you make a change to a query. So the user runs a page with a changed query, and ColdFusion tries to run the prepared statement from cache, error occurs. Adam has a work around, temporarily change your query to force the CF server to recreate your prepared statement. For example, add ‘and 1=1’ at the end, which doesn’t change the result set.I just wanted to post this here for future reference, because I always remember things better when I write it down. If anybody has any problems with the above scenarios, please leave a comment to enlighten me. 🙂