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

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

First release

  • svn:executable 属性の設定値: *
Line 
1 /**
2  * The SQL TextInput 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.TextInput;
34     import org.libspark.utils.SqlUtil;
35
36     public class SQLTextInput extends TextInput {
37         public var sqlConnection:SQLConnection = null;
38         public var delimiter:String = "";
39         public var frontCaption:String = "";
40         public var rearCaption:String = "";
41
42        /**
43         * Constructor
44         */
45         public function SQLTextInput() {
46           super();
47         }
48
49        /**
50         * Execute SQL and apply to DataGrid
51         * @param        sql     The SQL statement to execute
52         */
53         public function executeQuery(sql:String):void {
54             if (sqlConnection == null) {
55                 Alert.show("sqlConnection is null", "ERROR!");
56                 return;
57             }
58             if(!sqlConnection.connected) {
59                 Alert.show("SQLConnection is not connected", "ERROR!");
60                 return;
61             }
62             var result:Array = SqlUtil.getData(sqlConnection, sql);
63             var txt:String = "";
64             if (result != null) {
65                 if (result[1].data != null) {
66                     if (result[1].data.length != 0) {
67                         for each (var val:* in result[0]) {
68                             txt += result[1].data[0][val] + delimiter;
69                         }
70                     }
71                 }
72             }
73             this.text = frontCaption + txt.substring(0, txt.length - delimiter.length) + rearCaption;
74         }
75     }
76 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。