For the record, I’m creating an iOS application (iPhone and iPad).
Here’s the setup of my problem:
I have a sqlite db that I cannot change. This DB has a id field of type GUID. Now, I know that sqlite doesn’t have an actual GUID type, which is fine. The values were created using a hash that I have access to. The sqlite db was created from a SQL Server DB using a converter I do not have access to. I’d like to avoid using the hash to recreate the guid (which I can do).
This is essentially my question: Is there a native way to decode the guid column type into something Objective-c can read?
EDIT: I originally pulled the values out with sqlite3_column_text, and the values displayed as asian characters. I updated it to the code below, but the translation is giving me the incorrect guid value:
NSString* query = [NSString stringWithFormat:
@"select CcoDrugPage.Id, CcoDrugPage.Title, DetailText.Text "
"from CcoDrugPage inner join DetailText on CcoDrugPage.TextId = DetailText.Id "
"where CcoDrugPage.DrugName = '%@' and PrototypeSuffix like 'Drug%%' "
"order by SortOrder "
"limit %i "
, self.title, initial ? 2 : 100];
sqlite3_stmt* statement;
if(sqlite3_prepare_v2(db, [query UTF8String], -1, &statement, nil) == SQLITE_OK) {
int i = 0;
while(sqlite3_step(statement) == SQLITE_ROW) {
DrugSection* section = [[[DrugSection alloc] init] autorelease];
char* rowData = (char*)sqlite3_column_text(statement, 0);
CFUUIDRef uuidObj = CFUUIDCreateWithBytes(nil,
rowData[0],
rowData[1],
rowData[2],
rowData[3],
rowData[4],
rowData[5],
rowData[6],
rowData[7],
rowData[8],
rowData[9],
rowData[10],
rowData[11],
rowData[12],
rowData[13],
rowData[14],
rowData[15]);
section.pageID = (NSString*)CFUUIDCreateString(nil, uuidObj);
CFRelease(uuidObj);
rowData = (char*)sqlite3_column_text(statement, 1);
NSString* sectionTitle = [NSString stringWithUTF8String:rowData];
rowData = (char*)sqlite3_column_text(statement, 2);
NSString* sectionText = [NSString stringWithUTF8String:rowData];
It appears the issue here was due to the actual GUID field being corrupt in the converted SQLite database. The converted hex value in the field contained 59 characters, and we all know that GUIDs contain at most 32 characters if you don’t include the braces and dashes.
I had the client convert the field to play TEXT to solve the problem.