我想将表从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?
} …Run Code Online (Sandbox Code Playgroud)