如何在iOS中的一个方法中执行2个Sql查询。如果第二个查询需要在第一个查询结果的基础上执行,则如何执行?怎么做到这一点?我试过'Union
',但却无法实现所需要的东西?
+(void)deleteData{
NSString * docDBPath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/audiocall2.db"];
sqlite3 * db;
int status;
status = sqlite3_open([docDBPath UTF8String], &db);
if( status != SQLITE_OK)
{
NSLog(@"Error opening DB Code : %d",status);
}
const char *sql="SELECT * FROM callhistory GROUP BY number ORDER BY id DESC";
sqlite3_stmt * stmt = NULL;
status = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
if(status != SQLITE_OK)
{
NSLog(@"Error preparing sql %d",status);
}
// if(sqlite3_step(stmt) == SQLITE_DONE)
// {
//
// }
while (sqlite3_step(stmt) == SQLITE_ROW)
{
NSData *image_data=[NSData dataWithBytes:sqlite3_column_blob(stmt,6) length:length];
NSLog(@"Name : %@ Phone : %d :%@ :start %@:end %@:bool %@",name,uniqueid,number,starttime,endtime,connected);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
我需要执行另一个基于第一个查询的查询
第二次查询。
Const char *sql DELETE FROM callhistory WHERE id<'2';