我在livecode中创建了一个使用sqlite数据库的应用程序。应用程序使用以下代码连接到数据库库:
on preopenstack
--Used to connect to the database when application
--first open and open the menu stack
set the itemDelimiter to " "
put item 2 of the name of the current stack into stackname
put the length of stackname into namelength
put char 2 to namelength-1 stackname into stackname
if stackname= "FoodPoisoningInvestigator" then
-- Open a connection to the database and store
--the database id into global variable so
--other handlers can access it
put the effective filename of this stack into tFolderPath
set the itemDelimiter to slash
delete last item of tFolderPath
put tFolderPath & "/mysql2.sqlite" into gDatabasePath
put revOpenDatabase("sqlite",gDatabasePath) into gDatabaseID
end if
end preopenstack
在独立设置对话框的文件设置中,我选择了mysql2.sqlite,它在创建windows standalone时添加到文件夹中,但不是用于android。该应用程序安装在移动设备上,但即使我在安装之前手动将其添加到文件夹,它也无法连接到数据库。
我做错了什么?
答案 0 :(得分:0)
也许,你的应用程序没有权限访问apk包中的数据库,或者gDatabasePath没有包含你期望的内容或路径不存在。请注意,.apk包是一个zip文件,无法直接访问,因此使用虚拟路径。试试
put specialFolderPath("engine") & "/mysql2.sqlite" into gDatabasePath
或将数据库安装到
specialFolderPath("documents")
并使用
put specialFolderPath("documents") & "/mysql2.sqlite" into gDatabasePath