標籤:sqlite3 關閉 關閉資料庫 條件陳述式 style nbsp 取出 track null
.資料庫的增刪查改的方法
sqlite3_exec(db, [sql UTF8String], NULL, NULL, &erro);
資料庫的使用
步驟:01.匯入架構<sqlite3.h>
02.建立資料庫(sqlite3_exec)並開啟資料庫(sqlite3_open())
03.建立表,加入欄位(sqlite3_exec)
04.實現資料庫的增,刪,改,查詢操作(sqlite3_exec)
05.關閉資料庫(sqlite3_close())
查詢操作步驟:
01.校正語句是否合法:sqlite3_prepare_v2
02.綁定要查詢的資料:sqlite3_bind_text
03.迴圈尋找內容(依據行):sqlite3_step
04.取出這一行裡面的資料(依據相應的類):sqlite3_column_text
.SQL語句使用的公式
建表:
01. creat table 表名(欄位名 欄位類型,欄位名 欄位類型)
02. creat table if not exist 表名(欄位名欄位類型,欄位名 欄位類型)
列如:creat table if not exist user(id integer,name text,phone text);
插入:insert into 表名(欄位,欄位)values (‘內容’。‘內容’);
刪除:delete from 表名 where 欄位 = ‘要刪的內容’;
改動:update 表名 set 欄位 = ‘改動的內容‘ where欄位 = ‘改動前的內容‘
set後面是新的資料,where後面是之前的資料
查詢:
01.select *from 表名 查詢全部的欄位(*表示全部)。
02.select 欄位1。欄位2....from表名;
如:select *from user;
條件陳述式:
where 欄位 = 內容;
where 欄位 is 內容;//相當=
where 欄位 != 內容。
where 欄位 is not 內容;
where 欄位 > 內容;
where 欄位 > 內容 and 欄位>內容;&& where欄位 > 內容 or 欄位 > 內容
iOS-資料庫sqlite的使用