SQLite区分大小写和不区分大小写搜索

时间:2014-01-05 03:13:13

标签: objective-c macos cocoa sqlite

我的 NSMutableArray 带有 NSMutableDictionary ,带有 SQLite 搜索结果。我需要在区分大小写和不区分大小写的搜索之间做出区分。如果我在这里阅读一些主题,他们会说SQLite默认返回区分大小写的结果。他们建议您使用 COLLATE nocase 进行不区分大小写的搜索。实际上,使用以下代码,无论是否有COLLATE nocase,我都会得到相同的结果。我做错了什么?

const char *sql;
if (checkButtonR5.state == 1) { // checkButtonR5 is a checkbox button.  If it's on, it tells a search will be case-sensitive.
    sql = "Select address,date,name,age,ID From data1a WHERE request LIKE ?";
} else {
    sql = "Select address,date,name,age,ID From data1a WHERE request LIKE ? COLLATE nocase";
}

sqlite3_stmt *statement; // outputFile is a file path
if (sqlite3_open([outputFile UTF8String], &connection) == SQLITE_OK){
    if(sqlite3_prepare_v2(connection, sql, -1, &statement, NULL) != SQLITE_OK) {
        //NSLog(@"It cannot connect the database file.");
    }
    NSString *bindParam = [NSString stringWithFormat:@"%%%@%%",rqt];
    if(sqlite3_bind_text(statement, 1, [bindParam UTF8String], -1, SQLITE_TRANSIENT) != SQLITE_OK){
        //NSLog(@"Problem binding search text param.");
    } else {
        while (sqlite3_step(statement) == SQLITE_ROW) {
            char *field0 = (char *) sqlite3_column_text(statement, 0); // address
            NSString *field1Str0 = [[NSString alloc]initWithUTF8String:field0];
            NSString *str0 = [[NSString alloc]initWithFormat:@"%@", field1Str0];
            ...
            ...
        }
        sqlite3_finalize(statement);
        sqlite3_close(connection);
    }
}

感谢您的帮助。

0 个答案:

没有答案