出于某种原因,我的应用程序在 "NSAssert1(0, @"Error while looping search view.'%s'", sqlite3_errmsg(database));"处失败 SQL 语句是可以的,因为我在打开数据库时使用了相同的语句。我没有得到任何有用的错误:-(
我对此很陌生,但不是一个完全陌生的人我做错了什么?
请注意,我已取出“strSearch”以确保这不是错误。
- (void)searchComponents:(NSString *)strSearch {
NSString *qry;
qry = [NSString stringWithFormat:@"SELECT ID, ON_SAP, SAP_PART, SAP_DESC, MOQ FROM HONEYWELL WHERE SAP_PART LIKE '%ZX%' ORDER BY SAP_PART", strSearch];
NSLog(@"query : %@", qry);
if(searchStmt == nil) {
if(sqlite3_prepare_v2(database, [qry UTF8String] , -1, &searchStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating search view statement. '%s'", sqlite3_errmsg(database));
}
// Loop through the results
if(sqlite3_step(searchStmt) == SQLITE_ROW) {
// Read the data from the result row
NSLog(@"New row selected");
}
else {
NSAssert1(0, @"Error while looping search view. '%s'", sqlite3_errmsg(database));
}
// Release the compiled statement from memory
sqlite3_finalize(searchStmt);
// Set isDetailViewHydrated as YES, so we do not get it again from the database.
isDetailViewHydrated = YES;
}
该方法在它自己的类(名为 Coffee)中,从 MasterViewController 调用
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"Text changed %@",searchText);
Coffee *coffeObj = [[Coffee alloc] init];
[coffeObj searchComponents:@"%ZX%"];
}
这个想法是在从搜索字段搜索时更改选择语句。有没有人知道这样做的好例子?