On Feb 12, 2008, at 3:51 PM, Igor Tandetnik wrote:

> Diego Souza <[EMAIL PROTECTED]>
> wrote:
>> I wasn't able to figure this out. I'm trying to execute a query like
>> this:
>>
>> SELECT columns FROM table WHERE column LIKE ?
>>
>> However, I'd like to use % or _ placeholders. For instance in the
>> following
>> code:
>>
>>  sqlite3_prepare_v2(db, "SELECT columns FROM table WHERE column LIKE
>>  ?", -1, stmt, 0); sqlite3_bind_text16(stmt, 1, "myutf16txt", bytes,
>> SQLITE_STATIC);
>>
>> How do I insert the % stuff ?
>
> You can make them part of the parameter value:
>
> sqlite3_bind_text16(stmt, 1, "%myutf16txt%", bytes, SQLITE_STATIC);
>
> Or, you can change the statement to something like this:
>
> SELECT columns FROM table WHERE column LIKE '%' || ? || '%';
>
> Igor Tandetnik

Also, don't forget to carefully read the notes about the optimizer.  
In particular:

The right-hand side of the GLOB or LIKE operator must be a literal  
string value that does not begin with a wildcard. If the right-hand  
side is a parameter that is bound to a string, then no optimization  
is attempted.

So if you bind the parameter then optimization is disabled, which may  
be important depending on what you are doing. In my case I needed  
fast lookups from a large db so I had to make the LIKE/GLOB parameter  
part of the SQL statement I was preparing.

Peter

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

Reply via email to