title: Connecting Flex to SQLite
body: <p>In Flash builder, I'm struggling with basics of data retrieval from local database. Using Lita, I created a SQLite database with a single basic (item) table located in a "DAO" folder .It is meant to populate a List. and I have 2 problems:</p>
  
  <ol>
  <li>How to embed the database (with all its pre-populated data) without recreating it from scratch as shown in many tutorials ?</li>
  <li>For the purpose of prototyping, how to link the data retrieved a single MXML file directly in the list without creating many other classes (ok, in this cases the number of required classes would be limited) such as :</li>
  </ol>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        title="HomeView" &gt;
  
  &lt;fx:Script&gt;
  
    &lt;![CDATA[
  
        import flash.data.SQLConnection
        import flash.data.SQLStatement;
        import flash.filesystem.File;
        import flash.filesystem.FileMode;
        import mx.collections.ArrayCollection;`
  
        private function get myData():ArrayCollection 
        {
            var stmt:SQLStatement = new SQLStatement();
            stmt.sqlConnection = new SQLConnection();
  
            stmt.sqlConnection.open(File.applicationStorageDirectory.resolvePath("dao/MyDatabase.db"));
            stmt.text = "SELECT id, name FROM Item";
  
            stmt.execute();
            var result:Array = stmt.getResult().data;
  
            if (result)
            {
                var list:ArrayCollection = new ArrayCollection();
                list.source(result); 
                return list; 
            } else {
                return null; 
            } 
        }
        ]]&gt;
      &lt;/fx:Script&gt;
  
      &lt;s:List id="list" top="0" bottom="0" left="0" right="0" 
             dataProvider="{myData}" &gt;
      &lt;s:itemRenderer&gt;
      &lt;fx:Component&gt;
      &lt;s:IconItemRenderer label="{myData.name}"&gt;
      &lt;/s:IconItemRenderer&gt;
      &lt;/fx:Component&gt;
      &lt;/s:itemRenderer&gt;
      &lt;/s:List&gt;
      &lt;/s:View&gt;
  </code></pre>