第一遍
(不完全)封裝sqlite工具,使用該工具,可以實現對模型資料的增刪改查.
注意:sqlite資料庫中是不區分大小寫的;
import uikit
class sqlitetool: nsobject
//開啟指定資料庫檔案
func opendb() -> void else
}//建立**
func createtable() -> void else
}//刪除**
func droptable() -> void else
}//修改**
func altertable() -> void else
}//執行語句
func execsqlite(sql : string) -> bool
}
第二篇
**定義的是student模型;
import uikit
class student: nsobject
//使用該方法初始化student物件的時候,直接對屬性進行賦值
init(name : string,age : int,score : double)
//插入
func insertstu() -> bool
//刪除
func deletestu() -> bool
//更新
func updatestu(newstu : student) -> bool
}
第三遍
下面**是在控制器中例項化student物件,進行資料庫操作
注意:例項化的乙個student物件,即為乙個模型
class viewcontroller: uiviewcontroller
}
資料庫SQLite應用
1 匯入sqlite庫和標頭檔案 1 import 2 開啟資料庫,如果在開啟的時候遇到了問題,則關閉它並丟擲乙個斷言錯誤。1 sqlite3 database 2if sqlite3 open self datafilepath utf8string database 3 sqlite ok 3 ...
SQLite 簡單的資料庫
1.建立資料庫和表 引數1.資料儲存的檔案位置 引數2.檔案建立工廠類,這裡不需要,寫為空 db sqlitedatabase.openorcreatedatabase data data com.coderqi.android2 lesson 04 database database.db nul...
SQLite資料庫簡單使用
二 建立資料庫 sqlite3 student.db 建立名為student的資料庫 sqlite3命令,引數就是資料庫的名稱,如果該資料庫已存在,則使用,如果不存在,則新建乙個 如圖 三 建立表 create table person id integer primary key autoincr...