mercredi 16 septembre 2015

ViewController receiving ID instead of the data from a SQLite query

I have a view having a Database which has a 'word' table (stores words) and I want to retrieve and send the data to another ViewController, but instead of receiving the actual word, I am getting the id.

Here is my code.

(void)getListData {

//tableData = [[NSMutableArray alloc]init];
sqlite3_stmt *statement;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dexternotedb.sqlite"];

if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
    WordListViewController *temp = APP_DELEGATE.wordListViewController;
    NSLog(@"word id %ld",(long)[temp.wordId integerValue]);

    NSString *sql=[NSString stringWithFormat:@"SELECT * FROM words WHERE word_id=\"%@\"",APP_DELEGATE.wordListViewController.wordId];
    const char *read_stmt = [sql UTF8String];
    NSLog(@"select query%@",sql);


    if(sqlite3_prepare_v2(database, read_stmt, -1, &statement, NULL) == SQLITE_OK){
        sqlite3_bind_int(statement, 1, [temp.wordId integerValue]);

       while(sqlite3_step(statement) == SQLITE_ROW) {
           NSString *word1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
           [word addObject:word1];
           NSString *meaning1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
           [meaning addObject:meaning1];

           NSString *sentence1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
           [Sentence addObject:sentence1];

       }


    sqlite3_finalize(statement);
} else {
            sqlite3_close(database);
            NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));

}

Aucun commentaire:

Enregistrer un commentaire