2010-02-22 178 views
0

我試圖將一個NSString值綁定到我的SQL查詢中,但它不工作,我不知道我在做什麼錯。 這裏是我的查詢:LIKE語句的Sqlite3_bind(Objective-C)


Select * from fiche where fichetype = 'EVENT' and sdate like '?%' ORDER BY cdate DESC 

而且我使用的這部分代碼的值綁定:


sqlite3_bind_text(getEventStatement, 1, [value UTF8String], -1, SQLITE_TRANSIENT); 

這個查詢工作在我的數據庫罰款,但沒有在Xcode。我也嘗試類似的東西:


Select * from fiche where fichetype = 'EVENT' and sdate GLOB '?*' ORDER BY cdate DESC 

這一個在Xcode的工作,但所有值都顯示,?*不起作用。

有人嗎?謝謝,

回答

0

對於那些與LIKE聲明有同樣問題的人來說,這裏是爲我工作的解決方案。 首先我改變我的查詢這樣的:


Select * from fiche where fichetype = 'EVENT' and sdate like ?001 ORDER BY cdate DESC 

不要把引號的參數令牌001,然後創建一個把%到你正在尋找一個新的字符串:


NSString *theString = [NSString stringWithFormat:@"%@%%", myValue]; 

最後,只需要字符串綁定到準備好的語句是這樣的:


sqlite3_bind_text(getEventStatement, 1, [theString UTF8String], -1, SQLITE_STATIC); 

有樂趣,