Created
August 2, 2012 16:37
-
-
Save ccgus/3238464 to your computer and use it in GitHub Desktop.
FMDB custom functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[db makeFunctionNamed:@"UTTypeConformsTo" maximumArguments:2 withBlock:^(sqlite3_context *context, int argc, sqlite3_value **argv) { | |
if (sqlite3_value_type(argv[0]) == SQLITE_TEXT) { | |
const unsigned char *a = sqlite3_value_text(argv[0]); | |
const unsigned char *b = sqlite3_value_text(argv[1]); | |
CFStringRef as = CFStringCreateWithCString(0x00, (const char*)a, kCFStringEncodingUTF8); | |
CFStringRef bs = CFStringCreateWithCString(0x00, (const char*)b, kCFStringEncodingUTF8); | |
sqlite3_result_int(context, UTTypeConformsTo(as, bs)); | |
CFRelease(as); | |
CFRelease(bs); | |
} | |
else { | |
NSLog(@"Unknown formart for UTTypeConformsToSQLiteCallBackFunction (%d) %s:%d", sqlite3_value_type(argv[0]), __FUNCTION__, __LINE__); | |
sqlite3_result_null(context); | |
} | |
}]; | |
// later on: | |
FMResultSet *rs = [db executeQuery:@"select displayName, key from items where UTTypeConformsTo(uti, 'public.image') order by 2"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment