lundi 8 juin 2015

Add new column to SQLite in iOS

I'm trying to insert two new column to my SQLite database if the column is not available. Everything goes great and also the 'added' BOOL is YES. But these columns are not on my table !

-(void)checkColumnExists
{
    NSString *dbPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"movieData.sqlite"];
    const char *dbpath = [dbPath UTF8String];
    sqlite3 *contactDB;

    sqlite3_open(dbpath, &contactDB);

    sqlite3_stmt *selectStmt;

    const char *sqlStatement = "SELECT borrowMovie from myMovies";
    if(sqlite3_prepare_v2(contactDB, sqlStatement, -1, &selectStmt, NULL) != SQLITE_OK){
        //ALTER TABLE {tableName} ADD COLUMN COLNew {type};
        const char *sqlStatement1 = "ALTER TABLE myMovies ADD COLUMN borrowMovie TEXT, borrowDate TEXT";
        BOOL added = sqlite3_prepare_v2(contactDB, sqlStatement1, -1, &selectStmt, NULL);
    }
} 

Aucun commentaire:

Enregistrer un commentaire