开发者

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 :

  1. Create a temporary table.
  2. Put all the data in it.
  3. Drop the initial table.
  4. Create a table with the new field.
  5. Send data from the temporary table to the new table

If you want more help, give us your table structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜