Salut à tous,

Je code sur Objective C.

J'ai une requete SQL ci dessous qui fonctionne bien sans WHERE.
Mais dès que je mets une condition WHERE, lorsque la condition est rempli celà marche par contre dès que la condition n'est pas remplie ca plante et ca donne :

2013-11-07 17:17:02.605 Footix[6296:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:

.....


libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) .
Comment cela se fait et comment puis je éviter ce plantage merci pour votre aide.

la commande SQL :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
const char *sql = "SELECT id, intitule, nbonnereponse, reponse1, reponse2,reponse3,reponse4 FROM  tabledesquestions WHERE nbonnereponse <> 1"
partie du code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- (NSMutableArray *) getaquestion{
    NSMutableArray *QuestionArray = [[NSMutableArray alloc] init];
    @try {
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"questions.sqlite"];
        BOOL success = [fileMgr fileExistsAtPath:dbPath];
        if(!success)
        {
            NSLog(@"Cannot locate database file '%@'.", dbPath);
        }
        if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
        {
            NSLog(@"An error has occured.");
        }
 
        const char *sql = "SELECT id, intitule, nbonnereponse, reponse1, reponse2,reponse3,reponse4 FROM  tabledesquestions WHERE nbonnereponse <> 1";
        sqlite3_stmt *sqlStatement;
        if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
        {
            NSLog(@"Problem with prepare statement");
        }
 
        //
        while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
            ListeQuestions *MaQuestion = [
[ListeQuestions alloc]init];
 
 
            MaQuestion.questionId = sqlite3_column_int(sqlStatement, 0);
             MaQuestion.numreponse = sqlite3_column_int(sqlStatement, 2);
 
 
            //pour les CHAR
            MaQuestion.intquestion = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
 
 
            //pour les Images
            const char *raw1 = sqlite3_column_blob(sqlStatement, 3);
            int rawLen1 = sqlite3_column_bytes(sqlStatement, 3);
            NSData *data1 = [NSData dataWithBytes:raw1 length:rawLen1];
            MaQuestion.reponse1 = [[UIImage alloc] initWithData:data1];
 
            const char *raw2 = sqlite3_column_blob(sqlStatement, 4);
            int rawLen2 = sqlite3_column_bytes(sqlStatement, 4);
            NSData *data2 = [NSData dataWithBytes:raw2 length:rawLen2];
            MaQuestion.reponse2 = [[UIImage alloc] initWithData:data2];
 
 
            [QuestionArray addObject:MaQuestion];
 
        }
    }
    @catch (NSException *exception) {
        NSLog(@"An exception occured: %@", [exception reason]);
    }
    @finally {
        return QuestionArray;
    }