jeudi 10 décembre 2015

database.query prepare statement binding not working

I have this prepare statement working

String [] selectionArgs = new String[]{level, col1, col1_value};

db.query(Table, null,                      //table & columns
         level + " = ? AND " +             //selection 
            "? != ? AND " +
            "length(" + col1 + ") = " + col1.length,  //**here is question point**
         selectionArgs,                    // selectionArgs
         null, null, "RANDOM()",           // order by
         Integer.toString(count));         // number of retrieve

Notice that length is raw Inline. not with "?" and it's working.

But when I change it to as the following

String [] selectionArgs = new String[]{level, col1, col1_value, 
                                   col1, Integer.toString(col1.length)}; //added for length

db.query(Table, null,                      //table & columns
         level + " = ? AND " +             //selection 
            "? != ? AND " +
            "length(?) = ?",  //**here is question point**
         selectionArgs,                    // selectionArgs
         null, null, "RANDOM()",           // order by
         Integer.toString(count));         // number of retrieve

It is not working anymore.

Does anyone have any idea why it is. If u have, please give me some explanation. Give my thanks to u all in advance.

Aucun commentaire:

Enregistrer un commentaire