【问题标题】:Variables/parameters in Sqlite query for Iphone AppIphone App 的 Sqlite 查询中的变量/参数
【发布时间】:2009-12-11 16:07:39
【问题描述】:

在我的 Iphone 应用中,我创建了这个查询:

"SELECT * FROM visuel where id_visuel = 1"

所以我有这个功能非常好:

- (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,但我不知道该怎么做。

谢谢,

【问题讨论】:

    标签: iphone objective-c sqlite


    【解决方案1】:

    好吧,首先将您的查询更改为参数化查询,就像您在那里一样。然后,就在您调用sqlite3_step 之前,将正确的 id 绑定到参数:

    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) {
    

    【讨论】:

    • 感谢您的帮助。但是现在,如果我按照你说的做,我必须正确:对于 visuelId =1 做那个... visualId =2 做那个............我已经创建了一个 UITableView 并且我想要例如将行号放置为 visuelId。何人这样做?
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 2011-11-16
    • 2013-02-13
    • 2017-05-10
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多