1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "transaction_log_connection.h"
25
using namespace drizzled;
27
TransactionLogConnection::TransactionLogConnection(string &host, uint16_t port,
28
string &username, string &password,
29
bool drizzle_protocol)
32
drizzleProtocol(drizzle_protocol)
39
drizzle_create(&drizzle);
40
drizzle_con_create(&drizzle, &connection);
41
drizzle_con_set_tcp(&connection, (char *)host.c_str(), port);
42
drizzle_con_set_auth(&connection, (char *)username.c_str(),
43
(char *)password.c_str());
44
drizzle_con_add_options(&connection,
45
drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
46
ret= drizzle_con_connect(&connection);
47
if (ret != DRIZZLE_RETURN_OK)
49
errorHandler(NULL, ret, "when trying to connect");
54
void TransactionLogConnection::query(const std::string &str_query,
55
drizzle_result_st *result)
58
if (drizzle_query_str(&connection, result, str_query.c_str(), &ret) == NULL ||
59
ret != DRIZZLE_RETURN_OK)
61
if (ret == DRIZZLE_RETURN_ERROR_CODE)
63
cerr << "Error executing query: " <<
64
drizzle_result_error(result) << endl;
65
drizzle_result_free(result);
69
cerr << "Error executing query: " <<
70
drizzle_con_error(&connection) << endl;
71
drizzle_result_free(result);
76
if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
78
cerr << "Could not buffer result: " <<
79
drizzle_con_error(&connection) << endl;
80
drizzle_result_free(result);
86
void TransactionLogConnection::errorHandler(drizzle_result_st *res,
87
drizzle_return_t ret, const char *when)
91
cerr << "Got error: " << drizzle_con_error(&connection) << " "
94
else if (ret == DRIZZLE_RETURN_ERROR_CODE)
96
cerr << "Got error: " << drizzle_result_error(res)
97
<< " (" << drizzle_result_error_code(res) << ") " << when << endl;
98
drizzle_result_free(res);
102
cerr << "Got error: " << ret << " " << when << endl;