InitMysqlConnection

This commit is contained in:
aozhiwei 2018-09-26 20:04:19 +08:00
parent ffe6975391
commit d08a92ba6c
2 changed files with 52 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#include <a8/stringlist.h>
#include <a8/csvreader.h>
#include <a8/udplog.h>
#include <a8/mysql.h>
#include <google/protobuf/message.h>
@ -72,3 +74,43 @@ bool ReadCsvMetaFile(const std::string& filename,
return true;
}
void InitMysqlConnection(a8::mysql::Query* query)
{
a8::UdpLog::Instance()->Info("show variables like 'character%';", {});
a8::UdpLog::Instance()->Info("Variable_name\tValue", {});
#if 1
query->ExecScript("SET character_set_server=utf8;", {});
query->ExecScript("SET NAMES utf8;", {});
#endif
query->ExecQuery("show variables like 'character%';", {});
while (!query->Eof()) {
std::string line;
line = query->GetValue(0).GetString() + "\t" + query->GetValue(1).GetString();
a8::UdpLog::Instance()->Info(line.c_str(), {});
assert(!(query->GetValue(0).GetString() == "character_set_client" &&
query->GetValue(1).GetString() != "utf8"));
assert(!(query->GetValue(0).GetString() == "character_set_connection" &&
query->GetValue(1).GetString() != "utf8"));
assert(!(query->GetValue(0).GetString() == "character_set_database" &&
query->GetValue(1).GetString() != "utf8"));
assert(!(query->GetValue(0).GetString() == "character_set_results" &&
query->GetValue(1).GetString() != "utf8"));
assert(!(query->GetValue(0).GetString() == "character_set_server" &&
query->GetValue(1).GetString() != "utf8"));
assert(!(query->GetValue(0).GetString() == "character_set_system" &&
query->GetValue(1).GetString() != "utf8"));
query->Next();
}
a8::UdpLog::Instance()->Info("show variables like '%collation%';", {});
a8::UdpLog::Instance()->Info("Variable_name\tValue", {});
query->ExecQuery("show variables like '%collation%';", {});
while (!query->Eof()) {
std::string line;
line = query->GetValue(0).GetString() + "\t" + query->GetValue(1).GetString();
a8::UdpLog::Instance()->Info(line.c_str(), {});
assert(query->GetValue(1).GetString() == "utf8_general_ci");
query->Next();
}
}

View File

@ -9,6 +9,14 @@ namespace google
}
}
namespace a8
{
namespace mysql
{
class Query;
}
}
bool ReadCsvMetaFile(const std::string& filename,
google::protobuf::Message* prototype,
std::function<void (google::protobuf::Message*)> push_back_func);
@ -66,3 +74,5 @@ static void SetToRepeatedField(const T1& t1, T2& t2)
*t2.Add() = val;
}
}
void InitMysqlConnection(a8::mysql::Query* query);