在 SQLite Android 中执行以下查询时出现错误
sDataBase.execSQL(query);
插入联系人(ID,FirstName,LastName,PhoneNumber,EmailId,Status)值('ae0caa6a-8ff6-d63f-0253-110b20ac2127','xxx','xxx','9008987887','xxx@gmail.com', '是'),('9afab56e-a18a-47f2-fd62-35c78d8e0d94','yyy','yyy','7890988909','yyy@gmail.com','是'),('378d757a-ee60-07a4 -e8bc-396b402c3270','zzz','zzz','9000898454','zzz@gmail.com','是')
注意:这在 SQLServer 中执行良好,在 Android SQLite 中出现错误。
Error: sqlite returned: error code = 1, msg = near ",": syntax error, db=/data/data/myapp.contactmanager/databases/webview.db
编辑 1:我在值之间添加了空格,但仍然出现错误
insert into 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')
编辑 2:使用是否可以在 SQLite 数据库中一次插入多行来更改查询?还是行不通
INSERT INTO Contacts
SELECT 'ae0caa6a-8ff6-d63f-0253-110b20ac2127' AS ID, 'xxx' AS FirstName, 'xxx' AS LastName, '9008987887' AS PhoneNumber, 'xxx@gmail.com' AS EmailId, 'Yes' AS 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'
编辑 3:我在编辑 2.End of Sync 状态中犯了一个小错误before UNION i have included comma
,所以我得到了一个错误。现在删除并且工作正常。
INSERT INTO Contacts
SELECT 'ae0caa6a-8ff6-d63f-0253-110b20ac2127' AS ID, 'xxx' AS FirstName, 'xxx' AS LastName, '9008987887' AS PhoneNumber, 'xxx@gmail.com' AS EmailId, 'Yes' AS 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'