72
drizzle_create(*this);
80
operator drizzle_st*()
74
class result_c : noncopyable
79
memset(&b_, 0, sizeof(b_));
84
drizzle_result_free(&b_);
91
operator drizzle_result_st*()
94
b_.reset(new drizzle_result_st, drizzle_result_free);
87
98
const char* error()
89
return drizzle_result_error(&b_);
100
return drizzle_result_error(*this);
92
103
uint16_t error_code()
94
return drizzle_result_error_code(&b_);
105
return drizzle_result_error_code(*this);
97
108
uint16_t column_count()
99
return drizzle_result_column_count(&b_);
110
return drizzle_result_column_count(*this);
102
113
uint64_t row_count()
104
return drizzle_result_row_count(&b_);
115
return drizzle_result_row_count(*this);
107
118
drizzle_column_st* column_next()
109
return drizzle_column_next(&b_);
120
return drizzle_column_next(*this);
112
123
drizzle_row_t row_next()
114
return drizzle_row_next(&b_);
125
return drizzle_row_next(*this);
117
128
void column_seek(uint16_t i)
119
drizzle_column_seek(&b_, i);
130
drizzle_column_seek(*this, i);
122
133
void row_seek(uint64_t i)
124
drizzle_row_seek(&b_, i);
135
drizzle_row_seek(*this, i);
127
138
size_t* row_field_sizes()
129
return drizzle_row_field_sizes(&b_);
140
return drizzle_row_field_sizes(*this);
132
drizzle_result_st b_;
143
boost::shared_ptr<drizzle_result_st> b_;
135
146
class connection_c : noncopyable
138
149
explicit connection_c(drizzle_c& drizzle)
140
drizzle_con_create(&drizzle.b_, &b_);
151
drizzle_con_create(drizzle, *this);
145
drizzle_con_free(&b_);
157
drizzle_con_free(*this);
160
operator drizzle_con_st*()
148
165
const char* error()
150
return drizzle_con_error(&b_);
167
return drizzle_con_error(*this);
153
170
void set_tcp(const char* host, in_port_t port)
155
drizzle_con_set_tcp(&b_, host, port);
172
drizzle_con_set_tcp(*this, host, port);
158
175
void set_auth(const char* user, const char* password)
160
drizzle_con_set_auth(&b_, user, password);
177
drizzle_con_set_auth(*this, user, password);
163
180
void set_db(const char* db)
165
drizzle_con_set_db(&b_, db);
182
drizzle_con_set_db(*this, db);
168
185
drizzle_return_t query(result_c& result, const char* str, size_t str_size)
170
187
drizzle_return_t ret;
171
drizzle_query(&b_, &result.b_, str, str_size, &ret);
172
if (ret == DRIZZLE_RETURN_OK)
173
ret = drizzle_result_buffer(&result.b_);
188
drizzle_query(*this, result, str, str_size, &ret);
190
ret = drizzle_result_buffer(result);
184
201
return query(result, str, strlen(str));
204
result_c query(const char* str, size_t str_size)
207
if (query(result, str, str_size))
208
throw bad_query(error());
212
result_c query(const std::string& str)
214
return query(str.data(), str.size());
217
result_c query(const char* str)
219
return query(str, strlen(str));
222
void read_conf_files();
187
224
drizzle_con_st b_;
267
309
std::string out_;
313
const char* get_conf(const T& c, const std::string& v)
315
typename T::const_iterator i = c.find(v);
316
return i == c.end() ? NULL : i->second.c_str();
319
void connection_c::read_conf_files()
323
vector<string> conf_files;
326
boost::array<char, MAX_PATH> d;
327
GetWindowsDirectoryA(d.data(), d.size());
328
conf_files.push_back(string(d.data()) + "/my.cnf");
329
conf_files.push_back(string(d.data()) + "/drizzle.cnf");
330
conf_files.push_back(string(d.data()) + "/drizzle.conf");
333
conf_files.push_back("/etc/mysql/my.cnf");
334
conf_files.push_back("/etc/drizzle/drizzle.cnf");
335
conf_files.push_back("/etc/drizzle/drizzle.conf");
337
if (const char* d = getenv("HOME"))
339
conf_files.push_back(string(d) + "/.my.cnf");
340
conf_files.push_back(string(d) + "/.drizzle.conf");
343
map<string, string> conf;
344
BOOST_FOREACH(string& it, conf_files)
346
ifstream is(it.c_str());
347
bool client_section = false;
348
for (string s; getline(is, s); )
350
size_t i = s.find('#');
351
if (i != string::npos)
354
if (boost::starts_with(s, "["))
356
client_section = s == "[client]";
359
else if (!client_section)
362
if (i != string::npos)
363
conf[boost::trim_copy(s.substr(0, i))] = boost::trim_copy(s.substr(i + 1));
366
if (conf.count("host") || conf.count("port"))
367
set_tcp(get_conf(conf, "host"), atoi(get_conf(conf, "port")));
368
if (conf.count("user") || conf.count("password"))
369
set_auth(get_conf(conf, "user"), get_conf(conf, "password"));