まずは、SQLiteデータベースへの接続方法です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | private var sqlConn:SQLConnection; private var sqlStmt:SQLStatement; public function sqlConnect():void { trace("sqlConnect"); sqlConn = new SQLConnection(); var dbFolder:File = File.applicationDirectory; var dbPath:File = dbFolder.resolvePath(MySQLQuery.STR_DB_NAME); sqlConn.addEventListener(SQLEvent.OPEN, dbOpenHandler); sqlConn.addEventListener(SQLErrorEvent.ERROR, errorHandler); sqlConn.open(dbPath); } |
次に、SQL(Select, Insert, Update, Delete etc.)文の発行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | public function selectData():void { trace("selectData"); sqlStmt = new SQLStatement(); sqlStmt.sqlConnection = sqlConn; sqlStmt.text = MySQLQuery.strSelectQuery; sqlStmt.addEventListener(SQLEvent.RESULT, selectDataHandler); sqlStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); sqlStmt.execute(); } public function insertData():void { trace("insertData"); sqlStmt = new SQLStatement(); sqlStmt.sqlConnection = sqlConn; sqlStmt.text = MySQLQuery.strInsertQuery; sqlStmt.addEventListener(SQLEvent.RESULT, insertDataHandler); sqlStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); sqlStmt.execute(); } public function updateData():void { trace("updateData"); sqlStmt = new SQLStatement(); sqlStmt.sqlConnection = sqlConn; sqlStmt.text = MySQLQuery.strUpdateQuery; sqlStmt.addEventListener(SQLEvent.RESULT, updateDataHandler); sqlStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); sqlStmt.execute(); } public function deleteData():void { trace("deleteData"); sqlStmt = new SQLStatement(); sqlStmt.sqlConnection = sqlConn; sqlStmt.text = MySQLQuery.strDeleteQuery; sqlStmt.addEventListener(SQLEvent.RESULT, deleteDataHandler); sqlStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); sqlStmt.execute(); } |
そして、イベントハンドラー
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | private function selectDataHandler(event:SQLEvent):void { trace("selectDataHandler"); getDataResult(); } private function insertDataHandler(event:SQLEvent):void { trace("insertDataHandler"); selectData(); } private function updateDataHandler(event:SQLEvent):void { trace("updateDataHandler"); selectData(); } private function deleteDataHandler(event:SQLEvent):void { trace("deleteDataHandler"); selectData(); } private function errorHandler(event:SQLErrorEvent):void { trace("errorHandler"); trace(event.error.message); } |
最後にデータ取得
1 2 3 4 5 6 7 | private function getDataResult():void { trace("getDataResult"); var dataResult:SQLResult = sqlStmt.getResult(); m_objData = dataResult.data; } |
http://www.necst.co.jp/product/umiswc/column/air/chap8.html
http://www.mztm.jp/2013/04/01/sqlite/
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d4c.html
http://www.youtube.com/watch?v=_RFQ55y_2LU
http://code.jeffm.me/lang/as3/saving-data-into-sqlite-with-adobe-air-flash-and-android
http://blog.livedoor.jp/s26_fla/archives/cat_151032.html
http://chitose-web.blogspot.com/2012/02/adobe-airsqlite.html
0 件のコメント:
コメントを投稿