SQLite WHERE子句不使用VARCHAR

时间:2016-02-07 19:55:53

标签: android mysql sqlite where-clause

mydb.execSQL("CREATE TABLE IF NOT EXISTS customer " + "  ( id INT(10) NOT NULL , name_surname VARCHAR (50) NOT NULL , card INT(10) NOT NULL , PRIMARY KEY(id) );");
mydb.execSQL("INSERT INTO customer (id, name_surname , card ) VALUES ('194', 'aaa' , '21' );");

Cursor cursor = ajcinemaDB.rawQuery("SELECT * FROM customer WHERE name_surname=? " , new String[] {"aaa"});


    int idColumn = cursor.getColumnIndex("id");
    int name_surnameColumn = cursor.getColumnIndex("name_surname");
    int cardColumn = cursor.getColumnIndex("card");


    cursor.moveToFirst();


    if(cursor != null && (cursor.getCount() > 0)){

        do {


            String id = cursor.getString(idColumn);
            String name_surname = cursor.getString(name_surnameColumn);
            String card = cursor.getString(cardColumn);

            custinfo = custinfo  + card + "\n";


        }while(cursor.moveToNext());

    } else {
        Toast.makeText(this, "No Results ", Toast.LENGTH_SHORT).show();
    }

为什么这个where子句什么都不返回?

此特定子句适用于id(int),但不适用于name_surname(varchar)。

我也尝试过常规和原始查询,结果相同。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试以下rawQuery语句:

  1. Cursor cursor = ajcinemaDB.rawQuery("SELECT id, name_surname, card FROM customer WHERE name_surname=? " , new String[] {"aaa"});

  2. Cursor cursor = ajcinemaDB.rawQuery("SELECT * FROM customer WHERE name_surname='aaa'",null);