Android: SQLite Query not binding integer parameters?

I am having problems creating queries with parameters in a database on the Android platform (2.2). I created the table as follows:

db.execSQL("CREATE VIRTUAL TABLE " + Msg._TABLE_NAME + " USING FTS3 ("
            + Msg._ID + " INTEGER, "
            (...)
            + Msg.READ + " SHORT DEFAULT 0,"
            + Msg.URGENT + " SHORT DEFAULT 0"
            + ");");

Then I try to execute the query using a parameterized query:

String[] columns = new String[] {Msg.ROWID, Msg.TITLE, Msg.READ, Msg.URGENT};
(...)
getContentResolver().query(Msg.CONTENT_URI, columns, 
    Msg.URGENT + "=? AND " + Msg.READ + "=?" + , whereArgs, null);

where whereArgschanges for each request:

String[] urgentUnread = new String[]{"1", "0"};
String[] regularUnread = new String[]{"0", "0"};

but no matter what, it returns 0 results / rows, even if the data exists. The content provider does not change the parameters, and the query returns nothing using QueryBuilder, as well as when calling the query directly:

Cursor c = db.query(tables, columns, where, whereArgs, groupBy, having, orderBy, limit);

The query works if I just concat string:

getContentResolver().query(Msg.CONTENT_URI, columns, 
    Msg.READ + "=0 AND " + Msg.URGENT + "=1", null, null);

, , param- . Dalvik ( ), , , '?'. , :)

, JavaDoc , StringS, ... ... ... WTF

?

.

+3
1

OP, , FTS3. VIRTUAL TABLE USING FTS3, .

(Msg_content), , 2 :

db.execSQL("CREATE TABLE " + Msg._TABLE_NAME + " (" +
    Msg._ID + PRIMARY_KEY_AUTOINC + 
    Msg.PRIORITY + " TEXT," +
    Msg.RECEIVED + " INTEGER," +
    Msg.MOBILE_STATUS + " INTEGER DEFAULT 0," +
    Msg.READ + " SHORT DEFAULT 0," +
    Msg.FLASH + " SHORT DEFAULT 0" +
");");

db.execSQL("CREATE VIRTUAL TABLE " + MsgText._TABLE_NAME + " USING FTS3 (" + 
    MsgText._ID + PRIMARY_KEY +
    MsgText.TITLE + " TEXT," +
    MsgText.CONTENT + " TEXT," +
    MsgText.KEYWORDS + " TEXT," +
    "FOREIGN KEY(" + MsgText._ID + ") " +
    "REFERENCES " + Msg._TABLE_NAME + "(" + Msg._ID + ") " +
");");

View :

db.execSQL("CREATE VIEW IF NOT EXISTS " + View.MSG_CONTENT +
    " AS SELECT " +
    Msg._TABLE_NAME + "." + Msg._ID + ", " +
    Msg._TABLE_NAME + "." + Msg.READ + ", " +
    Msg._TABLE_NAME + "." + Msg.FLASH + ", " +
(...)
    MsgText._TABLE_NAME + "." + MsgText.TITLE + ", " +
    MsgText._TABLE_NAME + "." + MsgText.CONTENT +
    " FROM " + Msg._TABLE_NAME + ", " + MsgText._TABLE_NAME +
    " WHERE " + Msg._TABLE_NAME + "." + Msg._ID + "=" +
    MsgText._TABLE_NAME + "." + MsgText._ID);

, , . , .

, - , .

Cheers,
Pes

P.S. Checked Meta , .

+3

Source: https://habr.com/ru/post/1788906/


All Articles