inline CFDateRef SQLite3StatementCreateDateWithColumn(SQLite3StatementRef statement, CFIndex index) { CFDateRef date = NULL; CFStringRef string = NULL; switch (SQLite3StatementGetColumnType(statement, index)) { // For integer and float, we're interpreting as unix timestamp case kSQLite3TypeInteger: case kSQLite3TypeFloat: date = CFDateCreate(statement->allocator, SQLite3StatementGetInt64WithColumn(statement, index) - kCFAbsoluteTimeIntervalSince1970); break; // For string we're using default format case kSQLite3TypeString: string = SQLite3StatementCreateStringWithColumn(statement, index); date = CFDateFormatterCreateDateFromString(statement->allocator, statement->connection->defaultDateFormatter, string, NULL); CFRelease(string); break; // For blobs, nulls (or unknown column type?) we're leaving it as NULL case kSQLite3TypeData: case kSQLite3TypeNULL: default: break; } return date; }
Boolean GetMetadataForFile(void* thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile) { /* Pull any available metadata from the file at the specified path */ /* Return the attribute keys and attribute values in the dict */ /* Return TRUE if successful, FALSE if there was no data provided */ Boolean success; CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathToFile, kCFURLPOSIXPathStyle, false); CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL); CFReadStreamOpen(stream); CFPropertyListFormat format; CFStringRef errorString = NULL; CFPropertyListRef ticket = CFPropertyListCreateFromStream(kCFAllocatorDefault, stream, /*streamLength*/ 0, kCFPropertyListImmutable, &format, &errorString ); if (errorString) { printf("failed creating property list from stream\n"); printf("error = %s\n", (const char*) errorString); success = FALSE; } else { CFTypeRef value; value = CFDictionaryGetValue(ticket, kMDItemTitle); if (value) { CFDictionarySetValue(attributes, kMDItemTitle, value); } value = CFDictionaryGetValue(ticket, kMDItemTextContent); if (value) { CFDictionarySetValue(attributes, kMDItemTextContent, value); } value = CFDictionaryGetValue(ticket, kMDItemDisplayName); if (value) CFDictionarySetValue(attributes, kMDItemDisplayName, value); CFDateFormatterRef dateFormatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle); value = CFDictionaryGetValue(ticket, kMDItemLastUsedDate); if (value && dateFormatter) { printf("trying to parse date \n"); CFDateRef curDate = CFDateFormatterCreateDateFromString(NULL, dateFormatter, value, NULL); printf("got cur date\n"); if (curDate) CFDictionarySetValue(attributes, kMDItemLastUsedDate, curDate); } success = TRUE; } // contents are kMDItemTextContent CFReadStreamClose(stream); CFRelease(stream); CFRelease(fileURL); return success; }