~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/transaction_log/utilities/transaction_log_connection.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
#include "transaction_log_connection.h"
22
 
#include <iostream>
23
 
 
24
 
using namespace std;
25
 
using namespace drizzled;
26
 
 
27
 
TransactionLogConnection::TransactionLogConnection(string &host, uint16_t port,
28
 
                                                   string &username, string &password,
29
 
                                                   bool drizzle_protocol)
30
 
  :
31
 
    hostName(host),
32
 
    drizzleProtocol(drizzle_protocol)
33
 
{
34
 
  drizzle_return_t ret;
35
 
 
36
 
  if (host.empty())
37
 
    host= "localhost";
38
 
 
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)
48
 
  {
49
 
    errorHandler(NULL, ret, "when trying to connect");
50
 
    throw 1;
51
 
  }
52
 
}
53
 
 
54
 
void TransactionLogConnection::query(const std::string &str_query,
55
 
                                     drizzle_result_st *result)
56
 
{
57
 
  drizzle_return_t ret;
58
 
  if (drizzle_query_str(&connection, result, str_query.c_str(), &ret) == NULL ||
59
 
      ret != DRIZZLE_RETURN_OK)
60
 
  {
61
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
62
 
    {
63
 
      cerr << "Error executing query: " <<
64
 
        drizzle_result_error(result) << endl;
65
 
      drizzle_result_free(result);
66
 
    }
67
 
    else
68
 
    {
69
 
      cerr << "Error executing query: " <<
70
 
        drizzle_con_error(&connection) << endl;
71
 
      drizzle_result_free(result);
72
 
    }
73
 
    return;
74
 
  }
75
 
 
76
 
  if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
77
 
  {
78
 
    cerr << "Could not buffer result: " <<
79
 
        drizzle_con_error(&connection) << endl;
80
 
    drizzle_result_free(result);
81
 
    return;
82
 
  }
83
 
  return;
84
 
}
85
 
 
86
 
void TransactionLogConnection::errorHandler(drizzle_result_st *res,
87
 
  drizzle_return_t ret, const char *when)
88
 
{
89
 
  if (res == NULL)
90
 
  {
91
 
    cerr << "Got error: " << drizzle_con_error(&connection) << " "
92
 
      << when << endl;
93
 
  }
94
 
  else if (ret == DRIZZLE_RETURN_ERROR_CODE)
95
 
  {
96
 
    cerr << "Got error: " << drizzle_result_error(res)
97
 
      << " (" << drizzle_result_error_code(res) << ") " << when << endl;
98
 
    drizzle_result_free(res);
99
 
  }
100
 
  else
101
 
  {
102
 
    cerr << "Got error: " << ret << " " << when << endl;
103
 
  }
104
 
 
105
 
  return;
106
 
}