-(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