Setting user_version in sqlite

后端 未结 2 1242
清歌不尽
清歌不尽 2021-01-03 07:25

I have seen other questions on here about reading the user_version, and that seems to be working fine for me. However I\'m trying to use sqlite in FMDB to set my version nu

2条回答
  •  死守一世寂寞
    2021-01-03 08:06

    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.

提交回复
热议问题