20
20
#include <config.h>
21
#include "transaction_log_connection.h"
21
#include <plugin/transaction_log/utilities/transaction_log_connection.h>
22
22
#include <iostream>
24
24
using namespace std;
26
26
TransactionLogConnection::TransactionLogConnection(string &host, uint16_t port,
27
27
string &username, string &password,
28
bool drizzle_protocol)
31
drizzleProtocol(drizzle_protocol)
28
bool drizzle_protocol) :
30
drizzleProtocol(drizzle_protocol)
38
drizzle_create(&drizzle);
39
drizzle_con_create(&drizzle, &connection);
40
drizzle_con_set_tcp(&connection, (char *)host.c_str(), port);
41
drizzle_con_set_auth(&connection, (char *)username.c_str(),
42
(char *)password.c_str());
43
drizzle_con_add_options(&connection,
44
drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
45
ret= drizzle_con_connect(&connection);
37
drizzle= drizzle_create();
41
errorHandler(NULL, DRIZZLE_RETURN_MEMORY, "drizzle_create() failed");
42
throw "drizzle_create() failed";
45
connection= drizzle_con_create(drizzle);
46
if (connection == NULL)
48
errorHandler(NULL, DRIZZLE_RETURN_MEMORY, "drizzle_create() failed");
49
throw "drizzle_con_create() failed";
51
drizzle_con_set_tcp(connection, (char *)host.c_str(), port);
52
drizzle_con_set_auth(connection, (char *)username.c_str(), (char *)password.c_str());
54
drizzle_con_add_options(connection,
55
drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
57
drizzle_return_t ret= drizzle_con_connect(connection);
46
59
if (ret != DRIZZLE_RETURN_OK)
48
61
errorHandler(NULL, ret, "when trying to connect");
54
67
drizzle_result_st *result)
56
69
drizzle_return_t ret;
57
if (drizzle_query_str(&connection, result, str_query.c_str(), &ret) == NULL ||
71
if (drizzle_query_str(connection, result, str_query.c_str(), &ret) == NULL ||
58
72
ret != DRIZZLE_RETURN_OK)
60
74
if (ret == DRIZZLE_RETURN_ERROR_CODE)
75
89
if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
77
91
cerr << "Could not buffer result: " <<
78
drizzle_con_error(&connection) << endl;
92
drizzle_con_error(connection) << endl;
79
93
drizzle_result_free(result);
85
98
void TransactionLogConnection::errorHandler(drizzle_result_st *res,
86
drizzle_return_t ret, const char *when)
99
drizzle_return_t ret, const char *when)
90
cerr << "Got error: " << drizzle_con_error(&connection) << " "
103
cerr << "Got error: " << drizzle_con_error(connection) << " " << when << endl;
93
105
else if (ret == DRIZZLE_RETURN_ERROR_CODE)
95
cerr << "Got error: " << drizzle_result_error(res)
96
<< " (" << drizzle_result_error_code(res) << ") " << when << endl;
107
cerr << "Got error: " << drizzle_result_error(res) << " (" << drizzle_result_error_code(res) << ") " << when << endl;
97
108
drizzle_result_free(res);
101
112
cerr << "Got error: " << ret << " " << when << endl;