~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Mark Atwood
  • Date: 2011-11-30 07:06:47 UTC
  • mfrom: (2463.1.6 drizzle-include)
  • Revision ID: me@mark.atwood.name-20111130070647-ixp7oalp70hkbt6l
mergeĀ lp:~brianaker/drizzle/libdrizzle-2.0-not-install

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
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>
23
23
 
24
24
using namespace std;
25
25
 
26
26
TransactionLogConnection::TransactionLogConnection(string &host, uint16_t port,
27
27
                                                   string &username, string &password,
28
 
                                                   bool drizzle_protocol)
29
 
  :
30
 
    hostName(host),
31
 
    drizzleProtocol(drizzle_protocol)
 
28
                                                   bool drizzle_protocol) :
 
29
  hostName(host),
 
30
  drizzleProtocol(drizzle_protocol)
32
31
{
33
 
  drizzle_return_t ret;
34
 
 
35
32
  if (host.empty())
 
33
  {
36
34
    host= "localhost";
37
 
 
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);
 
35
  }
 
36
 
 
37
  drizzle= drizzle_create();
 
38
 
 
39
  if (drizzle == NULL)
 
40
  {
 
41
    errorHandler(NULL, DRIZZLE_RETURN_MEMORY, "drizzle_create() failed");
 
42
    throw "drizzle_create() failed";
 
43
  }
 
44
 
 
45
  connection= drizzle_con_create(drizzle);
 
46
  if (connection == NULL)
 
47
  {
 
48
    errorHandler(NULL, DRIZZLE_RETURN_MEMORY, "drizzle_create() failed");
 
49
    throw "drizzle_con_create() failed";
 
50
  }
 
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());
 
53
 
 
54
  drizzle_con_add_options(connection,
 
55
                          drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
 
56
 
 
57
  drizzle_return_t ret= drizzle_con_connect(connection);
 
58
 
46
59
  if (ret != DRIZZLE_RETURN_OK)
47
60
  {
48
61
    errorHandler(NULL, ret, "when trying to connect");
54
67
                                     drizzle_result_st *result)
55
68
{
56
69
  drizzle_return_t ret;
57
 
  if (drizzle_query_str(&connection, result, str_query.c_str(), &ret) == NULL ||
 
70
 
 
71
  if (drizzle_query_str(connection, result, str_query.c_str(), &ret) == NULL ||
58
72
      ret != DRIZZLE_RETURN_OK)
59
73
  {
60
74
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
66
80
    else
67
81
    {
68
82
      cerr << "Error executing query: " <<
69
 
        drizzle_con_error(&connection) << endl;
 
83
        drizzle_con_error(connection) << endl;
70
84
      drizzle_result_free(result);
71
85
    }
72
86
    return;
75
89
  if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
76
90
  {
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);
80
94
    return;
81
95
  }
82
 
  return;
83
96
}
84
97
 
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)
87
100
{
88
101
  if (res == NULL)
89
102
  {
90
 
    cerr << "Got error: " << drizzle_con_error(&connection) << " "
91
 
      << when << endl;
 
103
    cerr << "Got error: " << drizzle_con_error(connection) << " " << when << endl;
92
104
  }
93
105
  else if (ret == DRIZZLE_RETURN_ERROR_CODE)
94
106
  {
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);
98
109
  }
99
110
  else
100
111
  {
101
112
    cerr << "Got error: " << ret << " " << when << endl;
102
113
  }
103
 
 
104
 
  return;
105
114
}