I’ve made an Adnroid program in Eclipse that reads a csv file and inputs the info into an SQLite database, and using
dbCursor = database.query(DATABASE_TABLE, new String[]{KEY_ROWID, KEY_ITEMTYPE, KEY_QUANTITY}, null, null, null, null, null);
int iRow = dbCursor.getColumnIndex(KEY_ROWID);
int iType = dbCursor.getColumnIndex(KEY_ITEMTYPE);
int iQuantity = dbCursor.getColumnIndex(KEY_QUANTITY);
for(dbCursor.moveToFirst(); !dbCursor.isAfterLast(); dbCursor.moveToNext()){
allData = allData + " " + dbCursor.getString(iRow) + "\t " + dbCursor.getString(iType) + "\t\t\t " + dbCursor.getString(iQuantity) + "\n";
}
and then printing out allData in a textview box has worked just fine.
Then I wanted to use
dbCursor = database.rawQuery("SELECT KEY_ROWID , SUM(KEY_ITEMTYPE) FROM DATABASE_TABLE GROUP BY KEY_ROWID", null);
for(dbCursor.moveToFirst(); !dbCursor.isAfterLast(); dbCursor.moveToNext()){
allDataSum = allDataSum + " " + dbCursor.getString(0);
} //I know this will probably not print what I want correctly but that's a problem for another day
When I try to print this I get the error “10-25 22:06:35.016: I/Database(1911): sqlite returned: error code = 1, msg = no such table: DATABASE_TABLE”.
I then opened DDMS File Explorer and copied the database onto my desktop and then tried viewing the database with a command tool but again got an error, “SQL error: no such table: inventory”.
How can the emulator show me what I want to see from .query() (but not from .rawQuery) when apparently there is no table in the database? Everything about I use the query and rawQuery is identical, so it’s not a case of not opening the db for rawQuery or something like that.
It appears that you’re using a static variables named DATABASE_TABLE, KEY_ROWID, and KEY_ITEMTYPE containing your actual names. When you use this with rawQuery, you’ll have to do
Notice that when you make the query using
database.queryyou don’t have these variables in quotes, that’s why it works.