【问题标题】:Sqlite3 database file doesn't work in android device[Corona SDK]Sqlite3 数据库文件在 android 设备中不起作用[Corona SDK]
【发布时间】:2014-04-20 21:03:53
【问题描述】:

我尝试将数据库文件复制到 systems.documentsDirectory 以便能够写入设备中的数据库文件,如下所述:http://docs.coronalabs.com/api/library/system/pathForFile.html

但是,它似乎无法在设备中运行。能否请您分析一下代码并告诉我哪里做错了?

--IN DAO模块

local sqlite3 = require "sqlite3"

Dao={}

path = system.pathForFile( "barfi" , system.DocumentsDirectory )

db = sqlite3.open(path)

--在项目文件夹中(另存为)

barfi.txt

--主要

local function copyFile( srcName, srcPath, dstName, dstPath, overwrite )
    local results = true                -- assume no errors

    -- Copy the source file to the destination file
    --
    local rfilePath = system.pathForFile( srcName, srcPath )
    local wfilePath = system.pathForFile( dstName, dstPath )

    local rfh = io.open( rfilePath, "rb" )              
    local wfh = io.open( wfilePath, "wb" )

    if  not wfh then
        print( "writeFileName open error!" )
        results = false                 -- error
    else
        -- Read the file from the Resource directory and write it to the destination directory
        local data = rfh:read( "*a" )

        if not data then
            print( "read error!" )
            results = false     -- error
        else
            if not wfh:write( data ) then
                print( "write error!" ) 
                results = false -- error
            end
        end
    end

        -- Clean up our file handles
        rfh:close()
        wfh:close()

        return results  
end

copyFile( "Barfi.txt", nil, "Barfi", system.DocumentsDirectory, true )

【问题讨论】:

  • 抱歉,我认为数据库在设备中工作正常。必须是 smt 否则会损坏显示。

标签: android sqlite lua coronasdk


【解决方案1】:

这段代码运行良好。数据库正在设备中工作。必须是 smt else。

【讨论】:

    猜你喜欢
    • 2015-08-10
    • 1970-01-01
    • 2014-06-09
    • 2013-06-08
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多