调用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,&pErrMsg); auto sql2 = _T("insert into users values('administrator','管理员',20,'2000-1-1');"); retVal = sqlite3_exec(db,CW2A(sql2,CP_UTF8),&pErrMsg);
返回结果同样需要转换回来:
原文链接:https://www.f2er.com/sqlite/198416.html