问题
I'm trying to use the SQLite rawQuery method, based on the code here:
Android record exists() in database?
...but I get "The method rawQuery(String, String[]) is undefined for the type OdaaDBOpenHelper Authorize_Activity_DynamicControls.java" with this code:
OdaaDBOH = new OdaaDBOpenHelper(this);
. . .
private boolean RecordExists(String _id) {
// This:
Cursor cursor = OdaaDBOH.rawQuery("select 1 from NAPOLEON_DYNAMITE_TABLE where _id=%s",
// or this:
//Cursor cursor = OdaaDOdaaDBOpenHelperBOH.rawQuery("select 1 from
NAPOLEON_DYNAMITE_TABLE where _id=%s",
new String[] { _id });
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
. . .
// from referenced unit:
public class OdaaDBOpenHelper extends SQLiteOpenHelper {
I tried it both using the instance name of my SQLiteOpenHelper-derived class, and using the class name itself (commented out in the code above).
What must I do to implement rawQuery() or cause it to be recognized/acknowledged?
回答1:
From that question correct answer:
Consider that mDb is your SqlLiteDatabase class...
OdaaDBOH should be an instance of a SQLiteDatabase
if you want to use rawQuery
on it, most likely you are providing the implementation of a SQLiteOpenHelper
there, which of course doesn't have a method rawQuery
.
回答2:
rawQuery()
is a method on SQLiteDatabase
, not SQLiteOpenHelper
. Call getReadableDatabase()
or getWritableDatabase()
on your SQLiteOpenHelper
to get a SQLiteDatabase
.
来源:https://stackoverflow.com/questions/9891772/what-must-i-do-to-implement-sqlites-rawquery-method