本文整理汇总了C++中DBQuery::init方法的典型用法代码示例。如果您正苦于以下问题:C++ DBQuery::init方法的具体用法?C++ DBQuery::init怎么用?C++ DBQuery::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBQuery
的用法示例。
在下文中一共展示了DBQuery::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool TestBlob::init()
{
//一段测试blob存储的测试代码.
auto checkTable = DBMgr::getRef().infoQuery("desc tb_testBlob");
if (checkTable->getErrorCode() != QEC_SUCCESS)
{
LOGI("create talbe tb_testBlob ");
DBQuery q("CREATE TABLE `tb_testBlob` ( "
"`uID` bigint(20) unsigned NOT NULL, "
"PRIMARY KEY(`uID`) "
") ENGINE = MyISAM DEFAULT CHARSET = utf8");
checkTable = DBMgr::getRef().infoQuery(q.popSQL());
if (checkTable->getErrorCode() != QEC_SUCCESS)
{
LOGE("create talbe tb_testBlob error=" << checkTable->getLastError());
return false;
}
}
//版本升级自动alter add 新字段.
DBMgr::getRef().infoQuery("alter table `tb_testBlob` add `bag` blob");
//blob test
DBQuery q;
q.init("insert into tb_testBlob(uID, bag)values(?,?) on duplicate key update bag=?");
std::string apendBin;
for (int i = 0; i < 256; i++)
{
apendBin.append(1, (char)i);
}
WriteStream wsdb(0);
wsdb << (UserID)1;
wsdb << apendBin;
std::string blob(wsdb.getStreamBody(), wsdb.getStreamBodyLen());
q.add(1);
q.add(blob);
q.add(blob);
auto result = DBMgr::getRef().infoQuery(q.popSQL());
if (result->getErrorCode() != QEC_SUCCESS )
{
LOGE("update blob error. msg=" << result->getLastError());
return false;
}
q.init("select bag from tb_testBlob where uID=?");
q.add(1);
result = DBMgr::getRef().infoQuery(q.popSQL());
if (result->getErrorCode() != QEC_SUCCESS)
{
LOGE("select blob error. errorMsg=" << result->getLastError());
return false;
}
try
{
if (result->haveRow())
{
std::string blob;
*result >> blob;
ReadStream rs(blob.c_str(), (zsummer::proto4z::Integer)blob.length(), false);
UserID uID = 0;
std::string resBlob;
rs >> uID;
rs >> resBlob;
if (resBlob != apendBin)
{
LOGE("write to blob binary is not equal to res bin");
return false;
}
}
}
catch (const std::runtime_error & e)
{
LOGE("test blog read error. catch:" << e.what());
return false;
}
catch (...)
{
LOGE("test blog read error. catch:other.");
return false;
}
return true;
}