开发者

How to reset a sqlite DB in Adobe AIR application

This is for an Adobe AIR HTML/JS application. I'm running the following function from the body tag onLoad and it seems to work ok, but is there a "best practices" way of doing this? I need the DB reset each time the application is started.

function loadAirSql(){

    this.conn = new air.SQLConnection();
    var folder = air.File.applicationStorageDirectory;
    开发者_如何转开发var dbFile = folder.resolvePath("localDBFile.db");
    conn.open(dbFile);

    //make sure DB is reset with each session
    conn.begin();
    var dropStmt = new air.SQLStatement();
    dropStmt.sqlConnection = conn;
    dropStmt.text = "DROP TABLE IF EXISTS myTable";
    dropStmt.execute();
    conn.commit();

    //recreate the sql table
    conn.begin();
    var createStmt = new air.SQLStatement();
    createStmt.sqlConnection = conn;
    createStmt.text = "CREATE TABLE IF NOT EXISTS myTable (myTableID INTEGER PRIMARY KEY AUTOINCREMENT, myColumn TEXT)";
    createStmt.execute();
    conn.commit();

};


Your approach pretty much is best practice for resetting any database. I'm just wondering, if you are not keeping data, wouldn't be a LOT easier to just keep your data in a dictionary in memory ?

It surely would save you from writing a lot of SQL :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜