import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
import flash.data.SQLConnection; // () import flash.data.SQLStatement; // import flash.data.SQLResult; // import flash.data.SQLMode; // , , (, ) import flash.events.SQLErrorEvent; // import flash.events.SQLEvent; // (OPEN, UPDATE ..) import flash.filesystem. File ; // * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- var dbFile: File = File .desktopDirectory.resolvePath ( "testDB.sqlite" ); // Specify the path to the database file (In our case, this is the desktop)
- var DBConnection: SQLConnection = new SQLConnection (); // Connect to the base
- DBConnection.addEventListener (SQLErrorEvent.ERROR, DBError); // Add an event handler that occurs during the connection
- DBConnection.addEventListener (SQLEvent.OPEN, DBOpen); // Add an event handler for a successful connection
- DBConnection.open (dbFile); // Actually initialize the opening of the database
- / **
- * This function handles connection errors.
- * /
- private function DBError (e: SQLErrorEvent): void
- {
- trace ( "Error message:" , e.error.message);
- trace ( "Details:" , e.error.details);
- }
- / **
- * This function handles a successful connection.
- * /
- private function DBOpen (e: SQLEvent): void
- {
- trace ( "The database was created successfully" );
- }
* This source code was highlighted with Source Code Highlighter .
- var GroupsTable: String = "CREATE TABLE IF NOT EXISTS groups (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT)" ;
* This source code was highlighted with Source Code Highlighter .
- var statement: SQLStatement = new SQLStatement (); // Create an object
- statement.sqlConnection = DBConnection; // Specify the base in relation to which we will execute the query
- statement.text = GroupsTable; // Specify the text of the request
- statement.addEventListener (SQLErrorEvent.ERROR, DBError); // Add an event handler that occurs during the connection
- statement.addEventListener (SQLEvent.RESULT, TableResult); // Add an event handler that occurs when the table is created successfully
- statement.execute (); // Initialize request processing
- / **
- * This function handles successful table creation.
- * /
- private function TableResult (e: SQLEvent): void
- {
- trace ( "Table created" );
- }
* This source code was highlighted with Source Code Highlighter .
- var PeoplesTable: String = "CREATE TABLE peoples (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, lname TEXT, fname TEXT, ffname TEXT, date TEXT, group_id INTEGER)" ;
- var statement: SQLStatement = new SQLStatement (); // Create an object
- statement.sqlConnection = DBConnection; // Specify the base in relation to which we will execute the query
- statement.text = PeoplesTable; // Specify the text of the request
- statement.addEventListener (SQLErrorEvent.ERROR, DBError); // Add an event handler that occurs during the connection
- statement.addEventListener (SQLEvent.RESULT, TableResult); // Add an event handler that occurs when the table is created successfully
- statement.execute (); // Initialize request processing
* This source code was highlighted with Source Code Highlighter .
- var InsertIntoPeoples: String = "INSERT INTO peoples (lname, fname, ffname, date, group_id) VALUES (@ column0, @ column1, @ column2, @ column3, @ column4)" ;
- var LNameArray: Array = [ "Ivanov" , "Sidorov" , "Kozlov" , "Ignatenko" , "Borschev" , "Kolchenko" , "Buzyakin" ];
- var FNameArray: Array = [ "Ivan" , "Nikolai" , "Artem" , "Igor" , "Sergey" , "Boris" , "Alexey" ];
- var FFNameArray: Array = [ "Alekseevich" , "Borisovich" , "Igorevich" , "Artemovich" , "Nikolaevich" , "Ivanovich" , "Sergeevich" ];
- var statement2: SQLStatement = new SQLStatement ();
- statement2.sqlConnection = DBConnection;
- statement2.text = InsertIntoPeoples;
- statement2.addEventListener (SQLErrorEvent.ERROR, DBError);
- statement2.addEventListener (SQLEvent.RESULT, InsertResult);
- for ( var j: Number = 0; j <100; j ++)
- {
- statement2.parameters [ "@ column0" ] = LNameArray [ Math .round ( Math .random () * 6)];
- statement2.parameters [ "@ column1" ] = FNameArray [ Math. around ( Math .random () * 6)];
- statement2.parameters [ "@ column2" ] = FFNameArray [ Math. around ( Math .random () * 6)];
- statement2.parameters [ "@ column3" ] = ( Math .round ( Math .random () * 30) + 1) + ':' + ( Math .round ( Math .random () * 11) + 1) + ': ' + ( Math. Around ( Math .random () * 2009) + 1);
- statement2.parameters [ "@ column4" ] = Math .round ( Math .random () * 3);
- statement2.execute ();
- }
- / **
- * This function handles the successful addition of data to the table.
- * /
- private function InsertResult (e: SQLEvent): void
- {
- trace ( "Add to table successfully" );
- }
* This source code was highlighted with Source Code Highlighter .
- var q: String = "SELECT * FROM groups ORDER BY name" ;
- var getGroupStat: SQLStatement = new SQLStatement ();
- getGroupStat.sqlConnection = DBConnection;
- getGroupStat.text = q;
- getGroupStat.addEventListener (SQLErrorEvent.ERROR, DBError);
- getGroupStat.addEventListener (SQLEvent.RESULT, GetGroupResult);
- getGroupStat.execute ();
- / **
- * Handles the result of the GetGroup () function.
- * /
- private function GetGroupResult (e: SQLEvent): void
- {
- var result: SQLResult = e.target.getResult ();
- var GroupArray: ArrayCollection = new ArrayCollection ();
- if (result.data)
- for ( var i: Number = 0; i <result.data.length; i ++)
- GroupArray.addItem (result.data [i]);
- }
* This source code was highlighted with Source Code Highlighter .
- [[ object Object], [ object Object], [ object Object], [ object Object]]
Source: https://habr.com/ru/post/73311/
All Articles