簡體   English   中英

帶有NSInvocation方法參數的函數

[英]Function with argument to a NSInvocation method

我有誰正在使用那些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];

因此,在我的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);
}

問題在於第二個函數無法正常工作(庫例程按順序調用),因為我已經以相同的方式調用了第一個函數(我想能夠同時使用參數執行許多查詢)。 我聽說使用NSInvocation可以解決此問題,但是我不知道如何使用NSInvocation轉換代碼。 有人可以幫我嗎?

最好的祝福,

您可能遇到的問題是,在sqlite3_close之后,您准備的語句無效。 每次打開數據庫時,都需要創建一個新的准備好的語句。

  1. 使用sqlite3_open打開數據庫。
  2. sqlite3_prepare和朋友准備語句。
  3. sqlite3_bind綁定。
  4. 使用sqlite3_step
  5. 然后,確保您調用sqlite3_finalize
  6. 使用sqlite3_close關閉數據庫。

您不能只重置該語句,因為該語句是為其他數據庫句柄准備的。

NB

我對SQLite不太熟悉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM