我試圖插入兩個新列到我的SQLite數據庫,如果列不可用。一切都很好,並且「添加」BOOL是YES。但是這些專欄不在我的桌子上!在iOS中添加新列到SQLite
-(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);
}
}
所以,你準備語句,然後....什麼。您還沒有閱讀過如何正確使用sqlite3。 – Droppy
是的,這是問題,你有鏈接或遵循什麼? @Droppy – Rudi
這裏是[一](http://www.wassen.net/sqlite-c.html)。我只是簡單地搜索「使用sqlite3_prepare_v2」。 – Droppy