I'm still new to Adobe Air / Flex and still pretty new to SQL.
I downloaded this ( http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air ... -part-1 /) and looked at it and I'm trying to implement the same idea.
I think this is just something stupid. I am using Flex Builder. I created a new project for desktop applications, I did not import anything.
I added a DataGrid object and attached it to an ArrayCollection:
I try to do this when the program is initialized, it will load data from the database, if it exists, otherwise it will create a new one.
The problem is that the datagrid is empty when the application starts. No column headers, no data, nothing. I tried to change a whole bunch of things, I used a debugger to make sure that all functions are called the way they should. I do not know what I am doing wrong. I compared my code with the previous code, I was looking for tutorials on Google. Does anyone know what I'm doing wrong?
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="672" height="446" applicationComplete="onFormLoaded()" title="iRecipes"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; private var sqlConnection:SQLConnection; [Bindable] private var recipeList:ArrayCollection; private function onFormLoaded():void { sqlConnection = new SQLConnection(); openDataBase(); } private function openDataBase():void { var file:File = File.userDirectory.resolvePath("recipes.db"); sqlConnection.open(file, SQLMode.CREATE); if(!file.exists) { createDatabase(); } populateRecipeList() } private function createDatabase():void { var statement:SQLStatement = new SQLStatement(); statement.sqlConnection = sqlConnection; statement.text = "CREATE TABLE Recipes (recipeId INTEGER PRIMARY KEY AUTOINCREMENT, recipeName TEXT, authorName TEXT)"; statement.execute(); statement.text = "INSERT INTO Recipes (recipeName, authorName) VALUES (:recipeName, :authorName)"; statement.parameters[":recipeName"] = "Soup"; statement.parameters[":authorName"] = "Joel Johnson"; statement.execute(); statement.parameters[":recipeName"] = "Garbage"; statement.parameters[":authorName"] = "Bob Vila"; statement.execute(); } private function populateRecipeList():void { var statement:SQLStatement = new SQLStatement(); statement.sqlConnection = sqlConnection; statement.text = "SELECT * FROM Recipes"; statement.execute(); recipeList = new ArrayCollection(statement.getResult().data); } ]]> </mx:Script> <mx:DataGrid dataProvider="{recipeList}"> </mx:DataGrid> </mx:WindowedApplication>
source share