views:

165

answers:

1

Hi,

I try to bind a NSString value into my SQL query but its not working, and I don't know what I'm doing wrong. Here is my query:


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

And I'm using this part of code to bind the value:


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

This query is working fine in my database but not in Xcode. I also try something else like that:


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

This one works in Xcode but all value are display, the ?* is not working.

Anyone? Thanks,

A: 

For those who have the same problem with LIKE statement, here is the solution working for me. first I change my query like that:


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

Do not put quotes in the parameter tokens ?001, then create a new strings that put the % into what you are looking for:


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

Finally, just have to bind the string to the prepared statement like this:


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

have fun,

ludo