Hello,

I am trying to use parameters in a LIKE query. I have the following
code which uses Sqlite C/C++ API.

const char *sql = "SELECT word FROM words WHERE word LIKE ?1 || '%'
ORDER BY freq DESC LIMIT 10;";

int rc = sqlite3_prepare_v2 (db, sql, -1, &stmt, NULL);
if ( rc != SQLITE_OK )
     return false;

sqlite3_bind_text ( stmt, 1, data , -1, NULL );

Unfortunaltly, this won't work. Sqlite is executing the statement
successfully, but I am not getting the expected result. When I execute
the same statement after removing parameters it works perfectly.
Something like,

const char *sql = "SELECT word FROM words WHERE word LIKE 'word'%'
ORDER BY freq DESC LIMIT 10;";

It looks like concatentation with parameters is not working for some
reason. To debug the issue, I hooked up sqlite3_trace and
sqlite3_profile and printed the SQL being executed. Unfortunatly,
these routines won't give the SQL with values bound to it.

I am running out of ideas and any help would be great to address the problem.

Thanks
-- 
-n
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to