2010-03-11 104 views
3

這是怎麼回事?我期望下面的刪除從表中刪除所有內容。對於我來說,sqlite3的行爲有沒有根本的誤解?sqlite3刪除不會刪除所有內容?

sqlite> .schema 

CREATE TABLE ip_domain_table (ip_domain TEXT, answer TEXT, ttl INTEGER, PRIMARY KEY(ip_domain, answer, ttl)); 

sqlite> select count(*) from ip_domain_table where ttl < 9999999999 ; 

1605343 

sqlite> pragma cache_size=100000; delete from ip_domain_table where ttl < 9999999999; 

sqlite> select count(*) from ip_domain_table where ttl < 9999999999 ; 

258 

Q:爲什麼計數顯示 「258」?它不應該是0嗎?

如果我這樣做,它會刪除所有條目按預期方式。

sqlite> select count(*) from ip_domain_table; 

1605343 

sqlite> pragma cache_size=100000; delete from ip_domain_table; 

sqlite> select count(*) from ip_domain_table; 

0 

回答

3

重要的是要記住,SQLite的有一種叫做type affinity,這意味着每個列的數據類型僅僅是建議,並沒有得到執行是非常重要的。所有列類型都可以存儲任何類型的數據。這意味着您的整數列可以存儲大於9999999999的數字,甚至可以存儲字符串。

我會做到以下幾點:

  1. 檢查所有的TTL值都小於9999999999
  2. 是什麼結果「SELECT * FROM ip_domain_table限制1」後,你的第一個刪除?如果結果的ttl列是一個字符串或一個大於9999999999的數字,那麼您有答案。

簡單地使用delete from ip_domain_table;沒有什麼不對,就像你上面做的那樣。

祝你好運!

0

首先,請注意您的表的ttl列是而不是的主鍵。它可能包含大於您指定的9999999999的值。

然後,如果你想刪除表中的所有條目,試試這個來代替:

DELETE FROM ip_domain_table;