sqlite3 alter command delete my db
In the begininng of my app, i am running a sqlite3 command on existing sqlite3 DB. The command goes like that:
sqlStmt = "ALTER TABLE projects ADD COLUMN guid integer DEFAULT 0";开发者_运维知识库
if (sqlite3_prepare_v2(db, sqlStmt, -1, &compiledStmt, NULL) == SQLITE_OK){
sqlite3_step(compiledStmt);
}
what happens is that all my data is lost, and a "journal" file is showing (and never deleted). I don't what to do - i understand it has something to do with transactions and locking. Please help.
This is a normal behavior since Sqlite doesn't support complex operations. Please, refer to the documentation.
So, all you have to do is :
- Create a temporary table.
- Put all the data in it.
- Drop the initial table.
- Create a table with the new field.
- Send data from the temporary table to the new table
If you want more help, give us your table structure.
精彩评论