前端之家收集整理的这篇文章主要介绍了
SQLite 简单用法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CString UTF8ToUni(char* UTF8)
{
DWORD dwUnicodeLen; //转换后Unicode的长度
TCHAR *pwText; //保存Unicode的指针
CString strUnicode; //返回值
//获得转换后的长度,并分配内存
dwUnicodeLen = MultiByteToWideChar(CP_UTF8,UTF8,-1,NULL,0);
pwText = new TCHAR[dwUnicodeLen];
if (!pwText)
{
return strUnicode;
}
//转为Unicode
MultiByteToWideChar(CP_UTF8,pwText,dwUnicodeLen);
//转为CString
strUnicode.Format(_T("%s"),pwText);
//清除内存
delete []pwText;
//返回转换好的Unicode字串
return strUnicode;
}
void Testsqlite()
{
CString sTitle;
int iRet=0;
const char* sDbName=("history");
if (sqlITE_OK==sqlite3_open(sDbName,&m_conn))
{
const char* ssql=("SELECT * FROM BOOKMARK ");
if (sqlITE_OK==sqlite3_prepare_v2(m_conn,ssql,strlen(ssql),&m_stmt,NULL))
{
iRet=sqlite3_step(m_stmt);
while (sqlITE_ROW==iRet)
{
const unsigned char* ansiTitle=sqlite3_column_text(m_stmt,1);
sTitle=UTF8ToUni((char*)ansiTitle);
MessageBox(sTitle);
iRet=sqlite3_step(m_stmt);
}
sqlite3_finalize(m_stmt);
}
sqlite3_close(m_conn);
}
}
原文链接:https://www.f2er.com/sqlite/200904.html