我可以将这两个查询结合起来吗?
我在第二个查询中找不到表的错误,我认为这与第一个查询中的一些 sqlite 调用有关。
NSString *dayName = del.dayName;
int rowCount = del.tableRowNumber;
NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"banklist" ofType:@"sqlite3"];
if(sqlite3_open([sqLiteDb UTF8String], &_database) == SQLITE_OK)
{
NSString *sqlStatement = [NSString stringWithFormat:@"UPDATE %@ SET recipe_name='%@' WHERE cell_id='%i'",dayName, info.name, rowCount];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(_database, [sqlStatement UTF8String] , -1, &compiledStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_text( compiledStatement, 1, [sqLiteDb UTF8String], -1, SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE )
{
NSLog( @"Save Error: %s", sqlite3_errmsg(_database) );
}
else
{
sqlite3_reset(compiledStatement);
}
sqlite3_finalize(compiledStatement);
NSString *sqlStatement2 = [NSString stringWithFormat:@"UPDATE %@ SET recipe_id = (SELECT key FROM recipes WHERE name = Monday.recipe_name)",dayName];
sqlite3_stmt *compiledStatement2;
if(sqlite3_prepare_v2(_database, [sqlStatement2 UTF8String] , -1, &compiledStatement2, NULL) == SQLITE_OK)
{
sqlite3_bind_text( compiledStatement2, 1, [sqLiteDb UTF8String], -1, SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement2) != SQLITE_DONE )
{
NSLog( @"Save Error: %s", sqlite3_errmsg(_database) );
}
else
{
sqlite3_reset(compiledStatement2);
}
sqlite3_finalize(compiledStatement2);
}
sqlite3_close(_database);
谢谢