On Sat, 18 Jun 2011 17:01:41 +1000, Zettai Muri
<zettaim...@gmail.com> wrote:

>Hi All,
>
>Could someone tell me how to use bound parameters with LIKE and where
>the % wildcards should be placed?
>
>I currently have the following code extract:
>char *sql = "SELECT * FROM foo WHERE name LIKE :bp";
>
>rc = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, &tail);
>sqlite3_bind_text( stmt,
>                          sqlite3_bind_parameter_index(stmt, "%:bp%"),
>                          "bar",
>                          -1,
>                         SQLITE_TRANSIENT );
>
>It compiles but doesn't return any results.
>
>If I directly query the database using:
>SELECT * FROM foo WHERE name LIKE %bar%;
>
>This returns results.

Have the C program include the % in the text parameter:

sqlite3_bind_text( stmt,
        sqlite3_bind_parameter_index(stmt, "%:bp%"),
               "%bar%", ......

Or rewrite the SQL as 

char *sql = "SELECT * FROM foo WHERE name LIKE '%' || :bp || '%'";
-- 
  (  Kees Nuyt
  )
c[_]
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to