0 Replies Latest reply on Feb 22, 2011 1:31 AM by PurpleCowCom

    Using SQLITE result as variable in FlexEvent

    PurpleCowCom

      The desktop application I'm writing mainly calls XML files from a remote server and then displays the feeds. One of these displays is the current weather. The feed I'm connecting to makes use of a variable for the city. To custom this I have created a local SQLite database where the user can update the city they want the weather for.

       

      Everything is working fine, but I'm unable to take the var extracted from the SQLite database and use it inside the FlexEvent handler to specify the var of the city for the feed. I URGENTLY need to get this working!! Is there anybody out there that can help?

       

      The FlexEvent handler looks as follow:

       

      protected function weather_creationCompleteHandler(event:FlexEvent):void

      {

      getDataResult12.token = weatherFeed.getData("weather", myWeather);

      }

       

       

      myWeather is the variable that needs to be changed to the data retreived from the SQLite database.

       

       

      The SQLite database section looks as follow:

       

       

      import flash.data.SQLStatement;

      import flash.errors.SQLError;

      import flash.events.SQLErrorEvent;

      import flash.events.SQLEvent;

       

       

       

      private var sqlc:SQLConnection = new SQLConnection();

      private var sqls:SQLStatement = new SQLStatement();

      private var sqls2:SQLStatement = new SQLStatement();

      private var sqls3:SQLStatement = new SQLStatement();

       

       

       

      [Bindable]

      private var dp:ArrayCollection = new ArrayCollection();

      private var data:Array = new Array();

      private var myWeather:String;

       

       

       

      private function init():void

      {

       

      var db:File = File.applicationStorageDirectory.resolvePath("preferences.db");

      sqlc.openAsync(db);

      sqlc.addEventListener(SQLEvent.OPEN, db_opened);

      sqlc.addEventListener(SQLErrorEvent.ERROR, error);

      sqls.addEventListener(SQLErrorEvent.ERROR, error);

      sqls.addEventListener(SQLEvent.RESULT, resault);

       

      }

       

       

       

      private function db_opened(e:SQLEvent):void

      {

      sqls.sqlConnection = sqlc;

      sqls2.sqlConnection = sqlc;

      sqls3.sqlConnection = sqlc;

       

      sqls.text = "CREATE TABLE IF NOT EXISTS preferences ( id INTEGER PRIMARY KEY AUTOINCREMENT, world_news INTEGER, sa_news INTEGER, bus_news INTEGER, weather TEXT);";

      sqls.execute();

       

      sqls2.text = "SELECT id FROM preferences LIMIT 1";

      sqls2.execute();

       

      if (dp.length == 0)

      {

      trace ("null");

      sqls3.text = "INSERT INTO preferences (world_news, sa_news, bus_news, weather) VALUES('1','0','0','Cape Town');";

      sqls3.execute();

      refresh();

      }

      else

      {

      trace ("not null");

      refresh();

      }

      }

       

       

       

       

       

      private function addItem():void

      {

      sqls.text = "INSERT INTO preferences (world_news, sa_news, bus_news, weather) VALUES('1','0','0','Cape Town');";

      sqls.execute();

       

      refresh();

      }

       

      private function UpdateItem():void

      {

      sqls.text = "UPDATE preferences SET weather = '"+WeatherInput.text+"' WHERE id = 1";

      sqls.execute();

       

      refresh();

      }

       

      private function refresh(e:TimerEvent = null):void

      {

      var timer:Timer = new Timer(10,1);

      timer.addEventListener(TimerEvent.TIMER, refresh);

       

      if ( !sqls.executing )

      {

      sqls.text = "SELECT * FROM preferences LIMIT 1"

      sqls.execute();

      }

      else

      {

      timer.start();

      }

      }

       

       

       

      private function resault(e:SQLEvent):void

      {

      data = sqls.getResult().data;

      dp = new ArrayCollection(data);

      }

       

      private function error(e:SQLErrorEvent):void

      {

      Alert.show(e.toString());

      }