How to deal with accented characters in iOS SQLite?

前端 未结 3 1987
轮回少年
轮回少年 2021-01-02 01:47

I need to perform a SELECT queries that are insensitive to case and accents. For demo purposes, I create a table like that:

create table table
(
  column tex         


        
3条回答
  •  生来不讨喜
    2021-01-02 02:05

    Here is my solution of LIKE problem

    static void myLow(sqlite3_context *context, int argc, sqlite3_value **argv)
    {
        NSString* str = [[NSString alloc] initWithUTF8String:
                                (const char *)sqlite3_value_text(argv[0])];
        const char* s = [[str lowercaseString] UTF8String];
        sqlite3_result_text(context, s, strlen(s), NULL);
        [str release];
    }
    
    // call it once after opening db
    sqlite3_create_function(_db, "myLow", 1, SQLITE_UTF8,NULL, &myLow, NULL, NULL);
    

    And then instead of query

    SELECT * FROM table WHERE column LIKE 'a'
    

    you should use

    SELECT * FROM table WHERE myLow(column) LIKE 'a'
    

提交回复
热议问题