1

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:

  1. I stored the user_version sqlite value on the Parse Webservices to update it manualy.
  2. I check with localize the iPhone language to know what DB I want to download (I have the same DB with 2 languages)
  3. I check if it is the 1st time running the APP or not with NSUserDefaults.
  4. If it is the first time it gonna check the language and then download the correct DB from my server.
  5. 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];


            }

        }
    }];}
4

1 回答 1

1

听起来您在这里尝试做的是为您的应用程序提供一组数据,并让您的应用程序在启动时检查是否有新数据。

我的建议是在 sqlite 数据文件中找到另一种方法,让您的应用程序使用它来查看服务器上是否有新数据。如果不下载它,真的没有什么好方法可以查看该文件中的内容。更好的是在您的应用程序可以查询的服务器上放置一些东西,以确定它是否需要下载新数据。

我建议做一些事情,比如在文件上使用时间戳。如果您正确执行此操作,您可能会利用NSURLCache为您处理一些逻辑。

祝你好运!

于 2013-08-27T00:43:06.797 回答