我在下面做了一个SQL查询。我得到了一个例外情况,我已经证明了这一点。任何帮助表示赞赏。
INSERT OR REPLACE INTO CLAIMS (DATE ,TIME , ADDRESS , CITY,
STATE , POSTAL , PHFNAME ,PHLNAME ,PHEMAIL ,PHPHONE ,AGENCY ,POLICY ,VEHICLENAME,
YEAR ,MAKE ,MODEL ,PLATELICENSE ,LSTATE ,VIN ,DRIVERNAME,DRFNAME ,DRLNAME ,
DRPHONE ,DREMAIL ,DRLICENSE) VALUES("Wednesday, May 4, 2011",
"10:39:10 PM EDT", "400 Chatham","Pune", "Penn", "45223", "John",
"Richard","jsmith@newyahoo.com","+1-11111111111",
"Three Rivers Insurance","(null)", "(null)", "(null)",
"(null)", "(null)","(null)", "(null)", "(null)","(null)",
"(null)", "(null)","(null)", "(null)","(null)") WHERE DATE LIKE
'Wednesday, May 4,%' AND TIME = '10:39:10 PM EDT'
SQLiteManager: Likely SQL syntax error:
[ near "WHERE": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
答案 0 :(得分:4)
我同时面对同步表插入和更新的问题,最后我使用了。 要使用insert或replace语句,您需要使用需要主键列放置where子句的coalesce函数。
COALESCE((SELECT PRIMARY_KEY_COLUMN FROM TABLE_NAME WHERE UNIQUE_COLUMN = 'VALUE'),
(SELECT MAX(PRIMARY_KEY_COLUMN)+1 FROM TABLE_NAME))
它对我有用,例如
INSERT OR REPLACE INTO TBL_ADDRESSES
(ADDRESS_ID,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS_NAME,CITY,DB_ID)
VALUES (
COALESCE((SELECT ADDRESS_ID FROM TBL_ADDRESSES WHERE DB_ID = '111'),
(SELECT MAX(ADDRESS_ID)+1 FROM TBL_ADDRESSES)),
'IT 27','Pratap DSFSDSDDSDSF','test add ','IT 27','Jaipur','111') ;
答案 1 :(得分:2)
INSERT OR REPLACE
不支持WHERE
子句,请参阅SQLite Insert doc。您可以在WHERE
语句中使用UPDATE
子句,请参阅SQLite Insert doc
如果您能告诉我们您想要的信息,可以帮到您吗?