简体   繁体   English

带有NSInvocation方法参数的函数

[英]Function with argument to a NSInvocation method

I have a controller view who is using thoses 2 functions: 我有谁正在使用那些2函数的控制器视图:


[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: 因此,在我的ressourceManager中,下面是第二个函数的详细信息:


- (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. 我听说使用NSInvocation可以解决此问题,但是我不知道如何使用NSInvocation转换代码。 Someone can help me? 有人可以帮我吗?

Best Regards, 最好的祝福,

The problem you could be having is that your prepared statement is invalid after sqlite3_close . 您可能遇到的问题是,在sqlite3_close之后,您准备的语句无效。 You need to create a new prepared statement each time you open the database. 每次打开数据库时,都需要创建一个新的准备好的语句。

  1. Open the database with sqlite3_open . 使用sqlite3_open打开数据库。
  2. Prepare the statement with sqlite3_prepare and friends. sqlite3_prepare和朋友准备语句。
  3. Bind with sqlite3_bind . sqlite3_bind绑定。
  4. Step with sqlite3_step . 使用sqlite3_step
  5. Afterwards, ensure you call sqlite3_finalize . 然后,确保您调用sqlite3_finalize
  6. Close the database with sqlite3_close . 使用sqlite3_close关闭数据库。

You can't just reset the statement, because that statement was prepared for a different database handle. 您不能只重置该语句,因为该语句是为其他数据库句柄准备的。

NB NB

I'm not too familiar with SQLite. 我对SQLite不太熟悉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM