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;
    } | 
Partager