Hi Expert!
I have a general question about using WHERE clauses in SQLite. I have worked with SQLite some and know my way around. However, I'm having trouble with WHERE clauses.
I have an Android application in which I'm needing to do a few simple operations with the SQLite WHERE clause. However, despite experimenting with the WHERE clause
all day, I've come up empty. I am trying to perform very simple SQLite commands (e.g. SELECT name FROM tablename WHERE _id=2 or DELETE FROM tablename WHERE
name='somename'). But, every time I use the where clause I either get 0 rows returned (in the case of a SELECT) or have 0 rows deleted.
The table name is correct. The column names are correct. (I haven't had any trouble selecting or inserting as long as I don't specify a WHERE clause.) I made sure
that the queries/statements were well formed. I've tried both raw queries/statements as well as the methods (I made sure to use the correct methods for SELECT and
DELETE {e.g. rawQuery() or query() for SELECT}) provided from the SQLiteDatabase class in Android, but nothing has worked.
All I need is to be able to perform simple queries/statements using the WHERE clause. Does anyone have any insight as to what's happening?
Thanks in advance!
AVADHESH PATEL
30-May-2013private boolean isRequestExists(int requestId) {Cursor cursor = null;
boolean result = false;
try {
String[] args = { "" + requestId };
StringBuffer sbQuery = new StringBuffer("SELECT * from ").append(
TABLE_NAME).append(" where _id=?");
cursor = getReadableDatabase().rawQuery(sbQuery.toString(), args);
if (cursor != null && cursor.moveToFirst()) {
result = true;
}
} catch (Exception e) {
Log.e("Requestdbhelper", e.toString());
}
return result;
}