您好我是iphone的新手,我试图从数据库中选择值我通过sqlite3_bind_int()给出条件一切正常(即数据库打开)但是当我编译行sqlite3_step(语句)时它没有取出值,但根据我的查询,它应该获取值。我不知道天气这些数值是否合并。
使用sqlite3_bind_int()绑定值后,如何通过NSLog()检查完整查询。
以下是我用过的代码,请帮助我
- (void) getDataToDisplay:(NSString *)dbPath
{
if (sqlite3_open([dbPath UTF8String], &MYDB) == SQLITE_OK)
{
const char *sql;
sql="select name,address,phonenumber from doctorlist where sno between %d and %d";
if(sqlite3_prepare_v2(MYDB, sql, -1, &mystmt, NULL) != SQLITE_OK)
{
NSLOG(@"Insert Values");
}
sqlite3_bind_int(mystmt,1,10);
sqlite3_bind_int(mystmt, 2,15);
while(sqlite3_step(mystmt) == SQLITE_ROW)
{
[DoctorName addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 0)]]];
[DoctorAddress addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 1)]]];
[PhoneNumber addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 2)]]];
}
}
sqlite3_reset(mystmt);
if(MYDB)sqlite3_close(MYDB);
}
提前致谢
答案 0 :(得分:1)
你应该读取:
sql="select name,address,phonenumber from doctorlist where sno between ?1 and ?2";