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