PDA

View Full Version : Strange SQLite




Pinus
Dec 15, 2008, 03:55 PM
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
Dec 15, 2008, 05:13 PM
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:


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

Pinus
Dec 16, 2008, 01:27 AM
Hi,

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

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

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

Pinus
Dec 16, 2008, 02:18 AM
I finally got it solved by appending "%" before and after "nameToSearch" before passing it to "sqlite3_bind_text".

Pinus.