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
drizzle_result_st* TransactionLogConnection::query(std::string &str_query)
57
drizzle_result_st* result= new drizzle_result_st;
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;
75
if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
77
cerr << "Could not buffer result: " <<
78
drizzle_con_error(&connection) << endl;
84
void TransactionLogConnection::errorHandler(drizzle_result_st *res,
85
drizzle_return_t ret, const char *when)
89
cerr << "Got error: " << drizzle_con_error(&connection) << " "
92
else if (ret == DRIZZLE_RETURN_ERROR_CODE)
94
cerr << "Got error: " << drizzle_result_error(res)
95
<< " (" << drizzle_result_error_code(res) << ") " << when << endl;
96
drizzle_result_free(res);
100
cerr << "Got error: " << ret << " " << when << endl;