2015-11-08 89 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 ...")