gpt4 book ai didi

ios - 迁移 SQLCipher 版本。 2.x 数据库到版本。 3.x 使用 FMDB

转载 作者:行者123 更新时间:2023-11-29 02:29:53 25 4
gpt4 key购买 nike

我看到了以下页面,我明白我应该执行查询“PRAGMA cipher_migrate”。

https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_migrate

但我不知道如何在 FMDatabase 上使用它。以下代码不起作用...(好像不仅仅是执行的时机不对。。。)

如果您尝试使用 FMDatabase 将 SQLCipher ver.2.x DB 迁移到 ver.3.x,请告诉我您的解决方法。

- (FMDatabase *)openDB {

NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directory = [directories objectAtIndex:0];
NSString *path = [directory stringByAppendingPathComponent:dbFileName];
FMDatabase *dataBase = [FMDatabase databaseWithPath:path];

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
int version = [userDefault integerForKey:DATABASE_TABLE_VERSION];

if(version==1){

if(![dataBase openWithFlags:SQLITE_OPEN_READWRITE]){
@throw [NSException exceptionWithName:@"DBException"
reason:@"openWithFlags"
userInfo:nil];
}

if(![dataBase setKey:SQLCIPHER_KEY]){
@throw [NSException exceptionWithName:@"DBException"
reason:@"setKey"
userInfo:nil];
}

if(![dataBase executeStatements:@"PRAGMA kdf_iter = 4000"]){
@throw [NSException exceptionWithName:@"DBException"
reason:@"executeStatements:kdf_iter"
userInfo:nil];
}

[userDefault setInteger:2 forKey:DATABASE_TABLE_VERSION];
[userDefault synchronize];

return dataBase;
}

if(![dataBase open]){
@throw [NSException exceptionWithName:@"DBException"
reason:@"open"
userInfo:nil];
}

if(![dataBase setKey:SQLCIPHER_KEY]){
@throw [NSException exceptionWithName:@"DBException"
reason:@"setKey"
userInfo:nil];
}

return dataBase;
}

- (NSMutableArray *)selectUser{

FMDatabase *dataBase = [self openDB];
NSString *sql = @"select * from t_user";
FMResultSet *resultSet = [dataBase executeQuery:sql];

NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects: nil];

while ([resultSet next]){
[mutableArray addObject:[resultSet resultDictionary]];
}

[resultSet close];
[dataBase close];
return mutableArray;
}

最佳答案

我认为您需要在连接之后和任何执行之前立即设置密码。

如果您使用

PRAGMA kdf_iter = 4000

你不需要使用

PRAGMA cipher_migrate

关于ios - 迁移 SQLCipher 版本。 2.x 数据库到版本。 3.x 使用 FMDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com