Merge lp:~linuxjedi/sysbench/add-attachsql-driver into lp:sysbench

Proposed by Andrew Hutchings
Status: Merged
Approved by: Alexey Kopytov
Approved revision: 124
Merged at revision: 124
Proposed branch: lp:~linuxjedi/sysbench/add-attachsql-driver
Merge into: lp:sysbench
Diff against target: 836 lines (+696/-7)
11 files modified
configure.ac (+23/-0)
sysbench/Makefile.am (+6/-2)
sysbench/db_driver.c (+3/-0)
sysbench/db_driver.h (+4/-0)
sysbench/drivers/Makefile.am (+5/-1)
sysbench/drivers/attachsql/Makefile.am (+19/-0)
sysbench/drivers/attachsql/drv_attachsql.c (+632/-0)
sysbench/tests/db/common.lua (+1/-1)
sysbench/tests/db/oltp.lua (+1/-1)
sysbench/tests/db/select_random_points.lua (+1/-1)
sysbench/tests/db/select_random_ranges.lua (+1/-1)
To merge this branch: bzr merge lp:~linuxjedi/sysbench/add-attachsql-driver
Reviewer Review Type Date Requested Status
Alexey Kopytov Approve
Review via email: mp+238541@code.launchpad.net

Description of the change

This adds a sysbench driver so that libAttachSQL can be used to talk to MySQL servers.

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2012-09-23 13:09:08 +0000
+++ configure.ac 2014-10-16 09:41:21 +0000
@@ -107,6 +107,14 @@
107)107)
108AC_CACHE_CHECK([whether to compile with Drizzle support], [ac_cv_use_drizzle], [ac_cv_use_drizzle=no])108AC_CACHE_CHECK([whether to compile with Drizzle support], [ac_cv_use_drizzle], [ac_cv_use_drizzle=no])
109109
110# Check if we should compile with libattachsql support
111AC_ARG_WITH([attachsql],
112 AS_HELP_STRING([--with-attachsql],[compile with libattachsql support (default is enabled)]),
113 [ac_cv_use_attachsql=$withval], [ac_cv_use_attachsql=yes]
114)
115AC_CACHE_CHECK([whether to compile with libattachsql support], [ac_cv_use_attachsql], [ac_cv_use_attachsql=no])
116
117
110# Check if we should compile with Oracle support118# Check if we should compile with Oracle support
111AC_ARG_WITH([oracle],119AC_ARG_WITH([oracle],
112 AS_HELP_STRING([--with-oracle],[compile with Oracle support (default is disabled)]),120 AS_HELP_STRING([--with-oracle],[compile with Oracle support (default is disabled)]),
@@ -188,6 +196,20 @@
188fi196fi
189AM_CONDITIONAL(USE_DRIZZLE, test x$ac_cv_libdrizzle = xyes)197AM_CONDITIONAL(USE_DRIZZLE, test x$ac_cv_libdrizzle = xyes)
190198
199if test x$ac_cv_use_attachsql != xno; then
200 AC_LIB_HAVE_LINKFLAGS(attachsql,,
201 [#include <libattachsql-1.0/attachsql.h>],
202 [
203 const char *version= attachsql_get_library_version();
204 ])
205fi
206if test "x$ac_cv_libattachsql" = "xyes"
207then
208 AC_DEFINE(USE_ATTACHSQL,1,[Define to 1 if you want to compile with libattachsql support])
209fi
210AM_CONDITIONAL(USE_ATTACHSQL, test x$ac_cv_libattachsql = xyes)
211
212
191AM_CONDITIONAL(USE_ORACLE, test x$ac_cv_use_oracle != xno)213AM_CONDITIONAL(USE_ORACLE, test x$ac_cv_use_oracle != xno)
192if test x$ac_cv_use_oracle != xno; then214if test x$ac_cv_use_oracle != xno; then
193 AC_DEFINE(USE_ORACLE,1,[Define to 1 if you want to compile with Oracle support])215 AC_DEFINE(USE_ORACLE,1,[Define to 1 if you want to compile with Oracle support])
@@ -428,6 +450,7 @@
428sysbench/drivers/drizzle/Makefile450sysbench/drivers/drizzle/Makefile
429sysbench/drivers/oracle/Makefile451sysbench/drivers/oracle/Makefile
430sysbench/drivers/pgsql/Makefile452sysbench/drivers/pgsql/Makefile
453sysbench/drivers/attachsql/Makefile
431sysbench/tests/Makefile454sysbench/tests/Makefile
432sysbench/tests/cpu/Makefile455sysbench/tests/cpu/Makefile
433sysbench/tests/fileio/Makefile456sysbench/tests/fileio/Makefile
434457
=== modified file 'sysbench/Makefile.am'
--- sysbench/Makefile.am 2012-08-30 17:59:06 +0000
+++ sysbench/Makefile.am 2014-10-16 09:41:21 +0000
@@ -29,6 +29,10 @@
29drizzle_ldadd = drivers/drizzle/libsbdrizzle.a $(LIBDRIZZLE)29drizzle_ldadd = drivers/drizzle/libsbdrizzle.a $(LIBDRIZZLE)
30endif30endif
3131
32if USE_ATTACHSQL
33attachsql_ldadd = drivers/attachsql/libsbattachsql.a $(LIBATTACHSQL)
34endif
35
32if USE_ORACLE36if USE_ORACLE
33ora_ldadd = drivers/oracle/libsboracle.a $(ORA_LIBS)37ora_ldadd = drivers/oracle/libsboracle.a $(ORA_LIBS)
34endif38endif
@@ -49,7 +53,7 @@
49sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \53sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \
50 tests/memory/libsbmemory.a tests/cpu/libsbcpu.a \54 tests/memory/libsbmemory.a tests/cpu/libsbcpu.a \
51 tests/mutex/libsbmutex.a scripting/libsbscript.a \55 tests/mutex/libsbmutex.a scripting/libsbscript.a \
52 $(mysql_ldadd) $(drizzle_ldadd) $(pgsql_ldadd) $(ora_ldadd) $(lua_ldadd)56 $(mysql_ldadd) $(drizzle_ldadd) $(attachsql_ldadd) $(pgsql_ldadd) $(ora_ldadd) $(lua_ldadd)
5357
54sysbench_LDFLAGS = $(EXTRA_LDFLAGS) $(mysql_ldflags) $(pgsql_ldflags) $(ora_ldflags) $(lua_ldflags)58sysbench_LDFLAGS = $(EXTRA_LDFLAGS) $(mysql_ldflags) $(attachsql_ldflags) $(pgsql_ldflags) $(ora_ldflags) $(lua_ldflags)
5559
5660
=== modified file 'sysbench/db_driver.c'
--- sysbench/db_driver.c 2012-08-30 08:43:42 +0000
+++ sysbench/db_driver.c 2014-10-16 09:41:21 +0000
@@ -114,6 +114,9 @@
114#ifdef USE_DRIZZLE114#ifdef USE_DRIZZLE
115 register_driver_drizzle(&drivers);115 register_driver_drizzle(&drivers);
116#endif116#endif
117#ifdef USE_ATTACHSQL
118 register_driver_attachsql(&drivers);
119#endif
117#ifdef USE_DRIZZLECLIENT120#ifdef USE_DRIZZLECLIENT
118 register_driver_drizzleclient(&drivers);121 register_driver_drizzleclient(&drivers);
119#endif122#endif
120123
=== modified file 'sysbench/db_driver.h'
--- sysbench/db_driver.h 2011-07-19 14:49:27 +0000
+++ sysbench/db_driver.h 2014-10-16 09:41:21 +0000
@@ -309,6 +309,10 @@
309int register_driver_drizzle(sb_list_t *);309int register_driver_drizzle(sb_list_t *);
310#endif310#endif
311311
312#ifdef USE_ATTACHSQL
313int register_driver_attachsql(sb_list_t *);
314#endif
315
312#ifdef USE_DRIZZLECLIENT316#ifdef USE_DRIZZLECLIENT
313int register_driver_drizzleclient(sb_list_t *);317int register_driver_drizzleclient(sb_list_t *);
314#endif318#endif
315319
=== modified file 'sysbench/drivers/Makefile.am'
--- sysbench/drivers/Makefile.am 2009-06-10 23:43:32 +0000
+++ sysbench/drivers/Makefile.am 2014-10-16 09:41:21 +0000
@@ -22,6 +22,10 @@
22DRIZZLE_DIR = drizzle22DRIZZLE_DIR = drizzle
23endif23endif
2424
25if USE_ATTACHSQL
26ATTACHSQL_DIR = attachsql
27endif
28
25if USE_ORACLE29if USE_ORACLE
26ORACLE_DIR = oracle30ORACLE_DIR = oracle
27endif31endif
@@ -30,4 +34,4 @@
30PGSQL_DIR = pgsql34PGSQL_DIR = pgsql
31endif35endif
3236
33SUBDIRS = $(MYSQL_DIR) $(ORACLE_DIR) $(PGSQL_DIR) $(DRIZZLE_DIR)37SUBDIRS = $(MYSQL_DIR) $(ORACLE_DIR) $(PGSQL_DIR) $(DRIZZLE_DIR) $(ATTACHSQL_DIR)
3438
=== added directory 'sysbench/drivers/attachsql'
=== added file 'sysbench/drivers/attachsql/Makefile.am'
--- sysbench/drivers/attachsql/Makefile.am 1970-01-01 00:00:00 +0000
+++ sysbench/drivers/attachsql/Makefile.am 2014-10-16 09:41:21 +0000
@@ -0,0 +1,19 @@
1# Copyright (C) 2009 Sun Microsystems, Inc.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17noinst_LIBRARIES = libsbattachsql.a
18
19libsbattachsql_a_SOURCES = drv_attachsql.c
020
=== added file 'sysbench/drivers/attachsql/drv_attachsql.c'
--- sysbench/drivers/attachsql/drv_attachsql.c 1970-01-01 00:00:00 +0000
+++ sysbench/drivers/attachsql/drv_attachsql.c 2014-10-16 09:41:21 +0000
@@ -0,0 +1,632 @@
1/* Copyright 2014 Hewlett-Packard Development Company, L.P.
2 based on the Drizzle driver:
3 Copyright (C) 2009 Sun Microsystems, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20#ifdef HAVE_CONFIG_H
21# include "config.h"
22#endif
23
24#ifdef HAVE_STRING_H
25# include <string.h>
26#endif
27#ifdef HAVE_STRINGS_H
28# include <strings.h>
29#endif
30#include <stdio.h>
31
32#include <stdint.h>
33#include <libattachsql-1.0/attachsql.h>
34
35#include "sb_options.h"
36
37#include "db_driver.h"
38
39#define DEBUG(format, ...) do { if (db_globals.debug) log_text(LOG_DEBUG, format, __VA_ARGS__); } while (0)
40
41/* Drizzle driver arguments */
42
43static sb_arg_t attachsql_drv_args[] =
44{
45 {"attachsql-host", "libAttachSQL server host", SB_ARG_TYPE_LIST, "localhost"},
46 {"attachsql-port", "libAttachSQL server port", SB_ARG_TYPE_INT, "4427"},
47 {"attachsql-socket", "libAttachSQL socket", SB_ARG_TYPE_STRING, NULL},
48 {"attachsql-user", "libAttachSQL user", SB_ARG_TYPE_STRING, ""},
49 {"attachsql-password", "libAttachSQL password", SB_ARG_TYPE_STRING, ""},
50 {"attachsql-db", "libAttachSQL database name", SB_ARG_TYPE_STRING, "sbtest"},
51 {NULL, NULL, SB_ARG_TYPE_NULL, NULL}
52};
53
54typedef struct
55{
56 sb_list_t *hosts;
57 unsigned int port;
58 char *socket;
59 char *user;
60 char *password;
61 char *db;
62} attachsql_drv_args_t;
63
64/* AttachSQL driver capabilities
65 * At a later date we will add prepared statements to this
66 */
67
68static drv_caps_t attachsql_drv_caps =
69{
70 .multi_rows_insert = 1,
71 .prepared_statements = 1,
72 .auto_increment = 1,
73 .serial = 0,
74 .unsigned_int = 0,
75};
76
77static attachsql_drv_args_t args; /* driver args */
78
79static sb_list_item_t *hosts_pos;
80
81static pthread_mutex_t hosts_mutex;
82
83/* libAttachSQL driver operations */
84
85static int attachsql_drv_init(void);
86static int attachsql_drv_describe(drv_caps_t *);
87static int attachsql_drv_connect(db_conn_t *);
88static int attachsql_drv_disconnect(db_conn_t *);
89static int attachsql_drv_prepare(db_stmt_t *, const char *);
90static int attachsql_drv_bind_param(db_stmt_t *, db_bind_t *, unsigned int);
91static int attachsql_drv_bind_result(db_stmt_t *, db_bind_t *, unsigned int);
92static int attachsql_drv_execute(db_stmt_t *, db_result_set_t *);
93static int attachsql_drv_fetch(db_result_set_t *);
94static int attachsql_drv_fetch_row(db_result_set_t *, db_row_t *);
95static unsigned long long attachsql_drv_num_rows(db_result_set_t *);
96static int attachsql_drv_query(db_conn_t *, const char *, db_result_set_t *);
97static int attachsql_drv_free_results(db_result_set_t *);
98static int attachsql_drv_close(db_stmt_t *);
99static int attachsql_drv_store_results(db_result_set_t *);
100static int attachsql_drv_done(void);
101
102/* libAttachSQL driver definition */
103
104static db_driver_t attachsql_driver =
105{
106 .sname = "attachsql",
107 .lname = "libAttachSQL driver",
108 .args = attachsql_drv_args,
109 .ops =
110 {
111 attachsql_drv_init,
112 attachsql_drv_describe,
113 attachsql_drv_connect,
114 attachsql_drv_disconnect,
115 attachsql_drv_prepare,
116 attachsql_drv_bind_param,
117 attachsql_drv_bind_result,
118 attachsql_drv_execute,
119 attachsql_drv_fetch,
120 attachsql_drv_fetch_row,
121 attachsql_drv_num_rows,
122 attachsql_drv_free_results,
123 attachsql_drv_close,
124 attachsql_drv_query,
125 attachsql_drv_store_results,
126 attachsql_drv_done
127 },
128 .listitem = {NULL, NULL}
129};
130
131
132/* Local functions */
133
134/* Register libAttachSQL driver */
135
136
137int register_driver_attachsql(sb_list_t *drivers)
138{
139 SB_LIST_ADD_TAIL(&attachsql_driver.listitem, drivers);
140
141 return 0;
142}
143
144
145/* libAttachSQL driver initialization */
146
147
148int attachsql_drv_init(void)
149{
150 args.hosts = sb_get_value_list("attachsql-host");
151 if (SB_LIST_IS_EMPTY(args.hosts))
152 {
153 log_text(LOG_FATAL, "No libAttachSQL hosts specified, aborting");
154 return 1;
155 }
156 hosts_pos = args.hosts;
157 pthread_mutex_init(&hosts_mutex, NULL);
158
159 args.port = (unsigned int)sb_get_value_int("attachsql-port");
160 args.socket = sb_get_value_string("attachsql-socket");
161 args.user = sb_get_value_string("attachsql-user");
162 args.password = sb_get_value_string("attachsql-password");
163 args.db = sb_get_value_string("attachsql-db");
164 attachsql_library_init();
165 return 0;
166}
167
168
169/* Describe database capabilities (possibly depending on table type) */
170
171
172int attachsql_drv_describe(drv_caps_t *caps )
173{
174 *caps = attachsql_drv_caps;
175
176 return 0;
177}
178
179
180/* Connect to libAttachSQL database */
181
182
183int attachsql_drv_connect(db_conn_t *sb_conn)
184{
185 attachsql_connect_t *con= NULL;
186 const char *host;
187 attachsql_error_t *error= NULL;
188 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
189
190 if (args.socket)
191 {
192 DEBUG("attachsql_connect_create(\"%s\", \"%s\", \"%s\", \"%s\")",
193 args.socket,
194 args.user,
195 args.password,
196 args.db);
197 con= attachsql_connect_create(args.socket,
198 0,
199 args.user,
200 args.password,
201 args.db,
202 &error);
203 } else {
204
205 pthread_mutex_lock(&hosts_mutex);
206 hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
207 if (hosts_pos == args.hosts)
208 hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
209 host = SB_LIST_ENTRY(hosts_pos, value_t, listitem)->data;
210 pthread_mutex_unlock(&hosts_mutex);
211
212 DEBUG("attachsql_connect_create(\"%s\", %u, \"%s\", \"%s\", \"%s\")",
213 host,
214 args.port,
215 args.user,
216 args.password,
217 args.db);
218 con= attachsql_connect_create(host,
219 args.port,
220 args.user,
221 args.password,
222 args.db,
223 &error);
224 }
225 if (con == NULL)
226 {
227 log_text(LOG_FATAL, "unable to Add libAttachSQL Connection, aborting...");
228 log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
229 attachsql_error_free(error);
230 return 1;
231 }
232 attachsql_connect_set_option(con, ATTACHSQL_OPTION_SEMI_BLOCKING, NULL);
233
234 if (!attachsql_connect(con, &error))
235 {
236 log_text(LOG_FATAL, "unable to connect to libAttachSQL server");
237 log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
238 attachsql_error_free(error);
239 attachsql_connect_destroy(con);
240 return 1;
241
242 }
243
244 while (aret != ATTACHSQL_RETURN_IDLE)
245 {
246 aret = attachsql_connect_poll(con, &error);
247
248 if (error)
249 {
250 log_text(LOG_FATAL, "unable to connect to libAttachSQL server");
251 log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
252 attachsql_error_free(error);
253 attachsql_connect_destroy(con);
254 return 1;
255 }
256 }
257
258 sb_conn->ptr = con;
259
260 return 0;
261}
262
263
264/* Disconnect from libAttachSQL database */
265
266
267int attachsql_drv_disconnect(db_conn_t *sb_conn)
268{
269 attachsql_connect_t *con = (attachsql_connect_t *)sb_conn->ptr;
270
271 if (con != NULL)
272 {
273 DEBUG("attachsql_connect_destroy(%p)", con);
274 attachsql_connect_destroy(con);
275 }
276 return 0;
277}
278
279
280/* Prepare statement */
281
282
283int attachsql_drv_prepare(db_stmt_t *stmt, const char *query)
284{
285 attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
286 attachsql_error_t *error= NULL;
287 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
288 attachsql_statement_prepare(con, strlen(query), query, &error);
289 while(aret != ATTACHSQL_RETURN_EOF)
290 {
291 aret= attachsql_connect_poll(con, &error);
292 if (error)
293 {
294 log_text(LOG_ALERT, "libAttachSQL Prepare Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
295 attachsql_error_free(error);
296 return SB_DB_ERROR_FAILED;
297 }
298 }
299
300 return 0;
301}
302
303
304/* Bind parameters for prepared statement */
305int attachsql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, unsigned int len)
306{
307 /* libAttachSQL doesn't do this, you do this during execute
308 * this is because sysbench doesn't set the values until that time
309 */
310
311 if (stmt->bound_param != NULL)
312 free(stmt->bound_param);
313 stmt->bound_param = (db_bind_t *)malloc(len * sizeof(db_bind_t));
314 if (stmt->bound_param == NULL)
315 return 1;
316 memcpy(stmt->bound_param, params, len * sizeof(db_bind_t));
317 stmt->bound_param_len = len;
318
319 return 0;
320
321}
322
323
324/* Bind results for prepared statement */
325int attachsql_drv_bind_result(db_stmt_t *stmt, db_bind_t *params, unsigned int len)
326{
327 (void)stmt;
328 (void)params;
329 (void)len;
330 /* libAttachSQL doesn't do this, you get after execute */
331 return 0;
332}
333
334
335/* Execute prepared statement */
336
337
338int attachsql_drv_execute(db_stmt_t *stmt, db_result_set_t *rs)
339{
340 (void) rs;
341 attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
342 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
343 attachsql_error_t *error= NULL;
344
345 uint16_t i;
346 int8_t tinyint;
347 int16_t smallint;
348 int32_t normalint;
349 int64_t bigint;
350 float float_type;
351 double double_type;
352 db_time_t *time_data;
353 if (con == NULL)
354 return 1;
355
356 for (i= 0; i < stmt->bound_param_len; i++)
357 {
358 db_bind_t *param= &stmt->bound_param[i];
359 switch(param->type)
360 {
361 case DB_TYPE_TINYINT:
362 tinyint= *(int8_t*)param->buffer;
363 attachsql_statement_set_int(con, i, tinyint, NULL);
364 break;
365 case DB_TYPE_SMALLINT:
366 smallint= *(int16_t*)param->buffer;
367 attachsql_statement_set_int(con, i, smallint, NULL);
368 break;
369 case DB_TYPE_INT:
370 normalint= *(int32_t*)param->buffer;
371 attachsql_statement_set_int(con, i, normalint, NULL);
372 break;
373 case DB_TYPE_BIGINT:
374 bigint= *(int64_t*)param->buffer;
375 attachsql_statement_set_bigint(con, i, bigint, NULL);
376 break;
377 case DB_TYPE_FLOAT:
378 float_type= *(float*)param->buffer;
379 attachsql_statement_set_float(con, i, float_type, NULL);
380 break;
381 case DB_TYPE_DOUBLE:
382 double_type= *(double*)param->buffer;
383 attachsql_statement_set_double(con, i, double_type, NULL);
384 break;
385 case DB_TYPE_TIME:
386 time_data= (db_time_t*)param->buffer;
387 attachsql_statement_set_time(con, i, time_data->hour, time_data->minute, time_data->second, 0, false, NULL);
388 break;
389 case DB_TYPE_DATE:
390 case DB_TYPE_DATETIME:
391 case DB_TYPE_TIMESTAMP:
392 time_data= (db_time_t*)param->buffer;
393 attachsql_statement_set_datetime(con, i, time_data->year, time_data->month, time_data->day, time_data->hour, time_data->minute, time_data->second, 0, NULL);
394 break;
395 case DB_TYPE_CHAR:
396 case DB_TYPE_VARCHAR:
397 attachsql_statement_set_string(con, i, param->max_len, param->buffer, NULL);
398 case DB_TYPE_NONE:
399 default:
400 attachsql_statement_set_null(con, i, NULL);
401 /* Not supported */
402 }
403 }
404
405 attachsql_statement_execute(con, &error);
406
407 while(aret != ATTACHSQL_RETURN_EOF)
408 {
409 aret= attachsql_connect_poll(con, &error);
410 if (aret == ATTACHSQL_RETURN_ROW_READY)
411 {
412 return 0;
413 }
414 if (error)
415 {
416 log_text(LOG_ALERT, "libAttachSQL Execute Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
417 attachsql_error_free(error);
418 return SB_DB_ERROR_FAILED;
419 }
420 }
421
422 return SB_DB_ERROR_NONE;
423}
424
425
426/* Execute SQL query */
427
428
429int attachsql_drv_query(db_conn_t *sb_conn, const char *query,
430 db_result_set_t *rs)
431{
432 (void) rs;
433 attachsql_connect_t *con = sb_conn->ptr;
434 unsigned int rc;
435 attachsql_error_t *error= NULL;
436 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
437
438 /* Close any previous query */
439 attachsql_query_close(con);
440
441 DEBUG("attachsql_query(%p, \"%s\", %u)",
442 con,
443 query,
444 strlen(query));
445 attachsql_query(con, strlen(query), query, 0, NULL, &error);
446
447 while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
448 {
449 aret= attachsql_connect_poll(con, &error);
450
451 if (error)
452 {
453 rc= attachsql_error_code(error);
454 if (rc == 1213 || rc == 1205 || rc == 1020)
455 {
456 attachsql_error_free(error);
457 return SB_DB_ERROR_DEADLOCK;
458 }
459 log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
460 attachsql_error_free(error);
461 return SB_DB_ERROR_FAILED;
462 }
463 }
464 //rs->connection->ptr= con;
465 DEBUG("attachsql_query \"%s\" returned %d", query, aret);
466
467 return SB_DB_ERROR_NONE;
468}
469
470
471/* Fetch row from result set of a prepared statement */
472
473
474int attachsql_drv_fetch(db_result_set_t *rs)
475{
476 /* NYI */
477 attachsql_connect_t *con = rs->connection->ptr;
478 size_t tmp_len;
479 uint16_t columns, col;
480 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
481 attachsql_error_t *error= NULL;
482
483 while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
484 {
485 aret= attachsql_connect_poll(con, &error);
486
487 if (error)
488 {
489 log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
490 attachsql_error_free(error);
491 return 1;
492 }
493 }
494 if (aret == ATTACHSQL_RETURN_EOF)
495 {
496 return 1;
497 }
498 attachsql_statement_row_get(con, NULL);
499 columns= attachsql_query_column_count(con);
500 for (col= 0; col < columns; col++)
501 {
502 switch (attachsql_statement_get_column_type(con, col))
503 {
504 case ATTACHSQL_COLUMN_TYPE_TINY:
505 case ATTACHSQL_COLUMN_TYPE_SHORT:
506 case ATTACHSQL_COLUMN_TYPE_LONG:
507 case ATTACHSQL_COLUMN_TYPE_YEAR:
508 case ATTACHSQL_COLUMN_TYPE_INT24:
509 attachsql_statement_get_int(con, col, &error);
510 break;
511 case ATTACHSQL_COLUMN_TYPE_LONGLONG:
512 attachsql_statement_get_bigint(con, col, &error);
513 break;
514 case ATTACHSQL_COLUMN_TYPE_FLOAT:
515 attachsql_statement_get_float(con, col, &error);
516 break;
517 case ATTACHSQL_COLUMN_TYPE_DOUBLE:
518 attachsql_statement_get_double(con, col, &error);
519 break;
520 default:
521 attachsql_statement_get_char(con, col, &tmp_len, &error);
522 break;
523 }
524 }
525 attachsql_query_row_next(con);
526
527 return 0;
528}
529
530
531/* Fetch row from result set of a query */
532
533
534int attachsql_drv_fetch_row(db_result_set_t *rs, db_row_t *row)
535{
536 attachsql_error_t *error= NULL;
537 attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
538
539 /* NYI */
540
541 attachsql_connect_t *con = rs->connection->ptr;
542
543 while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
544 {
545 aret= attachsql_connect_poll(con, &error);
546
547 if (error)
548 {
549 log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
550 attachsql_error_free(error);
551 return 1;
552 }
553 }
554 if (aret == ATTACHSQL_RETURN_EOF)
555 {
556 return 1;
557 }
558 row->ptr= attachsql_query_row_get(con, NULL);
559 attachsql_query_row_next(con);
560
561 return 0;
562}
563
564
565/* Return the number of rows in a result set */
566
567
568unsigned long long attachsql_drv_num_rows(db_result_set_t *rs)
569{
570 return rs->nrows;
571}
572
573
574/* Store results from the last query */
575
576
577int attachsql_drv_store_results(db_result_set_t *rs)
578{
579 int ret= 0;
580 db_row_t row;
581 /* libAttachSQL can't do things in this order */
582 while (ret == 0)
583 {
584 if (rs->statement != NULL)
585 {
586 ret= attachsql_drv_fetch(rs);
587 }
588 else
589 {
590 ret= attachsql_drv_fetch_row(rs, &row);
591 }
592 }
593
594 return SB_DB_ERROR_NONE;
595}
596
597
598/* Free result set */
599
600
601int attachsql_drv_free_results(db_result_set_t *rs)
602{
603
604 if (rs->connection->ptr != NULL)
605 {
606 DEBUG("attachsql_query_close(%p)", rs->connection->ptr);
607 attachsql_query_close(rs->connection->ptr);
608 return 0;
609 }
610
611 return 1;
612}
613
614
615/* Close prepared statement */
616
617
618int attachsql_drv_close(db_stmt_t *stmt)
619{
620 attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
621 attachsql_statement_close(con);
622
623 return 0;
624}
625
626
627/* Uninitialize driver */
628int attachsql_drv_done(void)
629{
630 return 0;
631}
632
0633
=== modified file 'sysbench/tests/db/common.lua'
--- sysbench/tests/db/common.lua 2011-12-01 19:43:29 +0000
+++ sysbench/tests/db/common.lua 2014-10-16 09:41:21 +0000
@@ -20,7 +20,7 @@
20 i = table_id20 i = table_id
2121
22 print("Creating table 'sbtest" .. i .. "'...")22 print("Creating table 'sbtest" .. i .. "'...")
23 if (db_driver == "mysql") then23 if ((db_driver == "mysql") or (db_driver == "attachsql")) then
24 query = [[24 query = [[
25CREATE TABLE sbtest]] .. i .. [[ (25CREATE TABLE sbtest]] .. i .. [[ (
26id INTEGER UNSIGNED NOT NULL ]] ..26id INTEGER UNSIGNED NOT NULL ]] ..
2727
=== modified file 'sysbench/tests/db/oltp.lua'
--- sysbench/tests/db/oltp.lua 2011-12-01 19:43:29 +0000
+++ sysbench/tests/db/oltp.lua 2014-10-16 09:41:21 +0000
@@ -5,7 +5,7 @@
5function thread_init(thread_id)5function thread_init(thread_id)
6 set_vars()6 set_vars()
77
8 if (db_driver == "mysql" and mysql_table_engine == "myisam") then8 if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then
9 begin_query = "LOCK TABLES sbtest WRITE"9 begin_query = "LOCK TABLES sbtest WRITE"
10 commit_query = "UNLOCK TABLES"10 commit_query = "UNLOCK TABLES"
11 else11 else
1212
=== modified file 'sysbench/tests/db/select_random_points.lua'
--- sysbench/tests/db/select_random_points.lua 2010-10-29 02:15:54 +0000
+++ sysbench/tests/db/select_random_points.lua 2014-10-16 09:41:21 +0000
@@ -14,7 +14,7 @@
1414
15 print("Creating table 'sbtest'...")15 print("Creating table 'sbtest'...")
1616
17 if (db_driver == "mysql") then17 if ((db_driver == "mysql") or (db_driver == "attachsql")) then
18 query = [[18 query = [[
19 CREATE TABLE sbtest (19 CREATE TABLE sbtest (
20 id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,20 id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
2121
=== modified file 'sysbench/tests/db/select_random_ranges.lua'
--- sysbench/tests/db/select_random_ranges.lua 2010-10-29 02:15:54 +0000
+++ sysbench/tests/db/select_random_ranges.lua 2014-10-16 09:41:21 +0000
@@ -14,7 +14,7 @@
1414
15 print("Creating table 'sbtest'...")15 print("Creating table 'sbtest'...")
1616
17 if (db_driver == "mysql") then17 if ((db_driver == "mysql") or (db_driver == "attachsql")) then
18 query = [[18 query = [[
19 CREATE TABLE sbtest (19 CREATE TABLE sbtest (
20 id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,20 id INTEGER UNSIGNED NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,

Subscribers

People subscribed via source and target branches

to status/vote changes: