Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Pinus

macrumors newbie
Original poster
Nov 25, 2008
3
0
I have some code that works judt fine when I do a simple 'select' statement :

const char *sql = "SELECT * FROM aliments WHERE nom_alm = ?;
sqlite3_stmt *statement;

if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [nameToSearch UTF8String], -1, SQLITE_TRANSIENT);
....

The same code with the sql query : "SELECT * FROM aliments WHERE nom_alm LIKE '%?%'" returns nothing instead of 3 rows, as verified with a GUI client.

Is there something I should now regarding "sqlite3_bind_text" when we do a "SELECT LIKE" statement ?

Thanks.

Pinus.
 

beachdog

macrumors member
Aug 10, 2008
86
0
I've had the same problem, and I don't know exactly why, but when I use a different parameter substitution approach it works properly. Try this, instead of the '?' parameter:

Code:
const char *sql = "SELECT * FROM aliments WHERE nom_alm = :ltr";
 

Pinus

macrumors newbie
Original poster
Nov 25, 2008
3
0
Hi,

Thanks for the tip. But it doesn't solve the issue with 'LIKE' statement.

This one works just fine :
Code:
const char *sql = "SELECT * FROM aliments WHERE nom_alm = :ltr";

But this one still fails to return any row :
Code:
const char *sql = "SELECT * FROM aliments WHERE nom_alm LIKE '%:ltr%'";
 

Pinus

macrumors newbie
Original poster
Nov 25, 2008
3
0
[solved]

I finally got it solved by appending "%" before and after "nameToSearch" before passing it to "sqlite3_bind_text".

Pinus.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.