1

I am a newbie here. I am trying to generate UUIDs using the following code..

- (NSString *)GetUUID
{
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    //CFUUIDBytes number = CFUUIDGetUUIDBytes (theUUID);
    DLog(@"Howwww :%@", theUUID);
    CFRelease(theUUID);
    return [(NSString *)string autorelease];
}

I am getting the result in a string as..

NSString *result = [self GetUUID];

Now the problem is I am unable to store it inside my sqlite database. I am trying to store it in a VARCHAR column using the statement

sqlite3_bind_text(compiledStatement, 10, [_idNumber UTF8String], -1, SQLITE_TRANSIENT);

Please can anyone help me out here. Thanks..

Hadi
  • 1,212
  • 2
  • 17
  • 31

1 Answers1

0

Here is a method that return the UUID as a NSString, just save it in the db as a string.

- (NSString *)newUUID
{
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID);
    CFRelease(theUUID);
    return (NSString *)string;
}

If you need a c string:

NSString *uuidString = [self newUUID];
const char *uuidCString = [uuidString cStringUsingEncoding:NSASCIIStringEncoding];
zaph
  • 111,848
  • 21
  • 189
  • 228
  • I am saving it in the db as nsstring.. but it is not saving it somehow.. its saving some other value.. – Hadi Sep 22 '11 at 03:12