jeudi 16 juillet 2015

Save information from NSTextField in sqlite database (objective-c)

Since some months I am interested in coding. At the moment I am working on a programm which saves informations from textfields in a sqlite3 database. I am programming this project on Objective C in Xcode for Mac. Unfortunately I have problems in inserting data into my database. When I insert it and open my database in Terminal I just get this information in the cell for the string:

Here ist my code:

NSString *Bt = [NSString stringWithFormat:@"%@", Text]; //Theres a IBOutlet NSTextField  *Text; in the Header data of the class


dbPath=@"/Users/Desktop/database.db";

if (sqlite3_open([dbPath UTF8String], &database)!=SQLITE_OK) {
    sqlite3_close(database);
    NSLog(@"Failed to open database");
} else {
    char *errorMessage;
    NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO table (table) VALUES (\"%@\")", Bt];
    const char *insert_stmt = [insertSQL UTF8String];
    if(sqlite3_exec(database, insert_stmt, NULL, NULL, &errorMessage)==SQLITE_OK){
        NSLog(@"Data inserted");
        [db_status setFloatValue:5];
    }

}

}

It would be great if somebody can help me. I think it is just a small error but I don´t get the problem ;(

Best regards, Robby

Aucun commentaire:

Enregistrer un commentaire