Xcode,在iPhone上非常奇怪的SQLite SQL SELECT LIKE问题

时间:2012-06-06 16:00:08

标签: iphone sqlite select

我为我的iPhone制作了一个SQLite应用程序。 当我在放置在iMac上的SQLite数据库上测试我的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);
}

1 个答案:

答案 0 :(得分:0)

解决 - 查看评论。我仍然不能100%确定为什么/如何解决这个问题..