Connecting to the SQLite database using flex in Adobe AIR (3) (query)

Source: Internet
Author: User
SeriesArticleNavigation
  1. Using flex in Adobe AIR to connect to the SQLite database (1) (creating databases and tables)
  2. Use flex in Adobe AIR to connect to the SQLite database (2) (add, delete, modify, and statement parameters)
  3. Connecting to the SQLite database using flex in Adobe AIR (3) (query)
  4. Connecting to the SQLite database using flex in Adobe AIR (4) (Transaction)
  5. Index of flex and fms3 articles
  6. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.