SQLite 3的中文讀寫

2021-08-01 14:07:33 字數 834 閱讀 7347

呼叫sqlite3_open函式預設建立的資料庫encoding=utf-8,執行sqlite3_exec時需要將對應的字串轉換為utf-8格式多位元組字串。比如:

sqlite3*db;

auto retval = sqlite3_open("

test.db

", &db);

char*perrmsg;

auto sql = "

create table users(userid varchar(20) primary key, name varchar(50), age int, birthday datetime);";

retval = sqlite3_exec(db, sql, 0, 0, &perrmsg);

auto sql2 = _t("

insert into users values('administrator', '管理員', 20, '2000-1-1');");

retval = sqlite3_exec(db, cw2a(sql2, cp_utf8), 0, 0, &perrmsg);

返回結果同樣需要轉換回來:

cppsqlite3db db;

db.open(

"test.db");

string sql = cw2a(_t("

select * from users where name like '李%';

"), cp_utf8);

auto query =db.execquery(sql.c_str());

while (!query.eof())

SQLite 3的中文讀寫

呼叫sqlite3 open函式預設建立的資料庫encoding utf 8,執行sqlite3 exec時需要將對應的字串轉換為utf 8格式多位元組字串。比如 sqlite3 db auto retval sqlite3 open test.db db char perrmsg auto sql...

使用sqlite3 模組操作sqlite3資料庫

python內建了sqlite3模組,可以操作流行的嵌入式資料庫sqlite3。如果看了我前面的使用 pymysql 操作mysql資料庫這篇文章就更簡單了。因為它們都遵循pep 249,所以操作方法幾乎相同。廢話就不多說了,直接看 吧。都差不多,首先匯入模組,然後建立連線,然後獲取游標物件,之後利...

Sqlite3併發讀寫注意事項

最近專案中涉及到sqlite併發讀寫的問題,參考一些文件並結合自己的實踐,對sqlite3併發問題總結了幾點 sqlite3總共有三種事務型別 begin deferred immediate exclusive transcation,五種鎖,按鎖的級別依次是 unlocked shared re...