Off the clock ... Get Me out of here. Use Swift to share a single example of managing Fmdb databases:
Created by Qin Zhiwei on 14-6-12.import uikitclass zwdbmanager:nsobject {//If the Fmdbdatabase header file is added to the bridge file Var database:f Mdatabase? var lock:nslock? Create a singleton class Func shareinstance ()->zwdbmanager{struct qzsingle{static var predicate:dispatch_once_t = 0; static Var Instance:zwdbmanager? = nil}//guaranteed singleton only creates once dispatch_once (&qzsingle.predicate,{qzsingle.instance = Zwdbmanage R ()}) return qzsingle.instance! }//Construct method to create the database and open init () {var path:string = Nshomedirectory (). stringbyappendingstring ("/documents/mca.db") Lock = Nslock () dataBase = Fmdatabase (Path:path) if database!. Open () {var createimgtablesql:string = "CREATE table if not exists imginfo (Id integer PRIMARY key AutoIncrement , Picname varchar (picpath), FID varchar ((), UserID varchar (256)) "//here to pass two parameters: the first SQL to create a table, and the second for Multiple parameters (if the second argument is empty, then [] is empty; If multiple arguments are stored in the parameter array, the entire array is treated as a second parameter(Number of incoming) var issuccessed:bool = database!. Executeupdate (Createimgtablesql,withargumentsinarray: []) if issuccessed {println ("Success! ")}else{println (database!. Lasterrormessage ())}}}}
Not much else to say, the code commented some. The individual is also in the learning stage, if there are errors, please criticize correct. Reprint please specify the source ~!!!! Share an exchange group: Love Crazy, Love coding:209476515