selectionArgs in SQLiteQueryBuilder doesn't work with integer values in columns

后端 未结 3 1078
忘了有多久
忘了有多久 2021-01-01 00:38

I\'m trying to select some data from database and I have two slices of code to do it:

cursor = builder.query(db,
                    new String[]{\"col1\", \         


        
3条回答
  •  星月不相逢
    2021-01-01 01:12

    You need to convert your int id into string before passing to your query because the parameter array is of type string. For example:

    cursor = builder.query(db, new String[]{"col1", "col2", "col3"},
        "id = ?", new String[]{String.valueOf(getSID(db))}, null, null, null);
    

    The reason why it works in second type of query is because you are appending the integer value with string which automatically converts the int into String. For example:

    int i = 10;
    String s = i + "";   //now 10 is in string
    

提交回复
热议问题