-(NSMutableArray*) fetchMakeNamesYear1:(int) year1 Year2:(int) year2 compileStaement: (sqlite3_stmt*)compiledStatement
{
NSMutableArray *makeNames=[NSMutableArray array];
NSString *selectQuery=[NSString stringWithFormat:@"SELECT DISTINCT Make FROM Inventory WHERE [Year] BETWEEN 2009 AND 2012 AND Make IS NOT NULL ORDER BY Make",year1 ,year2 ];
// if (sqlite3_exec(((StorageManager*)[StorageManager sharedStorageManager]).database, [selectQuery cStringUsingEncoding:NSUTF8StringEncoding], NULL, NULL, NULL) == SQLITE_OK)
// {
//
// }
if(sqlite3_prepare_v2(((StorageManager*)[StorageManager sharedStorageManager]).database, [selectQuery UTF8String] , -1, &compiledStatement, NULL) != SQLITE_OK)
{
return nil;
}
while (sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSLog(@"return TYpe: %d",sqlite3_column_type(compiledStatement, 5));
if (sqlite3_column_text(compiledStatement, 5)!= NULL)
{
**NSString *makeName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)];**
[makeNames addObject:makeName];
}
sqlite3_reset(compiledStatement);
}
[self finalize:compiledStatement];
return makeNames ;
由sqlite3_column_text返回的值(compiledStatement,5)是NULL。
在我的數據庫中,第5列的數據類型是nvarchar [50]。
它的列名是「製作」
我的表名是「庫存」
在上面的例子中我已經爲,並從今年硬編碼值。
我在sqlite管理器中嘗試了相同的sql查詢,我發現數據顯示所有make名稱。 我還發現sqlite3_column_type(compileStatement,5)回退5(SQLITE_NULL 5),但根據我的列類型它應該是3(SQLITE_TEXT 3)
有人可以洞察上述行爲嗎?
謝謝,我在這裏犯了一個大錯。我是根據不同領域排列在表中的索引來理解專欄。保存了我的時間:) – Rahul