2014-05-21 71 views
0

我試圖運行我的數據庫這個請求:NS_ERROR_FAILURE上重複鍵與SQL請求

INSERT INTO scnScenarios (id,version,description,author,created_at,updated_at,tailNumber,flightLegCounter,name) 
VALUES ('98','','','','2014-05-21 22:04:05','','9001','12','bolo') ON DUPLICATE KEY UPDATE ID=last_insert_rowid() , description='',author=''; 

返回此錯誤:

SQLiteManager: Likely SQL syntax error: INSERT INTO scnScenarios (id,version,description,author,created_at,updated_at,tailNumber,flightLegCounter,name) 
VALUES ('98','','','','2014-05-21 22:04:05','','9001','12','bolo') ON DUPLICATE KEY UPDATE ID=last_insert_rowid() , description='',author=''; [ near "ON": syntax error ] 
Exception Name: NS_ERROR_FAILURE 
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement] 

回答

0

的SQLite的INSERT statement沒有啓動的重複鍵子句。

處理此問題的最簡單方法是使用多個語句:首先嚐試UPDATE,如果該記錄不存在(如果受影響的記錄數爲零),請執行INSERT。請參閱SQLite - UPSERT not INSERT or REPLACE