Search code examples
iphoneobjective-cnsinvocation

Function with argument to a NSInvocation method


I have a controller view who is using thoses 2 functions:


[appDelegate getFichesInfo:[[self.fichesCategory idModuleFiche] intValue] ]; //first function
self.fiche = (Fiche *)[appDelegate.fichesInfo objectAtIndex:0];


[appDelegate getFichesVisuels:[[self.fiche idFiche] intValue] ];  //second function not working
self.fiche = (Fiche *)[appDelegate.fichesInfo objectAtIndex:0];

So in my ressourceManager, here is the 2nd function in details:


- (void)getFichesVisuels:(int)value {

    fichesVisuels = [[NSMutableArray alloc] init];

    sqlite3 *database;

    if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) {
        sqlite3_reset(getFichesVisuelsStatement);


        sqlite3_bind_int(getFichesVisuelsStatement, 1,  value);

        while(sqlite3_step(getFichesVisuelsStatement) == SQLITE_ROW) {


            NSString *aTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(getFichesVisuelsStatement , 7)];
            NSString *aLpath = [NSString stringWithUTF8String:(char *)sqlite3_column_text(getFichesVisuelsStatement , 8)];

            Visuel *visuel = [[Visuel alloc] initWithName:aTitle lpath:aLpath];

            [fichesVisuels addObject:visuel];
        }

    }
    sqlite3_close(database);
}

The problem is that the 2nd function is not working (librairies routine called out of sequence) because I am already calling the 1st function in the same way (I wanna be able to execute many query using arguments in the same times). I heard that using NSInvocation can be the solution to this problem, but I don't know how to turn my code using NSInvocation. Someone can help me?

Best Regards,


Solution

  • The problem you could be having is that your prepared statement is invalid after sqlite3_close. You need to create a new prepared statement each time you open the database.

    1. Open the database with sqlite3_open.
    2. Prepare the statement with sqlite3_prepare and friends.
    3. Bind with sqlite3_bind.
    4. Step with sqlite3_step.
    5. Afterwards, ensure you call sqlite3_finalize.
    6. Close the database with sqlite3_close.

    You can't just reset the statement, because that statement was prepared for a different database handle.

    NB

    I'm not too familiar with SQLite.