wcdb icon indicating copy to clipboard operation
wcdb copied to clipboard

iOS读取bundle里的数据库错误

Open tanxiuguang opened this issue 5 years ago • 1 comments

The language of WCDB

Swift

The version of WCDB

v1.0.8.2

The platform of WCDB

iOS

The installation of WCDB

Cocoapods

What's the issue?

Post the outputs or screenshots for errors.

Explain what you want by example or code in English.

swift 版本真机还是不可以,模拟器上能正常运行 [WCDB][ERROR] Code:systemCall(513), Type:SystemCall, Path:/var/containers/Bundle/Application/17CFC729-A8E8-45D9-A71B-0D0B0201168A/rare.app/rare.db,Message:您没有将文件“rare.db”存储到文件夹“xx”中的权限。,Operation:262 Unexpected error: Code:systemCall(513), Type:SystemCall, Path:/var/containers/Bundle/Application/17CFC729-A8E8-45D9-A71B-0D0B0201168A/rare.app/rare.db,Message:您没有将文件“rare.db”存储到文件夹“xx”中的权限。,Operation:262.

262的错误代码 应该是这行代码产生的

do {
            try fileManager.setAttributes(attributes, ofItemAtPath: path)
        } catch let error as NSError {
            throw Error.reportSystemCall(operation: .setAttributes,
                                         path: path,
                                         errno: error.code,
                                         message: error.localizedDescription)
        }

把这段代码注释掉会运行到下面

guard !handle.isReadonly else {
                let handleStatement = try handle.prepare(CommonStatement.getJournalMode)
                try handleStatement.step()
                let journalMode: String = handleStatement.columnValue(atIndex: 0)
                try handleStatement.finalize()
                assert(journalMode.caseInsensitiveCompare("WAL") == ComparisonResult.orderedSame,
                       "It is not possible to open read-only WAL databases.")
                return
            }

但是我查看我的db file的JournalMode已经设置成delete,为什么这里还是WAL? handle.isReadonly 这个判断是判断db文件的什么属性?看代码没看明白

tanxiuguang avatar Jan 30 '21 09:01 tanxiuguang

Maybe you can try to set the path under the application's Documents folder, for example:

let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let dbPath = NSURL.init(string: documentPath)?.appendingPathComponent("rare.db") 

tamarous avatar Feb 18 '21 16:02 tamarous