Iphone App的Sqlite查询中的变量/参数 [英] Variables/parameters in Sqlite query for Iphone App
本文介绍了Iphone App的Sqlite查询中的变量/参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Iphone App中我创建了这个查询:
In my Iphone App I have created this query:
"SELECT * FROM visuel where id_visuel = 1"
所以我有这个功能非常好:
And so I have this function that works very well:
- (void)getVisuel {
visuelArray = [[NSMutableArray alloc] init];
sqlite3 *database;
if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) {
sqlite3_reset(getVisuelStatement);
while(sqlite3_step(getVisuelParcStatement) == SQLITE_ROW) {
NSString *aTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(getVisuelStatement , 2)];
NSString *aLpath = [NSString stringWithUTF8String:(char *)sqlite3_column_text(getVisuelStatement , 3)];
Visuel *aVisuel = [[Visuel alloc] initWithName:aTitle lpath:aLpath];
[visuelArray addObject:aVisuel];
}
}
sqlite3_close(database);
}
我想要的是更改查询像这样:SELECT * FROM visuel where id_visuel =?
我不想拥有静态ID,但我不知道该怎么做。
What I want is to change the query like this: "SELECT * FROM visuel where id_visuel = ?" I don't want to have a static id, but I don't know how to do that.
谢谢,
推荐答案
好吧,首先将查询更改为参数化查询,就像在那里一样。然后,在您调用 sqlite3_step
之前,将正确的id绑定到参数:
Well, first change your query to your parameterized query like you have there. Then, just before you call sqlite3_step
bind the right id to the parameter:
sqlite3_reset(getVisuelStatement);
//Add these two lines
int visuelId = 1; //Put whatever id you want in here.
sqlite3_bind_int(getVisuelParcStatement, 1, visuelId);
while(sqlite3_step(getVisuelParcStatement) == SQLITE_ROW) {
这篇关于Iphone App的Sqlite查询中的变量/参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文