我正在尝试使用iOS应用程序,允许用户使用GameKit通过蓝牙同步他们的sqlite数据库。有没有办法在sqlite shell上使用任何一个sqlite objective-c库执行等效的.dump?
答案 0 :(得分:3)
您可以创建备份数据库文件,将其发送,然后在目标设备上进行合并。创建备份文件的代码如下:
- (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);
}
答案 1 :(得分:-1)
我不这么认为。但是,您可以执行SELECT *语句,然后在回调函数中迭代argc。
像
这样的东西void callback (void *param, int argc, char **argv, char **azColName)
{
for(int i=0;i<argc;i++)
{
get ... azColName[i] ... argv[i]
}
}