sqlite 增刪改查

2021-10-07 07:06:24 字數 1149 閱讀 8900

公共**

private sqlitedatabase database =

getwritabledatabase()

;

1.新增新資料

database.

execsql

("insert into "

+ tablename +

" (_id,name,passname,time) values(?,?,?,?)"

, new object)

;

2.刪除資料,多個條件符號容易迷,只寫了多個條件,注意空格

database.

execsql

("delete from "

+ table_name_chat_record +

" where name = '"

+ name +

"'"+

"and source = '"

+ passname +

"'")

;

3.修改資料,同刪除,只列舉多個條件,單個條件刪除即可

database.

execsql

("update "

+ tablename +

" set time= ? , content = ? , source = ?,staues = ? where name = '"

+ name +

"'",

new object)

;

4.查詢資料

cursor cursor = database.

rawquery

("select * from "

+ tablename

+" where name = ?"

+"and source = ?"

, new string)

;#查詢的返回物件

while

(cursor != null && cursor.

movetonext()

)

僅供學習參考

sqlite的增刪改查

基本步驟 1.開啟資料庫 2.處理資料 3.關閉資料庫 先設定全域性變數 lazy var documentspath string 指標 var db opaquepointer?nil var stmt opaquepointer?nil 建立或開啟資料庫 func createoropenda...

資料儲存 SQLite增刪改查

增contentvalues.put name 張三 contentvalues.put age 18 contentvalues.put clazz 計算機1301班 db.insert book null,contentvalues contentvalues.clear contentvalu...

sqlite3增刪改查

增刪改查 查詢資料 sqlite3 sql std string pathname std string sql line select from tablename 查詢所有列if sqlite3 open v2 pathname.c str sql,開啟方式 null sqlite3 final...