Setting user_version in sqlite

▼魔方 西西 提交于 2019-11-30 15:57:36

If you need to set PRAGMA user_version use:

[self.db setUserVersion:yourUserVersion]; // yourUserVersion is of uint32_t type

To read current user_version user

[self.db userVersion];                   // returned value is of uint32_t type

FMDB encapsulate it since 2013 so you don't have to deal with it yourself.

Documentation:

http://ccgus.github.io/fmdb/html/Categories/FMDatabase+FMDatabaseAdditions.html

PS: @HalR I think you can accept my answer as is it probably more useful for visitor searching for "how to set user_version PRAGMA" and it also solves your problem with neater solution as well.

I was about to post a bounty when I figured out the issue. And as often happens, I was just being a bonehead

I was doing executeQuery where I should have been doing executeUpdate

_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];

should instead be:

_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 executeUpdate:query];

executing a Pragma is NOT a query, executeQuery doesn't do anything with it. It is instead in the same category as UPDATE, INSERT, and DELETE.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!