我的应用中有两个数据库(customerDB& s-customerDB)。我想将customerDB信息传输到s-customerDB。 我使用以下步骤, 1.打开s-customerDB。 2. Attach和insert语句返回成功resultCode。
但是“select”查询返回0对象。
请指导我做错了什么。
NSString *tempString = [[NSString alloc]initWithString:@" attach DATABASE 'customerDB.db' as customer "];
int resultCode = sqlite3_exec(_database, [tempString UTF8String], NULL, NULL, NULL);
[tempString release]; tempString = nil;
if (resultCode == SQLITE_OK) //Working
{
NSString *table = [[NSString alloc]initWithString:@"Employee"];
tempString = [[NSString alloc]initWithString:@"INSERT INTO"];
tempString = [tempString stringByAppendingFormat:@" %@ select * from customer.%@ ",table,table];
sqlite3_stmt *stmt_version = 0x00;
resultCode = sqlite3_prepare_v2(_database, [tempString UTF8String], -1, &stmt_version, NULL);
[tempString release]; tempString = nil;
sqlite3_finalize(stmt_version);
NSArray *tempArraty = [self executeSelectSqlQuery:@"select * from Employee" error:nil];
if (resultCode == SQLITE_OK) //Working
{
return YES;
}
答案 0 :(得分:0)
我在代码中发现了问题。我必须使用sqlite3_exec而不是sqlite3_prepare_v2来执行插入查询。