我对Adobe Air/Flex还是个新手,对SQL也相对陌生。
我已经下载了this(http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air…-part-1/)的代码,并且一直在研究它,试图实现同样的想法。
我认为这只是一些愚蠢的东西。我正在使用Flex Builder。我创建了一个新的桌面应用程序项目,没有导入任何东西。
我添加了一个DataGrid对象,并将其绑定到一个ArrayCollection:
我试图使程序初始化时从数据库加载数据(如果存在),否则它将创建一个新的数据库。
问题是,当应用程序运行时,数据网格为空。没有列标题,没有数据,什么也没有。我尝试过改变很多东西,使用调试器确保所有函数都按照预期被调用。我不知道我做错了什么。我已经将我的代码与之前提到的代码进行了比较,还在Google上寻找教程。有人知道我做错了什么吗?
我已经下载了this(http://coenraets.org/blog/2008/11/using-the-sqlite-database-access-api-in-air…-part-1/)的代码,并且一直在研究它,试图实现同样的想法。
我认为这只是一些愚蠢的东西。我正在使用Flex Builder。我创建了一个新的桌面应用程序项目,没有导入任何东西。
我添加了一个DataGrid对象,并将其绑定到一个ArrayCollection:
我试图使程序初始化时从数据库加载数据(如果存在),否则它将创建一个新的数据库。
问题是,当应用程序运行时,数据网格为空。没有列标题,没有数据,什么也没有。我尝试过改变很多东西,使用调试器确保所有函数都按照预期被调用。我不知道我做错了什么。我已经将我的代码与之前提到的代码进行了比较,还在Google上寻找教程。有人知道我做错了什么吗?
<?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>