Remove unsupported Oracle, Drizzle and AttachSQL drivers from the source tree.
This commit is contained in:
@ -28,7 +28,7 @@ endif
|
||||
|
||||
SUBDIRS = $(LUAJIT_DIR) $(CK_DIR) src tests
|
||||
|
||||
EXTRA_DIST = autogen.sh README.md README-WIN.txt README-Oracle.md ChangeLog \
|
||||
EXTRA_DIST = autogen.sh README.md README-WIN.txt ChangeLog \
|
||||
snap/snapcraft.yaml.in third_party/cram \
|
||||
debian/changelog debian/compat debian/control debian/copyright \
|
||||
debian/dirs debian/docs debian/install debian/rules \
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
**WARNING: Oracle support is unmaintained as of sysbench 1.0. You may
|
||||
want to
|
||||
try [sysbench 0.5](https://github.com/akopytov/sysbench/tree/0.5)
|
||||
instead. The corresponding code and instructions below are still in the
|
||||
source tree in case somebody wants to update them. Patches are always
|
||||
welcome! **
|
||||
|
||||
--------------------------------------------------------------
|
||||
Oracle Build steps
|
||||
--------------------------------------------------------------
|
||||
|
||||
Using Ubuntu 14.04 - intructions dated for 21/09/2016 (Was built on AWS
|
||||
in an r3.xlarge These actions were done against 0.5 checkout)
|
||||
|
||||
* Setup Oracle Instant Client -
|
||||
https://help.ubuntu.com/community/Oracle%20Instant%20Client download
|
||||
from
|
||||
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html.
|
||||
|
||||
The following RPM's and upload them to the server:
|
||||
- oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
|
||||
- oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
|
||||
|
||||
```
|
||||
alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
|
||||
alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
|
||||
```
|
||||
|
||||
* Install Cuda - http://www.r-tutor.com/gpu-computing/cuda-installation/cuda7.5-ubuntu
|
||||
|
||||
```
|
||||
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb
|
||||
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
|
||||
sudo apt-get update
|
||||
sudo apt-get install cuda
|
||||
export CUDA_HOME=/usr/local/cuda-7.5
|
||||
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
|
||||
|
||||
PATH=${CUDA_HOME}/bin:${PATH}
|
||||
export PATH
|
||||
echo "/usr/lib/oracle/12.1/client64/lib" > /etc/ld.so.conf.d/oracle-client-12.1.conf
|
||||
ldconfig
|
||||
```
|
||||
|
||||
* Build sysbench
|
||||
Use the following `configure` option to build with Oracle support:
|
||||
```
|
||||
./configure --with-oracle="/usr/lib/oracle/12.1/client64"
|
||||
```
|
||||
|
||||
Run the following commands to allow sysbench use the full number of cores:
|
||||
```
|
||||
sudo sh -c 'for x in /sys/class/net/eth0/queues/rx-*; do echo ffffffff> $x/rps_cpus; done'
|
||||
sudo sh -c "echo 32768 > /proc/sys/net/core/rps_sock_flow_entries"
|
||||
sudo sh -c "echo 4096 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt"
|
||||
```
|
||||
@ -190,9 +190,6 @@ To compile sysbench without MySQL support, use `--without-mysql`. If no
|
||||
database drivers are available database-related scripts will not work,
|
||||
but other benchmarks will be functional.
|
||||
|
||||
See [README-Oracle.md](README-Oracle.md) for instructions on building
|
||||
with Oracle client libraries.
|
||||
|
||||
# Usage
|
||||
|
||||
## General Syntax
|
||||
|
||||
77
configure.ac
77
configure.ac
@ -127,40 +127,6 @@ AS_IF([test "x$with_mysql" != "xno"],
|
||||
[mysql_support=no])
|
||||
AC_MSG_RESULT([$mysql_support])
|
||||
|
||||
# Check if we should compile with Drizzle support
|
||||
AC_ARG_WITH([drizzle],
|
||||
AS_HELP_STRING([--with-drizzle],
|
||||
[compile with Drizzle support (default is disabled)]),
|
||||
[], [with_drizzle=no])
|
||||
AC_MSG_CHECKING([whether to compile with Drizzle support])
|
||||
AS_IF([test "x$with_drizzle" != "xno"],
|
||||
[drizzle_support=yes],
|
||||
[drizzle_support=no])
|
||||
AC_MSG_RESULT([$drizzle_support])
|
||||
|
||||
# Check if we should compile with libattachsql support
|
||||
AC_ARG_WITH([attachsql],
|
||||
AS_HELP_STRING([--with-attachsql],
|
||||
[compile with libattachsql support (default is disabled)]),
|
||||
[], [with_attachsql=no])
|
||||
AC_MSG_CHECKING([whether to compile with libattachsql support])
|
||||
AS_IF([test "x$with_attachsql" != "xno"],
|
||||
[attachsql_support=yes],
|
||||
[attachsql_support=no])
|
||||
AC_MSG_RESULT([$attachsql_support])
|
||||
|
||||
|
||||
# Check if we should compile with Oracle support
|
||||
AC_ARG_WITH([oracle],
|
||||
AS_HELP_STRING([--with-oracle],
|
||||
[compile with Oracle support (default is disabled)]),
|
||||
[], [with_oracle=no])
|
||||
AC_MSG_CHECKING([whether to compile with Oracle support])
|
||||
AS_IF([test "x$with_oracle" != "xno"],
|
||||
[oracle_support=yes],
|
||||
[oracle_support=no])
|
||||
AC_MSG_RESULT([$oracle_support])
|
||||
|
||||
# Check if we should compile with PostgreSQL support
|
||||
AC_ARG_WITH([pgsql],
|
||||
AS_HELP_STRING([--with-pgsql],
|
||||
@ -219,43 +185,6 @@ AC_CHECK_LIB(m, sqrt)
|
||||
|
||||
SB_CHECK_MYSQL
|
||||
|
||||
AS_IF([test "x$with_drizzle" != xno], [
|
||||
AC_LIB_HAVE_LINKFLAGS(drizzle,,
|
||||
[#include <libdrizzle/drizzle.h>],
|
||||
[
|
||||
int x= DRIZZLE_RETURN_ERROR_CODE;
|
||||
const char *version= drizzle_version();
|
||||
])
|
||||
AS_IF([test "x$ac_cv_libdrizzle" = xyes], [
|
||||
AC_DEFINE([USE_DRIZZLE],1,
|
||||
[Define to 1 if you want to compile with Drizzle support])
|
||||
])
|
||||
])
|
||||
AM_CONDITIONAL(USE_DRIZZLE, test x$ac_cv_libdrizzle = xyes)
|
||||
|
||||
AS_IF([test "x$with_attachsql" != xno], [
|
||||
AC_LIB_HAVE_LINKFLAGS(attachsql,,
|
||||
[#include <libattachsql-1.0/attachsql.h>],
|
||||
[
|
||||
const char *version= attachsql_get_library_version();
|
||||
])
|
||||
AS_IF([test "x$ac_cv_libattachsql" = xyes], [
|
||||
AC_DEFINE(USE_ATTACHSQL,1,
|
||||
[Define to 1 if you want to compile with libattachsql support])
|
||||
])
|
||||
])
|
||||
AM_CONDITIONAL(USE_ATTACHSQL, test x$ac_cv_libattachsql = xyes)
|
||||
|
||||
|
||||
AS_IF([test x$with_oracle != xno], [
|
||||
AC_DEFINE(USE_ORACLE,1,[Define to 1 if you want to compile with Oracle support])
|
||||
ORA_LIBS="-L${sb_with_oracle}/lib -lclntsh"
|
||||
ORA_CFLAGS="-I${with_oracle}/include -I${with_oracle}/rdbms/demo -I${with_oracle}/rdbms/public"
|
||||
AC_SUBST([ORA_LIBS])
|
||||
AC_SUBST([ORA_CFLAGS])
|
||||
])
|
||||
AM_CONDITIONAL(USE_ORACLE, test x$with_oracle != xno)
|
||||
|
||||
AS_IF([test x$with_pgsql != xno], [
|
||||
AC_CHECK_PGSQL([$with_pgsql])
|
||||
USE_PGSQL=1
|
||||
@ -468,10 +397,7 @@ third_party/concurrency_kit/Makefile
|
||||
src/Makefile
|
||||
src/drivers/Makefile
|
||||
src/drivers/mysql/Makefile
|
||||
src/drivers/drizzle/Makefile
|
||||
src/drivers/oracle/Makefile
|
||||
src/drivers/pgsql/Makefile
|
||||
src/drivers/attachsql/Makefile
|
||||
src/tests/Makefile
|
||||
src/tests/cpu/Makefile
|
||||
src/tests/fileio/Makefile
|
||||
@ -501,9 +427,6 @@ AC_MSG_RESULT([mandir : $(eval echo ${mandir})])
|
||||
AC_MSG_RESULT([datadir : $(eval echo ${datadir})])
|
||||
AC_MSG_RESULT([])
|
||||
AC_MSG_RESULT([MySQL support : ${mysql_support}])
|
||||
AC_MSG_RESULT([Drizzle support : ${drizzle_support}])
|
||||
AC_MSG_RESULT([AttachSQL support : ${attachsql_support}])
|
||||
AC_MSG_RESULT([Oracle support : ${oracle_support}])
|
||||
AC_MSG_RESULT([PostgreSQL support : ${pgsql_support}])
|
||||
AC_MSG_RESULT([])
|
||||
AC_MSG_RESULT([LuaJIT : ${sb_use_luajit}])
|
||||
|
||||
@ -26,18 +26,6 @@ if USE_MYSQL
|
||||
mysql_ldadd = drivers/mysql/libsbmysql.a $(MYSQL_LIBS)
|
||||
endif
|
||||
|
||||
if USE_DRIZZLE
|
||||
drizzle_ldadd = drivers/drizzle/libsbdrizzle.a $(LIBDRIZZLE)
|
||||
endif
|
||||
|
||||
if USE_ATTACHSQL
|
||||
attachsql_ldadd = drivers/attachsql/libsbattachsql.a $(LIBATTACHSQL)
|
||||
endif
|
||||
|
||||
if USE_ORACLE
|
||||
ora_ldadd = drivers/oracle/libsboracle.a $(ORA_LIBS)
|
||||
endif
|
||||
|
||||
if USE_PGSQL
|
||||
pgsql_ldadd = drivers/pgsql/libsbpgsql.a $(PGSQL_LIBS)
|
||||
endif
|
||||
@ -56,8 +44,8 @@ xoroshiro128plus.h
|
||||
sysbench_LDADD = tests/fileio/libsbfileio.a tests/threads/libsbthreads.a \
|
||||
tests/memory/libsbmemory.a tests/cpu/libsbcpu.a \
|
||||
tests/mutex/libsbmutex.a \
|
||||
$(mysql_ldadd) $(drizzle_ldadd) $(attachsql_ldadd) $(pgsql_ldadd) \
|
||||
$(ora_ldadd) $(LUAJIT_LIBS) $(CK_LIBS)
|
||||
$(mysql_ldadd) $(pgsql_ldadd) \
|
||||
$(LUAJIT_LIBS) $(CK_LIBS)
|
||||
|
||||
sysbench_LDFLAGS = $(mysql_ldflags) $(attachsql_ldflags) \
|
||||
$(pgsql_ldflags) $(ora_ldflags) $(LUAJIT_LDFLAGS)
|
||||
sysbench_LDFLAGS = $(mysql_ldflags) \
|
||||
$(pgsql_ldflags) $(LUAJIT_LDFLAGS)
|
||||
|
||||
@ -103,18 +103,6 @@ int db_register(void)
|
||||
#ifdef USE_MYSQL
|
||||
register_driver_mysql(&drivers);
|
||||
#endif
|
||||
#ifdef USE_DRIZZLE
|
||||
register_driver_drizzle(&drivers);
|
||||
#endif
|
||||
#ifdef USE_ATTACHSQL
|
||||
register_driver_attachsql(&drivers);
|
||||
#endif
|
||||
#ifdef USE_DRIZZLECLIENT
|
||||
register_driver_drizzleclient(&drivers);
|
||||
#endif
|
||||
#ifdef USE_ORACLE
|
||||
register_driver_oracle(&drivers);
|
||||
#endif
|
||||
#ifdef USE_PGSQL
|
||||
register_driver_pgsql(&drivers);
|
||||
#endif
|
||||
|
||||
@ -323,22 +323,6 @@ void db_report_cumulative(sb_stat_t *);
|
||||
int register_driver_mysql(sb_list_t *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DRIZZLE
|
||||
int register_driver_drizzle(sb_list_t *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ATTACHSQL
|
||||
int register_driver_attachsql(sb_list_t *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_DRIZZLECLIENT
|
||||
int register_driver_drizzleclient(sb_list_t *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ORACLE
|
||||
int register_driver_oracle(sb_list_t *);
|
||||
#endif
|
||||
|
||||
#ifdef USE_PGSQL
|
||||
int register_driver_pgsql(sb_list_t *);
|
||||
#endif
|
||||
|
||||
@ -19,20 +19,8 @@ if USE_MYSQL
|
||||
MYSQL_DIR = mysql
|
||||
endif
|
||||
|
||||
if USE_DRIZZLE
|
||||
DRIZZLE_DIR = drizzle
|
||||
endif
|
||||
|
||||
if USE_ATTACHSQL
|
||||
ATTACHSQL_DIR = attachsql
|
||||
endif
|
||||
|
||||
if USE_ORACLE
|
||||
ORACLE_DIR = oracle
|
||||
endif
|
||||
|
||||
if USE_PGSQL
|
||||
PGSQL_DIR = pgsql
|
||||
endif
|
||||
|
||||
SUBDIRS = $(MYSQL_DIR) $(ORACLE_DIR) $(PGSQL_DIR) $(DRIZZLE_DIR) $(ATTACHSQL_DIR)
|
||||
SUBDIRS = $(MYSQL_DIR) $(PGSQL_DIR)
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
# based on the Drizzle driver:
|
||||
# Copyright (C) 2009 Sun Microsystems, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
noinst_LIBRARIES = libsbattachsql.a
|
||||
|
||||
libsbattachsql_a_SOURCES = drv_attachsql.c
|
||||
@ -1,622 +0,0 @@
|
||||
/* Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
based on the Drizzle driver:
|
||||
Copyright (C) 2009 Sun Microsystems, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libattachsql-1.0/attachsql.h>
|
||||
|
||||
#include "sb_options.h"
|
||||
|
||||
#include "db_driver.h"
|
||||
|
||||
#define DEBUG(format, ...) do { if (db_globals.debug) log_text(LOG_DEBUG, format, __VA_ARGS__); } while (0)
|
||||
|
||||
/* Drizzle driver arguments */
|
||||
|
||||
static sb_arg_t attachsql_drv_args[] =
|
||||
{
|
||||
{"attachsql-host", "libAttachSQL server host", SB_ARG_TYPE_LIST, "localhost"},
|
||||
{"attachsql-port", "libAttachSQL server port", SB_ARG_TYPE_INT, "4427"},
|
||||
{"attachsql-socket", "libAttachSQL socket", SB_ARG_TYPE_STRING, NULL},
|
||||
{"attachsql-user", "libAttachSQL user", SB_ARG_TYPE_STRING, ""},
|
||||
{"attachsql-password", "libAttachSQL password", SB_ARG_TYPE_STRING, ""},
|
||||
{"attachsql-db", "libAttachSQL database name", SB_ARG_TYPE_STRING, "sbtest"},
|
||||
{NULL, NULL, SB_ARG_TYPE_NULL, NULL}
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sb_list_t *hosts;
|
||||
unsigned int port;
|
||||
char *socket;
|
||||
char *user;
|
||||
char *password;
|
||||
char *db;
|
||||
} attachsql_drv_args_t;
|
||||
|
||||
/* AttachSQL driver capabilities
|
||||
* At a later date we will add prepared statements to this
|
||||
*/
|
||||
|
||||
static drv_caps_t attachsql_drv_caps =
|
||||
{
|
||||
.multi_rows_insert = 1,
|
||||
.prepared_statements = 1,
|
||||
.auto_increment = 1,
|
||||
.serial = 0,
|
||||
.unsigned_int = 0,
|
||||
};
|
||||
|
||||
static attachsql_drv_args_t args; /* driver args */
|
||||
|
||||
static sb_list_item_t *hosts_pos;
|
||||
|
||||
static pthread_mutex_t hosts_mutex;
|
||||
|
||||
/* libAttachSQL driver operations */
|
||||
|
||||
static int attachsql_drv_init(void);
|
||||
static int attachsql_drv_describe(drv_caps_t *);
|
||||
static int attachsql_drv_connect(db_conn_t *);
|
||||
static int attachsql_drv_disconnect(db_conn_t *);
|
||||
static int attachsql_drv_prepare(db_stmt_t *, const char *, size_t);
|
||||
static int attachsql_drv_bind_param(db_stmt_t *, db_bind_t *, size_t);
|
||||
static int attachsql_drv_bind_result(db_stmt_t *, db_bind_t *, size_t);
|
||||
static db_error_t attachsql_drv_execute(db_stmt_t *, db_result_t *);
|
||||
static int attachsql_drv_fetch(db_result_t *);
|
||||
static int attachsql_drv_fetch_row(db_result_t *, db_row_t *);
|
||||
static db_error_t attachsql_drv_query(db_conn_t *, const char *, size_t,
|
||||
db_result_t *);
|
||||
static int attachsql_drv_free_results(db_result_t *);
|
||||
static int attachsql_drv_close(db_stmt_t *);
|
||||
static int attachsql_drv_store_results(db_result_t *);
|
||||
static int attachsql_drv_done(void);
|
||||
|
||||
/* libAttachSQL driver definition */
|
||||
|
||||
static db_driver_t attachsql_driver =
|
||||
{
|
||||
.sname = "attachsql",
|
||||
.lname = "libAttachSQL driver",
|
||||
.args = attachsql_drv_args,
|
||||
.ops =
|
||||
{
|
||||
.init = attachsql_drv_init,
|
||||
.describe = attachsql_drv_describe,
|
||||
.connect = attachsql_drv_connect,
|
||||
.disconnect = attachsql_drv_disconnect,
|
||||
.prepare = attachsql_drv_prepare,
|
||||
.bind_param = attachsql_drv_bind_param,
|
||||
.bind_result = attachsql_drv_bind_result,
|
||||
.execute = attachsql_drv_execute,
|
||||
.fetch = attachsql_drv_fetch,
|
||||
.fetch_row = attachsql_drv_fetch_row,
|
||||
.free_results = attachsql_drv_free_results,
|
||||
.close = attachsql_drv_close,
|
||||
.query = attachsql_drv_query,
|
||||
.store_results = attachsql_drv_store_results,
|
||||
.done = attachsql_drv_done
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Local functions */
|
||||
|
||||
/* Register libAttachSQL driver */
|
||||
|
||||
|
||||
int register_driver_attachsql(sb_list_t *drivers)
|
||||
{
|
||||
SB_LIST_ADD_TAIL(&attachsql_driver.listitem, drivers);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* libAttachSQL driver initialization */
|
||||
|
||||
|
||||
int attachsql_drv_init(void)
|
||||
{
|
||||
args.hosts = sb_get_value_list("attachsql-host");
|
||||
if (SB_LIST_IS_EMPTY(args.hosts))
|
||||
{
|
||||
log_text(LOG_FATAL, "No libAttachSQL hosts specified, aborting");
|
||||
return 1;
|
||||
}
|
||||
hosts_pos = args.hosts;
|
||||
pthread_mutex_init(&hosts_mutex, NULL);
|
||||
|
||||
args.port = (unsigned int)sb_get_value_int("attachsql-port");
|
||||
args.socket = sb_get_value_string("attachsql-socket");
|
||||
args.user = sb_get_value_string("attachsql-user");
|
||||
args.password = sb_get_value_string("attachsql-password");
|
||||
args.db = sb_get_value_string("attachsql-db");
|
||||
attachsql_library_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Describe database capabilities (possibly depending on table type) */
|
||||
|
||||
|
||||
int attachsql_drv_describe(drv_caps_t *caps )
|
||||
{
|
||||
*caps = attachsql_drv_caps;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to libAttachSQL database */
|
||||
|
||||
|
||||
int attachsql_drv_connect(db_conn_t *sb_conn)
|
||||
{
|
||||
attachsql_connect_t *con= NULL;
|
||||
const char *host;
|
||||
attachsql_error_t *error= NULL;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
|
||||
if (args.socket)
|
||||
{
|
||||
DEBUG("attachsql_connect_create(\"%s\", \"%s\", \"%s\", \"%s\")",
|
||||
args.socket,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db);
|
||||
con= attachsql_connect_create(args.socket,
|
||||
0,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
&error);
|
||||
} else {
|
||||
|
||||
pthread_mutex_lock(&hosts_mutex);
|
||||
hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
|
||||
if (hosts_pos == args.hosts)
|
||||
hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
|
||||
host = SB_LIST_ENTRY(hosts_pos, value_t, listitem)->data;
|
||||
pthread_mutex_unlock(&hosts_mutex);
|
||||
|
||||
DEBUG("attachsql_connect_create(\"%s\", %u, \"%s\", \"%s\", \"%s\")",
|
||||
host,
|
||||
args.port,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db);
|
||||
con= attachsql_connect_create(host,
|
||||
args.port,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
&error);
|
||||
}
|
||||
if (con == NULL)
|
||||
{
|
||||
log_text(LOG_FATAL, "unable to Add libAttachSQL Connection, aborting...");
|
||||
log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return 1;
|
||||
}
|
||||
attachsql_connect_set_option(con, ATTACHSQL_OPTION_SEMI_BLOCKING, NULL);
|
||||
|
||||
if (!attachsql_connect(con, &error))
|
||||
{
|
||||
log_text(LOG_FATAL, "unable to connect to libAttachSQL server");
|
||||
log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
attachsql_connect_destroy(con);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
while (aret != ATTACHSQL_RETURN_IDLE)
|
||||
{
|
||||
aret = attachsql_connect_poll(con, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
log_text(LOG_FATAL, "unable to connect to libAttachSQL server");
|
||||
log_text(LOG_FATAL, "error %d: %s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
attachsql_connect_destroy(con);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sb_conn->ptr = con;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Disconnect from libAttachSQL database */
|
||||
|
||||
|
||||
int attachsql_drv_disconnect(db_conn_t *sb_conn)
|
||||
{
|
||||
attachsql_connect_t *con = (attachsql_connect_t *)sb_conn->ptr;
|
||||
|
||||
if (con != NULL)
|
||||
{
|
||||
DEBUG("attachsql_connect_destroy(%p)", con);
|
||||
attachsql_connect_destroy(con);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Prepare statement */
|
||||
|
||||
|
||||
int attachsql_drv_prepare(db_stmt_t *stmt, const char *query, size_t len)
|
||||
{
|
||||
attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
|
||||
attachsql_error_t *error= NULL;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
attachsql_statement_prepare(con, len, query, &error);
|
||||
while(aret != ATTACHSQL_RETURN_EOF)
|
||||
{
|
||||
aret= attachsql_connect_poll(con, &error);
|
||||
if (error)
|
||||
{
|
||||
log_text(LOG_ALERT, "libAttachSQL Prepare Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Bind parameters for prepared statement */
|
||||
int attachsql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, size_t len)
|
||||
{
|
||||
/* libAttachSQL doesn't do this, you do this during execute
|
||||
* this is because sysbench doesn't set the values until that time
|
||||
*/
|
||||
|
||||
if (stmt->bound_param != NULL)
|
||||
free(stmt->bound_param);
|
||||
stmt->bound_param = (db_bind_t *)malloc(len * sizeof(db_bind_t));
|
||||
if (stmt->bound_param == NULL)
|
||||
return 1;
|
||||
memcpy(stmt->bound_param, params, len * sizeof(db_bind_t));
|
||||
stmt->bound_param_len = len;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Bind results for prepared statement */
|
||||
int attachsql_drv_bind_result(db_stmt_t *stmt, db_bind_t *params, size_t len)
|
||||
{
|
||||
(void)stmt;
|
||||
(void)params;
|
||||
(void)len;
|
||||
/* libAttachSQL doesn't do this, you get after execute */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Execute prepared statement */
|
||||
|
||||
|
||||
db_error_t attachsql_drv_execute(db_stmt_t *stmt, db_result_t *rs)
|
||||
{
|
||||
(void) rs;
|
||||
attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
attachsql_error_t *error= NULL;
|
||||
|
||||
uint16_t i;
|
||||
int8_t tinyint;
|
||||
int16_t smallint;
|
||||
int32_t normalint;
|
||||
int64_t bigint;
|
||||
float float_type;
|
||||
double double_type;
|
||||
db_time_t *time_data;
|
||||
if (con == NULL)
|
||||
return 1;
|
||||
|
||||
for (i= 0; i < stmt->bound_param_len; i++)
|
||||
{
|
||||
db_bind_t *param= &stmt->bound_param[i];
|
||||
switch(param->type)
|
||||
{
|
||||
case DB_TYPE_TINYINT:
|
||||
tinyint= *(int8_t*)param->buffer;
|
||||
attachsql_statement_set_int(con, i, tinyint, NULL);
|
||||
break;
|
||||
case DB_TYPE_SMALLINT:
|
||||
smallint= *(int16_t*)param->buffer;
|
||||
attachsql_statement_set_int(con, i, smallint, NULL);
|
||||
break;
|
||||
case DB_TYPE_INT:
|
||||
normalint= *(int32_t*)param->buffer;
|
||||
attachsql_statement_set_int(con, i, normalint, NULL);
|
||||
break;
|
||||
case DB_TYPE_BIGINT:
|
||||
bigint= *(int64_t*)param->buffer;
|
||||
attachsql_statement_set_bigint(con, i, bigint, NULL);
|
||||
break;
|
||||
case DB_TYPE_FLOAT:
|
||||
float_type= *(float*)param->buffer;
|
||||
attachsql_statement_set_float(con, i, float_type, NULL);
|
||||
break;
|
||||
case DB_TYPE_DOUBLE:
|
||||
double_type= *(double*)param->buffer;
|
||||
attachsql_statement_set_double(con, i, double_type, NULL);
|
||||
break;
|
||||
case DB_TYPE_TIME:
|
||||
time_data= (db_time_t*)param->buffer;
|
||||
attachsql_statement_set_time(con, i, time_data->hour, time_data->minute, time_data->second, 0, false, NULL);
|
||||
break;
|
||||
case DB_TYPE_DATE:
|
||||
case DB_TYPE_DATETIME:
|
||||
case DB_TYPE_TIMESTAMP:
|
||||
time_data= (db_time_t*)param->buffer;
|
||||
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);
|
||||
break;
|
||||
case DB_TYPE_CHAR:
|
||||
case DB_TYPE_VARCHAR:
|
||||
attachsql_statement_set_string(con, i, param->max_len, param->buffer, NULL);
|
||||
case DB_TYPE_NONE:
|
||||
default:
|
||||
attachsql_statement_set_null(con, i, NULL);
|
||||
/* Not supported */
|
||||
}
|
||||
}
|
||||
|
||||
attachsql_statement_execute(con, &error);
|
||||
|
||||
while(aret != ATTACHSQL_RETURN_EOF)
|
||||
{
|
||||
aret= attachsql_connect_poll(con, &error);
|
||||
if (aret == ATTACHSQL_RETURN_ROW_READY)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
log_text(LOG_ALERT, "libAttachSQL Execute Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
}
|
||||
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Execute SQL query */
|
||||
|
||||
|
||||
db_error_t attachsql_drv_query(db_conn_t *sb_conn, const char *query,
|
||||
size_t len, db_result_t *rs)
|
||||
{
|
||||
(void) rs;
|
||||
attachsql_connect_t *con = sb_conn->ptr;
|
||||
unsigned int rc;
|
||||
attachsql_error_t *error= NULL;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
|
||||
/* Close any previous query */
|
||||
attachsql_query_close(con);
|
||||
|
||||
DEBUG("attachsql_query(%p, \"%s\", %u)",
|
||||
con,
|
||||
query,
|
||||
len);
|
||||
attachsql_query(con, len, query, 0, NULL, &error);
|
||||
|
||||
while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
|
||||
{
|
||||
aret= attachsql_connect_poll(con, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
rc= attachsql_error_code(error);
|
||||
if (rc == 1213 || rc == 1205 || rc == 1020)
|
||||
{
|
||||
attachsql_error_free(error);
|
||||
return DB_ERROR_IGNORABLE;
|
||||
}
|
||||
log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
}
|
||||
//rs->connection->ptr= con;
|
||||
DEBUG("attachsql_query \"%s\" returned %d", query, aret);
|
||||
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Fetch row from result set of a prepared statement */
|
||||
|
||||
|
||||
int attachsql_drv_fetch(db_result_t *rs)
|
||||
{
|
||||
/* NYI */
|
||||
attachsql_connect_t *con = rs->connection->ptr;
|
||||
size_t tmp_len;
|
||||
uint16_t columns, col;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
attachsql_error_t *error= NULL;
|
||||
|
||||
while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
|
||||
{
|
||||
aret= attachsql_connect_poll(con, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (aret == ATTACHSQL_RETURN_EOF)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
attachsql_statement_row_get(con, NULL);
|
||||
columns= attachsql_query_column_count(con);
|
||||
for (col= 0; col < columns; col++)
|
||||
{
|
||||
switch (attachsql_statement_get_column_type(con, col))
|
||||
{
|
||||
case ATTACHSQL_COLUMN_TYPE_TINY:
|
||||
case ATTACHSQL_COLUMN_TYPE_SHORT:
|
||||
case ATTACHSQL_COLUMN_TYPE_LONG:
|
||||
case ATTACHSQL_COLUMN_TYPE_YEAR:
|
||||
case ATTACHSQL_COLUMN_TYPE_INT24:
|
||||
attachsql_statement_get_int(con, col, &error);
|
||||
break;
|
||||
case ATTACHSQL_COLUMN_TYPE_LONGLONG:
|
||||
attachsql_statement_get_bigint(con, col, &error);
|
||||
break;
|
||||
case ATTACHSQL_COLUMN_TYPE_FLOAT:
|
||||
attachsql_statement_get_float(con, col, &error);
|
||||
break;
|
||||
case ATTACHSQL_COLUMN_TYPE_DOUBLE:
|
||||
attachsql_statement_get_double(con, col, &error);
|
||||
break;
|
||||
default:
|
||||
attachsql_statement_get_char(con, col, &tmp_len, &error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
attachsql_query_row_next(con);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Fetch row from result set of a query */
|
||||
|
||||
|
||||
int attachsql_drv_fetch_row(db_result_t *rs, db_row_t *row)
|
||||
{
|
||||
attachsql_error_t *error= NULL;
|
||||
attachsql_return_t aret= ATTACHSQL_RETURN_NONE;
|
||||
|
||||
/* NYI */
|
||||
|
||||
attachsql_connect_t *con = rs->connection->ptr;
|
||||
|
||||
while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
|
||||
{
|
||||
aret= attachsql_connect_poll(con, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
|
||||
attachsql_error_free(error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (aret == ATTACHSQL_RETURN_EOF)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
row->ptr= attachsql_query_row_get(con, NULL);
|
||||
attachsql_query_row_next(con);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Store results from the last query */
|
||||
|
||||
|
||||
int attachsql_drv_store_results(db_result_t *rs)
|
||||
{
|
||||
int ret= 0;
|
||||
db_row_t row;
|
||||
/* libAttachSQL can't do things in this order */
|
||||
while (ret == 0)
|
||||
{
|
||||
if (rs->statement != NULL)
|
||||
{
|
||||
ret= attachsql_drv_fetch(rs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret= attachsql_drv_fetch_row(rs, &row);
|
||||
}
|
||||
}
|
||||
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Free result set */
|
||||
|
||||
|
||||
int attachsql_drv_free_results(db_result_t *rs)
|
||||
{
|
||||
|
||||
if (rs->connection->ptr != NULL)
|
||||
{
|
||||
DEBUG("attachsql_query_close(%p)", rs->connection->ptr);
|
||||
attachsql_query_close(rs->connection->ptr);
|
||||
rs->connection->ptr = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Close prepared statement */
|
||||
|
||||
|
||||
int attachsql_drv_close(db_stmt_t *stmt)
|
||||
{
|
||||
attachsql_connect_t *con= (attachsql_connect_t *)stmt->connection->ptr;
|
||||
attachsql_statement_close(con);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Uninitialize driver */
|
||||
int attachsql_drv_done(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
# Copyright (C) 2009 Sun Microsystems, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
noinst_LIBRARIES = libsbdrizzle.a
|
||||
|
||||
libsbdrizzle_a_SOURCES = drv_drizzle.c
|
||||
@ -1,706 +0,0 @@
|
||||
/* Copyright (C) 2009 Sun Microsystems, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libdrizzle/drizzle_client.h>
|
||||
|
||||
#include "sb_options.h"
|
||||
|
||||
#include "db_driver.h"
|
||||
|
||||
#define DEBUG(format, ...) do { if (db_globals.debug) log_text(LOG_DEBUG, format, __VA_ARGS__); } while (0)
|
||||
|
||||
/* Drizzle driver arguments */
|
||||
|
||||
static sb_arg_t drizzle_drv_args[] =
|
||||
{
|
||||
{"drizzle-host", "Drizzle server host", SB_ARG_TYPE_LIST, "localhost"},
|
||||
{"drizzle-port", "Drizzle server port", SB_ARG_TYPE_INT, "4427"},
|
||||
{"drizzle-socket", "Drizzle socket", SB_ARG_TYPE_STRING, NULL},
|
||||
{"drizzle-user", "Drizzle user", SB_ARG_TYPE_STRING, ""},
|
||||
{"drizzle-password", "Drizzle password", SB_ARG_TYPE_STRING, ""},
|
||||
{"drizzle-db", "Drizzle database name", SB_ARG_TYPE_STRING, "sbtest"},
|
||||
{"drizzle-buffer", "Level of library buffering (none, field, row, all)", SB_ARG_TYPE_STRING, "none"},
|
||||
{"drizzle-mysql", "Use MySQL Protocol", SB_ARG_TYPE_BOOL, "off"},
|
||||
|
||||
{NULL, NULL, SB_ARG_TYPE_NULL, NULL}
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUFFER_NONE,
|
||||
BUFFER_FIELD,
|
||||
BUFFER_ROW,
|
||||
BUFFER_ALL
|
||||
} buffer_level;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sb_list_t *hosts;
|
||||
unsigned int port;
|
||||
char *socket;
|
||||
char *user;
|
||||
char *password;
|
||||
char *db;
|
||||
buffer_level buffer;
|
||||
int mysql;
|
||||
} drizzle_drv_args_t;
|
||||
|
||||
/* Drizzle driver capabilities */
|
||||
|
||||
static drv_caps_t drizzle_drv_caps =
|
||||
{
|
||||
.multi_rows_insert = 1,
|
||||
.prepared_statements = 0,
|
||||
.auto_increment = 1,
|
||||
.serial = 0,
|
||||
.unsigned_int = 0,
|
||||
};
|
||||
|
||||
static drizzle_drv_args_t args; /* driver args */
|
||||
|
||||
static sb_list_item_t *hosts_pos;
|
||||
|
||||
static pthread_mutex_t hosts_mutex;
|
||||
|
||||
static void column_info(drizzle_column_st *column);
|
||||
|
||||
/* Drizzle driver operations */
|
||||
|
||||
static int drizzle_drv_init(void);
|
||||
static int drizzle_drv_describe(drv_caps_t *);
|
||||
static int drizzle_drv_connect(db_conn_t *);
|
||||
static int drizzle_drv_disconnect(db_conn_t *);
|
||||
static int drizzle_drv_prepare(db_stmt_t *, const char *, size_t);
|
||||
static int drizzle_drv_bind_param(db_stmt_t *, db_bind_t *, size_t);
|
||||
static int drizzle_drv_bind_result(db_stmt_t *, db_bind_t *, size_t);
|
||||
static db_error_t drizzle_drv_execute(db_stmt_t *, db_result_t *);
|
||||
static int drizzle_drv_fetch(db_result_t *);
|
||||
static int drizzle_drv_fetch_row(db_result_t *, db_row_t *);
|
||||
static db_error_t drizzle_drv_query(db_conn_t *, const char *, size_t,
|
||||
db_result_t *);
|
||||
static int drizzle_drv_free_results(db_result_t *);
|
||||
static int drizzle_drv_close(db_stmt_t *);
|
||||
static int drizzle_drv_store_results(db_result_t *);
|
||||
static int drizzle_drv_done(void);
|
||||
|
||||
/* Drizzle driver definition */
|
||||
|
||||
static db_driver_t drizzle_driver =
|
||||
{
|
||||
.sname = "drizzle",
|
||||
.lname = "Drizzle driver",
|
||||
.args = drizzle_drv_args,
|
||||
.ops =
|
||||
{
|
||||
.init = drizzle_drv_init,
|
||||
.describe = drizzle_drv_describe,
|
||||
.connect = drizzle_drv_connect,
|
||||
.disconnect = drizzle_drv_disconnect,
|
||||
.prepare = drizzle_drv_prepare,
|
||||
.bind_param = drizzle_drv_bind_param,
|
||||
.bind_result = drizzle_drv_bind_result,
|
||||
.execute = drizzle_drv_execute,
|
||||
.fetch = drizzle_drv_fetch,
|
||||
.fetch_row = drizzle_drv_fetch_row,
|
||||
.free_results = drizzle_drv_free_results,
|
||||
.close = drizzle_drv_close,
|
||||
.query = drizzle_drv_query,
|
||||
.store_results = drizzle_drv_store_results,
|
||||
.done = drizzle_drv_done
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/* Local functions */
|
||||
|
||||
/* Register Drizzle driver */
|
||||
|
||||
|
||||
int register_driver_drizzle(sb_list_t *drivers)
|
||||
{
|
||||
SB_LIST_ADD_TAIL(&drizzle_driver.listitem, drivers);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Drizzle driver initialization */
|
||||
|
||||
|
||||
int drizzle_drv_init(void)
|
||||
{
|
||||
char *s;
|
||||
|
||||
args.hosts = sb_get_value_list("drizzle-host");
|
||||
if (SB_LIST_IS_EMPTY(args.hosts))
|
||||
{
|
||||
log_text(LOG_FATAL, "No Drizzle hosts specified, aborting");
|
||||
return 1;
|
||||
}
|
||||
hosts_pos = args.hosts;
|
||||
pthread_mutex_init(&hosts_mutex, NULL);
|
||||
|
||||
args.port = (unsigned int)sb_get_value_int("drizzle-port");
|
||||
args.socket = sb_get_value_string("drizzle-socket");
|
||||
args.user = sb_get_value_string("drizzle-user");
|
||||
args.password = sb_get_value_string("drizzle-password");
|
||||
args.db = sb_get_value_string("drizzle-db");
|
||||
s= sb_get_value_string("drizzle-buffer");
|
||||
if (!strcasecmp(s, "none"))
|
||||
args.buffer= BUFFER_NONE;
|
||||
else if (!strcasecmp(s, "field"))
|
||||
args.buffer= BUFFER_FIELD;
|
||||
else if (!strcasecmp(s, "row"))
|
||||
args.buffer= BUFFER_ROW;
|
||||
else if (!strcasecmp(s, "all"))
|
||||
args.buffer= BUFFER_ALL;
|
||||
|
||||
args.mysql= sb_get_value_flag("drizzle-mysql");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Describe database capabilities (possibly depending on table type) */
|
||||
|
||||
|
||||
int drizzle_drv_describe(drv_caps_t *caps )
|
||||
{
|
||||
*caps = drizzle_drv_caps;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to Drizzle database */
|
||||
|
||||
|
||||
int drizzle_drv_connect(db_conn_t *sb_conn)
|
||||
{
|
||||
drizzle_st *drizzle_lib= NULL;
|
||||
drizzle_con_st *con= NULL;
|
||||
const char *host;
|
||||
drizzle_return_t ret;
|
||||
|
||||
drizzle_lib= drizzle_create(drizzle_lib);
|
||||
|
||||
if (args.socket)
|
||||
{
|
||||
DEBUG("drizzle_con_add_uds(%p, %p \"%s\", \"%s\", \"%s\", \"%s\", %d)",
|
||||
drizzle_lib,
|
||||
con,
|
||||
args.socket,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
args.mysql ? DRIZZLE_CON_MYSQL : 0);
|
||||
con= drizzle_con_add_uds(drizzle_lib,
|
||||
con,
|
||||
args.socket,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
args.mysql ? DRIZZLE_CON_MYSQL : 0);
|
||||
} else {
|
||||
|
||||
pthread_mutex_lock(&hosts_mutex);
|
||||
hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
|
||||
if (hosts_pos == args.hosts)
|
||||
hosts_pos = SB_LIST_ITEM_NEXT(hosts_pos);
|
||||
host = SB_LIST_ENTRY(hosts_pos, value_t, listitem)->data;
|
||||
pthread_mutex_unlock(&hosts_mutex);
|
||||
|
||||
DEBUG("drizzle_con_add_tcp(%p, %p \"%s\", %u, \"%s\", \"%s\", \"%s\", %d)",
|
||||
drizzle_lib,
|
||||
con,
|
||||
host,
|
||||
args.port,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
args.mysql ? DRIZZLE_CON_MYSQL : 0);
|
||||
con= drizzle_con_add_tcp(drizzle_lib,
|
||||
con,
|
||||
host,
|
||||
args.port,
|
||||
args.user,
|
||||
args.password,
|
||||
args.db,
|
||||
args.mysql ? DRIZZLE_CON_MYSQL : 0);
|
||||
}
|
||||
|
||||
if (con == NULL)
|
||||
{
|
||||
log_text(LOG_FATAL, "unable to Add Drizzle Connection, aborting...");
|
||||
log_text(LOG_FATAL, "error %d: %s", drizzle_errno(drizzle_lib),
|
||||
drizzle_error(drizzle_lib));
|
||||
return 1;
|
||||
}
|
||||
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
log_text(LOG_FATAL, "unable to connect to Drizzle server: %d", ret);
|
||||
log_text(LOG_FATAL, "error %d: %s", drizzle_errno(drizzle_lib),
|
||||
drizzle_error(drizzle_lib));
|
||||
free(con);
|
||||
return 1;
|
||||
|
||||
}
|
||||
sb_conn->ptr = con;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Disconnect from Drizzle database */
|
||||
|
||||
|
||||
int drizzle_drv_disconnect(db_conn_t *sb_conn)
|
||||
{
|
||||
drizzle_con_st *con = (drizzle_con_st *)sb_conn->ptr;
|
||||
|
||||
if (con != NULL)
|
||||
{
|
||||
DEBUG("drizzle_close(%p)", con);
|
||||
drizzle_con_close(con);
|
||||
free(con);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Prepare statement */
|
||||
|
||||
|
||||
int drizzle_drv_prepare(db_stmt_t *stmt, const char *query, size_t len)
|
||||
{
|
||||
|
||||
(void) len; /* unused */
|
||||
|
||||
/* Use client-side PS */
|
||||
stmt->emulated = 1;
|
||||
stmt->query = strdup(query);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Bind parameters for prepared statement */
|
||||
int drizzle_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, size_t len)
|
||||
{
|
||||
drizzle_con_st *con = (drizzle_con_st *)stmt->connection->ptr;
|
||||
|
||||
if (con == NULL)
|
||||
return 1;
|
||||
|
||||
/* Use emulation */
|
||||
if (stmt->bound_param != NULL)
|
||||
free(stmt->bound_param);
|
||||
stmt->bound_param = (db_bind_t *)malloc(len * sizeof(db_bind_t));
|
||||
if (stmt->bound_param == NULL)
|
||||
return 1;
|
||||
memcpy(stmt->bound_param, params, len * sizeof(db_bind_t));
|
||||
stmt->bound_param_len = len;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Bind results for prepared statement */
|
||||
int drizzle_drv_bind_result(db_stmt_t *stmt, db_bind_t *params, size_t len)
|
||||
{
|
||||
(void)stmt;
|
||||
(void)params;
|
||||
(void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Execute prepared statement */
|
||||
|
||||
|
||||
db_error_t drizzle_drv_execute(db_stmt_t *stmt, db_result_t *rs)
|
||||
{
|
||||
db_conn_t *con = stmt->connection;
|
||||
char *buf = NULL;
|
||||
unsigned int buflen = 0;
|
||||
unsigned int i, j, vcnt;
|
||||
char need_realloc;
|
||||
int n;
|
||||
|
||||
/* Use emulation */
|
||||
/* Build the actual query string from parameters list */
|
||||
need_realloc = 1;
|
||||
vcnt = 0;
|
||||
for (i = 0, j = 0; stmt->query[i] != '\0'; i++)
|
||||
{
|
||||
again:
|
||||
if (j+1 >= buflen || need_realloc)
|
||||
{
|
||||
buflen = (buflen > 0) ? buflen * 2 : 256;
|
||||
buf = realloc(buf, buflen);
|
||||
if (buf == NULL)
|
||||
{
|
||||
log_text(LOG_DEBUG, "ERROR: exiting drizzle_drv_execute(), memory allocation failure");
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
need_realloc = 0;
|
||||
}
|
||||
|
||||
if (stmt->query[i] != '?')
|
||||
{
|
||||
buf[j++] = stmt->query[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
n = db_print_value(stmt->bound_param + vcnt, buf + j, (int)(buflen - j));
|
||||
if (n < 0)
|
||||
{
|
||||
need_realloc = 1;
|
||||
goto again;
|
||||
}
|
||||
j += (unsigned int)n;
|
||||
vcnt++;
|
||||
}
|
||||
buf[j] = '\0';
|
||||
|
||||
con->error = drizzle_drv_query(con, buf, j, rs);
|
||||
free(buf);
|
||||
if (con->error != DB_ERROR_NONE)
|
||||
{
|
||||
log_text(LOG_DEBUG, "ERROR: exiting drizzle_drv_execute(), database error");
|
||||
return con->error;
|
||||
}
|
||||
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Execute SQL query */
|
||||
|
||||
|
||||
db_error_t drizzle_drv_query(db_conn_t *sb_conn, const char *query, size_t len,
|
||||
db_result_t *rs)
|
||||
{
|
||||
drizzle_con_st *con = sb_conn->ptr;
|
||||
unsigned int rc;
|
||||
drizzle_return_t ret;
|
||||
drizzle_result_st *result= NULL;
|
||||
|
||||
DEBUG("drizzle_query(%p, %p, \"%s\", %u, %p)",
|
||||
con,
|
||||
result,
|
||||
query,
|
||||
len,
|
||||
&ret);
|
||||
result= drizzle_query(con, NULL, query, len, &ret);
|
||||
DEBUG("drizzle_query(%p) == %d", con, ret);
|
||||
|
||||
if (ret == DRIZZLE_RETURN_ERROR_CODE)
|
||||
{
|
||||
rc= drizzle_result_error_code(result);
|
||||
/* Error code constants haven't been added yet to libdrizzle
|
||||
ER_LOCK_DEADLOCK==1213
|
||||
ER_LOCK_WAIT_TIMEOUT==1205
|
||||
ER_CHECKREAD==1020
|
||||
*/
|
||||
if (rc == 1213 || rc == 1205 ||
|
||||
rc == 1020)
|
||||
return DB_ERROR_IGNORABLE;
|
||||
log_text(LOG_ALERT, "Drizzle Query Failed: %u:%s",
|
||||
drizzle_result_error_code(result),
|
||||
drizzle_result_error(result));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
else if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "failed to execute Drizzle query: len==%d `%s`:",
|
||||
strlen(query), query);
|
||||
log_text(LOG_ALERT, "Error %d %s", drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
DEBUG("drizzle_query \"%s\" returned %d", query, ret);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
DEBUG("drizzle_query(%p, \"%s\") == NULL",con,query);
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
|
||||
|
||||
rs->ptr= result;
|
||||
rs->nrows= drizzle_result_row_count(result);
|
||||
DEBUG("drizzle_result_row_count(%p) == %d",result,rs->nrows);
|
||||
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Fetch row from result set of a prepared statement */
|
||||
|
||||
|
||||
int drizzle_drv_fetch(db_result_t *rs)
|
||||
{
|
||||
/* NYI */
|
||||
(void)rs;
|
||||
printf("in drizzle_drv_fetch_row!\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Fetch row from result set of a query */
|
||||
|
||||
|
||||
int drizzle_drv_fetch_row(db_result_t *rs, db_row_t *row)
|
||||
{
|
||||
/* NYI */
|
||||
printf("in drizzle_drv_fetch_row!\n");
|
||||
(void)rs; /* unused */
|
||||
(void)row; /* unused */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Store results from the last query */
|
||||
|
||||
|
||||
int drizzle_drv_store_results(db_result_t *rs)
|
||||
{
|
||||
|
||||
drizzle_con_st *con = rs->connection->ptr;
|
||||
drizzle_result_st *res = rs->ptr;
|
||||
drizzle_return_t ret;
|
||||
drizzle_column_st *column= NULL;
|
||||
unsigned int rc;
|
||||
|
||||
|
||||
if (con == NULL || res == NULL)
|
||||
return DB_ERROR_FATAL;
|
||||
|
||||
|
||||
if (args.buffer == BUFFER_ALL)
|
||||
{
|
||||
|
||||
ret= drizzle_result_buffer(res);
|
||||
DEBUG("drizzle_result_buffer(%p) = %d", res, ret);
|
||||
if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "drizzle_result_buffer failed: `%p`:", res);
|
||||
log_text(LOG_ALERT, "Error %d %s",
|
||||
drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
while ((column = drizzle_column_next(res)) != NULL)
|
||||
column_info(column);
|
||||
}
|
||||
else if (drizzle_result_column_count(res) > 0)
|
||||
{
|
||||
|
||||
drizzle_row_t row;
|
||||
drizzle_field_t field;
|
||||
uint64_t row_num;
|
||||
size_t offset= 0;
|
||||
size_t length;
|
||||
size_t total;
|
||||
|
||||
/* Read column meta-info */
|
||||
while (1)
|
||||
{
|
||||
column= drizzle_column_read(res, column, &ret);
|
||||
DEBUG("drizzle_column_read(%p,%p,%p) == %d",res, column, &ret, ret);
|
||||
if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "drizzle_column_read failed: `%p`:", res);
|
||||
log_text(LOG_ALERT, "Error %d %s",
|
||||
drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
if (column == NULL)
|
||||
break;
|
||||
|
||||
column_info(column);
|
||||
drizzle_column_free(column);
|
||||
}
|
||||
|
||||
/* Actually fetch rows */
|
||||
while (1) /* Loop for rows */
|
||||
{
|
||||
if (args.buffer == BUFFER_ROW)
|
||||
{
|
||||
row= drizzle_row_buffer(res, &ret);
|
||||
DEBUG("drizzle_row_buffer(%p, %p) == %p, %d",res, &ret, row, ret);
|
||||
if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "drizzle_row_buffer failed: `%p`:", res);
|
||||
log_text(LOG_ALERT, "Error %d %s",
|
||||
drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
|
||||
if (row == NULL)
|
||||
break;
|
||||
|
||||
DEBUG("drizzle_row_free(%p, %p)",res,row);
|
||||
drizzle_row_free(res, row);
|
||||
}
|
||||
else if (args.buffer == BUFFER_NONE || args.buffer == BUFFER_FIELD)
|
||||
{
|
||||
row_num= drizzle_row_read(res, &ret);
|
||||
DEBUG("drizzle_row_read(%p, %p) == %"PRIu64", %d",
|
||||
res, &ret, row_num, ret);
|
||||
if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "drizzle_row_read failed: `%p`:", res);
|
||||
log_text(LOG_ALERT, "Error %d %s",
|
||||
drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
|
||||
if (row_num == 0)
|
||||
break;
|
||||
|
||||
while (1) /* Loop for fields */
|
||||
{
|
||||
|
||||
if (args.buffer == BUFFER_FIELD)
|
||||
{
|
||||
/* Since an entire field is buffered, we don't need to worry about
|
||||
partial reads. */
|
||||
field= drizzle_field_buffer(res, &total, &ret);
|
||||
DEBUG("drizzle_field_buffer(%p, &p, %p) == %p, %x, %d",
|
||||
res, &total, &ret, field, total, ret);
|
||||
length= total;
|
||||
}
|
||||
else
|
||||
{
|
||||
field= drizzle_field_read(res, &offset, &length, &total, &ret);
|
||||
DEBUG("drizzle_field_read(%p, %p, %p, %p, %p) == "
|
||||
"%p, %x, %x, %x, %d",
|
||||
res, &offset, &length, &total, &ret,
|
||||
field, offset, length, total, ret);
|
||||
}
|
||||
|
||||
if (ret == DRIZZLE_RETURN_ROW_END)
|
||||
break;
|
||||
else if (ret != DRIZZLE_RETURN_OK)
|
||||
{
|
||||
rc = drizzle_con_errno(con);
|
||||
DEBUG("drizzle_errno(%p) = %u", drizzle_con_drizzle(con), rc);
|
||||
log_text(LOG_ALERT, "drizzle_field_(buffer|read) failed: `%p`:",
|
||||
res);
|
||||
log_text(LOG_ALERT, "Error %d %s",
|
||||
drizzle_con_errno(con),
|
||||
drizzle_con_error(con));
|
||||
return DB_ERROR_FATAL;
|
||||
}
|
||||
|
||||
if (args.buffer == BUFFER_FIELD)
|
||||
drizzle_field_free(field);
|
||||
|
||||
} /* while (1) Loop for fields */
|
||||
|
||||
} /* if (args.buffer) */
|
||||
|
||||
} /* while (1) */
|
||||
}
|
||||
return DB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Free result set */
|
||||
|
||||
|
||||
int drizzle_drv_free_results(db_result_t *rs)
|
||||
{
|
||||
|
||||
if (rs->ptr != NULL)
|
||||
{
|
||||
DEBUG("drizzle_result_free(%p)", rs->ptr);
|
||||
drizzle_result_free(rs->ptr);
|
||||
rs->ptr = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Close prepared statement */
|
||||
|
||||
|
||||
int drizzle_drv_close(db_stmt_t *stmt)
|
||||
{
|
||||
(void)stmt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Uninitialize driver */
|
||||
int drizzle_drv_done(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void column_info(drizzle_column_st *column)
|
||||
{
|
||||
DEBUG("Field: catalog=%s\n"
|
||||
" db=%s\n"
|
||||
" table=%s\n"
|
||||
" org_table=%s\n"
|
||||
" name=%s\n"
|
||||
" org_name=%s\n"
|
||||
" charset=%u\n"
|
||||
" size=%u\n"
|
||||
" type=%u\n"
|
||||
" flags=%u\n",
|
||||
drizzle_column_catalog(column), drizzle_column_db(column),
|
||||
drizzle_column_table(column), drizzle_column_orig_table(column),
|
||||
drizzle_column_name(column), drizzle_column_orig_name(column),
|
||||
drizzle_column_charset(column), drizzle_column_size(column),
|
||||
drizzle_column_type(column), drizzle_column_flags(column));
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
# Copyright (C) 2005 MySQL AB
|
||||
# Copyright (C) 2005-2008 Alexey Kopytov <akopytov@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
noinst_LIBRARIES = libsboracle.a
|
||||
|
||||
libsboracle_a_SOURCES = drv_oracle.c
|
||||
libsboracle_a_CPPFLAGS = $(ORA_CFLAGS) $(AM_CPPFLAGS)
|
||||
File diff suppressed because it is too large
Load Diff
@ -161,8 +161,7 @@ function create_table(drv, con, table_num)
|
||||
id_index_def = "PRIMARY KEY"
|
||||
end
|
||||
|
||||
if drv:name() == "mysql" or drv:name() == "attachsql" or
|
||||
drv:name() == "drizzle"
|
||||
if drv:name() == "mysql"
|
||||
then
|
||||
if sysbench.opt.auto_inc then
|
||||
id_def = "INTEGER NOT NULL AUTO_INCREMENT"
|
||||
|
||||
Reference in New Issue
Block a user