I must be doing something stupid here, because I have some very similar code that works fine. When I compile and run the code below, I get an android.database.sqlite.SQLiteException:
05-05 20:00:29.524: E/AndroidRuntime(12785): Caused by: android.database.sqlite.SQLiteException: near "VALUES": syntax error: , while compiling: INSERT INTO bookmarks_6616 (VALUES (
That’s the whole error. It’s as if an incomplete insert is being sent. The strangest thing is that the exception is being generated the first call to InsertHelper.getColumnIndex() which shouldn’t be compiling an insertion anyhow.
The code is below. I have checked, and the table does exist (it is empty, and created a few lines before.) The keys also have the correct values. I will probably switch back to using insert() without an insertHelper, but I would like to be able to figure out this bug! Any help is appreciated.
InsertHelper ihelper = new InsertHelper(dbHelper.mDb, tableName);
//Populate the DB table
final int idColumn = ihelper.getColumnIndex(BooksDbAdapter.KEY_CHID);
final int titleColumn = ihelper.getColumnIndex(BooksDbAdapter.KEY_CHAPTERTITLE);
final int urlColumn = ihelper.getColumnIndex(BooksDbAdapter.KEY_CHAPTERURL);
final int durationColumn = ihelper.getColumnIndex(BooksDbAdapter.KEY_DURATION);
for (RSSMessage msg : messages){
if (msg.imageMessage()) {
dbHelper.updateImage(lvid, msg.getImageURL());
} else {
ihelper.prepareForInsert();
ihelper.bind(idColumn, chid);
ihelper.bind(titleColumn, msg.getChapterTitle());
ihelper.bind(urlColumn, msg.getChapterURL());
ihelper.bind(durationColumn, msg.getDuration());
ihelper.execute();
chid++;
}
}
ihelper.close();
It turns out that the problem was simply a bad table name. Apparently, the error showed up as being on getColumnIndex() because no matching column could be found. I’m still not sure why the error showed an incomplete INSERT statement, but perhaps the compiler delayed the call to getColumnIndex until the results were needed.