1
/* Drizzle Client Library
2
* Copyright (C) 2011 Olaf van der Spek
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above
13
* copyright notice, this list of conditions and the following disclaimer
14
* in the documentation and/or other materials provided with the
17
* * The names of its contributors may not be used to endorse or
18
* promote products derived from this software without specific prior
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
#include <libdrizzle/libdrizzle.h>
42
class bad_query : public std::runtime_error
67
memset(&b_, 0, sizeof(b_));
72
drizzle_result_free(&b_);
77
return drizzle_result_error(&b_);
82
return drizzle_result_error_code(&b_);
85
uint16_t column_count()
87
return drizzle_result_column_count(&b_);
92
return drizzle_result_row_count(&b_);
95
drizzle_column_st* column_next()
97
return drizzle_column_next(&b_);
100
drizzle_row_t row_next()
102
return drizzle_row_next(&b_);
105
void column_seek(uint16_t i)
107
drizzle_column_seek(&b_, i);
110
void row_seek(uint64_t i)
112
drizzle_row_seek(&b_, i);
115
size_t* row_field_sizes()
117
return drizzle_row_field_sizes(&b_);
120
drizzle_result_st b_;
126
explicit connection_c(drizzle_c& drizzle)
128
drizzle_con_create(&drizzle.b_, &b_);
133
drizzle_con_free(&b_);
138
return drizzle_con_error(&b_);
141
void set_tcp(const char* host, in_port_t port)
143
drizzle_con_set_tcp(&b_, host, port);
146
void set_auth(const char* user, const char* password)
148
drizzle_con_set_auth(&b_, user, password);
151
void set_db(const char* db)
153
drizzle_con_set_db(&b_, db);
156
drizzle_return_t query(result_c& result, const char* str, size_t str_size)
158
drizzle_return_t ret;
159
drizzle_query(&b_, &result.b_, str, str_size, &ret);
160
if (ret == DRIZZLE_RETURN_OK)
161
ret = drizzle_result_buffer(&result.b_);
165
drizzle_return_t query(result_c& result, const std::string& str)
167
return query(result, str.data(), str.size());
170
drizzle_return_t query(result_c& result, const char* str)
172
return query(result, str, strlen(str));
179
inline drizzle_return_t query(drizzle_con_st* con, result_c& result, const char* str, size_t str_size)
181
drizzle_return_t ret;
182
drizzle_query(con, &result.b_, str, str_size, &ret);
183
if (ret == DRIZZLE_RETURN_OK)
184
ret = drizzle_result_buffer(&result.b_);
188
inline drizzle_return_t query(drizzle_con_st* con, result_c& result, const std::string& str)
190
return query(con, result, str.data(), str.size());
193
inline drizzle_return_t query(drizzle_con_st* con, result_c& result, const char* str)
195
return query(con, result, str, strlen(str));