在objective-c中是否有sqlite .dump等价物? [英] Is there a sqlite .dump equivalent in objective-c?

查看:113
本文介绍了在objective-c中是否有sqlite .dump等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iOS应用程序,允许用户使用GameKit通过蓝牙同步他们的sqlite数据库。有没有办法在sqlite shell上使用任何一个sqlite objective-c库执行等效的.dump?

I'm trying working on an iOS app that would allow users to sync their sqlite databases via Bluetooth using GameKit. Is there a way to perform the equivalent of .dump on the sqlite shell using any of the many sqlite objective-c libraries?

推荐答案

您可以创建备份数据库文件,将其发送,然后在目标设备上进行合并。创建备份文件的代码如下:

You can create a backup database file, send that over and then do the merging on the destination device. The code to create the backup file is as follows:

- (void) exportDB {

   sqlite3 *sourceDB, *destinationDB;
   sqlite3_backup *sql3Backup;

   NSString *sourceDBPath = @"/path/to/source/database";
   NSString *destinationDBPath = @"/path/to/destination/database";

   if(sqlite3_open([sourceDBPath UTF8String],&sourceDB) != SQLITE_OK){
       NSLog(@"%s\n",sqlite3_errmsg(sourceDB));
       return ;
   }

   if(sqlite3_open([destinationDBPath UTF8String],&destinationDB) != SQLITE_OK){
       sqlite3_close(sourceDB);
       NSLog(@"%s\n",sqlite3_errmsg(destinationDB));
       return;
   }

   sql3Backup = sqlite3_backup_init(destinationDB,"main",sourceDB,"main");
   if(sql3Backup == NULL){
       sqlite3_close(sourceDB);
       sqlite3_close(destinationDB);
       NSLog(@"%s\n",sqlite3_errmsg(destinationDB));
       return;
   }

   if(sqlite3_backup_step(sql3Backup, -1) != SQLITE_DONE){
       NSLog(@"%s\n",sqlite3_errmsg(destinationDB));
       return;
   }

   if(sqlite3_backup_finish(sql3Backup) != SQLITE_OK){
       NSLog(@"%s\n",sqlite3_errmsg(destinationDB));
       return;
   }

   sqlite3_close(sourceDB);
   sqlite3_close(destinationDB);
}

这篇关于在objective-c中是否有sqlite .dump等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆