Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created August 2, 2012 16:37
Show Gist options
  • Save ccgus/3238464 to your computer and use it in GitHub Desktop.
Save ccgus/3238464 to your computer and use it in GitHub Desktop.
FMDB custom functions
[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