SeriesArticleNavigation
- Using flex in Adobe AIR to connect to the SQLite database (1) (creating databases and tables)
- Use flex in Adobe AIR to connect to the SQLite database (2) (add, delete, modify, and statement parameters)
- Connecting to the SQLite database using flex in Adobe AIR (3) (query)
- Connecting to the SQLite database using flex in Adobe AIR (4) (Transaction)
- Index of flex and fms3 articles
- Free beauty video chat, multi-person video conferencing feature enhanced version (fms3 and flex development (with source code ))
This chapter mainly summarizes the table Query
1. Query
Synchronization version:
Private function query (): void
{
VaR stmt: sqlstatement = new sqlstatement ();
Stmt. sqlconnection = con;
Stmt. Text = "select empid, firstname, lastname, salary from EMP ";
Stmt.exe cute ();
VaR result: sqlresult = stmt. getresult ();
If (result. Data! = NULL)
{
VaR numresults: Int = result. Data. length;
For (var I: Int = 0; I <numresults; I ++)
{
VaR row: Object = result. Data [I];
VaR output: String = "empid:" + row. empid;
Output + = "; firstname:" + row. firstname;
Output + = "; lastname:" + row. lastname;
Output + = "; salary:" + row. salary;
Alert. Show (output );
}
}
}
Code Note:
Getresult () method: access to the sqlresult object of the execution result
The data attribute of sqlresult: The data returned when the statement is executed. If a statement does not return any data, this attribute is null. This is the purpose of this Code to determine whether it is empty.
2. partial query results
by default, When you execute the SELECT statement, all rows in the result set are retrieved at a time. What can we do if we need to query 1st rows?
the code for querying an asynchronous version instance of row 1st is as follows:
private var responder: responder;
private var stmt: sqlstatement;
private function querytop1 (): void
{< br> stmt = new sqlstatement ();
stmt. sqlconnection = con;
stmt. TEXT = "select empid, firstname, lastname, salary from EMP where firstname =: firstname";
stmt. parameters [": firstname"] = "F";
responder = new Responder (resulthandler, errorhandler);
stmt.exe cute (1, responder );
}
private function resulthandler (Result: sqlresult): void
{< br> If (result. Data! = NULL)
{< br> var numresults: Int = result. data. length;
for (var I: Int = 0; I {< br> var row: Object = result. data [I];
var output: String = "empid:" + row. empid;
output + = "; firstname:" + row. firstname;
output + = "; lastname:" + row. lastname;
output + = "; salary:" + row. salary;
alert. show (output);
}< BR >}
Private function errorhandler (error: sqlerror): void
{
Alert. Show (error. Message );
Alert. Show (error. Details );
}
Code Description:
Parameters of the execute () method are described as follows:
1st parameters: This value indicates the number of rows returned by the statement at a time. The default value is-1, indicating that all result rows are returned at a time,
2nd parameters: a responder object that specifies the method to be called when the operation succeeds or fails.
In this example, you can use the event listener to execute sqlstatement instead of the responder object to determine when the statement execution is completed or failed.
Stmt. addeventlistener (sqlevent. Result, resulthandler );
Stmt. addeventlistener (sqlerrorevent. error, errorhandler );
For specific code implementation, refer to previous articles.
3. Download Code
Http://files.cnblogs.com/aierong/Air_Test_SQLite3.rar
Favorites and sharing
Add QQ bookmarks to Baidu souzang and Yahoo favorites
RSS subscribe to me What is RSS?
Dongguan. Net Club
Welcome to join