我为我的 iPhone 制作了一个 SQLite 应用程序。当我在我的 iMac 上的 SQLite DB 上测试我的 SELECT 时,一切正常,但是在 iPhone 上我没有返回任何行。
SELECT ID, SAP_PART_NR, SAP_DESC, MOQ, INC, NLT, DISCOUNT_CODE, AD_EURO, AD_USD, OEM_EURO, OEM_USD FROM Component WHERE SAP_PART_NR LIKE '%AWM423%' LIMIT 200
现在奇怪的部分
当我在 iPhone 上使用下面的选择时,一条记录返回 SAP_PART_NR AWM42300V
SELECT ID, SAP_PART_NR, SAP_DESC, MOQ, INC, NLT, DISCOUNT_CODE, AD_EURO, AD_USD, OEM_EURO, OEM_USD FROM Component WHERE SAP_PART_NR LIKE '%AWM42%' LIMIT 200
在 iMac 上测试时,两个选择都返回一行(应该如此)
这是 iPhone/SQlite 上的某种错误吗?
我无法弄清楚....我所有的头发都变白了....:-(
非工作代码(未选择行)
-(void) searchDB:(NSString *)strSearch {
NSString *wildcardSearch = [NSString stringWithFormat:@"%%%@%%", strSearch];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if(searchSTMT == nil) {
const char *sql = "SELECT ID, SAP_PART_NR, SAP_DESC, MOQ, INC, NLT, DISCOUNT_CODE, AD_EURO, AD_USD, OEM_EURO, OEM_USD FROM Component WHERE SAP_PART_NR LIKE '%AWM4230%'";
if(sqlite3_prepare_v2(database, sql, -1, &searchSTMT, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating view statement. '%s'", sqlite3_errmsg(database));
}
if(SQLITE_DONE != sqlite3_step(searchSTMT)) {
while(sqlite3_step(searchSTMT) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(searchSTMT, 0);
Database *DatabaseObj = [[Database alloc] initWithPrimaryKey:primaryKey];
DatabaseObj.sapPart = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 1)];
DatabaseObj.sapDesc = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 2)];
DatabaseObj.sapMOQ = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 3)];
DatabaseObj.sapINC = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 4)];
DatabaseObj.sapNLT = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 5)];
DatabaseObj.sapDISCOUNT = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 6)];
DatabaseObj.oemEURO = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 7)];
DatabaseObj.oemUSD = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 8)];
DatabaseObj.adEURO = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 9)];
DatabaseObj.adUSD = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchSTMT, 10)];
[appDelegate.compArray addObject:DatabaseObj];
}
}
else
NSAssert1(0, @"Error while getting the rows. '%s'", sqlite3_errmsg(database));
//Reset the detail statement.
sqlite3_reset(searchSTMT);
}
选择工作代码 1 行
+ (void) getInitialDataToDisplay:(NSString *)dbPath {<p>
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
sqlite3_stmt *selectstmt = NULL;
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT ID, SAP_PART_NR, SAP_DESC, MOQ, INC, NLT, DISCOUNT_CODE, AD_EURO, AD_USD, OEM_EURO, OEM_USD FROM Component WHERE SAP_PART_NR LIKE '%AWM4230%'";
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Database *DatabaseObj = [[Database alloc] initWithPrimaryKey:primaryKey];
DatabaseObj.sapPart = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
DatabaseObj.sapDesc = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
DatabaseObj.sapMOQ = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
DatabaseObj.sapINC = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
DatabaseObj.sapNLT = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
DatabaseObj.sapDISCOUNT = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
//PRICES
DatabaseObj.oemEURO = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
DatabaseObj.oemUSD = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)];
DatabaseObj.adEURO = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 9)];
DatabaseObj.adUSD = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 10)];
[appDelegate.compArray addObject:DatabaseObj];
}
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
sqlite3_reset(selectstmt);
}