使用 sqlite 数据库部署 android 应用程序

Deploying android app with sqlite database

我在 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 独立时添加到文件夹中,但不用于 android。该应用程序安装在手机上,但即使我在安装前手动将其添加到文件夹中,也无法连接到数据库。

我做错了什么?

可能,您的应用没有权限访问 apk 包中的数据库,或者 gDatabasePath 不包含您期望的内容或路径不存在。请注意,.apk 包是一个 zip 文件,无法直接访问,因此使用了虚拟路径。尝试

put specialFolderPath("engine") & "/mysql2.sqlite" into gDatabasePath

或将数据库安装到

specialFolderPath("documents")

并使用

put specialFolderPath("documents") & "/mysql2.sqlite" into gDatabasePath