从数据库中选择数据时出现问题。我使用以下查询在数据库中创建了“文件夹表”
CREATE TABLE foldertable(fid integer primary key autoincrement,foldername text);
这是我根据 fid(folderid) 获取文件夹名称的代码
-(NSString *)getFolderFromDatabase:(int)folderId
{
NSString * retriveFolderName;
UIApplication * application=[UIApplication sharedApplication];
ScrapMemoAppDelegate * appDelegate=application.delegate;
NSString * destinationPath=[appDelegate getDestinationPath];
sqlite3 * database;
int retriveWhere=folderId;
if(sqlite3_open([destinationPath UTF8String], &database)==SQLITE_OK)
{
const char * query="select foldername from foldertable where fid = ?;";
sqlite3_stmt * statement;
if(sqlite3_prepare_v2(database, query, -1, &statement, NULL)==SQLITE_OK)
{
if (sqlite3_step(statement)==SQLITE_DONE)
{
sqlite3_bind_int(statement, 1, retriveWhere);
retriveFolderName=[NSString stringWithCString:sqlite3_column_text(statement,0) encoding:NSASCIIStringEncoding];
}
else
{
NSLog(@"Error %s",sqlite3_errmsg(database));
}
sqlite3_reset(statement);
}
sqlite3_close(database);
}
return retriveFolderName;
}
但是当我在终端上触发相同的查询时,我得到了空文件夹名称,它给出了正确的名称。请为我提供解决方案。