Search code examples
coldfusionrailocoldfusion-11lucee

queryExecute ColdFusion syntax vs Railo/Lucee syntax


I have a bunch of code that has been written against a Railo server. We are now trying to move some of that code over to a CF11 box and a Lucee box.

I have been using queryExecute like this:

rt = queryExecute(
        sql = 'select *
               from translation
               where    translationID = :translationID
                 and    translatedStr = :translatedStr'
    ,   params = {translationID: arguments.translationID
                , translatedStr: arguments.translatedStr}
    ,   options= {datasource: application.ds}
);

I was under the impression that the syntax was the same on CF11 but I am getting an error :

Parameter validation error for the QUERYEXECUTE function.
A built-in ColdFusion function cannot accept an assignment statement as a parameter, 
although it can accept expressions. For example, QUERYEXECUTE(d=a*b) is not acceptable. 

The above executeQuery works fine on Lucee. I am going to need to go through the whole code base and make it work on both CF11 AND on Lucee.

Can someone, who is more familiar with ACF, tell me what is the best way to do this. It appears that ACF is having trouble with the param names. If I remove sql = and params = that takes away some of the problem, although I like the readability of having them named. Also it appears that ACF doesn't like translationID: arguments.translationID and wants me to change it too translationID = arguments.translationID. I just want to make sure that there isn't something I am missing before I go through the time consuming process of making all the changes.


Solution

  • Pretty sure your parameters need to be in the form of a structure to include the value (and query param if you so choose).

    Try this:

    rt = queryExecute(
        "select *
          from translation
          where translationID = :translationID
              and translatedStr = :translatedStr",
        {
              translationID: {value: arguments.translationID},
              translatedStr: {value: arguments.translatedStr}
        },
        {datasource: application.ds}
    );