android - Insert Multiple Rows in SQLite Error (error code = 1) -
i getting error when executing following query in sqlite android
sdatabase.execsql(query);
insert contacts(id,firstname,lastname,phonenumber,emailid,status) values('ae0caa6a-8ff6-d63f-0253-110b20ac2127','xxx','xxx','9008987887','xxx@gmail.com','yes'),('9afab56e-a18a-47f2-fd62-35c78d8e0d94','yyy','yyy','7890988909','yyy@gmail.com','yes'),('378d757a-ee60-07a4-e8bc-396b402c3270','zzz','zzz','9000898454','zzz@gmail.com','yes')
note: executed fine in sqlserver, getting error in android sqlite.
error: sqlite returned: error code = 1, msg = near ",": syntax error, db=/data/data/myapp.contactmanager/databases/webview.db
edit 1: have added space between values still getting error
insert contacts(id, firstname, lastname, phonenumber, emailid,status) values ('ae0caa6a-8ff6-d63f-0253-110b20ac2127', 'xxx', 'xxx','9008987887', 'xxx@gmail.com', 'yes'), ('9afab56e-a18a-47f2-fd62-35c78d8e0d94', 'yyy', 'yyy', '7890988909', 'yyy@gmail.com', 'yes'), ('378d757a-ee60-07a4-e8bc-396b402c3270', 'zzz', 'zzz', '9000898454', 'zzz@gmail.com', 'yes')
edit 2: changed query using is possible insert multiple rows @ time in sqlite database? still not working
insert contacts select 'ae0caa6a-8ff6-d63f-0253-110b20ac2127' id, 'xxx' firstname, 'xxx' lastname, '9008987887' phonenumber, 'xxx@gmail.com' emailid, 'yes' status, union select '9afab56e-a18a-47f2-fd62-35c78d8e0d94', 'yyy', 'yyy', '7890988909', 'yyy@gmail.com', 'yes' union select '378d757a-ee60-07a4-e8bc-396b402c3270', 'zzz', 'zzz', '9000898454', 'zzz@gmail.com', 'yes'
edit 3: have did small mistake in edit 2. end of sync status before union have included comma
, got error. removed , working fine.
insert contacts select 'ae0caa6a-8ff6-d63f-0253-110b20ac2127' id, 'xxx' firstname, 'xxx' lastname, '9008987887' phonenumber, 'xxx@gmail.com' emailid, 'yes' status union select '9afab56e-a18a-47f2-fd62-35c78d8e0d94', 'yyy', 'yyy', '7890988909', 'yyy@gmail.com', 'yes' union select '378d757a-ee60-07a4-e8bc-396b402c3270', 'zzz', 'zzz', '9000898454', 'zzz@gmail.com', 'yes'
that's not how insert multiple rows in sqlite. see this post details.
if you, go either syntax in question's answer or, if want able insert single row @ once too, standard insert db (one, two) values (one, two)
, execute once each row you're inserting. you!
Comments
Post a Comment