chacham15
chacham15

Reputation: 14251

How to do NOT in LIKE query in SQLite?

I have a table as follows:

CREATE TABLE Foo(
    id      INT PRIMARY KEY,
    key     VARCHAR,
    value   VARCHAR
)

id       key     value
1        Hi      ABCDE/FGHI
2        Hi      DFGRT
3        Hi      FSEHU/

Pre-existing library function (edited for clarity):

char* Foo_getId(char *value){
    char *query = "SELECT id FROM Foo WHERE value LIKE ?";
    sqlite3_stmt *statement;
    int rc = sqlite3_prepare_v2(connection, query, strlen(query), &statement, NULL);
    rc = sqlite3_bind_text(statement, 1, value, strlen(value), SQLITE_STATIC);
    rc = sqlite3_step(statement);
    return strdup((char*)sqlite3_column_text(statement, 0));
}

My function:

char *getFooIdFromValueWithoutSlash(){
    return Foo_getId("WHAT GOES HERE???");
}
How do create a LIKE query such that it will match any value which does not contain a '/'?

E.g. SELECT * FROM Foo WHERE value LIKE '%!/%'

Note: the reason I am trying to do this is that I am interfacing with someone elses code of which I can only pass the value placed after the like.

Upvotes: 1

Views: 2210

Answers (2)

CL.
CL.

Reputation: 180070

You cannot construct a LIKE pattern that behaves the same as a NOT LIKE pattern; the only special characters are % and _.

That someone else's code is just not capable of doing what you want.

Upvotes: 1

Bill Gregg
Bill Gregg

Reputation: 7147

You mean this?

SELECT * FROM Foo WHERE value NOT LIKE '%/%'

Upvotes: 2

Related Questions