Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: execute case-sensitive LIKE query on a specific query

I want to run a SELECT ... LIKE query in SQLite that is case-sensitive. But I only want this one query to be case sensitive, and nothing else.

I know there is

PRAGMA case_sensitive_like = boolean;

But that seems to change all LIKE queries.

How can I enable case-sensitive LIKE on a single query?

Examples: I want a query for "FuN" to match "blah FuN blah", but not "foo fun bar".

(This is running under PHP using PDO)

I might be able to toggle that on, then off after the query but I can concerned about the repercussions that may have (efficiency etc). Is there any harm?

I don't have write access to the database.

(This is under Windows Server 2008)

I also tried SELECT id, summary, status FROM Tickets WHERE summary COLLATE BINARY LIKE '%OPS%'; but that did not do a case-sensitive SELECT, it still returned results returns like laptops.

like image 416
JBurace Avatar asked May 14 '12 20:05

JBurace


1 Answers

Why not go the simple way of using

PRAGMA case_sensitive_like = true/false;

before and after each query you want to be case sensitve? But beware- case sensitivity does only work for ASCII characters, not Unicode which makes SQlite not fully UC-compliant at this time.

Alternatively, SQlite allows applications to implement the REGEXP operator which might help according to www.sqlite.org/lang_expr.html.

like image 172
andig Avatar answered Oct 18 '22 15:10

andig