0

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

}

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.

Thanks,

1 Answer 1

2

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) {
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that help. But now, If I do what you say I will have to right: for visuelId =1 do that... visualId =2 do that............ I have created a UITableView and I want for example to put the number of the line for the visuelId. Hos to do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.