【问题标题】:Database Access in LuaLua 中的数据库访问
【发布时间】:2014-01-18 17:29:42
【问题描述】:

我正在尝试访问我在 SQLiteStudio 中创建的数据库并将其导出到我的项目文件夹中。但是,我收到此错误:

“文件已加密或不是数据库。”

这是我的代码:

 --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 )

你能告诉我为什么会出现这个错误吗?

【问题讨论】:

    标签: database sqlite lua coronasdk


    【解决方案1】:

    数据库是一个 .db 文件。您正在使用 SQL 命令“脚本”(或其他)。如果您从命令行创建一个空数据库,您应该能够运行该脚本(在 sql-command-line 等中)并重新创建数据库。查找 SQLiteStudio 保存实际数据库的位置,即 .db 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-21
      • 2018-07-28
      • 2011-03-24
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2015-01-14
      • 2018-04-24
      相关资源
      最近更新 更多