2015-11-08 87 views
-1

我在做下面的代碼錯了嗎?SQLite語法REPLACE + WHERE

CREATE TABLE IF NOT EXISTS chunks(x Integer(20) NOT NULL, y Integer(20) NOT NULL, 
      height Integer(20) NOT NULL, version Timestamp default (strftime('%s', CURRENT_TIME)), 
      datas Text NOT NULL); 
REPLACE INTO chunks VALUES(0,0,0,NULL,'Bla') WHERE x IS 0 AND y IS 0 AND height IS 0; 
+0

還是一樣的結果「錯誤:近‘WHERE’:語法錯誤」 – erinas

+0

更換'整數(20)'和'INTEGER'和'''用'=' –

+1

這個SQL語句沒有意義。描述你想做什麼。 –

回答

0

更換要求表,對你要搜索的列的唯一約束,始終刪除舊行,如果它發現之一。

一個更好的想法是明確檢查該行是否存在:

cursor.execute("UPDATE chunks SET ... WHERE x = ? AND y = ? AND height = ?", 
       [0, 0, 0]) 
if cursor.rowcount == 0: 
    cursor.execute("INSERT INTO chunks ...")