2014-01-18 31 views
0

我想訪問我在SQLiteStudio中創建的數據庫,並將其導出到我的項目文件夾中。但是,我收到此錯誤:Lua中的數據庫訪問

「文件被加密或不是數據庫。」

這裏是我的代碼:

--Include sqlite 
require "sqlite3" 
--Open data.db. If the file doesn't exist it will be created 
local path = system.pathForFile("library.sql", system.ResourceDirectory) 
db = sqlite3.open(path) 

--Handle the applicationExit event to close the db 
local function onSystemEvent(event) 
    if(event.type == "applicationExit") then    
     db:close() 
    end 
end 


--print the sqlite version to the terminal 
print("version " .. sqlite3.version()) 

--print all the table contents 
for row in db:nrows("SELECT * FROM book") do 
local text = row.bookName 
local t = display.newText(text, 20, 30 * row.id, null, 16) 
t:setTextColor(255,0,255) 
end 

--setup the system listener to catch applicationExit 
Runtime:addEventListener("system", onSystemEvent) 

你能告訴我爲什麼我收到這個錯誤?

回答

1

數據庫是一個.db文件。您正在使用SQL命令「腳本」(或其他)。如果你從命令行創建一個空的數據庫,你應該能夠運行該腳本(在sql-command-line等)並重新創建數據庫。找到SQLiteStudio在哪裏保存了實際的數據庫,一個.db文件。

+0

謝謝你,Schollii。 =) –