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