如何在sqlite3中更改表中现有列的默认值?
我有一个名为notesboolean列的表hidden.默认设置为true,我想将其设置为false.
我在这里看到了关于阅读user_version的其他问题,这似乎对我来说很好.但是,我正在尝试在FMDB中使用sqlite来设置我的版本号,而不是设置.
_db = [self openDatabase];
[_db executeUpdate:[StudentController creationString]];
[_db executeUpdate:[ReadingController creationString]];
[_db executeUpdate:[SessionController creationString]];
NSLog(@"User version is %i", userVersion);
NSString *query = [NSString stringWithFormat:@"PRAGMA USER_VERSION = %i", userVersion];
[_db executeQuery:query];
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
2014-01-16 22:16:25.438 MyApp[2810:1c103] User version is 2
2014-01-16 22:16:25.439 MyApp[2810:1c103] Query is PRAGMA USER_VERSION = 2
2014-01-16 22:18:09.272 MyApp[2810:1c103] Database copied and created
Run Code Online (Sandbox Code Playgroud)
在运行应用程序一段时间后,数据库保存并加载就好了,我重新启动应用程序并读取版本号,我调用它来检查版本号:
FMResultSet *ps = [_db executeQuery:@"PRAGMA USER_VERSION"];
NSDictionary *results = [[NSDictionary alloc] init];
while ([ps next]) {
results = [NSDictionary dictionaryWithDictionary:[ps resultDictionary]];
}
Run Code Online (Sandbox Code Playgroud)
结果是一个很好的字典:
(lldb) po …Run Code Online (Sandbox Code Playgroud)