coldfusion 9, params not found when using cfscript query

273 views Asked by At

I am getting this error:

Parameter 'user_id AND league_id' not found in the list of parameters specified

I am passing them in, and I can see them in a dump placed inside the function.

here's whats going in...

ac = {
    league_id = 1
    ,user_id = 3
    ,score1 = 14
    ,score2 = 10
};

this is the dump that is throwing the error....

writedump( Game.saveGame( argumentcollection = ac ) );

Here is the Game.saveGame function

public any function saveGame( required numeric league_id, required numeric user_id, required numeric score1, required numeric score2 ) {

    // writeDump( var=arguments ); // this dump shows league_id & user_id...
    var sql     = '';
    var tmp     = '';
    var r       = '';
    var q       = new query();

        q.setDatasource( this.dsn );

        q.addParam(
                name = 'league_id'
                ,value = '#val( arguments.league_id )#'
                ,cfsqltype =  'CF_SQL_BIGINT'
            );
        q.addParam(
                name = 'user_id'
                ,value = '#val( arguments.user_id )#'
                ,cfsqltype =  'CF_SQL_BIGINT'
            );
        q.addParam(
                name = 'score1'
                ,value = '#val( arguments.score1 )#'
                ,cfsqltype =  'CF_SQL_SMALLINT'
            );
        q.addParam(
                name = 'score2'
                ,value = '#val( arguments.score2 )#'
                ,cfsqltype =  'CF_SQL_SMALLINT'
            );

        sql = 'INSERT INTO
                games
                (
                    user_id
                    ,league_id
                    ,score1
                    ,score2
                )
            VALUES
                (
                    :user_id
                    ,:league_id
                    ,:score1
                    ,:score2
                )
        ';

        tmp = q.execute( sql = sql );

        r = tmp.getPrefix( q ); 

        q.clearParams();

    return r;

}

Here is some history of the issue - I am writing this locally and my system is running CF 11.2 - everything works fine... However, I had to host it on a CF 9.02 server, and that is when this error showed up - I cannot recreate it on my system although, I do recall seeing this error before, but for the life of me I cant find how I solved it then....

Any help or insight is appreciated.

Other params Windows server, MySQL 5.5, Apache 2.2

1

There are 1 answers

0
j-p On

Adam Wrote:

I can't spot what's wrong with your code, but you could perhaps clean things up a bit. There's no need to set each "property" on the query separately: blog.adamcameron.me/2014/01/

Following the ordinal param, instead of the named param, AND passing in the array of params in the condensed format, has solved my issue.

I may play with the name attribute and see if it is that, precisely.. or I may just deal with this as a solution.

Now, to change all my script queries!!!!! (I wish his article came up on google, when I was looking into the query.cfc syntax. :(

Thanks a bunch Adam!