-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
52 lines (48 loc) · 1.48 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "test.h"
#include<iostream>
#include "exception.h"
void MysqlClient::Initialize(mysqlx::Session* newSession){
if (globalMysqlClient != nullptr) {
throw ErrorAndLog(
"Called MysqlClient::Initialize after MysqlClient was initialized");
}
globalMysqlClient = new MysqlClient;
if (newSession == nullptr){
throw ErrorAndLog(
"Mysql session unavaible");
}
ClientSession_ = newSession;
}
MysqlClient* MysqlClient::Get(){
if(globalMysqlClient == nullptr){
throw ErrorAndLog("Get called before MysqlClient::Initialize");
}
return globalMysqlClient;
}
void MysqlClient::CreateHostname(std::string* hostname){
int id = int(globalMysqlClient->ClientSession_->getSchema("tokens").getTable("hostname").select("*").execute().count());
printf("this is the current id: %c",id);
std::string newname = "hostname";
id ++;
newname += "_";
newname += char(id);
//need to check the return value of a failed execute
try{
globalMysqlClient->ClientSession_->getSchema("tokens").getTable("hostname").insert("hostname").values(hostname).execute();
*hostname=newname;
}
catch(const std::exception&){
throw ErrorAndLog("Hostname could not be inserted in the DB");
}
}
int main(){
mysqlx::Session newSession(
"tokenauth.cg2rbsdaibs8.ap-northeast-1.rds.amazonaws.com",
"3306",
"neukind",
"Neukind.jp");
std::string hostname;
MysqlClient::Initialize(&newSession);
MysqlClient::Get()->CreateHostname(&hostname);
return 0;
}