I have this code:
-(int)queryUserVersion: (sqlite3*) db {
// get current database version of schema
static sqlite3_stmt *stmt_version;
if(sqlite3_prepare_v2(db, "PRAGMA user_version;", -1, &stmt_version, NULL) == SQLITE_OK) {
while(sqlite3_step(stmt_version) == SQLITE_ROW) {
databaseVersion = sqlite3_column_int(stmt_version, 0);
NSLog(@"%s: version %d", __FUNCTION__, databaseVersion);
}
NSLog(@"%s: the databaseVersion is: %d", __FUNCTION__, databaseVersion);
} else {
NSLog(@"%s: ERROR Preparing: , %s", __FUNCTION__, sqlite3_errmsg(db) );
}
sqlite3_finalize(stmt_version);
return databaseVersion;
}
I can check the sqlite user_version
that the user has on the iPhone Documents directory. I have the SQLite DB previous downloaded. I want to know everytime of user loads the app if the local SQLite user_version
is the same of the SQLite user_version
that I have on my server, if they are different it downloads the new version.
How can I check the SQLite user_version
before download it?
UPDATE
I was thinking about this, I'm using the Parse API
for some features on my app so i decided do this system:
- I stored the
user_version
sqlite value on the Parse Webservices to update it manualy. - I check with localize the iPhone language to know what DB I want to download (I have the same DB with 2 languages)
- I check if it is the 1st time running the APP or not with
NSUserDefaults
. - If it is the first time it gonna check the language and then download the correct DB from my server.
- If isn't the first time running the app I'll check on the Parse what is the current user_version and then compare it with the local
user_version
sqlite database on the iPhone. If it has a higher value it'll download the DB to update it.
New Problem: When I check the user_version on the Parse
, I use a query FindObjectsInBackgroundWithBlock
(assync) so... it will run the app before checking the user_version and do the DB download. How can I handle it? I already tried with a NSTimer
..
Code:
-(void)checkUserVersion{
PFQuery *query = [PFQuery queryWithClassName:@"sqliteversion"]; //1
// NSNumber *n=databaseVersion;
[query whereKey:@"user_version" equalTo:[NSNumber numberWithInt:[databaseVersion integerValue]]];//2
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {//4
if (!error && [objects count]>0) {
for (PFObject *object in objects) {
valor1=[[object objectForKey:@"Value"]intValue];
user_version=[NSNumber numberWithInt:valor1];
}
}
}];}