1
这是针对Adobe AIR HTML/JS应用程序的。我正在从body标签onLoad运行以下函数,它似乎工作正常,但有没有一个“最佳实践”的方式来做到这一点?每次应用程序启动时,我都需要重置DB。如何在Adobe AIR应用程序中重置sqlite数据库
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();
};