[英]Why does sqlite3_bind_int not appear to be working in my code?
Hi I am new to iphone, i tried to select the values from database i gave the conditions through sqlite3_bind_int() everything worksfine (ie. Database is opened) but when i compile the line sqlite3_step(statement) it is not fetching the values but according to my query it should fetch values. 嗨,我是iphone的新手,我试图从数据库中选择值,我通过sqlite3_bind_int()给出了条件,一切正常(例如,数据库已打开),但是当我编译行sqlite3_step(statement)时,它未获取值,但根据对我的查询它应该获取值。 I dont know weather the values are binded. 我不知道这些值是否绑定。
After the values are binded with sqlite3_bind_int() how to check the complete query through NSLog(). 将值与sqlite3_bind_int()绑定后,如何通过NSLog()检查完整的查询。
Below is the code i have used, plz help me 以下是我使用的代码,请帮我
- (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);
}
Thanks in advance 提前致谢
您的sql应该显示为:
sql="select name,address,phonenumber from doctorlist where sno between ?1 and ?2";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.