root/as3/SQLControls/src/org/libspark/snippets/controls/SQLList.as

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

First release

  • svn:executable 属性の設定値: *
Line 
1 /**
2  * The SQL List Class for AIR Application
3  *
4  * @author      Copyright (c) 2008 daoki2
5  * @version     1.0.0
6  * @link        http://snippets.libspark.org/
7  * @link        http://homepage.mac.com/daoki2/
8  *
9  * Copyright (c) 2008 daoki2
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  */
29
30 package org.libspark.snippets.controls {
31     import flash.data.SQLConnection;
32     import mx.controls.Alert;
33     import mx.controls.List;
34     import org.libspark.utils.SqlUtil;
35
36     public class SQLList extends List {
37         public var sqlConnection:SQLConnection = null;
38         public var delimiter:String = "";
39
40        /**
41         * Constructor
42         */
43         public function SQLList() {
44           super();
45         }
46
47        /**
48         * Execute SQL and apply to DataGrid
49         * @param        sql     The SQL statement to execute
50         */
51         public function executeQuery(sql:String):void {
52             if (sqlConnection == null) {
53                 Alert.show("sqlConnection is null", "ERROR!");
54                 return;
55             }
56             if(!sqlConnection.connected) {
57                 Alert.show("SQLConnection is not connected", "ERROR!");
58                 return;
59             }
60             var result:Array = SqlUtil.getData(sqlConnection, sql);
61             var query:Array = new Array();
62             if (result != null) {
63                 if (result[1].data != null) {
64                     var dataLength:Number = result[1].data.length;
65                     for (var i:uint = 0; i < dataLength; i++) {
66                         var txt:String = "";
67                         for each (var val:* in result[0]) {
68                             txt += result[1].data[i][val] + delimiter;
69                         }
70                         query.push(txt.substring(0, txt.length - delimiter.length));
71                     }
72                 }
73             }
74             this.dataProvider = query;
75         }
76     }
77 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。