What must I do to implement SQLite's rawQuery() method?

北战南征 提交于 2019-12-13 07:08:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!