2011-02-08 85 views
2

我創建了一個表中的SQLite鉻(HTML5):如何獲得所有列在sqlite中大於零的結果?

transaction.executeSql(
      'CREATE TABLE IF NOT EXISTS record('+ 
      'id INTEGER NOT NULL PRIMARY KEY,'+ 
      'fkindicatorspeciesid INTEGER NOT NULL REFERENCES indicatorspecies(indicatorspeciesid),'+ 
      'latitude INTEGER NOT NULL,'+ 
      'longitude INTEGER NOT NULL,'+ 
      'time TEXT NOT NULL,'+ 
      '`when` TEXT NOT NULL,'+ 
      'numberseen INTEGER NOT NULL,'+ 
      'notes TEXT NOT NULL,'+ 
      'online_recordid INTEGER,'+ 
      'status TEXT,'+ 
      'locationid INTEGER REFERENCES location(locationid),'+ 
      'surveyid INTEGER REFERENCES survey(id));', 
      [], nullHandler,errorHandler); 

然後我一些數據添加到它: enter image description here

現在我嘗試檢索所有的記錄,其中「online_recordid」較大則零:

select * from record where online_recordid > 0; 

我不應該讓我的紀錄回來,因爲沒有什麼在列「online_recordid」。問題是我確實拿回了唱片!

回答

0

這就是我最終解決它的方法。

select * from record where online_recordid <> '' and online_recordid > 0; 
0

只是檢查一下是否online_recordid不爲空:

select * from record where online_recordid > 0 and online_recordid is not null 

但是,行爲很奇怪。我試着和你做同樣的查詢,但我沒有收到任何記錄。也許我做了和你不同的事情。

+0

我試過你的線路,但得到的記錄沒有任何online_recordid。我認爲這可能是由cyberkiwi解釋的事情發生的。 – Timo 2011-02-11 01:17:17

1

SQLite uses a more general dynamic type system.

可以有效的已儲存 ''(空字符串)到online_recordid,即使它被定義爲 「整數」。這隻影響Type Affinity,並不像傳統的RDBMS那樣以任何方式限制數據。

最有可能發生的事情是,當您真正想要存儲的是NULL時,您的代碼將''插入online_recordid

當查詢online_recordid > 0觸發時,空白轉換成[something],使其成爲>0