Monday 18 February 2019
sqlite - Android bulk insert syntax error near ","
Answer
I would appreciate a shade of enlightenment on the following code, since I just can't seem to figure out why it has a syntax error near ",".
I'm trying to insert multiple rows at once in a single statement. I'm targeting API 10+. If I only have one set of VALUES(...) it's all good, and the row gets inserted, but as soon as I have more than one, it sends out an exception with the syntax error message.
SQLiteDatabase db = getWritableDatabase();
String insertRows = "INSERT INTO " + TABLE_FRIENDS +
" (" + KEY_USER_EMAIL + ", " + KEY_FRIEND + ", " + KEY_FRIEND_INTERACTIONS +
", " + KEY_ENABLED +") VALUES ";
int index;
for(index=0; index insertRows += "('" + userAccount.getEmail() +"', ";
Friend friend = friends.get(index);
insertRows+= "'" + friend.getEmail() +"', ";
insertRows+= "'" + friend.getInteractions() +"', ";
int enabled = friend.isEnabled() ? 1 : 0;
insertRows+= "'"+ enabled + "')";
if(index != friends.size()-1)
insertRows+= ",";
}
insertRows += ";";
db.execSQL(insertRows);
db.close();
I print the query out on my log and get:
INSERT INTO friends (user_email, friend_email, friend_interactions, friend_enabled) VALUES ('test2@test.com', 'vila@hotmail.com', '0', '0'),
('test2@test.com', 'anotherone@hotmail.com', '0', '0'),
('test2@test.com', 'yetanother@hotmail.com', '0', '0');
Help is very much appreciated.
Subscribe to:
Post Comments (Atom)
php - file_get_contents shows unexpected output while reading a file
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...
-
I have an app which needs a login and a registration with SQLite. I have the database and a user can login and register. But i would like th...
-
I would like to use enhanced REP MOVSB (ERMSB) to get a high bandwidth for a custom memcpy . ERMSB was introduced with the Ivy Bridge micro...
-
I am new to dask and I found so nice to have a module that makes it easy to get parallelization. I am working on a project where I was able ...
No comments:
Post a Comment