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

Importing XML Data Into A SQLite Table

09.21.2008
| 18852 views |
  • submit to reddit
        For inserting into 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;

			 
 /**
  * This is for importing xml data to a SQLite table 
  * @param node xml node
  * @param user the user whos data this is
  * 
  */			 
 public function importPostXML( node:XMLNode, user:User ):void
 {
	var query:String = "INSERT INTO posts (" + 
									"post_url," + 
									"post_hash," + 
									"post_desc," + 
									"post_tags," + 
									"post_time," + 
									"post_extended," + 
									"post_shared," + 
									"post_replace," + 
									"post_user)" + 
							"VALUES ( " + 
									":post_url," + 
									":post_hash," + 
									":post_desc," + 
									":post_tags," + 
									":post_time," + 
									":post_extended," + 
									":post_shared," + 
									":post_replace," +												
									":post_user)";
	sqlImport = new SQLStatement();
	sqlImport.sqlConnection = dbconn;
	sqlImport.addEventListener( SQLEvent.RESULT, onSQLSave );
	sqlImport.addEventListener( SQLErrorEvent.ERROR, onSQLError );
	sqlImport.text = query;
	
	sqlImport.parameters[":post_url"] = node.attributes.href;
	sqlImport.parameters[":post_hash"] = node.attributes.hash;
	sqlImport.parameters[":post_desc"] = node.attributes.description;
	sqlImport.parameters[":post_tags"] = node.attributes.tag;
	sqlImport.parameters[":post_time"] = node.attributes.time;
	sqlImport.parameters[":post_extended"] = node.attributes.extended;
	sqlImport.parameters[":post_shared"] = node.attributes.shared;
	sqlImport.parameters[":post_replace"] = node.attributes.replace;
	sqlImport.parameters[":post_user"] = user.user_name;
	
	sqlImport.execute();
	
	trace( "Importing XML to SQLite Database" );				
 }