MorFans Dev
折腾 - 开发 - 分享

easySQLite使用帮助

easySQLite使用帮助

项目地址:https://code.google.com/archive/p/easysqlite/

由于需要用到sqlite,经过一番兜兜转转,看到了easySQL,下载下来,还不错,就是有些地方说明不够详细,以此做补充

打开数据库

db.open(fileName);

使用时提示 “Database::open: unable to open database file”,可能是因为fileName编码不正确,因为此处要求ut8编码,尝试在前头加上 u8,例如:

db.open(u8″D:/中文文件夹名/test.db”);

或对fileName进行转码

//gbk转UTF-8
string GbkToUtf8(const std::string& strGbk)//传入的strGbk是GBK编码
{
	//gbk转unicode
	int len = MultiByteToWideChar(CP_ACP, 0, strGbk.c_str(), -1, NULL, 0);
	wchar_t *strUnicode = new wchar_t[len];
	wmemset(strUnicode, 0, len);
	MultiByteToWideChar(CP_ACP, 0, strGbk.c_str(), -1, strUnicode, len);
	//unicode转UTF-8
	len = WideCharToMultiByte(CP_UTF8, 0, strUnicode, -1, NULL, 0, NULL, NULL);
	char * strUtf8 = new char[len];
	WideCharToMultiByte(CP_UTF8, 0, strUnicode, -1, strUtf8, len, NULL, NULL);
	std::string strTemp(strUtf8);//此时的strTemp是UTF-8编码
	delete[]strUnicode;
	delete[]strUtf8;
	strUnicode = NULL;
	strUtf8 = NULL;
	return strTemp;
}


取字段值

    //load all records
    tbPerson.open();

    //list loaded records
    for (int index = 0; index < tbPerson.recordCount(); index++){
        if (Record* record = tbPerson.getRecord(index)) {
            Value* value = record->getValue("value");  //取value字段的值
            Value* value2 = record->getKeyIdValue();  //取主键ID
        }
    }
赞赏
魔帆博客,版权所有 | 如未注明,均为原创
本站均采用 BY-NC-ND 协议 (署名-非商业性使用-禁止演绎) 进行授权。
转载请注明来自本站文章:easySQLite使用帮助(https://www.morfans.cn/archives/2745)

Sonui

文章作者

回复 妈妈 取消回复

textsms
account_circle
email

  • 妈妈

    隔三差五来一趟,每次都有新气象!

    5年前 回复
  • mamayi

    一如既往的表示支持!

    5年前 回复

easySQLite使用帮助
easySQLite
扫描二维码继续阅读
2019-02-09