【问题标题】:Deploying android app with sqlite database使用 sqlite 数据库部署 android 应用程序
【发布时间】:2015-11-04 17:45:25
【问题描述】:

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

我做错了什么?

【问题讨论】:

    标签: android sqlite livecode


    【解决方案1】:

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

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

    或将数据库安装到

    specialFolderPath("documents")
    

    并使用

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

    【讨论】:

    • 马克,我尝试了put specialFolderPath("documents") & "/mysql2.sqlite" into gDatabasePath put revOpenDatabase("sqlite",gDatabasePath) into gDatabaseID,还在卡片调用测试中创建了一个字段,并使用put gDatabasePath into fld "test" 来显示数据库的位置。我得到/data/data/com.sheilsapp.FPI13/files/mysql2.sqlite。我知道在需要数据库数据的字段中获取 revdberr。
    • 马克,你解释说 .apk 包是一个 zip 文件。如何确定 sqlite 文件是否已添加到包中
    • 你可以解压文件,看看sqlite文件是否在那里,或者你可以使用there is a file gDatabasePath这样的语法。
    • 我还在苦苦挣扎。我已经解压缩,sqlite 文件在资产文件夹中。最大的文件夹是 lib 所以我猜它是存放应用程序的。根据这些信息有什么建议吗?
    • 使用the effective filename of this stack 显示该应用程序存储在/data/app/com.sheilsapp.FPI13 中。我试过 /data/app/com.sheilsapp.FPI13/files/mysql2.sqlite 作为数据库路径,但没有成功
    猜你喜欢
    • 2020-01-28
    • 1970-01-01
    • 2014-07-29
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多