0
我有兩個表'table1'和'table_00'。我想從表1還可以將一些數據table_00無法在iOS中使用多條語句在sqlite中將數據從一個表插入另一個表
我有這樣的方法,這樣做:
- (void)moveData {
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
databasePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"MYDB_3.db"]];
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &myDatabase) == SQLITE_OK) {
NSString *[email protected]"INSERT INTO TABLE_00 SELECT * FROM TABLE_1 WHERE ID=00000" ;
const char *insert_stmt = [insertSQL UTF8String];
//i am using only one 'insertSQL', i put two 'insertSQL' strings here for reference
//mulitple statements
NSString *[email protected]"INSERT INTO TABLE_00 SELECT * FROM TABLE_1 WHERE UTILITYID='00000';"
"INSERT INTO TABLE_01 SELECT * FROM TABLE_1 WHERE UTILITYID='00001';"
"INSERT INTO TABLE_02 SELECT * FROM TABLE_1 WHERE UTILITYID='00002';"
"INSERT INTO TABLE_03 SELECT * FROM TABLE_1 WHERE UTILITYID='00003';";
//this multiple query statement is not working
sqlite3_prepare_v2(myDatabase, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE) {
NSLog(@"data moved");
} else {
NSLog(@"data not moved");
}
sqlite3_finalize(statement);
sqlite3_close(myDatabase);
}
我把這種方法後,我可以用一個查詢移動數據,但是,我不能通過使用多個語句來移動數據。請告訴我爲什麼會發生這種情況?
在此先感謝。
嗨,我這樣做,和它說的數據移動,但是當我檢查到該表中,沒有數據 – 2014-10-03 20:21:08
是文字實際上 – 2014-10-03 20:26:48
我做到了,它工作。但我試圖用多個語句來做同樣的事情,在這種情況下,只有第一個語句執行。看看這個問題,我會再次修改它! – 2014-10-03 20:30:33