root/as3/SQLControls/samples/SQLiteViewer/SQLiteViewer.as

リビジョン 195, 2.4 kB (コミッタ: daoki2, コミット時期: 4 年 前)

Add directory

  • svn:executable 属性の設定値: *
Line 
1 import flash.events.*;
2 import mx.events.*;
3 import mx.collections.ArrayCollection;
4 import flash.filesystem.*;
5 import flash.net.FileFilter;
6 import flash.data.*;
7 import org.libspark.utils.SqlUtil;
8 import org.libspark.snippets.controls.SQLDataGrid;
9 import org.libspark.snippets.controls.SQLTableGrid;
10 import mx.containers.TitleWindow;
11
12 private var connection:SQLConnection = null;
13
14 private function bDBOpen_click(event:MouseEvent):void {
15     var dbFile:File = null;
16     if (tDBFilename.text == "") {
17         dbFile = new File();
18         var dbFilter:FileFilter = new FileFilter("DB File", "*.db");
19         try {
20             dbFile.browseForOpen("Open", [dbFilter]);
21             dbFile.addEventListener(Event.SELECT, dbFileSelected);
22         } catch (error:Error) {
23             trace("Failed:", error.message);
24         }
25     } else {
26         dbFile = new File("file://" + tDBFilename.text);
27         GetTableList(dbFile);
28     }
29 }
30
31 private function dbFileSelected(event:Event):void {
32     tDBFilename.text = event.target.nativePath;
33     GetTableList(File(event.target));
34 }
35
36 [Bindable]
37 private var lTableList_data:ArrayCollection = new ArrayCollection();
38
39 private function GetTableList(file:File):void {
40     if (connection != null) {
41         if (connection.connected) {
42             try {
43                 connection.close();
44             } catch (error:Error) {
45                 trace("Failed:", error.message);
46             }
47         }
48     }
49
50     connection = new SQLConnection();
51     try {
52         connection.open(file, SQLMode.READ);
53         var _tableList:Array = SqlUtil.getTableList(connection);
54         for each(var val:* in _tableList)
55             lTableList_data.addItem(val);
56         dbTable.sqlConnection = connection;
57         dbQuery.sqlConnection = connection;
58     } catch (error:Error) {
59         trace("Failed:", error.message);
60     }
61 }
62
63 private function lTableList_change(event:ListEvent):void {
64     dbTable.getColumnInfo(String(List(event.target).selectedItem));
65 }
66
67 private function bSQLExec_click(event:MouseEvent):void {
68     dbQuery.executeQuery(tSQLStatement.text);
69 }
70
71 private var dbQuery:SQLDataGrid = null;
72 private var dbTable:SQLTableGrid = null;
73
74 private function init():void {
75     dbTable = new SQLTableGrid();
76     dbTable.x = 290; dbTable.y = 60; dbTable.width = 490; dbTable.height = 205;
77     addChild(dbTable);
78     dbQuery = new SQLDataGrid();
79     dbQuery.x = 20; dbQuery.y = 320; dbQuery.width = 760; dbQuery.height = 260;
80     addChild(dbQuery);
81 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。