-(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]。
它的列名是“Make”
我的表名是“库存”
在上面的示例中,我为 to 和 from 年份硬编码了值。
我在 sqlite manager 中尝试了相同的 sql 查询,我发现所有品牌名称的数据都显示。我还发现 sqlite3_column_type(compileStatement,5) retuns 5 (SQLITE_NULL 5) 但根据我的列类型它应该是 3 (SQLITE_TEXT 3)
有人可以对上述行为有所了解吗?