将UUID存储在sqlite管理器中

时间:2011-09-22 02:30:37

标签: iphone sqlite uuid sqlitemanager

我是新手。我正在尝试使用以下代码生成UUID ..

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

我在字符串中得到结果为..

NSString *result = [self GetUUID];

现在问题是我无法将其存储在我的sqlite数据库中。我正在尝试使用语句

将其存储在VARCHAR列中
sqlite3_bind_text(compiledStatement, 10, [_idNumber UTF8String], -1, SQLITE_TRANSIENT);

请有人帮帮我。感谢..

1 个答案:

答案 0 :(得分:0)

这是一个将UUID作为NSString返回的方法,只需将其作为字符串保存在数据库中。

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

如果你需要一个c字符串:

NSString *uuidString = [self newUUID];
const char *uuidCString = [uuidString cStringUsingEncoding:NSASCIIStringEncoding];