Update the test
This commit is contained in:
parent
4bfe8250e9
commit
de3d3ae3d6
|
@ -393,41 +393,41 @@ void MysqlConnection::execSql(const std::string &sql,
|
|||
_exceptCb = exceptCallback;
|
||||
//_channel.enableWriting();
|
||||
LOG_TRACE << sql;
|
||||
if (paraNum == 0)
|
||||
{
|
||||
_loop->runInLoop([=]() {
|
||||
int err;
|
||||
//int mysql_real_query_start(int *ret, MYSQL *mysql, const char *q, unsigned long length)
|
||||
_waitStatus = mysql_real_query_start(&err, _mysqlPtr.get(), sql.c_str(), sql.length());
|
||||
LOG_TRACE << "real_query:" << _waitStatus;
|
||||
_execStatus = ExecStatus_RealQuery;
|
||||
if (_waitStatus == 0)
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
outputError();
|
||||
return;
|
||||
}
|
||||
// if (paraNum == 0)
|
||||
// {
|
||||
// _loop->runInLoop([=]() {
|
||||
// int err;
|
||||
// //int mysql_real_query_start(int *ret, MYSQL *mysql, const char *q, unsigned long length)
|
||||
// _waitStatus = mysql_real_query_start(&err, _mysqlPtr.get(), sql.c_str(), sql.length());
|
||||
// LOG_TRACE << "real_query:" << _waitStatus;
|
||||
// _execStatus = ExecStatus_RealQuery;
|
||||
// if (_waitStatus == 0)
|
||||
// {
|
||||
// if (err)
|
||||
// {
|
||||
// outputError();
|
||||
// return;
|
||||
// }
|
||||
|
||||
MYSQL_RES *ret;
|
||||
_waitStatus = mysql_store_result_start(&ret, _mysqlPtr.get());
|
||||
LOG_TRACE << "store_result:" << _waitStatus;
|
||||
_execStatus = ExecStatus_StoreResult;
|
||||
if (_waitStatus == 0)
|
||||
{
|
||||
_execStatus = ExecStatus_None;
|
||||
if (!ret)
|
||||
{
|
||||
outputError();
|
||||
return;
|
||||
}
|
||||
getResult(ret);
|
||||
}
|
||||
}
|
||||
setChannel();
|
||||
});
|
||||
return;
|
||||
}
|
||||
// MYSQL_RES *ret;
|
||||
// _waitStatus = mysql_store_result_start(&ret, _mysqlPtr.get());
|
||||
// LOG_TRACE << "store_result:" << _waitStatus;
|
||||
// _execStatus = ExecStatus_StoreResult;
|
||||
// if (_waitStatus == 0)
|
||||
// {
|
||||
// _execStatus = ExecStatus_None;
|
||||
// if (!ret)
|
||||
// {
|
||||
// outputError();
|
||||
// return;
|
||||
// }
|
||||
// getResult(ret);
|
||||
// }
|
||||
// }
|
||||
// setChannel();
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
_stmtPtr = std::shared_ptr<MYSQL_STMT>(mysql_stmt_init(_mysqlPtr.get()), [](MYSQL_STMT *stmt) {
|
||||
//Is it a blocking method?
|
||||
|
|
|
@ -54,7 +54,7 @@ class MysqlStmtResultImpl : public ResultImpl
|
|||
std::string fieldName = _fieldArray[i].name;
|
||||
std::transform(fieldName.begin(), fieldName.end(), fieldName.begin(), tolower);
|
||||
_fieldMap[fieldName] = i;
|
||||
LOG_TRACE << "row[" << fieldName << "].max_length=" << _fieldArray[i].max_length;
|
||||
//LOG_TRACE << "row[" << fieldName << "].max_length=" << _fieldArray[i].max_length;
|
||||
if (_rowsNum > 0)
|
||||
{
|
||||
if (_fieldArray[i].max_length > 0)
|
||||
|
|
|
@ -11,17 +11,17 @@ int main()
|
|||
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
|
||||
auto clientPtr = DbClient::newMysqlClient("host= 127.0.0.1 port =3306 dbname= test user = root ", 1);
|
||||
sleep(1);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
std::string str = formattedString("insert into users (user_id,user_name,org_name) values('%d','antao','default')", i);
|
||||
*clientPtr << str >> [](const Result &r) {
|
||||
std::cout << "insert rows:" << r.affectedRows() << std::endl;
|
||||
} >> [](const DrogonDbException &e) {
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
};
|
||||
}
|
||||
|
||||
*clientPtr << "select * from users" >> [](const Result &r) {
|
||||
// for (int i = 0; i < 10; i++)
|
||||
// {
|
||||
// std::string str = formattedString("insert into users (user_id,user_name,org_name) values('%d','antao','default')", i);
|
||||
// *clientPtr << str >> [](const Result &r) {
|
||||
// std::cout << "insert rows:" << r.affectedRows() << std::endl;
|
||||
// } >> [](const DrogonDbException &e) {
|
||||
// std::cerr << e.base().what() << std::endl;
|
||||
// };
|
||||
// }
|
||||
LOG_TRACE << "begin";
|
||||
*clientPtr << "select * from users where id!=139 order by id" << Mode::Blocking >> [](const Result &r) {
|
||||
std::cout << "rows:" << r.size() << std::endl;
|
||||
std::cout << "column num:" << r.columns() << std::endl;
|
||||
// for (auto row : r)
|
||||
|
@ -38,9 +38,11 @@ int main()
|
|||
} >> [](const DrogonDbException &e) {
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
};
|
||||
|
||||
LOG_TRACE << "end";
|
||||
LOG_TRACE << "begin";
|
||||
*clientPtr << "select * from users where id!=? order by id"
|
||||
<< 139 >>
|
||||
<< 139
|
||||
<< Mode::Blocking >>
|
||||
[](const Result &r) {
|
||||
std::cout << "rows:" << r.size() << std::endl;
|
||||
std::cout << "column num:" << r.columns() << std::endl;
|
||||
|
@ -52,5 +54,6 @@ int main()
|
|||
[](const DrogonDbException &e) {
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
};
|
||||
LOG_TRACE << "end";
|
||||
getchar();
|
||||
}
|
Loading…
Reference in New Issue