Managing Fmdb databases in Swift with a single example

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.