Update DB dependencies.
Fix reaction on DB initialization errors.
Priority: extra
Maintainer: @MAINTAINER@
Uploaders: @UPLOADERS@
-Build-Depends: debhelper (>= 7.0.50~), bison, chrpath, flex, glite-lb-types, glite-lb-ws-interface, gsoap, libc-ares-dev, libc-ares2, libclassad-dev, libclassad1, libcppunit-dev, libexpat1, libexpat1-dev, libglobus-gssapi-gsi-dev, libglite-jobid-api-c-dev, libglite-lb-common-dev, libglite-lb-state-machine-dev, libglite-lbjp-common-db-dev, libglite-lbjp-common-gss-dev, libglite-lbjp-common-gsoap-plugin-dev, libglite-lbjp-common-log-dev, libglite-lbjp-common-maildir-dev, libglite-lbjp-common-server-bones-dev, libglite-lbjp-common-trio-dev, libgridsite-dev, libmysqlclient-dev, libtool, libxml2, libxml2-dev, libvomsapi1, voms-dev
+Build-Depends: debhelper (>= 7.0.50~), bison, chrpath, flex, glite-lb-types, glite-lb-ws-interface, gsoap, libc-ares-dev, libc-ares2, libclassad-dev, libclassad1, libcppunit-dev, libexpat1, libexpat1-dev, libglobus-gssapi-gsi-dev, libglite-jobid-api-c-dev, libglite-lb-common-dev, libglite-lb-state-machine-dev, libglite-lbjp-common-db-dev, libglite-lbjp-common-gss-dev, libglite-lbjp-common-gsoap-plugin-dev, libglite-lbjp-common-log-dev, libglite-lbjp-common-maildir-dev, libglite-lbjp-common-server-bones-dev, libglite-lbjp-common-trio-dev, libgridsite-dev, libtool, libxml2, libxml2-dev, libvomsapi1, voms-dev
#TODO: lcas
Standards-Version: 3.9.1
Section: misc
BuildRequires: gridsite-devel
BuildRequires: gsoap-devel
BuildRequires: libxml2
-BuildRequires: mysql-devel
BuildRequires: c-ares-devel
BuildRequires: cppunit-devel
BuildRequires: gridsite-shared
char *cols[20];
glite_lbu_Statement stmt;
- if (!ctx->dbctx && glite_lbu_InitDBContext((glite_lbu_DBContext*) &ctx->dbctx, GLITE_LBU_DB_BACKEND_MYSQL, LOG_CATEGORY_LB_SERVER_DB) != 0) {
+ if (!ctx->dbctx && (ret = glite_lbu_InitDBContext((glite_lbu_DBContext*) &ctx->dbctx, GLITE_LBU_DB_BACKEND_MYSQL, LOG_CATEGORY_LB_SERVER_DB)) != 0) {
char *ed;
- glite_lbu_DBError(ctx->dbctx, NULL, &ed);
- edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, ed);
- free(ed);
+ if (ctx->dbctx) {
+ glite_lbu_DBError(ctx->dbctx, NULL, &ed);
+ edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, ed);
+ free(ed);
+ } else
+ edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, strerror(ret));
+
return EDG_WLL_ERROR_DB_INIT;
}
if (glite_lbu_DBConnect(ctx->dbctx,cs) != 0) return edg_wll_SetErrorDB(ctx);
edg_wll_ErrorCode edg_wll_Close(edg_wll_Context ctx)
{
- glite_lbu_DBClose(ctx->dbctx);
- glite_lbu_FreeDBContext(ctx->dbctx);
- ctx->dbctx = NULL;
+ if (ctx->dbctx) {
+ glite_lbu_DBClose(ctx->dbctx);
+ glite_lbu_FreeDBContext(ctx->dbctx);
+ ctx->dbctx = NULL;
+ }
return edg_wll_ResetError(ctx);
}
'lb.logger' => [ qw/cppunit:B libtool:B/ ],
'lb.logger-msg' => [ qw/cppunit:B activemq libtool:B/ ],
'lb.nagios' => [ qw/globus_proxy_utils:R/ ],
- 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms:B lcas gridsite bison:B libtool:B libxml2 flex:B/ ],
+ 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql-server:R cppunit:B gsoap:B classads voms:B lcas gridsite bison:B libtool:B libxml2 flex:B/ ],
'lb.state-machine' => [ qw/classads libtool:B libxslt:B expat:B/ ],
'lb.utils' => [ qw/cppunit:B libtool:B/ ],
'lb.ws-interface' => [ qw/libxslt:B tidy:B/ ],
'lb.ws-test' => [ qw/gsoap:B libtool:B/ ],
'lb.types' => [ qw// ],
'lb.harvester' => [ qw/docbook-utils:B libtool:B/ ],
- 'lbjp-common.db' => [ qw/mysql:B mysql-devel:B postgresql:B cppunit:B log4c:B libtool:B/ ],
+ 'lbjp-common.db' => [ qw/mysql-devel:B postgresql:B cppunit:B log4c:B libtool:B/ ],
'lbjp-common.log' => [ qw/log4c libtool:B/ ],
'lbjp-common.maildir' => [ qw/libtool:B/ ],
'lbjp-common.server-bones' => [ qw/libtool:B/ ],
'jobid.api-java' => [ qw/ant:B jdk:B/ ],
'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ],
'jp.doc' => [],
- 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ],
- 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ],
+ 'jp.index' => [ qw/gsoap globus_essentials:R globus:B mysql-server:R/ ],
+ 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B mysql-server:R/ ],
'jp.server-common' => [],
'jp.ws-interface' => [],
'gridsite.core' => [ qw/httpd-devel:B gsoap:B globus:B curl:B doxygen:B fuse-devel:B libxml2:B openssl:B doxygen:B/ ],
DEBUG:=-g -O0 -W -Wall
-os=${shell uname}
-DL_LIBS:=
-ifeq (${os},Linux)
- DL_LIBS:=-ldl
-endif
-
-MYSQL_SONAME:=$(shell ${top_srcdir}/project/get_soname.sh mysqlclient ${mysql-devel_prefix}/${libdir} ${mysql_prefix}/${libdir} ${mysql-devel_prefix}/lib ${mysql_prefix}/lib)
-PSQL_SONAME:=$(shell ${top_srcdir}/project/get_soname.sh pq ${postgresql_prefix}/${libdir} ${postgresql_prefix}/lib)
-
-MYSQL_CPPFLAGS:=-I${mysql-devel_prefix}/include -I${mysql-devel_prefix}/include/mysql
-PSQL_CPPFLAGS:=-I${postgresql_prefix}/include -I${postgresql_prefix}/include/postgresql
-
-
CFLAGS:= ${CFLAGS} \
${DEBUG} \
-DVERSION=\"${version}\" \
endif
ifneq (${mysql-devel_prefix},no)
OBJS:=${OBJS} db-mysql.o
- CFLAGS:=${CFLAGS} -DMYSQL_SONAME=\"${MYSQL_SONAME}\"
+ CFLAGS:=${CFLAGS} -DMYSQL_ENABLED=1
+ MYSQL_CFLAGS?=-I${mysql-devel_prefix}/include -I${mysql-devel_prefix}/include/mysql
+ MYSQL_LIBS?=-L${mysql-devel_prefix}/${libdir} -L${mysql-devel_prefix}/${libdir}/mysql -lmysqlclient
endif
ifneq (${postgresql_prefix},no)
OBJS:=${OBJS} db-pg.o
- CFLAGS:=${CFLAGS} -DPSQL_SONAME=\"${PSQL_SONAME}\"
+ CFLAGS:=${CFLAGS} -DPSQL_ENABLED=1
+ PSQL_CFLAGS?=-I${postgresql_prefix}/include -I${postgresql_prefix}/include/postgresql
+ PSQL_LIBS?=-L${postgresql_prefix}/${libdir} -lpq
endif
TEST_LIBS:=-L${cppunit_prefix}/${libdir} -lcppunit
LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}${prefix}/${libdir} ${LDFLAGS}
INSTALL:=libtool --mode=install install
-EXT_LIBS:=-lglite_lbu_trio -lglite_lbu_log -lpthread ${DL_LIBS}
+EXT_LIBS:=-lglite_lbu_trio -lglite_lbu_log ${MYSQL_LIBS} ${PSQL_LIBS}
TESTOBJS:=${OBJS} dbtest.o
OBJS:=${OBJS} db.o
HDRS:=db.h
default all: compile doc
-check_soname:
- if [ "${mysql-devel_prefix}" != no ]; then \
- if [ "${MYSQL_SONAME}" = notfound ]; then \
- echo "MySQL shared library not found!"; \
- false; \
- fi \
- fi
- if [ "${postgresql_prefix}" != no ]; then \
- if [ "${PSQL_SONAME}" = notfound ]; then \
- echo "PostgreSQL shared library not found!"; \
- false; \
- fi \
- fi
-
-libglite_lbu_db.la: check_soname ${LOBJS}
+libglite_lbu_db.la: ${LOBJS}
${LINK} ${version_info} -o $@ $+ ${EXT_LIBS}
-libglite_lbu_dbtest.la: check_soname ${LTESTOBJS}
+libglite_lbu_dbtest.la: ${LTESTOBJS}
${LINK} ${version_info} -o $@ $+ ${EXT_LIBS}
dbtest.lo dbtest.o: db.c db.h
${COMPILE} -DGLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH=10 -c $< -o $@
db_test_mysql: db_test_mysql.lo libglite_lbu_dbtest.la
- ${LINK} -o $@ $+ ${EXT_LIBS}
+ ${LINK} -o $@ $+
db_test_psql: db_test_psql.lo libglite_lbu_dbtest.la
- ${LINK} -o $@ $+ ${EXT_LIBS}
+ ${LINK} -o $@ $+
db_expire: db_expire.lo libglite_lbu_dbtest.la
- ${LINK} -o $@ $+ ${EXT_LIBS}
+ ${LINK} -o $@ $+
timezone: timezone.lo libglite_lbu_db.la
- ${LINKXX} -o $@ $+ ${TEST_LIBS} ${EXT_LIBS}
+ ${LINKXX} -o $@ $+ ${TEST_LIBS}
compile: libglite_lbu_db.la
rm -rvf Makefile.inc *.spec debian/
db-mysql.o db-mysql.lo: db-mysql.c
- ${COMPILE} ${MYSQL_CPPFLAGS} -c $<
+ ${COMPILE} ${MYSQL_CFLAGS} -c $<
db-pg.o db-pg.lo: db-pg.c
- ${COMPILE} ${PSQL_CPPFLAGS} -c $<
+ ${COMPILE} ${PSQL_CFLAGS} -c $<
db_test_mysql.o db_test_mysql.lo: db_test.c
${COMPILE} -DMYSQL_BACKEND=1 -c $< -o $@
db-mysql.lo: db-mysql.c db-int.h db.h
db-pg.lo: db-pg.c db-int.h db.h
-.PHONY: default all compile check examples doc stage dist distsrc distbin install clean test_coverage check_soname distclean
+.PHONY: default all compile check examples doc stage dist distsrc distbin install clean test_coverage distclean
Priority: extra
Maintainer: @MAINTAINER@
Uploaders: @UPLOADERS@
-Build-Depends: debhelper (>= 7.0.50~), chrpath, libcppunit-dev, liblog4c-dev, libglite-lbjp-common-trio-dev, libglite-lbjp-common-log-dev, libmysqlclient-dev, libmysqlclient16, libpq-dev, libtool
+Build-Depends: debhelper (>= 7.0.50~), chrpath, libcppunit-dev, liblog4c-dev, libglite-lbjp-common-trio-dev, libglite-lbjp-common-log-dev, libmysqlclient-dev, libpq-dev, libtool
Standards-Version: 3.9.1
Section: libs
Homepage: @URL@
+++ /dev/null
-#! /bin/sh
-#
-# Copyright (c) Members of the EGEE Collaboration. 2004-2010.
-# See http://www.eu-egee.org/partners for details on the copyright holders.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-lib=""
-filename="lib$1.so"
-shift
-for prefix in $@; do
- for dir in "$prefix" "$prefix/mysql"; do
- l=`find $dir -maxdepth 1 -name "${filename}"* 2>/dev/null | head -n 1`
- if [ -f "$l" ]; then
- lib=$l
- break
- fi
- done
- if [ x"" != x"$lib" ]; then
- break
- fi
-done
-
-if [ x"" != x"$lib" ]; then
- readelf -d $lib | grep SONAME | sed "s/.*\(${filename}.[0-9]\{1,\}\).*/\1/"
-else
- echo notfound
-fi
BuildRequires: cppunit-devel
BuildRequires: chrpath
BuildRequires: log4c-devel
-BuildRequires: mysql
BuildRequires: mysql-devel
BuildRequires: glite-lbjp-common-trio-devel
BuildRequires: glite-lbjp-common-log-devel
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
-#include <dlfcn.h>
-#include <pthread.h>
-
-#ifdef WIN32
-#include <windows.h>
-#ifndef STDCALL
-#define STDCALL __stdcall
-#endif
-#else
-#define STDCALL
-#endif
#include <mysql.h>
#include <mysqld_error.h>
#define MY_ISOKSTMT(STMT, RETRY) myisokstmt((STMT), __FUNCTION__, __LINE__, (RETRY))
#define USE_TRANS(CTX) ((CTX->generic.caps & GLITE_LBU_DB_CAP_TRANSACTIONS) != 0)
-#define LOAD(SYM, SYM2) if ((*(void **)(&mysql_module.SYM) = dlsym(mysql_module.lib, SYM2)) == NULL) { \
- err = ERR(ctx, ENOENT, "can't load symbol '%s' from mysql library (%s)", SYM2, dlerror()); \
- break; \
-}
};
-typedef struct {
- void *lib;
- pthread_mutex_t lock;
-
- void * STDCALL(*mysql_init)(void *);
- unsigned long STDCALL(*mysql_get_client_version)(void);
- int STDCALL(*mysql_options)(MYSQL *mysql, enum mysql_option option, const char *arg);
- unsigned int STDCALL(*mysql_errno)(MYSQL *mysql);
- const char *STDCALL(*mysql_error)(MYSQL *mysql);
- unsigned int STDCALL(*mysql_stmt_errno)(MYSQL_STMT *stmt);
- const char *STDCALL(*mysql_stmt_error)(MYSQL_STMT *stmt);
- MYSQL * STDCALL(*mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag);
- void STDCALL(*mysql_close)(MYSQL *mysql);
- int STDCALL(*mysql_query)(MYSQL *mysql, const char *stmt_str);
- MYSQL_RES *STDCALL(*mysql_store_result)(MYSQL *mysql);
- void STDCALL(*mysql_free_result)(MYSQL_RES *result);
- my_ulonglong STDCALL(*mysql_affected_rows)(MYSQL *mysql);
- my_bool STDCALL(*mysql_stmt_close)(MYSQL_STMT *);
- unsigned int STDCALL(*mysql_num_fields)(MYSQL_RES *result);
- unsigned long *STDCALL(*mysql_fetch_lengths)(MYSQL_RES *result);
- my_bool STDCALL(*mysql_stmt_bind_result)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
- int STDCALL(*mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *stmt_str, unsigned long length);
- int STDCALL(*mysql_stmt_store_result)(MYSQL_STMT *stmt);
- MYSQL_ROW STDCALL(*mysql_fetch_row)(MYSQL_RES *result);
- MYSQL_FIELD *STDCALL(*mysql_fetch_field)(MYSQL_RES *result);
- const char *STDCALL(*mysql_get_server_info)(MYSQL *mysql);
- MYSQL_STMT *STDCALL(*mysql_stmt_init)(MYSQL *mysql);
- my_bool STDCALL(*mysql_stmt_bind_param)(MYSQL_STMT *stmt, MYSQL_BIND *bind);
- int STDCALL(*mysql_stmt_execute)(MYSQL_STMT *stmt);
- int STDCALL(*mysql_stmt_fetch)(MYSQL_STMT *stmt);
- my_ulonglong STDCALL(*mysql_stmt_insert_id)(MYSQL_STMT *stmt);
- my_ulonglong STDCALL(*mysql_stmt_affected_rows)(MYSQL_STMT *stmt);
- MYSQL_RES *STDCALL(*mysql_stmt_result_metadata)(MYSQL_STMT *stmt);
- int STDCALL(*mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset);
-} mysql_module_t;
-
-
/* backend module declaration */
int glite_lbu_InitDBContextMysql(glite_lbu_DBContext *ctx_gen);
void glite_lbu_FreeDBContextMysql(glite_lbu_DBContext ctx_gen);
lastid: glite_lbu_LastidMysql,
};
-static mysql_module_t mysql_module = {
- lib: NULL,
- lock: PTHREAD_MUTEX_INITIALIZER,
-};
-
static int myerr(glite_lbu_DBContextMysql ctx, const char *source, int line);
static int myerrstmt(glite_lbu_StatementMysql stmt, const char *source, int line);
static int FetchRowSimple(glite_lbu_DBContextMysql ctx, MYSQL_RES *result, unsigned long *lengths, char **results);
static int FetchRowPrepared(glite_lbu_DBContextMysql ctx, glite_lbu_StatementMysql stmt, unsigned int n, unsigned long *lengths, char **results);
static void set_time(MYSQL_TIME *mtime, const double time);
-static void glite_lbu_DBCleanup(void);
static void glite_lbu_FreeStmt_int(glite_lbu_StatementMysql stmt);
int glite_lbu_InitDBContextMysql(glite_lbu_DBContext *ctx_gen) {
glite_lbu_DBContextMysql ctx;
- int err = 0;
- int ver_u;
ctx = calloc(1, sizeof *ctx);
if (!ctx) return ENOMEM;
*ctx_gen = (glite_lbu_DBContext)ctx;
- /* dynamic load the client library */
- pthread_mutex_lock(&mysql_module.lock);
- if (!mysql_module.lib) {
- mysql_module.lib = dlopen(MYSQL_SONAME, RTLD_LAZY | RTLD_LOCAL);
- if (!mysql_module.lib) return ERR(ctx, ENOENT, "dlopen(): " MYSQL_SONAME ": %s", dlerror());
- do {
- LOAD(mysql_init, "mysql_init");
- LOAD(mysql_get_client_version, "mysql_get_client_version");
- LOAD(mysql_options, "mysql_options");
- LOAD(mysql_errno, "mysql_errno");
- LOAD(mysql_error, "mysql_error");
- LOAD(mysql_stmt_errno, "mysql_stmt_errno");
- LOAD(mysql_stmt_error, "mysql_stmt_error");
- LOAD(mysql_real_connect, "mysql_real_connect");
- LOAD(mysql_close, "mysql_close");
- LOAD(mysql_query, "mysql_query");
- LOAD(mysql_store_result, "mysql_store_result");
- LOAD(mysql_free_result, "mysql_free_result");
- LOAD(mysql_affected_rows, "mysql_affected_rows");
- LOAD(mysql_stmt_close, "mysql_stmt_close");
- LOAD(mysql_num_fields, "mysql_num_fields");
- LOAD(mysql_fetch_lengths, "mysql_fetch_lengths");
- LOAD(mysql_stmt_bind_result, "mysql_stmt_bind_result");
- LOAD(mysql_stmt_prepare, "mysql_stmt_prepare");
- LOAD(mysql_stmt_store_result, "mysql_stmt_store_result");
- LOAD(mysql_fetch_row, "mysql_fetch_row");
- LOAD(mysql_fetch_field, "mysql_fetch_field");
- LOAD(mysql_get_server_info, "mysql_get_server_info");
- LOAD(mysql_stmt_init, "mysql_stmt_init");
- LOAD(mysql_stmt_bind_param, "mysql_stmt_bind_param");
- LOAD(mysql_stmt_execute, "mysql_stmt_execute");
- LOAD(mysql_stmt_fetch, "mysql_stmt_fetch");
- LOAD(mysql_stmt_insert_id, "mysql_stmt_insert_id");
- LOAD(mysql_stmt_affected_rows, "mysql_stmt_affected_rows");
- LOAD(mysql_stmt_result_metadata, "mysql_stmt_result_metadata");
- LOAD(mysql_stmt_fetch_column, "mysql_stmt_fetch_column");
-
- // check the runtime version
- ver_u = mysql_module.mysql_get_client_version();
- if (ver_u != MYSQL_VERSION_ID) {
- fprintf(stderr,"Warning: MySQL library version mismatch (compiled '%d', runtime '%d')\n", MYSQL_VERSION_ID, ver_u);
-#ifdef SYSLOG_H
- syslog(LOG_WARNING,"MySQL library version mismatch (compiled '%d', runtime '%d')", MYSQL_VERSION_ID, ver_u);
-#endif
- }
-
- pthread_mutex_unlock(&mysql_module.lock);
- atexit(glite_lbu_DBCleanup);
- } while(0);
-
- if (err) {
- dlclose(mysql_module.lib);
- mysql_module.lib = NULL;
- pthread_mutex_unlock(&mysql_module.lock);
- return err;
- }
- } else pthread_mutex_unlock(&mysql_module.lock);
-
return 0;
}
caps = 0;
- ver_s = mysql_module.mysql_get_server_info(m);
+ ver_s = mysql_get_server_info(m);
if (!ver_s || 3 != sscanf(ver_s,"%d.%d.%d",&major,&minor,&sub))
return ERR(ctx, EINVAL, "problem retreiving MySQL version");
version = 10000*major + 100*minor + sub;
static void glite_lbu_FreeStmt_int(glite_lbu_StatementMysql stmt) {
if (stmt) {
- if (stmt->result) mysql_module.mysql_free_result(stmt->result);
- if (stmt->stmt) mysql_module.mysql_stmt_close(stmt->stmt);
+ if (stmt->result) mysql_free_result(stmt->result);
+ if (stmt->stmt) mysql_stmt_close(stmt->stmt);
free(stmt->sql);
}
}
while (retry_nr == 0 || do_reconnect) {
do_reconnect = 0;
- if (mysql_module.mysql_query(ctx->mysql, cmd)) {
+ if (mysql_query(ctx->mysql, cmd)) {
/* error occured */
- switch (merr = mysql_module.mysql_errno(ctx->mysql)) {
+ switch (merr = mysql_errno(ctx->mysql)) {
case 0:
break;
case ER_DUP_ENTRY:
- ERR(ctx, EEXIST, mysql_module.mysql_error(ctx->mysql));
+ ERR(ctx, EEXIST, mysql_error(ctx->mysql));
return -1;
break;
case CR_SERVER_LOST:
case CR_SERVER_GONE_ERROR:
if (ctx->in_transaction) {
- ERR(ctx, ENOTCONN, mysql_module.mysql_error(ctx->mysql));
+ ERR(ctx, ENOTCONN, mysql_error(ctx->mysql));
return -1;
}
else if (retry_nr <= 0)
do_reconnect = 1;
break;
case ER_LOCK_DEADLOCK:
- ERR(ctx, EDEADLK, mysql_module.mysql_error(ctx->mysql));
+ ERR(ctx, EDEADLK, mysql_error(ctx->mysql));
return -1;
break;
default:
return -1;
}
stmt->generic.ctx = ctx_gen;
- stmt->result = mysql_module.mysql_store_result(ctx->mysql);
+ stmt->result = mysql_store_result(ctx->mysql);
if (!stmt->result) {
- if (mysql_module.mysql_errno(ctx->mysql)) {
+ if (mysql_errno(ctx->mysql)) {
MY_ERR(ctx);
free(stmt);
return -1;
}
*stmt_gen = (glite_lbu_Statement)stmt;
} else {
- MYSQL_RES *r = mysql_module.mysql_store_result(ctx->mysql);
- mysql_module.mysql_free_result(r);
+ MYSQL_RES *r = mysql_store_result(ctx->mysql);
+ mysql_free_result(r);
}
#ifdef LBS_DB_PROFILE
pid = getpid();
fprintf(stderr,"[%d] %s\n[%d] %3ld.%06ld (sum: %3ld.%06ld)\n",pid,cmd,pid,end.tv_sec,end.tv_usec,sum.tv_sec,sum.tv_usec);
#endif
- return mysql_module.mysql_affected_rows(ctx->mysql);
+ return mysql_affected_rows(ctx->mysql);
}
CLR_ERR(stmt->generic.ctx);
if (!stmt->result) return ERR(stmt->generic.ctx, ENOTSUP, "QueryColumns implemented only for simple API");
- while ((f = mysql_module.mysql_fetch_field(stmt->result))) cols[i++] = f->name;
+ while ((f = mysql_fetch_field(stmt->result))) cols[i++] = f->name;
return i == 0;
}
*stmt_gen = NULL;
// create the SQL command
- if ((stmt->stmt = mysql_module.mysql_stmt_init(ctx->mysql)) == NULL)
+ if ((stmt->stmt = mysql_stmt_init(ctx->mysql)) == NULL)
return STATUS(ctx);
// prepare the SQL command
retry = 1;
do {
- mysql_module.mysql_stmt_prepare(stmt->stmt, sql, strlen(sql));
+ mysql_stmt_prepare(stmt->stmt, sql, strlen(sql));
ret = MY_ISOKSTMT(stmt, &retry);
} while (ret == 0);
if (ret == -1) goto failed;
// number of fields (0 for no results)
- if ((meta = mysql_module.mysql_stmt_result_metadata(stmt->stmt)) != NULL) {
- stmt->nrfields = mysql_module.mysql_num_fields(meta);
- mysql_module.mysql_free_result(meta);
+ if ((meta = mysql_stmt_result_metadata(stmt->stmt)) != NULL) {
+ stmt->nrfields = mysql_num_fields(meta);
+ mysql_free_result(meta);
} else
stmt->nrfields = 0;
do {
// bind parameters
if (n) {
- if (mysql_module.mysql_stmt_bind_param(stmt->stmt, binds) != 0) {
+ if (mysql_stmt_bind_param(stmt->stmt, binds) != 0) {
MY_ERRSTMT(stmt);
ret = -1;
goto statement_failed;
// run
retry = 1;
do {
- mysql_module.mysql_stmt_execute(stmt->stmt);
+ mysql_stmt_execute(stmt->stmt);
ret = MY_ISOKSTMT(stmt, &retry);
} while (ret == 0);
statement_failed:
if (ret == -1) {
- if (mysql_module.mysql_stmt_errno(stmt->stmt) == ER_UNKNOWN_STMT_HANDLER) {
+ if (mysql_stmt_errno(stmt->stmt) == ER_UNKNOWN_STMT_HANDLER) {
// expired the prepared command ==> restore it
if (glite_lbu_PrepareStmtMysql(stmt->generic.ctx, stmt->sql, &newstmt) == -1) goto failed;
glite_lbu_FreeStmt_int(stmt);
// result
retry = 1;
do {
- mysql_module.mysql_stmt_store_result(stmt->stmt);
+ mysql_stmt_store_result(stmt->stmt);
ret = MY_ISOKSTMT(stmt, &retry);
} while (ret == 0);
if (ret == -1) goto failed;
free(lens);
}
CLR_ERR(stmt->generic.ctx);
- return mysql_module.mysql_stmt_affected_rows(stmt->stmt);
+ return mysql_stmt_affected_rows(stmt->stmt);
failed:
for (i = 0; i < n; i++) free(data[i]);
my_ulonglong i;
CLR_ERR(stmt_gen->ctx);
- i = mysql_module.mysql_stmt_insert_id(stmt->stmt);
+ i = mysql_stmt_insert_id(stmt->stmt);
assert(i < ((unsigned long int)-1) >> 1);
return (long int)i;
}
* helping function: find oud mysql error and sets on the context
*/
static int myerr(glite_lbu_DBContextMysql ctx, const char *source, int line) {
- return glite_lbu_DBSetError(&ctx->generic, EIO, source, line, mysql_module.mysql_error(ctx->mysql));
+ return glite_lbu_DBSetError(&ctx->generic, EIO, source, line, mysql_error(ctx->mysql));
}
* helping function: find oud mysql stmt error and sets on the context
*/
static int myerrstmt(glite_lbu_StatementMysql stmt, const char *source, int line) {
- return glite_lbu_DBSetError(stmt->generic.ctx, EIO, source, line, mysql_module.mysql_stmt_error(stmt->stmt));
+ return glite_lbu_DBSetError(stmt->generic.ctx, EIO, source, line, mysql_stmt_error(stmt->stmt));
}
* \return 1 OK
*/
static int myisokstmt(glite_lbu_StatementMysql stmt, const char *source, int line, int *retry) {
- switch (mysql_module.mysql_stmt_errno(stmt->stmt)) {
+ switch (mysql_stmt_errno(stmt->stmt)) {
case 0:
return 1;
break;
case ER_DUP_ENTRY:
- glite_lbu_DBSetError(stmt->generic.ctx, EEXIST, source, line, mysql_module.mysql_stmt_error(stmt->stmt));
+ glite_lbu_DBSetError(stmt->generic.ctx, EEXIST, source, line, mysql_stmt_error(stmt->stmt));
return -1;
break;
case CR_SERVER_LOST:
if (!cs) return ERR(ctx, EINVAL, "connect string not specified");
- if (!(*mysql = mysql_module.mysql_init(NULL))) return ERR(ctx, ENOMEM, NULL);
+ if (!(*mysql = mysql_init(NULL))) return ERR(ctx, ENOMEM, NULL);
- mysql_module.mysql_options(*mysql, MYSQL_READ_DEFAULT_FILE, "my");
+ mysql_options(*mysql, MYSQL_READ_DEFAULT_FILE, "my");
#if MYSQL_VERSION_ID >= 50013
/* XXX: may result in weird behaviour in the middle of transaction */
- mysql_module.mysql_options(*mysql, MYSQL_OPT_RECONNECT, &reconnect);
+ mysql_options(*mysql, MYSQL_OPT_RECONNECT, &reconnect);
#endif
host = user = pw = db = NULL;
/* ljocha: CLIENT_FOUND_ROWS added to make authorization check
* working in update_notif().
* Hope it does not break anything else */
- if (!mysql_module.mysql_real_connect(*mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
+ if (!mysql_real_connect(*mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
ret = MY_ERR(ctx);
db_close(*mysql);
*mysql = NULL;
* mysql close
*/
static void db_close(MYSQL *mysql) {
- if (mysql) mysql_module.mysql_close(mysql);
+ if (mysql) mysql_close(mysql);
}
CLR_ERR(ctx);
- if (!(row = mysql_module.mysql_fetch_row(result))) {
- if (mysql_module.mysql_errno((MYSQL *) ctx->mysql)) {
+ if (!(row = mysql_fetch_row(result))) {
+ if (mysql_errno((MYSQL *) ctx->mysql)) {
MY_ERR(ctx);
return -1;
} else return 0;
}
- nr = mysql_module.mysql_num_fields(result);
- len = mysql_module.mysql_fetch_lengths(result);
+ nr = mysql_num_fields(result);
+ len = mysql_fetch_lengths(result);
for (i=0; i<nr; i++) {
if (lengths) lengths[i] = len[i];
if (len[i]) {
goto failed;
}
}
- if (mysql_module.mysql_stmt_bind_result(stmt->stmt, binds) != 0) goto failedstmt;
+ if (mysql_stmt_bind_result(stmt->stmt, binds) != 0) goto failedstmt;
// fetch data, all can be truncated
retry = 1;
do {
- switch(mysql_module.mysql_stmt_fetch(stmt->stmt)) {
+ switch(mysql_stmt_fetch(stmt->stmt)) {
#ifdef MYSQL_DATA_TRUNCATED
case MYSQL_DATA_TRUNCATED:
#endif
retry = 1;
do {
- switch (mysql_module.mysql_stmt_fetch_column(stmt->stmt, binds + i, i, fetched)) {
+ switch (mysql_stmt_fetch_column(stmt->stmt, binds + i, i, fetched)) {
case 0: ret = 1; break;
case 1: ret = MY_ISOKSTMT(stmt, &retry); break;
case MYSQL_NO_DATA: ret = 0; goto quit; /* it's OK */
mtime->second = tm.tm_sec;
mtime->second_part = (time - itime) * 1000;
}
-
-
-static void glite_lbu_DBCleanup(void) {
- pthread_mutex_lock(&mysql_module.lock);
- if (mysql_module.lib) {
- dlclose(mysql_module.lib);
- mysql_module.lib = NULL;
- }
- pthread_mutex_unlock(&mysql_module.lock);
-}
-
-
#include <sys/types.h>
#include <assert.h>
-#include <dlfcn.h>
#include <errno.h>
-#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define set_error(CTX, CODE, DESC...) glite_lbu_DBSetError((glite_lbu_DBContext)(CTX), (CODE), __FUNCTION__, __LINE__, ##DESC)
-#define LOAD(SYM, SYM2) if ((*(void **)(&psql_module.SYM) = dlsym(psql_module.lib, SYM2)) == NULL) { \
- err = set_error(ctx, ENOENT, "can't load symbol '%s' from psql library (%s)", SYM2, dlerror()); \
- break; \
-}
-
struct glite_lbu_DBContextPsql_s {
struct glite_lbu_DBContext_s generic;
};
typedef struct glite_lbu_StatementPsql_s *glite_lbu_StatementPsql;
-typedef struct {
- void *lib;
- pthread_mutex_t lock;
-
- /* functions from 8.3.8 client library version (libpq-fe.h) */
- PGconn *STDCALL(*PQconnectdb)(const char *conninfo);
- ConnStatusType STDCALL(*PQstatus)(const PGconn *conn);
- void STDCALL(*PQfinish)(PGconn *conn);
- char *STDCALL(*PQerrorMessage)(const PGconn *conn);
- int STDCALL(*PQnfields)(const PGresult *res);
- char *STDCALL(*PQgetvalue)(const PGresult *res, int tup_num, int field_num);
- int STDCALL(*PQgetlength)(const PGresult *res, int tup_num, int field_num);
- void STDCALL(*PQclear)(PGresult *res);
- PGresult *STDCALL(*PQexec)(PGconn *conn, const char *query);
- ExecStatusType STDCALL(*PQresultStatus)(const PGresult *res);
- char *STDCALL(*PQresultErrorMessage)(const PGresult *res);
- char *STDCALL(*PQcmdTuples)(PGresult *res);
- int STDCALL(*PQntuples)(const PGresult *res);
- char *STDCALL(*PQfname)(const PGresult *res, int field_num);
- size_t STDCALL(*PQescapeStringConn)(PGconn *conn,
- char *to, const char *from, size_t length,
- int *error);
- void STDCALL(*PQfreemem)(void *ptr);
-} psql_module_t;
-
-
-static void glite_lbu_DBCleanup(void);
/* backend module declaration */
int glite_lbu_InitDBContextPsql(glite_lbu_DBContext *ctx_gen);
lastid: NULL/*glite_lbu_LastidPsql*/,
};
-static psql_module_t psql_module = {
- lib: NULL,
- lock: PTHREAD_MUTEX_INITIALIZER,
-};
-
/* nicer identifiers in PREPARE/EXECUTE commands */
static const char *prepared_names[4] = {"select", "update", "insert", "other"};
if (!ctx) return ENOMEM;
*ctx_gen = (glite_lbu_DBContext)ctx;
- /* dynamic load of the client library */
- pthread_mutex_lock(&psql_module.lock);
- if (!psql_module.lib) {
- psql_module.lib = dlopen(PSQL_SONAME, RTLD_LAZY | RTLD_LOCAL);
- if (!psql_module.lib) return set_error(ctx, ENOENT, "dlopen(): " PSQL_SONAME ": %s", dlerror());
- do {
- LOAD(PQconnectdb, "PQconnectdb");
- LOAD(PQstatus, "PQstatus");
- LOAD(PQfinish, "PQfinish");
- LOAD(PQerrorMessage, "PQerrorMessage");
- LOAD(PQnfields, "PQnfields");
- LOAD(PQgetvalue, "PQgetvalue");
- LOAD(PQgetlength, "PQgetlength");
- LOAD(PQclear, "PQclear");
- LOAD(PQexec, "PQexec");
- LOAD(PQresultStatus, "PQresultStatus");
- LOAD(PQresultErrorMessage, "PQresultErrorMessage");
- LOAD(PQcmdTuples, "PQcmdTuples");
- LOAD(PQntuples, "PQntuples");
- LOAD(PQfname, "PQfname");
- LOAD(PQescapeStringConn, "PQescapeStringConn");
- LOAD(PQfreemem, "PQfreemem");
-
- pthread_mutex_unlock(&psql_module.lock);
- atexit(glite_lbu_DBCleanup);
- } while(0);
-
- if (err) {
- dlclose(psql_module.lib);
- psql_module.lib = NULL;
- pthread_mutex_unlock(&psql_module.lock);
- return err;
- }
- } else pthread_mutex_unlock(&psql_module.lock);
-
return 0;
}
glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG,
"connection string = %s\n", pgcs);
- ctx->conn = psql_module.PQconnectdb(pgcs);
+ ctx->conn = PQconnectdb(pgcs);
free(pgcsbuf);
if (!ctx->conn) return ENOMEM;
- if (psql_module.PQstatus(ctx->conn) != CONNECTION_OK) {
- asprintf(&err, "Can't connect, %s", psql_module.PQerrorMessage(ctx->conn));
- psql_module.PQfinish(ctx->conn);
+ if (PQstatus(ctx->conn) != CONNECTION_OK) {
+ asprintf(&err, "Can't connect, %s", PQerrorMessage(ctx->conn));
+ PQfinish(ctx->conn);
ctx->conn = NULL;
set_error(ctx, EIO, err);
free(err);
glite_lbu_DBContextPsql ctx = (glite_lbu_DBContextPsql)ctx_gen;
if (ctx->conn) {
- psql_module.PQfinish(ctx->conn);
+ PQfinish(ctx->conn);
ctx->conn = NULL;
}
}
if (stmt->row >= stmt->nrows) return 0;
- n = psql_module.PQnfields(stmt->res);
+ n = PQnfields(stmt->res);
if (n <= 0) {
set_error(stmt->generic.ctx, EINVAL, "Result set w/o columns");
return -1;
}
for (i = 0; i < n; i++) {
/* sanity check for internal error (NULL when invalid row) */
- s = psql_module.PQgetvalue(stmt->res, stmt->row, i) ? : "";
+ s = PQgetvalue(stmt->res, stmt->row, i) ? : "";
if ((results[i] = strdup(s)) == NULL)
goto nomem;
if (lengths) lengths[i] = strlen(s);
if (!*stmt_gen) return;
stmt = (glite_lbu_StatementPsql)(*stmt_gen);
ctx = (glite_lbu_DBContextPsql)stmt->generic.ctx;
- if (stmt->res) psql_module.PQclear(stmt->res);
+ if (stmt->res) PQclear(stmt->res);
if (stmt->name) {
asprintf(&sql, "DEALLOCATE %s", stmt->name);
glite_common_log_msg(ctx->generic.log_category, LOG_PRIORITY_DEBUG, sql);
- stmt->res = psql_module.PQexec(ctx->conn, sql);
+ stmt->res = PQexec(ctx->conn, sql);
free(sql);
- psql_module.PQclear(stmt->res);
+ PQclear(stmt->res);
}
free(stmt->name);
free(stmt->sql);
//lprintf("command = %s\n", cmd);
glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, "command = %s\n", cmd);
if (stmt_out) *stmt_out = NULL;
- if ((res = psql_module.PQexec(ctx->conn, cmd)) == NULL) {
+ if ((res = PQexec(ctx->conn, cmd)) == NULL) {
ctx->generic.err.code = ENOMEM;
return -1;
}
- status = psql_module.PQresultStatus(res);
+ status = PQresultStatus(res);
if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
- errmsg = psql_module.PQresultErrorMessage(res);
+ errmsg = PQresultErrorMessage(res);
if (errmsg) {
errmsg = strdup(errmsg);
if ((pos = strrchr(errmsg, '\n')) != NULL) pos[0] = '\0';
}
set_error(ctx, EIO, errmsg);
free(errmsg);
- psql_module.PQclear(res);
+ PQclear(res);
return -1;
}
- nstr = psql_module.PQcmdTuples(res);
+ nstr = PQcmdTuples(res);
if (nstr && nstr[0]) n = atoi(nstr);
- else n = psql_module.PQntuples(res);
+ else n = PQntuples(res);
if (stmt_out) {
stmt = calloc(1, sizeof(*stmt));
stmt->generic.ctx = ctx_gen;
stmt->nrows = n;
*stmt_out = (glite_lbu_Statement)stmt;
} else {
- psql_module.PQclear(res);
+ PQclear(res);
}
return n;
}
glite_lbu_StatementPsql stmt = (glite_lbu_StatementPsql)stmt_gen;
int n, i;
- n = psql_module.PQnfields(stmt->res);
+ n = PQnfields(stmt->res);
for (i = 0; i < n; i++) {
- cols[i] = psql_module.PQfname(stmt->res, i);
+ cols[i] = PQfname(stmt->res, i);
}
return -1;
}
asprintf(&sqlPrep, "PREPARE %s AS %s", stmt->name, stmt->sql);
glite_common_log_msg(ctx_gen->log_category, LOG_PRIORITY_DEBUG, sqlPrep);
- res = psql_module.PQexec(ctx->conn, sqlPrep);
- if (psql_module.PQresultStatus(res) != PGRES_COMMAND_OK) {
- asprintf(&s, "error preparing command: %s", psql_module.PQerrorMessage(ctx->conn));
+ res = PQexec(ctx->conn, sqlPrep);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK) {
+ asprintf(&s, "error preparing command: %s", PQerrorMessage(ctx->conn));
set_error(ctx, EIO, s);
free(s); s = NULL;
goto quit;
quit:
free(sqlPrep);
- if (res) psql_module.PQclear(res);
+ if (res) PQclear(res);
if (!retval) return 0;
free(stmt->name);
return set_error(ctx, EINVAL, "PrepareStmt() not called");
if (stmt->res) {
- psql_module.PQclear(stmt->res);
+ PQclear(stmt->res);
stmt->res = NULL;
}
"blob, len = %lu, ptr = %p\n", binary_len, s);
if (s) {
tmp = malloc(2*binary_len + 1);
- psql_module.PQescapeStringConn(ctx->conn, tmp, s, binary_len, NULL);
+ PQescapeStringConn(ctx->conn, tmp, s, binary_len, NULL);
asprintf(&tmpdata[i], "'%s'", tmp);
glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG, "escaped: '%s'\n", tmpdata[i]);
free(tmp);
if (n) strcat(sql, ")");
glite_common_log_msg(ctx->generic.log_category, LOG_PRIORITY_DEBUG, sql);
- stmt->res = psql_module.PQexec(ctx->conn, sql);
- status = psql_module.PQresultStatus(stmt->res);
+ stmt->res = PQexec(ctx->conn, sql);
+ status = PQresultStatus(stmt->res);
if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
- asprintf(&s, "error executing prepared command '%s' parameters '%s': %s", stmt->sql, sql, psql_module.PQerrorMessage(ctx->conn));
+ asprintf(&s, "error executing prepared command '%s' parameters '%s': %s", stmt->sql, sql, PQerrorMessage(ctx->conn));
set_error(ctx, EIO, s);
free(s); s = NULL;
goto quit;
}
- nstr = psql_module.PQcmdTuples(stmt->res);
+ nstr = PQcmdTuples(stmt->res);
//lprintf("cmdtuples: '%s'\n", nstr);
if (nstr && nstr[0]) retval = atoi(nstr);
- else retval = psql_module.PQntuples(stmt->res);
+ else retval = PQntuples(stmt->res);
stmt->nrows = retval;
stmt->row = 0;
//lprintf("ntuples/retval: %d\n", retval);
free(sql);
return retval;
}
-
-
-static void glite_lbu_DBCleanup(void) {
- pthread_mutex_lock(&psql_module.lock);
- if (psql_module.lib) {
- dlclose(psql_module.lib);
- psql_module.lib = NULL;
- }
- pthread_mutex_unlock(&psql_module.lock);
-}
-
/* possible backends */
-#ifdef MYSQL_SONAME
+#ifdef MYSQL_ENABLED
extern glite_lbu_DBBackend_t mysql_backend;
#else
#define mysql_backend no_backend
#endif
-#ifdef PSQL_SONAME
+#ifdef PSQL_ENABLED
extern glite_lbu_DBBackend_t psql_backend;
#else
#define psql_backend no_backend