2016-05-18 1 views
0

私はiOS開発で初心者ですが問題があります。私はFMDBを使用してテーブルを更新しようとしていますが、すべてのシミュレータで動作していますが、実際のデバイスでは動作しません。私はすべての選択クエリが適切に実行されているので、dbがデバイスに転送されていると確信しています。一方、すべての更新クエリではありません。 NSNumberまたはNSIntegerを使用しようとしましたが、何もありません。実デバイス(fmdb)でアップデートテーブルが動作しない

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() 
    } 

上記のいずれの方法も機能しません。

助けが必要ですか?

答えて

1

問題は、dbファイルが読み取り専用のバンドルリソースにあることでした。 dbファイルをDocumentsフォルダにコピーすると、すべて正常に機能しました。

私はコード

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とコードのこの作品は余分である、あなたはそれを省略することができhttp://www.theappguruz.com/blog/use-sqlite-database-swift

で見つかりました。

関連する問題