DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Jonnie has posted 12 posts at DZone. View Full User Profile

Executing A Query From A SQLite Table

09.21.2008
| 7803 views |
  • submit to reddit
        For creating a SQLite table, use the code as follows:


//DB Connection
private var dbconn:SQLConnection;
//Query Statement
private var sqlQuery:SQLStatement;		
//Create Table Statement
private var sqlCreateTable:SQLStatement;
//Insert Statement
private var sqlInsert:SQLStatement;
//Import Statement
private var sqlImport:SQLStatement;

/**
 * Selects all posts 
 * @param args by the argument
 * 
 */			
public function getPosts():void
{
	var query:String = "SELECT * FROM posts ORDER BY post_time DESC";
	
	sqlQuery = new SQLStatement();
	sqlQuery.sqlConnection = dbconn;
	sqlQuery.addEventListener( SQLErrorEvent.ERROR, onSQLError );
	sqlQuery.addEventListener( SQLEvent.RESULT, onSQLResult_data );
	
	sqlQuery.text = query;
	
	sqlQuery.execute();
	
	trace( "Select posts query: " + query );
}

/**
 * Retrieves all post for current user 
 * @param user The current user that is logged in
 * 
 */			
public function getPostsForUser( user:User ):void
{
	var query:String = "SELECT * FROM posts WHERE post_user = '" + user.user_name + "'";				

	sqlQuery = new SQLStatement();
	sqlQuery.sqlConnection = dbconn;				
	sqlQuery.addEventListener( SQLErrorEvent.ERROR, onSQLError );
	sqlQuery.addEventListener( SQLEvent.RESULT, onSQLResult_data );
	
	sqlQuery.text = query;
	
	sqlQuery.execute();
	
	trace( "Posts for User query: " + query );
}