Jaffe的分享空間 Rotating Header Image

Xcode SQLite sqlite3_prepare_v2 sqlite3_step 新疑團

被奇怪既問題困擾左三個鐘, 本來看似好細既問題, 但可能太夜, 人太累,真係摸不著頭腦!

if (sqlite3_step(statement) == SQLITE_ROW) {
if (sqlite3_column_int(statement, 0) <= 0) {
// if first result = 0, then exit
sqlite3_close(myDB);
return;
}
}

行完呢句之後,如果resultset第一個數真係0的話,呢個function就會close database再return…

問題就係,之後既所有database action都會fail! google左好耐,sqlite3_clear_bindings, sqlite3_reset, sqlite3_finalize都試過晒,一樣唔掂!

最後,唯有出絕招,就係用個while loop process晒整個result set先順利咁走, 嘿,又真係無事!真係好奇!

while (sqlite3_step(statement) == SQLITE_ROW) {
value = sqlite3_column_int(statement, 0);
}

if (value == 0) {
sqlite3_close(myDB);
return;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: