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();
}
Why does this where clause return nothing ? I tested this query with comparing "id" and it worked fine. Though it doesn't work with the name_surname ( it is VARCHAR ). Any idea why is this happening ?
Aucun commentaire:
Enregistrer un commentaire