SQLite Preliminary interview

Source: Internet
Author: User
Tags sqlite

1. Create a database named Test

2. Add a student table, each record in the table including learning, name, score 3 fields

Project-build Phases-link Binary with Libraries------LIBSQLITE3.TBD

To set up a bridging file

#import <sqlite3.h>

Import UIKit

Class Viewcontroller:uiviewcontroller {

Lazy var documentspath:string={

Let Paths=nssearchpathfordirectoriesindomains (. Documentdirectory,. Userdomainmask,true)

Return paths.first!

}()

var Db:copaquepointer=nil

Override Func Viewdidload () {

Super.viewdidload ()

Createoropendatabase ()

CreateTable ()

}

}

Extension viewcontroller{

Create or open a database

Func createoropendatabase () {

Print ("\ (Nshomedirectory ())")

Let path:nsstring = "\ (documentspath)/test.sqlite3"

Let Filename=path. Utf8string

If Sqlite3_open (filename,&db)! = SQLITE_OK {

Print ("Create or Open failed ...")

Sqlite3_close (DB)

}

}

Create student Tables

Func createtable () {

Let string:nsstring = "CREATE table if not exists Student (ID integer primary key autoincrement,sno text,name Text,score,in Teger) "

Let sql = string. Utf8string

If Sqlite3_exec (db,sql,nil,nil,nil)! = sqlite_ok{

Print ("CREATE TABLE failed ...")

Sqlite3_close (DB)

}

}

}

SQLite Preliminary interview

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.