問(wèn)題描述
我正在嘗試解決為什么我的代碼對(duì)所有查詢都返回 null 的原因,最后發(fā)現(xiàn) sql 查詢什么都不返回.我用簡(jiǎn)約的代碼創(chuàng)建了一個(gè)新的 AIR 文檔 (s:WindowedApplication):
I am trying to troubleshoot why my code returned null for all my queries and finally found that sql query returns nothing. I created a new AIR document (s:WindowedApplication) with minimalistic code:
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var sqlConnection:SQLConnection;
private var select:SQLStatement;
private var databaseFile:File;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
var dbPath:String = "Movie Manager Settings/moovioDB2.db";
databaseFile = File.userDirectory.resolvePath(dbPath);
sqlConnection = new SQLConnection();
select = new SQLStatement();
sqlConnection.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
sqlConnection.openAsync();
}
private function onDatabaseOpen(event:SQLEvent):void
{
select.sqlConnection = sqlConnection;
var query:String = "SELECT title FROM movies";
select.text = query;
select.addEventListener(SQLEvent.RESULT, done);
select.execute();
}
private function done(event:SQLEvent):void{
var res:SQLResult = select.getResult();
}
]]>
</fx:Script>
除此代碼外,只有 Flex 創(chuàng)建的標(biāo)準(zhǔn)標(biāo)簽.執(zhí)行后,我收到此錯(cuò)誤:
Other than this code theres is just the standard tags created by Flex. Upon execution I get this error:
Error #2044: Unhandled SQLErrorEvent:. errorID=3115, operation=execute , message=Error #3115: SQL Error. , details=no such table: 'movies'
我已經(jīng)用 2 個(gè)不同的 sqlite 程序檢查了數(shù)據(jù)庫(kù)文件并成功執(zhí)行了查詢.電影"表和標(biāo)題"列都存在.如果重要,電影是 3 個(gè)表之一,并且有超過(guò) 10 個(gè)列都存在值.
I have checked the database file with 2 different sqlite programs and executed the query successfully. Both 'movies' table and 'title' column exists. In case it matters movies is one of 3 tables and has over 10 columns all with values present.
我做錯(cuò)了什么?我之前使用了相同的代碼(我認(rèn)為)并獲得了預(yù)期的結(jié)果,但現(xiàn)在經(jīng)過(guò)一些更改后,我什至可以在新文檔中使用此基本代碼.請(qǐng)檢查一下,看看我是否犯了一個(gè)愚蠢的錯(cuò)誤,因?yàn)槲铱床坏剿?)
What am I doing wrong? I used identical code(I thought) before with expected results, but after some changes now I can even get this basic code in a new document to work. Please check it out and see if I am making a stupid mistake because I can't see it :)
推薦答案
你能驗(yàn)證你打開的數(shù)據(jù)庫(kù)的路徑是你用外部工具檢查過(guò)的那個(gè)文件嗎?您可以在 AS3 代碼中使用 database_list pragma.就像執(zhí)行任何其他 SQL 語(yǔ)句一樣執(zhí)行它:
Can you verify that the path of the database you open is the one of that file you checked with external tools? You can use the database_list pragma from within you AS3 code. Just execute it as any other SQL statement:
[user@host ~]$ cd /tmp
[user@host tmp]$ sqlite3 foo.db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma database_list;
0|main|/tmp/foo.db
這篇關(guān)于SQL 錯(cuò)誤:“沒(méi)有這樣的表"的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!