更新 table 不适用于真实设备 (fmdb)
Update table doesn't work with a real device (fmdb)
我是 iOS 开发的新手,我遇到了问题。我正在尝试使用 FMDB 更新 table,但尽管它在所有模拟器中都有效,但它在真实设备上不起作用。我确定数据库已传输到设备,因为所有 select 查询都是 运行 正确的。另一方面,所有更新查询都没有。
我尝试过使用 NSNumber 或 NSInteger,但是……什么都没有。
if (database.open())
{
let rs = database.executeQuery("update \(TABLE_NAME) set x=1 where id=\(y.getId())",withArgumentsInArray: nil)
//database.executeUpdate("update \(TABLE_NAME) set x=1 where id=?", withArgumentsInArray:[NSInteger(y.getId())])
database.close()
}
以上解决方案均无效。
有什么帮助吗?
问题是 db 文件在只读的资源包中。
当我将 db 文件复制到 Documents 文件夹时,一切正常。
我在 http://www.theappguruz.com/blog/use-sqlite-database-swift
上找到
这段代码
class func copyFile(fileName: NSString) {
let dbPath: String = getPath(fileName as String)
let fileManager = NSFileManager.defaultManager()
if !fileManager.fileExistsAtPath(dbPath) {
let documentsURL = NSBundle.mainBundle().resourceURL
let fromPath = documentsURL!.URLByAppendingPathComponent(fileName as String)
var error : NSError?
do {
try fileManager.copyItemAtPath(fromPath.path!, toPath: dbPath)
} catch let error1 as NSError {
error = error1
}
let alert: UIAlertView = UIAlertView()
if (error != nil) {
alert.title = "Error Occured"
alert.message = error?.localizedDescription
} else {
alert.title = "Successfully Copy"
alert.message = "Your database copy successfully"
}
alert.delegate = nil
alert.addButtonWithTitle("Ok")
alert.show()
}
}
UIAlertView的代码是多余的,可以省略。
我是 iOS 开发的新手,我遇到了问题。我正在尝试使用 FMDB 更新 table,但尽管它在所有模拟器中都有效,但它在真实设备上不起作用。我确定数据库已传输到设备,因为所有 select 查询都是 运行 正确的。另一方面,所有更新查询都没有。 我尝试过使用 NSNumber 或 NSInteger,但是……什么都没有。
if (database.open())
{
let rs = database.executeQuery("update \(TABLE_NAME) set x=1 where id=\(y.getId())",withArgumentsInArray: nil)
//database.executeUpdate("update \(TABLE_NAME) set x=1 where id=?", withArgumentsInArray:[NSInteger(y.getId())])
database.close()
}
以上解决方案均无效。
有什么帮助吗?
问题是 db 文件在只读的资源包中。 当我将 db 文件复制到 Documents 文件夹时,一切正常。
我在 http://www.theappguruz.com/blog/use-sqlite-database-swift
上找到这段代码
class func copyFile(fileName: NSString) {
let dbPath: String = getPath(fileName as String)
let fileManager = NSFileManager.defaultManager()
if !fileManager.fileExistsAtPath(dbPath) {
let documentsURL = NSBundle.mainBundle().resourceURL
let fromPath = documentsURL!.URLByAppendingPathComponent(fileName as String)
var error : NSError?
do {
try fileManager.copyItemAtPath(fromPath.path!, toPath: dbPath)
} catch let error1 as NSError {
error = error1
}
let alert: UIAlertView = UIAlertView()
if (error != nil) {
alert.title = "Error Occured"
alert.message = error?.localizedDescription
} else {
alert.title = "Successfully Copy"
alert.message = "Your database copy successfully"
}
alert.delegate = nil
alert.addButtonWithTitle("Ok")
alert.show()
}
}
UIAlertView的代码是多余的,可以省略。