我想将表从 aDB 复制到另一个 bDB。
所以我做了一个方法。我认为打开 2 数据库和使用插入查询会起作用,但我不知道详细方法。
-(void)copyDatabaseTableSoruceFileName:(NSString *)source CopyFileName:(NSString *)copy
{
sqlite3 *sourceDatabase=NULL;
sqlite3 *copyDatabase=NULL;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDir = [paths objectAtIndex:0];
//source
[self copyFileIfNeed:source path:documentDir];
NSString *SourceDBPath = [documentDir stringByAppendingPathComponent:source];
if( sqlite3_open([SourceDBPath UTF8String],&sourceDatabase)!= SQLITE_OK )
{
NSLog(@"DB File Open Error :%@", SourceDBPath);
sourceDatabase = NULL;
}
//copy
[self copyFileIfNeed:copy path:documentDir];
NSString *CopyDBPath = [documentDir stringByAppendingPathComponent:copy];
if( sqlite3_open([CopyDBPath UTF8String],©Database)!= SQLITE_OK )
{
NSLog(@"DB File Open Error :%@", CopyDBPath);
copyDatabase = NULL;
}
//source to copy
// How in this area?
}
这样对吗?以及如何制作更多?//复制区域的源。