Always when execute the AIR app we can connect with the database file and create the same table and this may do loose data.
The simple way to resolve it is verify if the table is created into database file using a simple SQLite instruction IF NOT EXISTS
One way to resolve this problem is the code bellow. First function only connect with the database.db and the second function will create the table into database. A normal way to create one table, with out verify if the table alread created into database.db, using SQLite instructions is only CREATE TABLE, but it will create always when run app the table. Using IF NOT EXISTS we can resolve it.
private function init():void
{ conn = new SQLConnection(); try { var dbFile:File = File.applicationStorageDirectory.resolvePath("database.db"); conn.open(dbFile); } catch (error:SQLError) { trace("Error opening database"); trace("error.message:", error.message); trace("error.details:", error.details); return; } createTable();} private function createTable():void{ createStmt = new SQLStatement(); createStmt.sqlConnection = conn; var sql:String = ""; sql += "CREATE TABLE IF NOT EXISTS rssURL ("; sql += " id INTEGER PRIMARY KEY AUTOINCREMENT,"; sql += " postName TEXT,"; sql += " postURL TEXT,"; sql += " postText TEXT"; sql += ")"; createStmt.text = sql; try { createStmt.execute(); } catch (error:SQLError) { trace("Error creating table"); trace("CREATE TABLE error:", error); trace("error.message:", error.message); trace("error.details:", error.details); return; }}
+