Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

SQLite rawquery

0

56 views

I am getting an error with a rawquery on Eclipse on a DB in the assets directory. The DB is 'pre-loaded' with tables and data and the SQL string, first comment line, works in SQLite DB browser. When I copy the SQL string to code and modify to remove quotes it errors. The code below is from the 'standard' public class DataBaseHelper extends SQLiteOpenHelper{ .I am new to android/java and would appreciate any assistance or suggestions.

        public Cursor getAllSectionDescriptions( String DBtable, String source){
    //Works in DB: SELECT  "Description" FROM  "SectionProps"  WHERE   Source = "UK"        
    //String q = "SELECT  Description FROM  SectionProps  WHERE   Source = UK " ; <= errors in code
    String q = "SELECT  Description FROM " + DBtable + "  WHERE   Source = " + source + " "; //<== errors in code
    //06-24 16:53:03.373: ERROR/AndroidRuntime(1000): Caused by: android.database.sqlite.SQLiteException: no such table: SectionProps: , while compiling: SELECT  Description FROM  SectionProps  WHERE   Source = UK 

    Cursor mCursor = myDataBase.rawQuery(q, null);
    mCursor.moveToFirst();
    return mCursor;

}//end cursor

asked June 24, 2011 12:47 pm CDT
posted via StackOverflow

1 Answer

0
 

Looks like you have to put double quotes around your object names. So you'll want to do this:

String q = "SELECT  \"Description\" FROM \"" + DBtable + "\"  WHERE   Source = \"" + source + "\" ";

Note the double quotes preceded by the escape character '\'

answered June 24, 2011 1:29 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
SQLite: get day
March 24, 2011
SQLite for personal use
December 28, 2010