diff --git a/cmake/modules/FindMySQL.cmake b/cmake/modules/FindMySQL.cmake deleted file mode 100644 index 8cb9451bc2234..0000000000000 --- a/cmake/modules/FindMySQL.cmake +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. -# All rights reserved. -# -# For the licensing terms see $ROOTSYS/LICENSE. -# For the list of contributors see $ROOTSYS/README/CREDITS. - -# Find the native MySQL includes and library -# -# MYSQL_INCLUDE_DIR - where to find mysql.h, etc. -# MYSQL_LIBRARIES - List of libraries when using MySQL. -# MYSQL_FOUND - True if MySQL found. - -if(MYSQL_INCLUDE_DIR OR MYSQL_) - # Already in cache, be silent - SET(MYSQL_FIND_QUIETLY TRUE) -endif() - -if(NOT WIN32) - # Split into two find_program invocations to avoid user-specified - # mariadb_config being overridden by system mysql_config. - find_program(MYSQL_CONFIG_EXECUTABLE NAMES mysql_config mariadb_config - PATH_SUFFIXES bin - NO_DEFAULT_PATH - HINTS ${MYSQL_DIR} $ENV{MYSQL_DIR} - ) - # Will not overwrite if MYSQL_CONFIG_EXECUTABLE is already set. - find_program(MYSQL_CONFIG_EXECUTABLE NAMES mysql_config mariadb_config - PATH_SUFFIXES bin - PATHS /usr/local /usr - ) -endif() - -if(MYSQL_CONFIG_EXECUTABLE) - execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --cflags OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) - separate_arguments(MYSQL_CFLAGS) - string( REGEX MATCHALL "-I[^;]+" MYSQL_INCLUDE_DIRS "${MYSQL_CFLAGS}" ) - string( REPLACE "-I" "" MYSQL_INCLUDE_DIRS "${MYSQL_INCLUDE_DIRS}") - find_path(MYSQL_INCLUDE_DIR mysql.h PATHS ${MYSQL_INCLUDE_DIRS} NO_DEFAULT_PATH) - execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --libs OUTPUT_VARIABLE MYSQL_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() - -# If not yet found the includes, try again without using mysql_config (mariadb_config is a binary not relocatable) -if (NOT MYSQL_CONFIG_EXECUTABLE OR NOT MYSQL_INCLUDE_DIR) - find_path(MYSQL_INCLUDE_DIR mysql.h - PATH_SUFFIXES include/mysql include/mariadb - HINTS ${MYSQL_DIR} $ENV{MYSQL_DIR} - NO_DEFAULT_PATH - ) - if (NOT MYSQL_INCLUDE_DIR) - find_path(MYSQL_INCLUDE_DIR mysql.h - PATH_SUFFIXES include/mysql include/mariadb - PATHS /usr/local/mysql /usr/local /usr - ) - endif() - set(MYSQL_NAMES mysqlclient mysqlclient_r) - find_library(MYSQL_LIBRARY NAMES ${MYSQL_NAMES} - PATH_SUFFIXES lib lib/mariadb lib/mysql - lib/opt lib/opt/mariadb lib/opt/mysql - HINTS ${MYSQL_DIR} $ENV{MYSQL_DIR} - PATHS /usr/local/mysql /usr/local /usr - ) - set(MYSQL_LIBRARIES ${MYSQL_LIBRARY}) -endif() - -# handle the QUIETLY and REQUIRED arguments and set DCAP_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MySQL DEFAULT_MSG MYSQL_INCLUDE_DIR MYSQL_LIBRARIES) - -mark_as_advanced( - MYSQL_CONFIG_EXECUTABLE - MYSQL_LIBRARY - MYSQL_INCLUDE_DIR -) diff --git a/cmake/modules/FindODBC.cmake b/cmake/modules/FindODBC.cmake deleted file mode 100644 index c8ca477cca8b6..0000000000000 --- a/cmake/modules/FindODBC.cmake +++ /dev/null @@ -1,227 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindODBC --------- - -Find an Open Database Connectivity (ODBC) include directory and library. - -On Windows, when building with Visual Studio, this module assumes the ODBC -library is provided by the available Windows SDK. - -On Unix, this module allows to search for ODBC library provided by -unixODBC or iODBC implementations of ODBC API. -This module reads hint about location of the config program: - -.. variable:: ODBC_CONFIG - - Location of odbc_config or iodbc-config program - -Otherwise, this module tries to find the config program, -first from unixODBC, then from iODBC. -If no config program found, this module searches for ODBC header -and library in list of known locations. - -Imported targets -^^^^^^^^^^^^^^^^ - -This module defines the following :prop_tgt:`IMPORTED` targets: - -.. variable:: ODBC::ODBC - - Imported target for using the ODBC library, if found. - -Result variables -^^^^^^^^^^^^^^^^ - -.. variable:: ODBC_FOUND - - Set to true if ODBC library found, otherwise false or undefined. - -.. variable:: ODBC_INCLUDE_DIRS - - Paths to include directories listed in one variable for use by ODBC client. - May be empty on Windows, where the include directory corresponding to the - expected Windows SDK is already available in the compilation environment. - -.. variable:: ODBC_LIBRARIES - - Paths to libraries to linked against to use ODBC. - May just a library name on Windows, where the library directory corresponding - to the expected Windows SDK is already available in the compilation environment. - -.. variable:: ODBC_CONFIG - - Path to unixODBC or iODBC config program, if found or specified. - -Cache variables -^^^^^^^^^^^^^^^ - -For users who wish to edit and control the module behavior, this module -reads hints about search locations from the following variables: - -.. variable:: ODBC_INCLUDE_DIR - - Path to ODBC include directory with ``sql.h`` header. - -.. variable:: ODBC_LIBRARY - - Path to ODBC library to be linked. - -These variables should not be used directly by project code. - -Limitations -^^^^^^^^^^^ - -On Windows, this module does not search for iODBC. -On Unix, there is no way to prefer unixODBC over iODBC, or vice versa, -other than providing the config program location using the ``ODBC_CONFIG``. -This module does not allow to search for a specific ODBC driver. - -#]=======================================================================] - -# Define lists used internally -set(_odbc_include_paths) -set(_odbc_lib_paths) -set(_odbc_lib_names) -set(_odbc_required_libs_names) - -### Try Windows Kits ########################################################## -if(WIN32) - # List names of ODBC libraries on Windows - set(ODBC_LIBRARY odbc32.lib) - set(_odbc_lib_names odbc32;) - - # List additional libraries required to use ODBC library - if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") - set(_odbc_required_libs_names odbccp32;ws2_32) - elseif(MINGW) - set(_odbc_required_libs_names odbccp32) - endif() -endif() - -### Try unixODBC or iODBC config program ###################################### -if (UNIX) - find_program(ODBC_CONFIG - NAMES odbc_config iodbc-config - DOC "Path to unixODBC or iODBC config program") - mark_as_advanced(ODBC_CONFIG) -endif() - -if (UNIX AND ODBC_CONFIG) - # unixODBC and iODBC accept unified command line options - execute_process(COMMAND ${ODBC_CONFIG} --cflags - OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${ODBC_CONFIG} --libs - OUTPUT_VARIABLE _libs OUTPUT_STRIP_TRAILING_WHITESPACE) - - # Collect paths of include directories from CFLAGS - separate_arguments(_cflags NATIVE_COMMAND "${_cflags}") - foreach(arg IN LISTS _cflags) - if("${arg}" MATCHES "^-I(.*)$") - list(APPEND _odbc_include_paths "${CMAKE_MATCH_1}") - endif() - endforeach() - unset(_cflags) - - # Collect paths of library names and directories from LIBS - separate_arguments(_libs NATIVE_COMMAND "${_libs}") - foreach(arg IN LISTS _libs) - if("${arg}" MATCHES "^-L(.*)$") - list(APPEND _odbc_lib_paths "${CMAKE_MATCH_1}") - elseif("${arg}" MATCHES "^-l(.*)$") - set(_lib_name ${CMAKE_MATCH_1}) - string(REGEX MATCH "odbc" _is_odbc ${_lib_name}) - if(_is_odbc) - list(APPEND _odbc_lib_names ${_lib_name}) - else() - list(APPEND _odbc_required_libs_names ${_lib_name}) - endif() - unset(_lib_name) - endif() - endforeach() - unset(_libs) -endif() - -### Try unixODBC or iODBC in include/lib filesystems ########################## -if (UNIX AND NOT ODBC_CONFIG) - # List names of both ODBC libraries, unixODBC and iODBC - set(_odbc_lib_names odbc;iodbc;unixodbc;) -endif() - -### Find include directories ################################################## -find_path(ODBC_INCLUDE_DIR - NAMES sql.h - PATHS ${_odbc_include_paths}) - -if(NOT ODBC_INCLUDE_DIR AND WIN32) - set(ODBC_INCLUDE_DIR "") -endif() - -### Find libraries ############################################################ -if(NOT ODBC_LIBRARY) - find_library(ODBC_LIBRARY - NAMES ${_odbc_lib_names} - PATHS ${_odbc_lib_paths} - PATH_SUFFIXES odbc) - - foreach(_lib IN LISTS _odbc_required_libs_names) - find_library(_lib_path - NAMES ${_lib} - PATHS ${_odbc_lib_paths} # system parths or collected from ODBC_CONFIG - PATH_SUFFIXES odbc) - if(_lib_path) - list(APPEND _odbc_required_libs_paths ${_lib_path}) - endif() - unset(_lib_path CACHE) - endforeach() -endif() - -# Unset internal lists as no longer used -unset(_odbc_include_paths) -unset(_odbc_lib_paths) -unset(_odbc_lib_names) -unset(_odbc_required_libs_names) - -### Set result variables ###################################################### -set(_odbc_required_vars ODBC_LIBRARY) -if(NOT WIN32) - list(APPEND _odbc_required_vars ODBC_INCLUDE_DIR) -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ODBC DEFAULT_MSG ${_odbc_required_vars}) - -unset(_odbc_required_vars) - -mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR) - -set(ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIR}) -list(APPEND ODBC_LIBRARIES ${ODBC_LIBRARY}) -list(APPEND ODBC_LIBRARIES ${_odbc_required_libs_paths}) - -### Import targets ############################################################ -if(ODBC_FOUND) - if(NOT TARGET ODBC::ODBC) - if(IS_ABSOLUTE "${ODBC_LIBRARY}") - add_library(ODBC::ODBC UNKNOWN IMPORTED) - set_target_properties(ODBC::ODBC PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${ODBC_LIBRARY}") - else() - add_library(ODBC::ODBC INTERFACE IMPORTED) - set_target_properties(ODBC::ODBC PROPERTIES - IMPORTED_LIBNAME "${ODBC_LIBRARY}") - endif() - set_target_properties(ODBC::ODBC PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}") - - if(_odbc_required_libs_paths) - set_property(TARGET ODBC::ODBC APPEND PROPERTY - INTERFACE_LINK_LIBRARIES "${_odbc_required_libs_paths}") - endif() - endif() -endif() - -unset(_odbc_required_libs_paths) diff --git a/cmake/modules/FindPostgreSQL.cmake b/cmake/modules/FindPostgreSQL.cmake deleted file mode 100644 index 1026046ff7ef6..0000000000000 --- a/cmake/modules/FindPostgreSQL.cmake +++ /dev/null @@ -1,167 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# FindPostgreSQL -# -------------- -# -# Find the PostgreSQL installation. -# -# This module defines -# -# :: -# -# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking -# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers -# PostgreSQL_LIBRARY_DIRS - the link directories for PostgreSQL libraries -# PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8) - -# ---------------------------------------------------------------------------- -# History: -# This module is derived from the module originally found in the VTK source tree. -# -# ---------------------------------------------------------------------------- -# Note: -# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the -# version number of the implementation of PostgreSQL. -# In Windows the default installation of PostgreSQL uses that as part of the path. -# E.g C:\Program Files\PostgreSQL\8.4. -# Currently, the following version numbers are known to this module: -# "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0" -# -# To use this variable just do something like this: -# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4") -# before calling find_package(PostgreSQL) in your CMakeLists.txt file. -# This will mean that the versions you set here will be found first in the order -# specified before the default ones are searched. -# -# ---------------------------------------------------------------------------- -# You may need to manually set: -# PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are. -# PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are. -# If FindPostgreSQL.cmake cannot find the include files or the library files. -# -# ---------------------------------------------------------------------------- -# The following variables are set if PostgreSQL is found: -# PostgreSQL_FOUND - Set to true when PostgreSQL is found. -# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL -# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries -# PostgreSQL_LIBRARIES - The PostgreSQL libraries. -# -# ---------------------------------------------------------------------------- -# If you have installed PostgreSQL in a non-standard location. -# (Please note that in the following comments, it is assumed that -# points to the root directory of the include directory of PostgreSQL.) -# Then you have three options. -# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to /include and -# PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is -# 2) Use CMAKE_INCLUDE_PATH to set a path to /PostgreSQL<-version>. This will allow find_path() -# to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file -# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/include") -# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have -# installed PostgreSQL, e.g. . -# -# ---------------------------------------------------------------------------- - -set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include") -set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}") -set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.") -set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}") -set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4") - - -set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS} - "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") - -# Define additional search paths for root directories. -set( PostgreSQL_ROOT_DIRECTORIES - ENV PostgreSQL_ROOT - ${PostgreSQL_ROOT} -) -foreach(suffix ${PostgreSQL_KNOWN_VERSIONS}) - if(WIN32) - list(APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES - "PostgreSQL/${suffix}/lib") - list(APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES - "PostgreSQL/${suffix}/include") - endif() - if(UNIX) - list(APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES - "pgsql-${suffix}/lib") - list(APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES - "pgsql-${suffix}/include") - endif() -endforeach() - -# -# Look for an installation. -# -find_path(PostgreSQL_INCLUDE_DIR - NAMES libpq-fe.h - PATHS - # Look in other places. - ${PostgreSQL_ROOT_DIRECTORIES} - PATH_SUFFIXES - pgsql - postgresql - include - ${PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES} - # Help the user find it if we cannot. - DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}" -) - -# The PostgreSQL library. -set (PostgreSQL_LIBRARY_TO_FIND pq) -# Setting some more prefixes for the library -set (PostgreSQL_LIB_PREFIX "") -if ( WIN32 ) - set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib") - set (PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND}) -endif() - -find_library(PostgreSQL_LIBRARY - NAMES ${PostgreSQL_LIBRARY_TO_FIND} - PATHS - ${PostgreSQL_ROOT_DIRECTORIES} - PATH_SUFFIXES - lib - ${PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES} - # Help the user find it if we cannot. - DOC "The ${PostgreSQL_LIBRARY_DIR_MESSAGE}" -) -get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH) - -if (PostgreSQL_INCLUDE_DIR) - # Some platforms include multiple pg_config.hs for multi-lib configurations - # This is a temporary workaround. A better solution would be to compile - # a dummy c file and extract the value of the symbol. - file(GLOB _PG_CONFIG_HEADERS "${PostgreSQL_INCLUDE_DIR}/pg_config*.h") - foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS}) - if(EXISTS "${_PG_CONFIG_HEADER}") - file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str - REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") - if(pgsql_version_str) - string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" - "\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}") - break() - endif() - endif() - endforeach() - unset(pgsql_version_str) -endif() - -# Did we find anything? -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PostgreSQL - REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR - VERSION_VAR PostgreSQL_VERSION_STRING) -set(PostgreSQL_FOUND ${POSTGRESQL_FOUND}) - -# Now try to get the include and library path. -if(PostgreSQL_FOUND) - set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR}) - set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} ) - set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY}) -endif() - -mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_LIBRARY) diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake index 4d5bba6c0e10d..2f3b4b30f0458 100644 --- a/cmake/modules/RootBuildOptions.cmake +++ b/cmake/modules/RootBuildOptions.cmake @@ -145,10 +145,7 @@ ROOT_BUILD_OPTION(memory_termination OFF "Free internal ROOT memory before proce ROOT_BUILD_OPTION(minuit2_mpi OFF "Enable support for MPI in Minuit2") ROOT_BUILD_OPTION(minuit2_omp OFF "Enable support for OpenMP in Minuit2") ROOT_BUILD_OPTION(mpi OFF "Enable support for Message Passing Interface (MPI)") -ROOT_BUILD_OPTION(mysql OFF "Enable support for MySQL databases (deprecated)") -ROOT_BUILD_OPTION(odbc OFF "Enable support for ODBC databases (requires libiodbc or libodbc; deprecated)") ROOT_BUILD_OPTION(opengl ON "Enable support for OpenGL (requires libGL and libGLU)") -ROOT_BUILD_OPTION(pgsql OFF "Enable support for PostgreSQL (deprecated)") ROOT_BUILD_OPTION(proof OFF "Enable support for PROOF") ROOT_BUILD_OPTION(pyroot ON "Enable support for automatic Python bindings (PyROOT)") ROOT_BUILD_OPTION(pythia8 OFF "Enable support for Pythia 8.x [GPL]") @@ -396,14 +393,14 @@ foreach(opt afdsmgrd afs alien bonjour builtin_afterimage castor chirp cxx11 cxx cxxmodules exceptions geocad gfal glite globus gsl_shared hdfs html ios jemalloc krb5 ldap memstat minuit2 monalisa oracle pyroot-python2 pyroot_legacy pythia6 pythia6_nolink python qt qtgsi qt5web rfio ruby sapdb srp table - tcmalloc vmc xproofd) + tcmalloc vmc xproofd mysql odbc pgsql) if(${opt}) message(FATAL_ERROR ">>> '${opt}' is no longer part of ROOT ${ROOT_VERSION} build options.") endif() endforeach() #---Deprecated options------------------------------------------------------------------------ -foreach(opt mysql odbc pgsql) +foreach(opt ) if(${opt}) message(DEPRECATION ">>> Option '${opt}' is deprecated and will be removed in the next release of ROOT. Please contact root-dev@cern.ch should you still need it.") endif() diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake index d440319f65c04..579ce6883d25b 100644 --- a/cmake/modules/RootConfiguration.cmake +++ b/cmake/modules/RootConfiguration.cmake @@ -156,31 +156,11 @@ set(gl2pslibdir ${GL2PS_LIBRARY_DIR}) set(gl2pslib ${GL2PS_LIBRARY}) set(gl2psincdir ${GL2PS_INCLUDE_DIR}) -set(buildmysql ${value${mysql}}) -set(mysqllibdir ${MYSQL_LIBRARY_DIR}) -set(mysqllib ${MYSQL_LIBRARY}) -set(mysqlincdir ${MYSQL_INCLUDE_DIR}) - -set(buildoracle ${value${oracle}}) -set(oraclelibdir ${ORACLE_LIBRARY_DIR}) -set(oraclelib ${ORACLE_LIBRARY}) -set(oracleincdir ${ORACLE_INCLUDE_DIR}) - -set(buildpgsql ${value${pgsql}}) -set(pgsqllibdir ${PGSQL_LIBRARY_DIR}) -set(pgsqllib ${PGSQL_LIBRARY}) -set(pgsqlincdir ${PGSQL_INCLUDE_DIR}) - set(buildsqlite ${value${sqlite}}) set(sqlitelibdir ${SQLITE_LIBRARY_DIR}) set(sqlitelib ${SQLITE_LIBRARY}) set(sqliteincdir ${SQLITE_INCLUDE_DIR}) -set(buildodbc ${value${odbc}}) -set(odbclibdir ${OCDB_LIBRARY_DIR}) -set(odbclib ${OCDB_LIBRARY}) -set(odbcincdir ${OCDB_INCLUDE_DIR}) - set(builddavix ${value${davix}}) set(davixlibdir ${DAVIX_LIBRARY_DIR}) set(davixlib ${DAVIX_LIBRARY}) diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake index 7c410dfbd3347..2affa9cfb6235 100644 --- a/cmake/modules/SearchInstalledSoftware.cmake +++ b/cmake/modules/SearchInstalledSoftware.cmake @@ -818,20 +818,6 @@ if(builtin_openssl) endif() endif() -#---Check for MySQL------------------------------------------------------------------- -if(mysql) - message(STATUS "Looking for MySQL") - find_package(MySQL) - if(NOT MYSQL_FOUND) - if(fail-on-missing) - message(SEND_ERROR "MySQL libraries not found and they are required (mysql option enabled)") - else() - message(STATUS "MySQL not found. Switching off mysql option") - set(mysql OFF CACHE BOOL "Disabled because MySQL not found (${mysql_description})" FORCE) - endif() - endif() -endif() - #---Check for FastCGI----------------------------------------------------------- if(fcgi) message(STATUS "Looking for FastCGI") @@ -846,35 +832,6 @@ if(fcgi) endif() endif() - -#---Check for ODBC------------------------------------------------------------------- -if(odbc) - message(STATUS "Looking for ODBC") - find_package(ODBC) - if(NOT ODBC_FOUND) - if(fail-on-missing) - message(SEND_ERROR "ODBC libraries not found and they are required (odbc option enabled)") - else() - message(STATUS "ODBC not found. Switching off odbc option") - set(odbc OFF CACHE BOOL "Disabled because ODBC not found (${odbc_description})" FORCE) - endif() - endif() -endif() - -#---Check for PostgreSQL------------------------------------------------------------------- -if(pgsql) - message(STATUS "Looking for PostgreSQL") - find_package(PostgreSQL) - if(NOT PostgreSQL_FOUND) - if(fail-on-missing) - message(SEND_ERROR "PostgreSQL libraries not found and they are required (pgsql option enabled)") - else() - message(STATUS "PostgreSQL not found. Switching off pgsql option") - set(pgsql OFF CACHE BOOL "Disabled because PostgreSQL not found (${pgsql_description})" FORCE) - endif() - endif() -endif() - #---Check for SQLite------------------------------------------------------------------- if(sqlite) message(STATUS "Looking for SQLite") diff --git a/config/Makefile.in b/config/Makefile.in index 93fe04a41c062..ebca0f83a30c5 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -140,31 +140,11 @@ GL2PSLIBDIR := @gl2pslibdir@ GL2PSLIB := @gl2pslib@ GL2PSINCDIR := $(filter-out /usr/include, @gl2psincdir@) -BUILDMYSQL := @buildmysql@ -MYSQLLIBDIR := @mysqllibdir@ -MYSQLCLILIB := @mysqllib@ -MYSQLINCDIR := $(filter-out /usr/include, @mysqlincdir@) - -BUILDORACLE := @buildoracle@ -ORACLELIBDIR := @oraclelibdir@ -ORACLECLILIB := @oraclelib@ -ORACLEINCDIR := $(filter-out /usr/include, @oracleincdir@) - -BUILDPGSQL := @buildpgsql@ -PGSQLLIBDIR := @pgsqllibdir@ -PGSQLCLILIB := @pgsqllib@ -PGSQLINCDIR := $(filter-out /usr/include, @pgsqlincdir@) - BUILDSQLITE := @buildsqlite@ SQLITELIBDIR := @sqlitelibdir@ SQLITECLILIB := @sqlitelib@ SQLITEINCDIR := $(filter-out /usr/include, @sqliteincdir@) -BUILDODBC := @buildodbc@ -ODBCLIBDIR := @odbclibdir@ -ODBCCLILIB := @odbclib@ -ODBCINCDIR := $(filter-out /usr/include, @odbcincdir@) - BUILDDAVIX := @builddavix@ DAVIXLIBDIR := @davixlibdir@ DAVIXCLILIB := @davixlib@ diff --git a/core/base/src/TPluginManager.cxx b/core/base/src/TPluginManager.cxx index b888dd477dc5f..698e90bd59f97 100644 --- a/core/base/src/TPluginManager.cxx +++ b/core/base/src/TPluginManager.cxx @@ -47,10 +47,9 @@ file. Although now deprecated this method still works for backward compatibility, e.g.: ~~~ {.cpp} Plugin.TSQLServer: ^mysql: TMySQLServer MySQL "" - +Plugin.TSQLServer: ^pgsql: TPgSQLServer PgSQL "" Plugin.TVirtualFitter: * TFitter Minuit "TFitter(Int_t)" ~~~ -Where the + in front of Plugin.TSQLServer says that it extends the +Add a `+` in front of Plugin.TSQLServer to extend a previously existing definition of TSQLServer, useful when there is more than one plugin that can extend the same base class. The "" should be the constructor or a static method that generates an @@ -384,9 +383,8 @@ TPluginManager::~TPluginManager() /// Load plugin handlers specified in config file, like: /// ~~~ {.cpp} /// Plugin.TSQLServer: ^mysql: TMySQLServer MySQL "TMySQLServer(...)" -/// +Plugin.TSQLServer: ^pgsql: TPgSQLServer PgSQL "TPgSQLServer(...)" /// ~~~ -/// The + allows the extension of an already defined resource (see TEnv). +/// Add a `+` before `Plugin.` to allow for the extension of an already defined resource (see TEnv). void TPluginManager::LoadHandlersFromEnv(TEnv *env) { diff --git a/etc/plugins/TFile/P090_TSQLFile.C b/etc/plugins/TFile/P090_TSQLFile.C deleted file mode 100644 index a6441ffbefe77..0000000000000 --- a/etc/plugins/TFile/P090_TSQLFile.C +++ /dev/null @@ -1,7 +0,0 @@ -void P090_TSQLFile() -{ - gPluginMgr->AddHandler("TFile", "^mysql:", "TSQLFile", - "SQLIO", "TSQLFile(const char*,Option_t*,const char*,const char*)"); - gPluginMgr->AddHandler("TFile", "^oracle:", "TSQLFile", - "SQLIO", "TSQLFile(const char*,Option_t*,const char*,const char*)"); -} diff --git a/etc/plugins/TSQLServer/P010_TMySQLServer.C b/etc/plugins/TSQLServer/P010_TMySQLServer.C deleted file mode 100644 index bf731c20726cd..0000000000000 --- a/etc/plugins/TSQLServer/P010_TMySQLServer.C +++ /dev/null @@ -1,5 +0,0 @@ -void P010_TMySQLServer() -{ - gPluginMgr->AddHandler("TSQLServer", "^mysql:", "TMySQLServer", - "RMySQL", "TMySQLServer(const char*,const char*,const char*)"); -} diff --git a/etc/plugins/TSQLServer/P020_TPgSQLServer.C b/etc/plugins/TSQLServer/P020_TPgSQLServer.C deleted file mode 100644 index a6557d165cbe4..0000000000000 --- a/etc/plugins/TSQLServer/P020_TPgSQLServer.C +++ /dev/null @@ -1,8 +0,0 @@ -class TSQLServer; -TSQLServer* ROOT_Plugin_TPgSQLServer(const char*,const char*,const char*); - -void P020_TPgSQLServer() -{ - gPluginMgr->AddHandler("TSQLServer", "^pgsql:", "TPgSQLServer", - "PgSQL", "::ROOT_Plugin_TPgSQLServer(const char*,const char*,const char*)"); -} diff --git a/etc/plugins/TSQLServer/P040_TOracleServer.C b/etc/plugins/TSQLServer/P040_TOracleServer.C deleted file mode 100644 index 0aed40c9be269..0000000000000 --- a/etc/plugins/TSQLServer/P040_TOracleServer.C +++ /dev/null @@ -1,5 +0,0 @@ -void P040_TOracleServer() -{ - gPluginMgr->AddHandler("TSQLServer", "^oracle:", "TOracleServer", - "Oracle", "TOracleServer(const char*,const char*,const char*)"); -} diff --git a/etc/plugins/TSQLServer/P050_TODBCServer.C b/etc/plugins/TSQLServer/P050_TODBCServer.C deleted file mode 100644 index 811b4e38a8604..0000000000000 --- a/etc/plugins/TSQLServer/P050_TODBCServer.C +++ /dev/null @@ -1,9 +0,0 @@ -void P050_TODBCServer() -{ - gPluginMgr->AddHandler("TSQLServer", "^odbc:", "TODBCServer", - "RODBC", "TODBCServer(const char*,const char*,const char*)"); - gPluginMgr->AddHandler("TSQLServer", "^odbcn:", "TODBCServer", - "RODBC", "TODBCServer(const char*,const char*,const char*)"); - gPluginMgr->AddHandler("TSQLServer", "^odbcd:", "TODBCServer", - "RODBC", "TODBCServer(const char*,const char*,const char*)"); -} diff --git a/net/net/inc/TSQLStatement.h b/net/net/inc/TSQLStatement.h index e1fb38a65b70e..4fc33ad1958ae 100644 --- a/net/net/inc/TSQLStatement.h +++ b/net/net/inc/TSQLStatement.h @@ -89,7 +89,7 @@ class TSQLStatement : public TObject { virtual Bool_t GetBinary(Int_t, void* &, Long_t&) { return kFALSE; } /// \note Since ROOT 6.36, this API is defined to return new memory that must be released with /// `delete [] (unsigned char *) mem` by the caller. Older uses of this API (such as those of oracle, mysql, odbc) - /// that relied on internal buffer management (owning pointers) are deprecated/no longer supported. + /// that relied on internal buffer management (owning pointers) were removed in ROOT 6.38. virtual Bool_t GetLargeObject(Int_t col, void* &mem, Long_t& size) { return GetBinary(col, mem, size); } virtual Bool_t GetDate(Int_t, Int_t&, Int_t&, Int_t&) { return kFALSE; } diff --git a/net/net/src/TSQLStatement.cxx b/net/net/src/TSQLStatement.cxx index 7236bac0e6533..efef83d8e57db 100644 --- a/net/net/src/TSQLStatement.cxx +++ b/net/net/src/TSQLStatement.cxx @@ -222,7 +222,7 @@ /// is defined strictly to return new memory `mem` that must be released with /// `delete [] (unsigned char *) mem` by the caller. /// Older uses of this API (such as those of oracle, mysql, odbc) that relied on -/// internal buffer management (owning pointers) are deprecated/no longer supported. +/// internal buffer management (owning pointers) were removed in ROOT 6.38. /// //////////////////////////////////////////////////////////////////////////////// diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 4f46e6405bc94..25303e2993112 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -4,15 +4,6 @@ # For the licensing terms see $ROOTSYS/LICENSE. # For the list of contributors see $ROOTSYS/README/CREDITS. -if(mysql) - add_subdirectory(mysql) -endif() -if(odbc) - add_subdirectory(odbc) -endif() -if(pgsql) - add_subdirectory(pgsql) -endif() if(sqlite) add_subdirectory(sqlite) endif() diff --git a/sql/mysql/CMakeLists.txt b/sql/mysql/CMakeLists.txt deleted file mode 100644 index df61f18e6ea86..0000000000000 --- a/sql/mysql/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. -# All rights reserved. -# -# For the licensing terms see $ROOTSYS/LICENSE. -# For the list of contributors see $ROOTSYS/README/CREDITS. - -############################################################################ -# CMakeLists.txt file for building ROOT sql/mysql package -############################################################################ - -ROOT_STANDARD_LIBRARY_PACKAGE(RMySQL - HEADERS - TMySQLResult.h - TMySQLRow.h - TMySQLServer.h - TMySQLStatement.h - SOURCES - src/TMySQLResult.cxx - src/TMySQLRow.cxx - src/TMySQLServer.cxx - src/TMySQLStatement.cxx - DEPENDENCIES - Core - Net - RIO -) - -target_include_directories(RMySQL PUBLIC ${MYSQL_INCLUDE_DIR}) -target_link_libraries(RMySQL PUBLIC ${MYSQL_LIBRARIES}) diff --git a/sql/mysql/inc/LinkDef.h b/sql/mysql/inc/LinkDef.h deleted file mode 100644 index 65b5f66434f36..0000000000000 --- a/sql/mysql/inc/LinkDef.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifdef __CLING__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class TMySQLServer; -#pragma link C++ class TMySQLResult; -#pragma link C++ class TMySQLRow; -#pragma link C++ class TMySQLStatement; - -#endif diff --git a/sql/mysql/inc/TMySQLResult.h b/sql/mysql/inc/TMySQLResult.h deleted file mode 100644 index 72fa4d99b648b..0000000000000 --- a/sql/mysql/inc/TMySQLResult.h +++ /dev/null @@ -1,39 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TMySQLResult -#define ROOT_TMySQLResult - -#include "TSQLResult.h" - -#include - -class TMySQLResult : public TSQLResult { - -private: - MYSQL_RES *fResult{nullptr}; // query result (rows) - MYSQL_FIELD *fFieldInfo{nullptr}; // info for each field in the row - - Bool_t IsValid(Int_t field); - -public: - TMySQLResult(void *result); - ~TMySQLResult(); - - void Close(Option_t *opt="") final; - Int_t GetFieldCount() final; - const char *GetFieldName(Int_t field) final; - TSQLRow *Next() final; - - ClassDefOverride(TMySQLResult,0) // MySQL query result -}; - -#endif diff --git a/sql/mysql/inc/TMySQLRow.h b/sql/mysql/inc/TMySQLRow.h deleted file mode 100644 index 44bd0f1b4ddf3..0000000000000 --- a/sql/mysql/inc/TMySQLRow.h +++ /dev/null @@ -1,40 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TMySQLRow -#define ROOT_TMySQLRow - -#include "TSQLRow.h" - -#include - -class TMySQLRow : public TSQLRow { - -private: - MYSQL_RES *fResult{nullptr}; // current result set - MYSQL_ROW fFields; // current row - ULong_t *fFieldLength{nullptr}; // length of each field in the row - - Bool_t IsValid(Int_t field); - -public: - TMySQLRow(void *result, ULong_t rowHandle); - ~TMySQLRow(); - - void Close(Option_t *opt="") final; - ULong_t GetFieldLength(Int_t field) final; - const char *GetField(Int_t field) final; - - ClassDefOverride(TMySQLRow,0) // One row of MySQL query result -}; - -#endif - diff --git a/sql/mysql/inc/TMySQLServer.h b/sql/mysql/inc/TMySQLServer.h deleted file mode 100644 index 43e20d41f43d2..0000000000000 --- a/sql/mysql/inc/TMySQLServer.h +++ /dev/null @@ -1,89 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TMySQLServer -#define ROOT_TMySQLServer - -////////////////////////////////////////////////////////////////////////// -// // -// TMySQLServer // -// // -// MySQL server plugin implementing the TSQLServer interface. // -// // -// To open a connection to a server use the static method Connect(). // -// The db argument of Connect() is of the form: // -// mysql://[:][/], e.g. // -// mysql://pcroot.cern.ch:3456/test // -// // -// As an example of connecting to mysql we assume that the server is // -// running on the local host and that you have access to a database // -// named "test" by connecting using an account that has a username and // -// password of "tuser" and "tpass". You can set up this account // -// by using the "mysql" program to connect to the server as the MySQL // -// root user and issuing the following statement: // -// // -// mysql> GRANT ALL ON test.* TO 'tuser'@'localhost' IDENTIFIED BY 'tpass'; -// // -// If the test database does not exist, create it with this statement: // -// // -// mysql> CREATE DATABASE test; // -// // -// If you want to use a different server host, username, password, // -// or database name, just substitute the appropriate values. // -// To connect do: // -// // -// TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "tuser", "tpass"); -// // -////////////////////////////////////////////////////////////////////////// - -#include "TSQLServer.h" - -#include - -class TMySQLServer : public TSQLServer { - -protected: - MYSQL *fMySQL{nullptr}; // connection to MySQL server - TString fInfo; // server info string - -public: - TMySQLServer(const char *db, const char *uid, const char *pw); - ~TMySQLServer(); - - void Close(Option_t *opt="") final; - TSQLResult *Query(const char *sql) final; - Bool_t Exec(const char* sql) final; - TSQLStatement *Statement(const char *sql, Int_t = 100) final; - Bool_t HasStatement() const final; - Int_t SelectDataBase(const char *dbname) final; - TSQLResult *GetDataBases(const char *wild = nullptr) final; - TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) final; - TList *GetTablesList(const char* wild = nullptr) final; - TSQLTableInfo *GetTableInfo(const char* tablename) final; - TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) final; - Int_t GetMaxIdentifierLength() final { return 64; } - Int_t CreateDataBase(const char *dbname) final; - Int_t DropDataBase(const char *dbname) final; - Int_t Reload() final; - Int_t Shutdown() final; - const char *ServerInfo() final; - - Bool_t StartTransaction() final; - Bool_t Commit() final; - Bool_t Rollback() final; - - Bool_t PingVerify() final; - Int_t Ping() final; - - ClassDefOverride(TMySQLServer,0) // Connection to MySQL server -}; - -#endif diff --git a/sql/mysql/inc/TMySQLStatement.h b/sql/mysql/inc/TMySQLStatement.h deleted file mode 100644 index 859c87a4db9a2..0000000000000 --- a/sql/mysql/inc/TMySQLStatement.h +++ /dev/null @@ -1,130 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TMySQLStatement -#define ROOT_TMySQLStatement - -#include "TSQLStatement.h" - - -#include - -#if MYSQL_VERSION_ID < 40100 -typedef struct { int dummy; } MYSQL_STMT; -typedef struct { int dummy; } MYSQL_BIND; -#endif - -// MariaDB is fork of MySQL and still include definition of my_bool -// MariaDB major version is 10, therefore it confuses version ID here -#ifndef MARIADB_VERSION_ID -#if MYSQL_VERSION_ID > 80000 && MYSQL_VERSION_ID < 100000 -typedef bool my_bool; -#endif -#endif - -class TMySQLStatement : public TSQLStatement { - -protected: - - struct TParamData { - void *fMem{nullptr}; //! allocated data buffer - Int_t fSize{0}; //! size of allocated data - Int_t fSqlType{0}; //! sqltype of parameter - Bool_t fSign{kFALSE}; //! signed - not signed type - ULong_t fResLength{0}; //! length argument - my_bool fResNull{false}; //! indicates if argument is null - std::string fStrBuffer; //! special buffer to be used for string conversions - std::string fFieldName; //! buffer for field name - }; - - MYSQL_STMT *fStmt{nullptr}; //! executed statement - Int_t fNumBuffers{0}; //! number of statement parameters - MYSQL_BIND *fBind{nullptr}; //! array of bind data - TParamData *fBuffer{nullptr}; //! parameter definition structures - Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results - Int_t fIterationCount{-1}; //! number of iteration - Bool_t fNeedParBind{kFALSE}; //! indicates when parameters bind should be called - - Bool_t IsSetParsMode() const { return fWorkingMode==1; } - Bool_t IsResultSetMode() const { return fWorkingMode==2; } - - Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize = 0); - - long double ConvertToNumeric(Int_t npar); - const char *ConvertToString(Int_t npar); - - void FreeBuffers(); - void SetBuffersNumber(Int_t n); - - void *BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig = kTRUE, ULong_t size = 0); - - static ULong64_t fgAllocSizeLimit; - -private: - TMySQLStatement(const TMySQLStatement&) = delete; - TMySQLStatement &operator=(const TMySQLStatement&) = delete; - -public: - TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout = kTRUE); - virtual ~TMySQLStatement(); - - static ULong_t GetAllocSizeLimit(); - static void SetAllocSizeLimit(ULong_t sz); - - void Close(Option_t * = "") final; - - Int_t GetBufferLength() const final { return 1; } - Int_t GetNumParameters() final; - - Bool_t SetNull(Int_t npar) final; - Bool_t SetInt(Int_t npar, Int_t value) final; - Bool_t SetUInt(Int_t npar, UInt_t value) final; - Bool_t SetLong(Int_t npar, Long_t value) final; - Bool_t SetLong64(Int_t npar, Long64_t value) final; - Bool_t SetULong64(Int_t npar, ULong64_t value) final; - Bool_t SetDouble(Int_t npar, Double_t value) final; - Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final; - Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final; - Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final; - Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final; - Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final; - using TSQLStatement::SetTimestamp; - Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac = 0) final; - - Bool_t NextIteration() final; - - Bool_t Process() final; - Int_t GetNumAffectedRows() final; - - Bool_t StoreResult() final; - Int_t GetNumFields() final; - const char *GetFieldName(Int_t nfield) final; - Bool_t NextResultRow() final; - - Bool_t IsNull(Int_t npar) final; - Int_t GetInt(Int_t npar) final; - UInt_t GetUInt(Int_t npar) final; - Long_t GetLong(Int_t npar) final; - Long64_t GetLong64(Int_t npar) final; - ULong64_t GetULong64(Int_t npar) final; - Double_t GetDouble(Int_t npar) final; - const char *GetString(Int_t npar) final; - Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final; - Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final; - Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final; - Bool_t GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) final; - using TSQLStatement::GetTimestamp; - Bool_t GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t&) final; - - ClassDefOverride(TMySQLStatement, 0); // SQL statement class for MySQL DB -}; - -#endif diff --git a/sql/mysql/src/TMySQLResult.cxx b/sql/mysql/src/TMySQLResult.cxx deleted file mode 100644 index 2c44d471bbee5..0000000000000 --- a/sql/mysql/src/TMySQLResult.cxx +++ /dev/null @@ -1,113 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TMySQLResult.h" -#include "TMySQLRow.h" - - -ClassImp(TMySQLResult); - -//////////////////////////////////////////////////////////////////////////////// -/// MySQL query result. - -TMySQLResult::TMySQLResult(void *result) -{ - fResult = (MYSQL_RES *) result; - fRowCount = fResult ? mysql_num_rows(fResult) : 0; - fFieldInfo = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup MySQL query result. - -TMySQLResult::~TMySQLResult() -{ - if (fResult) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close query result. - -void TMySQLResult::Close(Option_t *) -{ - if (!fResult) - return; - - mysql_free_result(fResult); - fResult = nullptr; - fFieldInfo = nullptr; - fRowCount = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if result set is open and field index within range. - -Bool_t TMySQLResult::IsValid(Int_t field) -{ - if (!fResult) { - Error("IsValid", "result set closed"); - return kFALSE; - } - if (field < 0 || field >= GetFieldCount()) { - Error("IsValid", "field index out of bounds"); - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get number of fields in result. - -Int_t TMySQLResult::GetFieldCount() -{ - if (!fResult) { - Error("GetFieldCount", "result set closed"); - return 0; - } - return mysql_num_fields(fResult); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get name of specified field. - -const char *TMySQLResult::GetFieldName(Int_t field) -{ - if (!IsValid(field)) - return nullptr; - - if (!fFieldInfo) - fFieldInfo = mysql_fetch_fields(fResult); - - if (!fFieldInfo) { - Error("GetFieldName", "cannot get field info"); - return nullptr; - } - - return fFieldInfo[field].name; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get next query result row. The returned object must be -/// deleted by the user. - -TSQLRow *TMySQLResult::Next() -{ - if (!fResult) { - Error("Next", "result set closed"); - return nullptr; - } - MYSQL_ROW row = mysql_fetch_row(fResult); - if (!row) - return nullptr; - - return new TMySQLRow((void *) fResult, (ULong_t) row); -} diff --git a/sql/mysql/src/TMySQLRow.cxx b/sql/mysql/src/TMySQLRow.cxx deleted file mode 100644 index bd4b67eac9460..0000000000000 --- a/sql/mysql/src/TMySQLRow.cxx +++ /dev/null @@ -1,93 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TMySQLRow.h" - - -ClassImp(TMySQLRow); - -//////////////////////////////////////////////////////////////////////////////// -/// Single row of query result. - -TMySQLRow::TMySQLRow(void *res, ULong_t rowHandle) -{ - fResult = (MYSQL_RES *) res; - fFields = (MYSQL_ROW) rowHandle; - fFieldLength = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destroy row object. - -TMySQLRow::~TMySQLRow() -{ - if (fFields) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close row. - -void TMySQLRow::Close(Option_t *) -{ - if (!fFields) - return; - - fFields = nullptr; - fResult = nullptr; - fFieldLength = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if row is open and field index within range. - -Bool_t TMySQLRow::IsValid(Int_t field) -{ - if (!fFields) { - Error("IsValid", "row closed"); - return kFALSE; - } - if (field < 0 || field >= (Int_t)mysql_num_fields(fResult)) { - Error("IsValid", "field index out of bounds"); - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get length in bytes of specified field. - -ULong_t TMySQLRow::GetFieldLength(Int_t field) -{ - if (!IsValid(field)) - return 0; - - if (!fFieldLength) - fFieldLength = mysql_fetch_lengths(fResult); - - if (!fFieldLength) { - Error("GetFieldLength", "cannot get field length"); - return 0; - } - - return fFieldLength[field]; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get specified field from row (0 <= field < GetFieldCount()). - -const char *TMySQLRow::GetField(Int_t field) -{ - if (!IsValid(field)) - return nullptr; - - return fFields[field]; -} diff --git a/sql/mysql/src/TMySQLServer.cxx b/sql/mysql/src/TMySQLServer.cxx deleted file mode 100644 index 2fd388d01f666..0000000000000 --- a/sql/mysql/src/TMySQLServer.cxx +++ /dev/null @@ -1,827 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Fons Rademakers 15/02/2000 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TMySQLServer // -// // -// MySQL server plugin implementing the TSQLServer interface. // -// // -// To open a connection to a server use the static method Connect(). // -// The db argument of Connect() is of the form: // -// mysql://[:][/], e.g. // -// mysql://pcroot.cern.ch:3456/test // -// // -// As an example of connecting to mysql we assume that the server is // -// running on the local host and that you have access to a database // -// named "test" by connecting using an account that has a username and // -// password of "tuser" and "tpass". You can set up this account // -// by using the "mysql" program to connect to the server as the MySQL // -// root user and issuing the following statement: // -// // -// mysql> GRANT ALL ON test.* TO 'tuser'@'localhost' IDENTIFIED BY 'tpass'; -// // -// If the test database does not exist, create it with this statement: // -// // -// mysql> CREATE DATABASE test; // -// // -// If you want to use a different server host, username, password, // -// or database name, just substitute the appropriate values. // -// To connect do: // -// // -// TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "tuser", "tpass"); -// // -////////////////////////////////////////////////////////////////////////// - -#include "TMySQLServer.h" -#include "TMySQLResult.h" -#include "TMySQLStatement.h" -#include "TSQLColumnInfo.h" -#include "TSQLTableInfo.h" -#include "TSQLRow.h" -#include "TUrl.h" -#include "TList.h" -#include "TObjString.h" -#include "TObjArray.h" - -ClassImp(TMySQLServer); - -//////////////////////////////////////////////////////////////////////////////// -/// Open a connection to a MySQL DB server. The db arguments should be -/// of the form "mysql://[:][/]", e.g.: -/// "mysql://pcroot.cern.ch:3456/test". The uid is the username and pw -/// the password that should be used for the connection. -/// -/// In addition, several parameters can be specified in url after "?" symbol: -/// timeout=N n is connect timeout is seconds -/// socket=socketname socketname should be name of Unix socket, used -/// for connection -/// multi_statements tell the server that the client may send multiple -/// statements in a single string (separated by ;); -/// multi_results tell the server that the client can handle multiple -/// result sets from multiple-statement executions or -/// stored procedures -/// reconnect=0|1 enable or disable automatic reconnection to the server -/// if the connection is found to have been lost -/// compress use the compressed client/server protocol -/// cnf_file=filename Read options from the named option file instead of -/// from my.cnf -/// cnf_group=groupname Read options from the named group from my.cnf or the -/// file specified with cnf_file option -/// If several parameters are specified, they should be separated by "&" symbol -/// Example of connection argument: -/// TSQLServer::Connect("mysql://host.domain/test?timeout=10&multi_statements"); - -TMySQLServer::TMySQLServer(const char *db, const char *uid, const char *pw) -{ - fMySQL = nullptr; - fInfo = "MySQL"; - - TUrl url(db); - - if (!url.IsValid()) { - TString errmsg("malformed db argument "); - errmsg += db; - SetError(-1, errmsg.Data(), "TMySQLServer"); - MakeZombie(); - return; - } - - if (strncmp(url.GetProtocol(), "mysql", 5)) { - SetError(-1, "protocol in db argument should be mysql://", "TMySQLServer"); - MakeZombie(); - return; - } - - const char* dbase = url.GetFile(); - if (dbase) - if (*dbase=='/') dbase++; //skip leading "/" if appears - - fMySQL = new MYSQL; - mysql_init(fMySQL); - - ULong_t client_flag = 0; - TString socket; - - TString optstr = url.GetOptions(); - TObjArray* optarr = optstr.Tokenize("&"); - if (optarr!=0) { - TIter next(optarr); - TObject *obj = 0; - while ((obj = next()) != 0) { - TString opt = obj->GetName(); - opt.ToLower(); - opt.ReplaceAll(" ",""); - if (opt.Contains("timeout=")) { - opt.Remove(0, 8); - Int_t timeout = opt.Atoi(); - if (timeout > 0) { - UInt_t mysqltimeout = (UInt_t) timeout; - mysql_options(fMySQL, MYSQL_OPT_CONNECT_TIMEOUT, (const char*) &mysqltimeout); - if (gDebug) Info("TMySQLServer","Set timeout %d",timeout); - } - } else - if (opt.Contains("read_timeout=")) { - #if MYSQL_VERSION_ID >= 40101 - opt.Remove(0, 13); - Int_t timeout = opt.Atoi(); - if (timeout > 0) { - UInt_t mysqltimeout = (UInt_t) timeout; - mysql_options(fMySQL, MYSQL_OPT_READ_TIMEOUT, (const char*) &mysqltimeout); - if (gDebug) Info("TMySQLServer","Set read timeout %d", timeout); - } - #else - Warning("TMySQLServer","MYSQL_OPT_READ_TIMEOUT option not supported by this version of MySql"); - #endif - - } else - if (opt.Contains("write_timeout=")) { - #if MYSQL_VERSION_ID >= 40101 - opt.Remove(0, 14); - Int_t timeout = opt.Atoi(); - if (timeout > 0) { - UInt_t mysqltimeout = (UInt_t) timeout; - mysql_options(fMySQL, MYSQL_OPT_WRITE_TIMEOUT, (const char*) &mysqltimeout); - if (gDebug) Info("TMySQLServer","Set write timeout %d", timeout); - } - #else - Warning("TMySQLServer","MYSQL_OPT_WRITE_TIMEOUT option not supported by this version of MySql"); - #endif - } else - if (opt.Contains("reconnect=")) { - #if MYSQL_VERSION_ID >= 50013 - opt.Remove(0, 10); - bool reconnect_on = (opt=="1") || (opt=="true"); - mysql_options(fMySQL, MYSQL_OPT_RECONNECT, (const char*) &reconnect_on); - if (gDebug) Info("TMySQLServer","Set reconnect options %s", (reconnect_on ? "ON" : "OFF")); - #else - Warning("TMySQLServer","MYSQL_OPT_RECONNECT option not supported by this version of MySql"); - #endif - } else - if (opt.Contains("socket=")) { - socket = (obj->GetName()+7); - if (gDebug) Info("TMySQLServer","Use socket %s", socket.Data()); - } else - if (opt.Contains("multi_statements")) { - #if MYSQL_VERSION_ID >= 40100 - client_flag = client_flag | CLIENT_MULTI_STATEMENTS; - if (gDebug) Info("TMySQLServer","Use CLIENT_MULTI_STATEMENTS"); - #else - Warning("TMySQLServer","CLIENT_MULTI_STATEMENTS not supported by this version of MySql"); - #endif - } else - if (opt.Contains("multi_results")) { - #if MYSQL_VERSION_ID >= 40100 - client_flag = client_flag | CLIENT_MULTI_RESULTS; - if (gDebug) Info("TMySQLServer","Use CLIENT_MULTI_RESULTS"); - #else - Warning("TMySQLServer","CLIENT_MULTI_RESULTS not supported by this version of MySql"); - #endif - } else - if (opt.Contains("compress")) { - mysql_options(fMySQL, MYSQL_OPT_COMPRESS, 0); - if (gDebug) Info("TMySQLServer","Use compressed client/server protocol"); - } else - if (opt.Contains("cnf_file=")) { - const char* filename = (obj->GetName()+9); - mysql_options(fMySQL, MYSQL_READ_DEFAULT_FILE, filename); - if (gDebug) Info("TMySQLServer","Read mysql options from %s file", filename); - } else - if (opt.Contains("cnf_group=")) { - const char* groupname = (obj->GetName()+10); - mysql_options(fMySQL, MYSQL_READ_DEFAULT_GROUP, groupname); - if (gDebug) Info("TMySQLServer","Read mysql options from %s group of my.cnf file", groupname); - } - } - optarr->Delete(); - delete optarr; - } - - Int_t port = 3306; - if (url.GetPort()>0) port = url.GetPort(); - - if (mysql_real_connect(fMySQL, url.GetHost(), uid, pw, dbase, port, - (socket.Length()>0) ? socket.Data() : 0 , client_flag)) { - fType = "MySQL"; - fHost = url.GetHost(); - fDB = dbase; - fPort = port; - } else { - SetError(mysql_errno(fMySQL), mysql_error(fMySQL), "TMySQLServer"); - MakeZombie(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to MySQL DB server. - -TMySQLServer::~TMySQLServer() -{ - if (IsConnected()) - Close(); - delete fMySQL; -} - -// Reset error and check that server connected -#define CheckConnect(method, res) \ - { \ - ClearError(); \ - if (!IsConnected()) { \ - SetError(-1,"MySQL server is not connected",method); \ - return res; \ - } \ - } - - -// check last mysql error code -#define CheckErrNo(method, force, res) \ - { \ - unsigned int sqlerrno = mysql_errno(fMySQL); \ - if ((sqlerrno!=0) || force) { \ - const char* sqlerrmsg = mysql_error(fMySQL); \ - if (sqlerrno==0) { sqlerrno = 11111; sqlerrmsg = "MySQL error"; } \ - SetError(sqlerrno, sqlerrmsg, method); \ - return res; \ - } \ - } - - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to MySQL DB server. - -void TMySQLServer::Close(Option_t *) -{ - ClearError(); - - if (!fMySQL) - return; - - mysql_close(fMySQL); - fPort = -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SQL command. Result object must be deleted by the user. -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TMySQLServer::Query(const char *sql) -{ - CheckConnect("Query", 0); - - if (mysql_query(fMySQL, sql)) - CheckErrNo("Query",kTRUE,0); - - MYSQL_RES *res = mysql_store_result(fMySQL); - CheckErrNo("Query", kFALSE, 0); - - return new TMySQLResult(res); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SQL command which does not produce any result sets. -/// Returns kTRUE if successful. - -Bool_t TMySQLServer::Exec(const char* sql) -{ - CheckConnect("Exec", kFALSE); - - if (mysql_query(fMySQL, sql)) - CheckErrNo("Exec",kTRUE,kFALSE); - - return !IsError(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Select a database. Returns 0 if successful, non-zero otherwise. - -Int_t TMySQLServer::SelectDataBase(const char *dbname) -{ - CheckConnect("SelectDataBase", -1); - - Int_t res = mysql_select_db(fMySQL, dbname); - if (res==0) fDB = dbname; - else CheckErrNo("SelectDataBase", kTRUE, res); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all available databases. Wild is for wildcarding "t%" list all -/// databases starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TMySQLServer::GetDataBases(const char *wild) -{ - CheckConnect("GetDataBases", 0); - - MYSQL_RES *res = mysql_list_dbs(fMySQL, wild); - - CheckErrNo("GetDataBases", kFALSE, 0); - - return new TMySQLResult(res); -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all tables in the specified database. Wild is for wildcarding -/// "t%" list all tables starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TMySQLServer::GetTables(const char *dbname, const char *wild) -{ - CheckConnect("GetTables", 0); - - if (SelectDataBase(dbname) != 0) return nullptr; - - MYSQL_RES *res = mysql_list_tables(fMySQL, wild); - - CheckErrNo("GetTables", kFALSE, 0); - - return new TMySQLResult(res); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Return list of tables with specified wildcard. - -TList* TMySQLServer::GetTablesList(const char* wild) -{ - CheckConnect("GetTablesList", 0); - - MYSQL_RES *res = mysql_list_tables(fMySQL, wild); - - CheckErrNo("GetTablesList", kFALSE, 0); - - MYSQL_ROW row = mysql_fetch_row(res); - - TList *lst = nullptr; - - while (row!=0) { - CheckErrNo("GetTablesList", kFALSE, lst); - - const char *tablename = row[0]; - - if (tablename) { - if (!lst) { - lst = new TList(); - lst->SetOwner(kTRUE); - } - lst->Add(new TObjString(tablename)); - } - - row = mysql_fetch_row(res); - } - - mysql_free_result(res); - - return lst; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Produces SQL table info. -/// Object must be deleted by user. - -TSQLTableInfo *TMySQLServer::GetTableInfo(const char* tablename) -{ - CheckConnect("GetTableInfo", 0); - - if (!tablename || (*tablename==0)) return nullptr; - - TString sql; - sql.Form("SELECT * FROM `%s` LIMIT 1", tablename); - - if (mysql_query(fMySQL, sql.Data()) != 0) - CheckErrNo("GetTableInfo", kTRUE, 0); - - MYSQL_RES *res = mysql_store_result(fMySQL); - CheckErrNo("GetTableInfo", kFALSE, 0); - - unsigned int numfields = mysql_num_fields(res); - - MYSQL_FIELD* fields = mysql_fetch_fields(res); - - sql.Form("SHOW COLUMNS FROM `%s`", tablename); - TSQLResult* showres = Query(sql.Data()); - - if (!showres) { - mysql_free_result(res); - return nullptr; - } - - TList *lst = nullptr; - - unsigned int nfield = 0; - - TSQLRow* row = nullptr; - - while ((row = showres->Next()) != 0) { - const char* column_name = row->GetField(0); - const char* type_name = row->GetField(1); - - if ((nfield>=numfields) || - (strcmp(column_name, fields[nfield].name)!=0)) - { - SetError(-1,"mismatch in column names","GetTableInfo"); - break; - } - - Int_t sqltype = kSQL_NONE; - - Int_t data_size = -1; // size in bytes - Int_t data_length = -1; // declaration like VARCHAR(n) or NUMERIC(n) - Int_t data_scale = -1; // second argument in declaration - Int_t data_sign = -1; // signed type or not - - if (IS_NUM(fields[nfield].type)) { - if (fields[nfield].flags & UNSIGNED_FLAG) - data_sign = 0; - else - data_sign = 1; - } - - Bool_t nullable = (fields[nfield].flags & NOT_NULL_FLAG) == 0; - - data_length = fields[nfield].length; - if (data_length==0) data_length = -1; - -#if MYSQL_VERSION_ID >= 40100 - - switch (fields[nfield].type) { - case MYSQL_TYPE_TINY: - case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_LONG: - case MYSQL_TYPE_INT24: - case MYSQL_TYPE_LONGLONG: - sqltype = kSQL_INTEGER; - break; - case MYSQL_TYPE_DECIMAL: - sqltype = kSQL_NUMERIC; - data_scale = fields[nfield].decimals; - break; - case MYSQL_TYPE_FLOAT: - sqltype = kSQL_FLOAT; - break; - case MYSQL_TYPE_DOUBLE: - sqltype = kSQL_DOUBLE; - break; - case MYSQL_TYPE_TIMESTAMP: - sqltype = kSQL_TIMESTAMP; - break; - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_YEAR: - break; - case MYSQL_TYPE_STRING: - if (fields[nfield].charsetnr==63) - sqltype = kSQL_BINARY; - else - sqltype = kSQL_CHAR; - data_size = data_length; - break; - case MYSQL_TYPE_VAR_STRING: - if (fields[nfield].charsetnr==63) - sqltype = kSQL_BINARY; - else - sqltype = kSQL_VARCHAR; - data_size = data_length; - break; - case MYSQL_TYPE_BLOB: - if (fields[nfield].charsetnr==63) - sqltype = kSQL_BINARY; - else - sqltype = kSQL_VARCHAR; - data_size = data_length; - break; - case MYSQL_TYPE_SET: - case MYSQL_TYPE_ENUM: - case MYSQL_TYPE_GEOMETRY: - case MYSQL_TYPE_NULL: - break; - default: - if (IS_NUM(fields[nfield].type)) - sqltype = kSQL_NUMERIC; - } - -#endif - - if (!lst) - lst = new TList; - lst->Add(new TSQLColumnInfo(column_name, - type_name, - nullable, - sqltype, - data_size, - data_length, - data_scale, - data_sign)); - - nfield++; - delete row; - } - - mysql_free_result(res); - delete showres; - - sql.Form("SHOW TABLE STATUS LIKE '%s'", tablename); - - TSQLTableInfo* info = 0; - - TSQLResult* stats = Query(sql.Data()); - - if (stats!=0) { - row = 0; - - while ((row = stats->Next()) != 0) { - if (strcmp(row->GetField(0), tablename)!=0) { - delete row; - continue; - } - const char* comments = 0; - const char* engine = 0; - const char* create_time = 0; - const char* update_time = 0; - - for (int n=1;nGetFieldCount();n++) { - TString fname = stats->GetFieldName(n); - fname.ToLower(); - if (fname=="engine") engine = row->GetField(n); else - if (fname=="comment") comments = row->GetField(n); else - if (fname=="create_time") create_time = row->GetField(n); else - if (fname=="update_time") update_time = row->GetField(n); - } - - info = new TSQLTableInfo(tablename, - lst, - comments, - engine, - create_time, - update_time); - - delete row; - break; - } - delete stats; - } - - if (info==0) - info = new TSQLTableInfo(tablename, lst); - - return info; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all columns in specified table in the specified database. -/// Wild is for wildcarding "t%" list all columns starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TMySQLServer::GetColumns(const char *dbname, const char *table, - const char *wild) -{ - CheckConnect("GetColumns", 0); - - if (SelectDataBase(dbname) != 0) return nullptr; - - TString sql; - if (wild) - sql.Form("SHOW COLUMNS FROM %s LIKE '%s'", table, wild); - else - sql.Form("SHOW COLUMNS FROM %s", table); - - return Query(sql.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a database. Returns 0 if successful, non-zero otherwise. - -Int_t TMySQLServer::CreateDataBase(const char *dbname) -{ - CheckConnect("CreateDataBase", -1); - - Int_t res = mysql_query(fMySQL, Form("CREATE DATABASE %s",dbname)); - - CheckErrNo("CreateDataBase", kFALSE, res); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Drop (i.e. delete) a database. Returns 0 if successful, non-zero -/// otherwise. - -Int_t TMySQLServer::DropDataBase(const char *dbname) -{ - CheckConnect("DropDataBase", -1); - - Int_t res = mysql_query(fMySQL, Form("DROP DATABASE %s",dbname)); - - CheckErrNo("DropDataBase", kFALSE, res); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Reload permission tables. Returns 0 if successful, non-zero -/// otherwise. User must have reload permissions. - -Int_t TMySQLServer::Reload() -{ - CheckConnect("Reload", -1); - - Int_t res; - - #if MYSQL_VERSION_ID >= 80000 - res = mysql_query(fMySQL, "FLUSH PRIVILEGES"); - #else - res = mysql_reload(fMySQL); - #endif - - CheckErrNo("Reload", kFALSE, res); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shutdown the database server. Returns 0 if successful, non-zero -/// otherwise. User must have shutdown permissions. - -Int_t TMySQLServer::Shutdown() -{ - CheckConnect("Shutdown", -1); - - Int_t res; - -#if MYSQL_VERSION_ID >= 80000 - res = mysql_query(fMySQL, "SHUTDOWN"); -#elif MYSQL_VERSION_ID >= 50001 || \ - (MYSQL_VERSION_ID < 50000 && MYSQL_VERSION_ID >= 40103) - res = mysql_shutdown(fMySQL, SHUTDOWN_DEFAULT); -#else - res = mysql_shutdown(fMySQL); -#endif - - CheckErrNo("Shutdown", kFALSE, res); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return server info in form "MySQL ". - -const char *TMySQLServer::ServerInfo() -{ - CheckConnect("ServerInfo", 0); - - const char* res = mysql_get_server_info(fMySQL); - - CheckErrNo("ServerInfo", kFALSE, res); - - fInfo = "MySQL "; - fInfo += res; - - return fInfo.Data(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return kTRUE if TSQLStatement class is supported. -/// Starts from MySQL 4.1. - -Bool_t TMySQLServer::HasStatement() const -{ -#if MYSQL_VERSION_ID < 40100 - return kFALSE; -#else - return kTRUE; -#endif -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TMySQLStatement. - -TSQLStatement *TMySQLServer::Statement(const char *sql, Int_t) -{ -#if MYSQL_VERSION_ID < 40100 - ClearError(); - SetError(-1, "Statement class does not supported by MySQL version < 4.1", "Statement"); - return nullptr; -#else - - CheckConnect("Statement", 0); - - if (!sql || !*sql) { - SetError(-1, "no query string specified","Statement"); - return nullptr; - } - - MYSQL_STMT *stmt = mysql_stmt_init(fMySQL); - if (!stmt) - CheckErrNo("Statement", kTRUE, 0); - - if (mysql_stmt_prepare(stmt, sql, strlen(sql))) { - SetError(mysql_errno(fMySQL), mysql_error(fMySQL), "Statement"); - mysql_stmt_close(stmt); - return nullptr; - } - - return new TMySQLStatement(stmt, fErrorOut); - -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// Start transaction - -Bool_t TMySQLServer::StartTransaction() -{ - CheckConnect("StartTransaction", kFALSE); - - return TSQLServer::StartTransaction(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Commit changes - -Bool_t TMySQLServer::Commit() -{ - CheckConnect("Commit", kFALSE); - -#if MYSQL_VERSION_ID >= 40100 - - if (mysql_commit(fMySQL)) - CheckErrNo("Commit", kTRUE, kFALSE); - - return kTRUE; - -#else - - return TSQLServer::Commit(); - -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -/// Rollback changes - -Bool_t TMySQLServer::Rollback() -{ - CheckConnect("Rollback", kFALSE); - -#if MYSQL_VERSION_ID >= 40100 - - if (mysql_rollback(fMySQL)) - CheckErrNo("Rollback", kTRUE, kFALSE); - - return kTRUE; - -#else - - return TSQLServer::Rollback(); - -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute Ping to SQL Connection. -/// Since mysql_ping tries to reconnect by itself, -/// a double call to the mysql function is implemented. -/// Returns kTRUE if successful - -Bool_t TMySQLServer::PingVerify() -{ - CheckConnect("Ping", kFALSE); - - if (mysql_ping(fMySQL)) { - if (mysql_ping(fMySQL)) { - Error("PingVerify", "not able to automatically reconnect a second time"); - CheckErrNo("Ping", kTRUE, kFALSE); - } else - Info("PingVerify", "connection was lost, but could automatically reconnect"); - } - - return !IsError(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute Ping to SQL Connection using the mysql_ping function. -/// Returns 0 if successful, non-zero in case an error occured. - -Int_t TMySQLServer::Ping() -{ - CheckConnect("PingInt", kFALSE); - - return mysql_ping(fMySQL); -} diff --git a/sql/mysql/src/TMySQLStatement.cxx b/sql/mysql/src/TMySQLStatement.cxx deleted file mode 100644 index 39fa7fd9a608e..0000000000000 --- a/sql/mysql/src/TMySQLStatement.cxx +++ /dev/null @@ -1,1431 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// SQL statement class for MySQL // -// // -// See TSQLStatement class documentation for more details. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TMySQLStatement.h" -#include "TMySQLServer.h" -#include "TDataType.h" -#include "TDatime.h" -#include "snprintf.h" -#include "strlcpy.h" -#include - -ClassImp(TMySQLStatement); - -ULong64_t TMySQLStatement::fgAllocSizeLimit = 0x8000000; // 128 Mb - -//////////////////////////////////////////////////////////////////////////////// -/// Return limit for maximal allocated memory for single parameter - -ULong_t TMySQLStatement::GetAllocSizeLimit() -{ - return fgAllocSizeLimit; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set limit for maximal allocated memory for single parameter - -void TMySQLStatement::SetAllocSizeLimit(ULong_t sz) -{ - fgAllocSizeLimit = sz; -} - -#if MYSQL_VERSION_ID >= 40100 - -//////////////////////////////////////////////////////////////////////////////// -/// Normal constructor. -/// Checks if statement contains parameters tags. - -TMySQLStatement::TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout) : - TSQLStatement(errout), - fStmt(stmt) -{ - ULong_t paramcount = mysql_stmt_param_count(fStmt); - - if (paramcount>0) { - fWorkingMode = 1; - SetBuffersNumber(paramcount); - fNeedParBind = kTRUE; - fIterationCount = -1; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor. - -TMySQLStatement::~TMySQLStatement() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close statement. - -void TMySQLStatement::Close(Option_t *) -{ - if (fStmt) - mysql_stmt_close(fStmt); - - fStmt = nullptr; - - FreeBuffers(); -} - - -// Reset error and check that statement exists -#define CheckStmt(method, res) \ - { \ - ClearError(); \ - if (fStmt==0) { \ - SetError(-1,"Statement handle is 0",method); \ - return res; \ - } \ - } - -// check last mysql statement error code -#define CheckErrNo(method, force, res) \ - { \ - unsigned int stmterrno = mysql_stmt_errno(fStmt); \ - if ((stmterrno!=0) || force) { \ - const char* stmterrmsg = mysql_stmt_error(fStmt); \ - if (stmterrno==0) { stmterrno = 11111; stmterrmsg = "MySQL statement error"; } \ - SetError(stmterrno, stmterrmsg, method); \ - return res; \ - } \ - } - - -// check last mysql statement error code -#define CheckGetField(method, res) \ - { \ - ClearError(); \ - if (!IsResultSetMode()) { \ - SetError(-1,"Cannot get statement parameters",method); \ - return res; \ - } \ - if ((npar<0) || (npar>=fNumBuffers)) { \ - SetError(-1,Form("Invalid parameter number %d", npar),method); \ - return res; \ - } \ - } - -//////////////////////////////////////////////////////////////////////////////// -/// Process statement. - -Bool_t TMySQLStatement::Process() -{ - CheckStmt("Process",kFALSE); - - // if parameters was set, processing just means of closing parameters and variables - if (IsSetParsMode()) { - if (fIterationCount>=0) - if (!NextIteration()) return kFALSE; - fWorkingMode = 0; - fIterationCount = -1; - FreeBuffers(); - return kTRUE; - } - - if (mysql_stmt_execute(fStmt)) - CheckErrNo("Process",kTRUE, kFALSE); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of affected rows after statement is processed. - -Int_t TMySQLStatement::GetNumAffectedRows() -{ - CheckStmt("Process", -1); - - my_ulonglong res = mysql_stmt_affected_rows(fStmt); - - if (res == (my_ulonglong) -1) - CheckErrNo("GetNumAffectedRows", kTRUE, -1); - - return (Int_t) res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of statement parameters. - -Int_t TMySQLStatement::GetNumParameters() -{ - CheckStmt("GetNumParameters", -1); - - Int_t res = mysql_stmt_param_count(fStmt); - - CheckErrNo("GetNumParameters", kFALSE, -1); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Store result of statement processing to access them -/// via GetInt(), GetDouble() and so on methods. - -Bool_t TMySQLStatement::StoreResult() -{ - CheckStmt("StoreResult", kFALSE); - if (fWorkingMode!=0) { - SetError(-1,"Cannot store result for that statement","StoreResult"); - return kFALSE; - } - - if (mysql_stmt_store_result(fStmt)) - CheckErrNo("StoreResult",kTRUE, kFALSE); - - // allocate memeory for data reading from query - MYSQL_RES* meta = mysql_stmt_result_metadata(fStmt); - if (meta) { - int count = mysql_num_fields(meta); - - SetBuffersNumber(count); - - MYSQL_FIELD *fields = mysql_fetch_fields(meta); - - for (int n=0;n=fNumBuffers)) return nullptr; - - return fBuffer[nfield].fFieldName.empty() ? nullptr : fBuffer[nfield].fFieldName.c_str(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shift cursor to nect row in result set. - -Bool_t TMySQLStatement::NextResultRow() -{ - if ((fStmt==0) || !IsResultSetMode()) return kFALSE; - - Bool_t res = !mysql_stmt_fetch(fStmt); - - if (!res) { - fWorkingMode = 0; - FreeBuffers(); - } - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Increment iteration counter for statement, where parameter can be set. -/// Statement with parameters of previous iteration -/// automatically will be applied to database. - -Bool_t TMySQLStatement::NextIteration() -{ - ClearError(); - - if (!IsSetParsMode() || (fBind==0)) { - SetError(-1,"Cannot call for that statement","NextIteration"); - return kFALSE; - } - - fIterationCount++; - - if (fIterationCount==0) return kTRUE; - - if (fNeedParBind) { - fNeedParBind = kFALSE; - if (mysql_stmt_bind_param(fStmt, fBind)) - CheckErrNo("NextIteration",kTRUE, kFALSE); - } - - if (mysql_stmt_execute(fStmt)) - CheckErrNo("NextIteration", kTRUE, kFALSE); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Release all buffers, used by statement. - -void TMySQLStatement::FreeBuffers() -{ - if (fBuffer) { - for (Int_t n=0; nyear, tm->month, tm->day, - tm->hour, tm->minute, tm->second); - break; - } - case MYSQL_TYPE_TIME: { - MYSQL_TIME* tm = (MYSQL_TIME*) addr; - len = snprintf(buf, kSize, "%2.2d:%2.2d:%2.2d", - tm->hour, tm->minute, tm->second); - break; - } - case MYSQL_TYPE_DATE: { - MYSQL_TIME* tm = (MYSQL_TIME*) addr; - len = snprintf(buf, kSize, "%4.4d-%2.2d-%2.2d", - tm->year, tm->month, tm->day); - break; - } - default: - return nullptr; - } - - if (len >= kSize) - SetError(-1, Form("Cannot convert param %d into string - buffer too small", npar)); - - fBuffer[npar].fStrBuffer = buf; - - return fBuffer[npar].fStrBuffer.c_str(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field to numeric value. - -long double TMySQLStatement::ConvertToNumeric(Int_t npar) -{ - if (fBuffer[npar].fResNull) return 0; - - void* addr = fBuffer[npar].fMem; - Bool_t sig = fBuffer[npar].fSign; - - if (addr==0) return 0; - - switch(fBind[npar].buffer_type) { - case MYSQL_TYPE_LONG: - if (sig) return *((int*) addr); else - return *((unsigned int*) addr); - break; - case MYSQL_TYPE_LONGLONG: - if (sig) return *((Long64_t*) addr); else - return *((ULong64_t*) addr); - break; - case MYSQL_TYPE_SHORT: - if (sig) return *((short*) addr); else - return *((unsigned short*) addr); - break; - case MYSQL_TYPE_TINY: - if (sig) return *((char*) addr); else - return *((unsigned char*) addr); - break; - case MYSQL_TYPE_FLOAT: - return *((float*) addr); - break; - case MYSQL_TYPE_DOUBLE: - return *((double*) addr); - break; -#if MYSQL_VERSION_ID >= 50022 - case MYSQL_TYPE_NEWDECIMAL /* new MYSQL_TYPE fixed precision decimal */: -#endif - case MYSQL_TYPE_STRING: - case MYSQL_TYPE_VAR_STRING: - case MYSQL_TYPE_BLOB: { - char* str = (char*) addr; - ULong_t len = fBuffer[npar].fResLength; - if ((str==0) || (*str==0) || (len==0)) return 0; - Int_t size = fBuffer[npar].fSize; - if (1.*lenyear, tm->month, tm->day, - tm->hour, tm->minute, tm->second); - return rtm.Get(); - break; - } - case MYSQL_TYPE_DATE: { - MYSQL_TIME* tm = (MYSQL_TIME*) addr; - TDatime rtm(tm->year, tm->month, tm->day, 0, 0, 0); - return rtm.GetDate(); - break; - } - case MYSQL_TYPE_TIME: { - MYSQL_TIME* tm = (MYSQL_TIME*) addr; - TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second); - return rtm.GetTime(); - break; - } - - default: - return 0; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Checks if field value is null. - -Bool_t TMySQLStatement::IsNull(Int_t npar) -{ - CheckGetField("IsNull", kTRUE); - - return fBuffer[npar].fResNull; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as integer. - -Int_t TMySQLStatement::GetInt(Int_t npar) -{ - CheckGetField("GetInt", 0); - - if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && fBuffer[npar].fSign) - return (Int_t) *((int*) fBuffer[npar].fMem); - - return (Int_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned integer. - -UInt_t TMySQLStatement::GetUInt(Int_t npar) -{ - CheckGetField("GetUInt", 0); - - if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && !fBuffer[npar].fSign) - return (UInt_t) *((unsigned int*) fBuffer[npar].fMem); - - return (UInt_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as long integer. - -Long_t TMySQLStatement::GetLong(Int_t npar) -{ - CheckGetField("GetLong", 0); - - if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONG) && fBuffer[npar].fSign) - return (Long_t) *((int*) fBuffer[npar].fMem); - - return (Long_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as 64-bit integer. - -Long64_t TMySQLStatement::GetLong64(Int_t npar) -{ - CheckGetField("GetLong64", 0); - - if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && fBuffer[npar].fSign) - return (Long64_t) *((Long64_t*) fBuffer[npar].fMem); - - return (Long64_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned 64-bit integer. - -ULong64_t TMySQLStatement::GetULong64(Int_t npar) -{ - CheckGetField("GetULong64", 0); - - if ((fBuffer[npar].fSqlType==MYSQL_TYPE_LONGLONG) && !fBuffer[npar].fSign) - return (ULong64_t) *((ULong64_t*) fBuffer[npar].fMem); - - return (ULong64_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as double. - -Double_t TMySQLStatement::GetDouble(Int_t npar) -{ - CheckGetField("GetDouble", 0); - - if (fBuffer[npar].fSqlType==MYSQL_TYPE_DOUBLE) - return (Double_t) *((double*) fBuffer[npar].fMem); - - return (Double_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as string. - -const char *TMySQLStatement::GetString(Int_t npar) -{ - CheckGetField("GetString", 0); - - if ((fBind[npar].buffer_type==MYSQL_TYPE_STRING) - || (fBind[npar].buffer_type==MYSQL_TYPE_BLOB) - || (fBind[npar].buffer_type==MYSQL_TYPE_VAR_STRING) -#if MYSQL_VERSION_ID >= 50022 - || (fBuffer[npar].fSqlType==MYSQL_TYPE_NEWDECIMAL) -#endif - ) { - if (fBuffer[npar].fResNull) return nullptr; - char *str = (char *) fBuffer[npar].fMem; - ULong_t len = fBuffer[npar].fResLength; - Int_t size = fBuffer[npar].fSize; - if (1.*lenyear; - month = tm->month; - day = tm->day; - break; - } - default: - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time. - -Bool_t TMySQLStatement::GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) -{ - CheckGetField("GetTime", kFALSE); - - if (fBuffer[npar].fResNull) return kFALSE; - - switch(fBind[npar].buffer_type) { - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_TIMESTAMP: - case MYSQL_TYPE_TIME: { - MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem; - if (tm==0) return kFALSE; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - break; - } - default: - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date & time. - -Bool_t TMySQLStatement::GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) -{ - CheckGetField("GetDatime", kFALSE); - - if (fBuffer[npar].fResNull) return kFALSE; - - switch(fBind[npar].buffer_type) { - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_TIMESTAMP: { - MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem; - if (tm==0) return kFALSE; - year = tm->year; - month = tm->month; - day = tm->day; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - break; - } - default: - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time stamp. - -Bool_t TMySQLStatement::GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t& frac) -{ - CheckGetField("GetTimstamp", kFALSE); - - if (fBuffer[npar].fResNull) return kFALSE; - - switch(fBind[npar].buffer_type) { - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_TIMESTAMP: { - MYSQL_TIME* tm = (MYSQL_TIME*) fBuffer[npar].fMem; - if (tm==0) return kFALSE; - year = tm->year; - month = tm->month; - day = tm->day; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - frac = 0; - break; - } - default: - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter type to be used as buffer. -/// Used in both setting data to database and retrieving data from data base. -/// Initialize proper MYSQL_BIND structure and allocate required buffers. - -Bool_t TMySQLStatement::SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize) -{ - if ((npar<0) || (npar>=fNumBuffers)) return kFALSE; - - fBuffer[npar].fMem = nullptr; - fBuffer[npar].fSize = 0; - fBuffer[npar].fResLength = 0; - fBuffer[npar].fResNull = false; - fBuffer[npar].fStrBuffer.clear(); - - ULong64_t allocsize = 0; - - Bool_t doreset = false; - - switch (sqltype) { - case MYSQL_TYPE_LONG: allocsize = sizeof(int); break; - case MYSQL_TYPE_LONGLONG: allocsize = sizeof(Long64_t); break; - case MYSQL_TYPE_SHORT: allocsize = sizeof(short); break; - case MYSQL_TYPE_TINY: allocsize = sizeof(char); break; - case MYSQL_TYPE_FLOAT: allocsize = sizeof(float); break; - case MYSQL_TYPE_DOUBLE: allocsize = sizeof(double); break; -#if MYSQL_VERSION_ID >= 50022 - case MYSQL_TYPE_NEWDECIMAL /* new MYSQL_TYPE fixed precision decimal */: -#endif - case MYSQL_TYPE_STRING: allocsize = sqlsize > 256 ? sqlsize : 256; break; - case MYSQL_TYPE_VAR_STRING: allocsize = sqlsize > 256 ? sqlsize : 256; break; - case MYSQL_TYPE_MEDIUM_BLOB: - case MYSQL_TYPE_LONG_BLOB: - case MYSQL_TYPE_BLOB: allocsize = sqlsize >= 65525 ? sqlsize : 65535; break; - case MYSQL_TYPE_TINY_BLOB: allocsize = sqlsize > 255 ? sqlsize : 255; break; - case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_TIMESTAMP: - case MYSQL_TYPE_DATETIME: allocsize = sizeof(MYSQL_TIME); doreset = true; break; - default: SetError(-1, Form("SQL type not supported: %d", sqltype),"SetSQLParamType"); return kFALSE; - } - - // SL: 256 bytes is default size value for string or tiny blob - // therefore small fgAllocSizeLimit only has effect for data over limit of 256 bytes - if ((fgAllocSizeLimit > 256) && (allocsize > fgAllocSizeLimit)) - allocsize = fgAllocSizeLimit; - - fBuffer[npar].fMem = malloc(allocsize); - fBuffer[npar].fSize = allocsize; - fBuffer[npar].fSqlType = sqltype; - fBuffer[npar].fSign = sig; - - if (fBuffer[npar].fMem && doreset) - memset(fBuffer[npar].fMem, 0, allocsize); - - fBind[npar].buffer_type = enum_field_types(sqltype); - fBind[npar].buffer = fBuffer[npar].fMem; - fBind[npar].buffer_length = allocsize; - fBind[npar].is_null= &(fBuffer[npar].fResNull); - fBind[npar].length = &(fBuffer[npar].fResLength); - fBind[npar].is_unsigned = !sig; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check boundary condition before setting value of parameter. -/// Return address of parameter buffer. - -void *TMySQLStatement::BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig, ULong_t size) -{ - ClearError(); - - if (!IsSetParsMode()) { - SetError(-1,"Cannot set parameter for statement", method); - return 0; - } - - if ((npar<0) || (npar>=fNumBuffers)) { - SetError(-1,Form("Invalid parameter number %d",npar), method); - return 0; - } - - if ((fIterationCount==0) && (fBuffer[npar].fSqlType==0)) - if (!SetSQLParamType(npar, sqltype, sig, size)) { - SetError(-1,"Cannot initialize parameter buffer", method); - return 0; - } - - if ((fBuffer[npar].fSqlType!=sqltype) || - (fBuffer[npar].fSign != sig)) return 0; - - fBuffer[npar].fResNull = false; - - return fBuffer[npar].fMem; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set NULL as parameter value. -/// If NULL should be set for statement parameter during first iteration, -/// one should call before proper Set... method to identify type of argument for -/// the future. For instance, if one suppose to have double as type of parameter, -/// code should look like: -/// stmt->SetDouble(2, 0.); -/// stmt->SetNull(2); - -Bool_t TMySQLStatement::SetNull(Int_t npar) -{ - void* addr = BeforeSet("SetNull", npar, MYSQL_TYPE_LONG); - - if (addr!=0) - *((int*) addr) = 0; - - if ((npar>=0) && (npar= fBuffer[npar].fSize) { - free(fBuffer[npar].fMem); - - fBuffer[npar].fMem = malloc(len+1); - fBuffer[npar].fSize = len + 1; - - fBind[npar].buffer = fBuffer[npar].fMem; - fBind[npar].buffer_length = fBuffer[npar].fSize; - - addr = fBuffer[npar].fMem; - fNeedParBind = kTRUE; - } - - if (value) - strlcpy((char*) addr, value, fBuffer[npar].fSize); - else - ((char *)addr)[0] = 0; - - fBuffer[npar].fResLength = len; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as binary data. - -Bool_t TMySQLStatement::SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize) -{ - if (size>=maxsize) maxsize = size + 1; - - int bin_type = MYSQL_TYPE_BLOB; - if (maxsize > 65525) bin_type = MYSQL_TYPE_MEDIUM_BLOB; - if (maxsize > 16777205) bin_type = MYSQL_TYPE_LONG_BLOB; - - void* addr = BeforeSet("SetBinary", npar, bin_type, true, maxsize); - - if (addr==0) return kFALSE; - - if (size >= fBuffer[npar].fSize) { - free(fBuffer[npar].fMem); - - fBuffer[npar].fMem = malloc(size+1); - fBuffer[npar].fSize = size + 1; - - fBind[npar].buffer = fBuffer[npar].fMem; - fBind[npar].buffer_length = fBuffer[npar].fSize; - - addr = fBuffer[npar].fMem; - fNeedParBind = kTRUE; - } - - memcpy(addr, mem, size); - - fBuffer[npar].fResLength = size; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date. - -Bool_t TMySQLStatement::SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) -{ - MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetDate", npar, MYSQL_TYPE_DATE); - - if (addr!=0) { - addr->year = year; - addr->month = month; - addr->day = day; - } - - return (addr!=0); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as time. - -Bool_t TMySQLStatement::SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) -{ - MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetTime", npar, MYSQL_TYPE_TIME); - - if (addr!=0) { - addr->hour = hour; - addr->minute = min; - addr->second = sec; - } - - return (addr!=0); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date & time. - -Bool_t TMySQLStatement::SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) -{ - MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetDatime", npar, MYSQL_TYPE_DATETIME); - - if (addr!=0) { - addr->year = year; - addr->month = month; - addr->day = day; - addr->hour = hour; - addr->minute = min; - addr->second = sec; - } - - return (addr!=0); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp. - -Bool_t TMySQLStatement::SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t) -{ - MYSQL_TIME* addr = (MYSQL_TIME*) BeforeSet("SetTimestamp", npar, MYSQL_TYPE_TIMESTAMP); - - if (addr!=0) { - addr->year = year; - addr->month = month; - addr->day = day; - addr->hour = hour; - addr->minute = min; - addr->second = sec; - } - - return (addr!=0); -} - -#else - -//////////////////////////////////////////////////////////////////////////////// -/// Normal constructor. -/// For MySQL version < 4.1 no statement is supported - -TMySQLStatement::TMySQLStatement(MYSQL_STMT*, Bool_t) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor. - -TMySQLStatement::~TMySQLStatement() -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close statement - -void TMySQLStatement::Close(Option_t *) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Process statement. - -Bool_t TMySQLStatement::Process() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of affected rows after statement is processed. - -Int_t TMySQLStatement::GetNumAffectedRows() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of statement parameters. - -Int_t TMySQLStatement::GetNumParameters() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Store result of statement processing to access them -/// via GetInt(), GetDouble() and so on methods. - -Bool_t TMySQLStatement::StoreResult() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of fields in result set. - -Int_t TMySQLStatement::GetNumFields() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns field name in result set. - -const char* TMySQLStatement::GetFieldName(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shift cursor to nect row in result set. - -Bool_t TMySQLStatement::NextResultRow() -{ - return kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Increment iteration counter for statement, where parameter can be set. -/// Statement with parameters of previous iteration -/// automatically will be applied to database. - -Bool_t TMySQLStatement::NextIteration() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Release all buffers, used by statement. - -void TMySQLStatement::FreeBuffers() -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Allocate buffers for statement parameters/ result fields. - -void TMySQLStatement::SetBuffersNumber(Int_t) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field value to string. - -const char* TMySQLStatement::ConvertToString(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field to numeric value. - -long double TMySQLStatement::ConvertToNumeric(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Checks if field value is null. - -Bool_t TMySQLStatement::IsNull(Int_t) -{ - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as integer. - -Int_t TMySQLStatement::GetInt(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned integer. - -UInt_t TMySQLStatement::GetUInt(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as long integer. - -Long_t TMySQLStatement::GetLong(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as 64-bit integer. - -Long64_t TMySQLStatement::GetLong64(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned 64-bit integer. - -ULong64_t TMySQLStatement::GetULong64(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as double. - -Double_t TMySQLStatement::GetDouble(Int_t) -{ - return 0.; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as string. - -const char *TMySQLStatement::GetString(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as binary array. - -Bool_t TMySQLStatement::GetBinary(Int_t, void* &, Long_t&) -{ - return kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date. - -Bool_t TMySQLStatement::GetDate(Int_t, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time. - -Bool_t TMySQLStatement::GetTime(Int_t, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date & time. - -Bool_t TMySQLStatement::GetDatime(Int_t, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time stamp. - -Bool_t TMySQLStatement::GetTimestamp(Int_t, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter type to be used as buffer. -/// Used in both setting data to database and retriving data from data base. -/// Initialize proper MYSQL_BIND structure and allocate required buffers. - -Bool_t TMySQLStatement::SetSQLParamType(Int_t, int, Bool_t, ULong_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check boundary condition before setting value of parameter. -/// Return address of parameter buffer. - -void *TMySQLStatement::BeforeSet(const char*, Int_t, Int_t, Bool_t, ULong_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set NULL as parameter value. -/// If NULL should be set for statement parameter during first iteration, -/// one should call before proper Set... method to identify type of argument for -/// the future. For instance, if one suppose to have double as type of parameter, -/// code should look like: -/// stmt->SetDouble(2, 0.); -/// stmt->SetNull(2); - -Bool_t TMySQLStatement::SetNull(Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as integer. - -Bool_t TMySQLStatement::SetInt(Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsigned integer. - -Bool_t TMySQLStatement::SetUInt(Int_t, UInt_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as long integer. - -Bool_t TMySQLStatement::SetLong(Int_t, Long_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as 64-bit integer. - -Bool_t TMySQLStatement::SetLong64(Int_t, Long64_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsigned 64-bit integer. - -Bool_t TMySQLStatement::SetULong64(Int_t, ULong64_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as double. - -Bool_t TMySQLStatement::SetDouble(Int_t, Double_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as string. - -Bool_t TMySQLStatement::SetString(Int_t, const char*, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as binary data. - -Bool_t TMySQLStatement::SetBinary(Int_t, void*, Long_t, Long_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date. - -Bool_t TMySQLStatement::SetDate(Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as time. - -Bool_t TMySQLStatement::SetTime(Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date & time. - -Bool_t TMySQLStatement::SetDatime(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp. - -Bool_t TMySQLStatement::SetTimestamp(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -#endif // MYSQL_VERSION_ID > 40100 diff --git a/sql/odbc/CMakeLists.txt b/sql/odbc/CMakeLists.txt deleted file mode 100644 index 4264a088acea5..0000000000000 --- a/sql/odbc/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. -# All rights reserved. -# -# For the licensing terms see $ROOTSYS/LICENSE. -# For the list of contributors see $ROOTSYS/README/CREDITS. - -############################################################################ -# CMakeLists.txt file for building ROOT sql/odbc package -############################################################################ - -ROOT_STANDARD_LIBRARY_PACKAGE(RODBC - HEADERS - TODBCResult.h - TODBCRow.h - TODBCServer.h - TODBCStatement.h - SOURCES - src/TODBCResult.cxx - src/TODBCRow.cxx - src/TODBCServer.cxx - src/TODBCStatement.cxx - DEPENDENCIES - Net - RIO -) - -if(NOT MSVC) - target_compile_options(RODBC PUBLIC -Wno-deprecated-declarations) -endif() -target_include_directories(RODBC PUBLIC ${ODBC_INCLUDE_DIR}) -target_link_libraries(RODBC PUBLIC ${ODBC_LIBRARIES}) diff --git a/sql/odbc/inc/LinkDef.h b/sql/odbc/inc/LinkDef.h deleted file mode 100644 index a50e66e3b25a8..0000000000000 --- a/sql/odbc/inc/LinkDef.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifdef __CLING__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class TODBCServer; -#pragma link C++ class TODBCResult; -#pragma link C++ class TODBCRow; -#pragma link C++ class TODBCStatement; - -#endif diff --git a/sql/odbc/inc/TODBCResult.h b/sql/odbc/inc/TODBCResult.h deleted file mode 100644 index 8097a378737fd..0000000000000 --- a/sql/odbc/inc/TODBCResult.h +++ /dev/null @@ -1,49 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TODBCResult -#define ROOT_TODBCResult - -#include "TSQLResult.h" - -#include "TString.h" - - -#ifdef __CLING__ -typedef void * SQLHSTMT; -#else -#ifdef WIN32 -#include "windows.h" -#endif -#include -#endif - - -class TODBCResult : public TSQLResult { - -protected: - SQLHSTMT fHstmt; - Int_t fFieldCount{0}; - TString fNameBuffer; - -public: - TODBCResult(SQLHSTMT stmt); - virtual ~TODBCResult(); - - void Close(Option_t *opt="") final; - Int_t GetFieldCount() final { return fFieldCount; } - const char *GetFieldName(Int_t field) final; - TSQLRow *Next() final; - - ClassDefOverride(TODBCResult,0) // ODBC query result -}; - -#endif diff --git a/sql/odbc/inc/TODBCRow.h b/sql/odbc/inc/TODBCRow.h deleted file mode 100644 index d0cbc603dc137..0000000000000 --- a/sql/odbc/inc/TODBCRow.h +++ /dev/null @@ -1,53 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TODBCRow -#define ROOT_TODBCRow - -#include "TSQLRow.h" - -#include "TString.h" - -#ifdef __CLING__ -typedef void * SQLHSTMT; -#else -#ifdef WIN32 -#include "windows.h" -#endif -#include -#endif - -class TODBCRow : public TSQLRow { - -protected: - SQLHSTMT fHstmt; - Int_t fFieldCount{0}; - char **fBuffer{nullptr}; - ULong_t *fLengths{nullptr}; - - void CopyFieldValue(Int_t field); - -private: - TODBCRow(const TODBCRow&) = delete; - TODBCRow &operator=(const TODBCRow&) = delete; - -public: - TODBCRow(SQLHSTMT stmt, Int_t fieldcount); - virtual ~TODBCRow(); - - void Close(Option_t *opt="") final; - ULong_t GetFieldLength(Int_t field) final; - const char *GetField(Int_t field) final; - - ClassDefOverride(TODBCRow,0) // One row of ODBC query result -}; - -#endif diff --git a/sql/odbc/inc/TODBCServer.h b/sql/odbc/inc/TODBCServer.h deleted file mode 100644 index d47504c411a0d..0000000000000 --- a/sql/odbc/inc/TODBCServer.h +++ /dev/null @@ -1,78 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TODBCServer -#define ROOT_TODBCServer - -#include "TSQLServer.h" - -#ifdef __CLING__ -typedef void * SQLHENV; -typedef void * SQLHDBC; -typedef short SQLRETURN; -#else -#ifdef WIN32 -#include "windows.h" -#endif -#include -#endif - -class TList; - -class TODBCServer : public TSQLServer { - -private: - SQLHENV fHenv; - SQLHDBC fHdbc; - TString fServerInfo; // string with DBMS name and version like MySQL 4.1.11 or Oracle 10.01.0030 - TString fUserId; - - Bool_t ExtractErrors(SQLRETURN retcode, const char* method); - - Bool_t EndTransaction(Bool_t commit); - - static TList* ListData(Bool_t isdrivers); - -public: - TODBCServer(const char* db, const char *uid, const char *pw); - virtual ~TODBCServer(); - - static TList* GetDrivers(); - static void PrintDrivers(); - static TList* GetDataSources(); - static void PrintDataSources(); - - void Close(Option_t *opt="") final; - TSQLResult *Query(const char *sql) final; - Bool_t Exec(const char* sql) final; - TSQLStatement *Statement(const char *sql, Int_t = 100) final; - Bool_t HasStatement() const final { return kTRUE; } - Int_t SelectDataBase(const char *dbname) final; - TSQLResult *GetDataBases(const char *wild = nullptr) final; - TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) final; - TList *GetTablesList(const char* wild = nullptr) final; - TSQLTableInfo* GetTableInfo(const char* tablename) final; - TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) final; - Int_t GetMaxIdentifierLength() final; - Int_t CreateDataBase(const char *dbname) final; - Int_t DropDataBase(const char *dbname) final; - Int_t Reload() final; - Int_t Shutdown() final; - const char *ServerInfo() final; - - Bool_t StartTransaction() final; - Bool_t Commit() final; - Bool_t Rollback() final; - - ClassDefOverride(TODBCServer,0) // Connection to MySQL server -}; - -#endif diff --git a/sql/odbc/inc/TODBCStatement.h b/sql/odbc/inc/TODBCStatement.h deleted file mode 100644 index 21d1b75e17dd8..0000000000000 --- a/sql/odbc/inc/TODBCStatement.h +++ /dev/null @@ -1,129 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TODBCStatement -#define ROOT_TODBCStatement - -#include "TSQLStatement.h" - - -#ifdef __CLING__ -typedef void * SQLHSTMT; -typedef UShort_t SQLUSMALLINT; -typedef UInt_t SQLUINTEGER; -typedef Short_t SQLSMALLINT; -typedef Short_t SQLRETURN; -#else -#ifdef WIN32 -#include "windows.h" -#endif -#include -#endif - -class TODBCStatement : public TSQLStatement { - -protected: - #ifdef __CLING__ - struct ODBCBufferRec_t; - #else - struct ODBCBufferRec_t { - Int_t fBroottype; - Int_t fBsqltype; - Int_t fBsqlctype; - void *fBbuffer; - Int_t fBelementsize; - SQLLEN *fBlenarray; - char *fBstrbuffer; - char *fBnamebuffer; - }; - #endif - -protected: - SQLHSTMT fHstmt; - Int_t fBufferPreferredSize{0}; - ODBCBufferRec_t *fBuffer{nullptr}; - Int_t fNumBuffers{0}; - Int_t fBufferLength{0}; // number of entries for each parameter/column - Int_t fBufferCounter{0}; // used to indicate position in buffers - SQLUSMALLINT *fStatusBuffer{nullptr}; - Int_t fWorkingMode{0}; // 1 - setting parameters, 2 - reading results, 0 - unknown - SQLUINTEGER fNumParsProcessed{0}; // contains number of parameters, affected by last operation - SQLUINTEGER fNumRowsFetched{0}; // indicates number of fetched rows - ULong64_t fLastResultRow{0}; // stores values of row number after last fetch operation - - void *GetParAddr(Int_t npar, Int_t roottype = 0, Int_t length = 0); - long double ConvertToNumeric(Int_t npar); - const char *ConvertToString(Int_t npar); - - Bool_t BindColumn(Int_t ncol, SQLSMALLINT sqltype, SQLUINTEGER size); - Bool_t BindParam(Int_t n, Int_t type, Int_t size = 1024); - - Bool_t ExtractErrors(SQLRETURN retcode, const char* method); - - void SetNumBuffers(Int_t isize, Int_t ilen); - void FreeBuffers(); - - Bool_t IsParSettMode() const { return fWorkingMode==1; } - Bool_t IsResultSet() const { return fWorkingMode==2; } - -public: - TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout = kTRUE); - virtual ~TODBCStatement(); - - virtual void Close(Option_t * = "") final; - - Int_t GetBufferLength() const final { return fBufferLength; } - Int_t GetNumParameters() final; - - Bool_t SetNull(Int_t npar) final; - Bool_t SetInt(Int_t npar, Int_t value) final; - Bool_t SetUInt(Int_t npar, UInt_t value) final; - Bool_t SetLong(Int_t npar, Long_t value) final; - Bool_t SetLong64(Int_t npar, Long64_t value) final; - Bool_t SetULong64(Int_t npar, ULong64_t value) final; - Bool_t SetDouble(Int_t npar, Double_t value) final; - Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final; - Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final; - Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final; - Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final; - Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final; - using TSQLStatement::SetTimestamp; - Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac = 0) final; - - Bool_t NextIteration() final; - - Bool_t Process() final; - Int_t GetNumAffectedRows() final; - - Bool_t StoreResult() final; - Int_t GetNumFields() final; - const char *GetFieldName(Int_t nfield) final; - Bool_t NextResultRow() final; - - Bool_t IsNull(Int_t) final; - Int_t GetInt(Int_t npar) final; - UInt_t GetUInt(Int_t npar) final; - Long_t GetLong(Int_t npar) final; - Long64_t GetLong64(Int_t npar) final; - ULong64_t GetULong64(Int_t npar) final; - Double_t GetDouble(Int_t npar) final; - const char *GetString(Int_t npar) final; - Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final; - Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final; - Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final; - Bool_t GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) final; - using TSQLStatement::GetTimestamp; - Bool_t GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t&) final; - - ClassDefOverride(TODBCStatement, 0); //ODBC implementation of TSQLStatement -}; - -#endif diff --git a/sql/odbc/src/TODBCResult.cxx b/sql/odbc/src/TODBCResult.cxx deleted file mode 100644 index 2e3a67d88a788..0000000000000 --- a/sql/odbc/src/TODBCResult.cxx +++ /dev/null @@ -1,90 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TODBCResult.h" -#include "TODBCRow.h" - - -ClassImp(TODBCResult); - -//////////////////////////////////////////////////////////////////////////////// -/// Constructor - -TODBCResult::TODBCResult(SQLHSTMT stmt) -{ - fHstmt = stmt; - fFieldCount = 0; - - SQLSMALLINT columnCount; - - SQLRETURN retcode = SQLNumResultCols(fHstmt, &columnCount); - - if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) - fFieldCount = columnCount; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup ODBC query result. - -TODBCResult::~TODBCResult() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close (cleanup) ODBC result object. Deletes statement - -void TODBCResult::Close(Option_t *) -{ - SQLFreeHandle(SQL_HANDLE_STMT, fHstmt); - fHstmt = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get name of specified field. - -const char *TODBCResult::GetFieldName(Int_t field) -{ - SQLCHAR columnName[1024]; - - SQLSMALLINT nameLength; - SQLSMALLINT dataType; - SQLULEN columnSize; - SQLSMALLINT decimalDigits; - SQLSMALLINT nullable; - - SQLRETURN retcode = - SQLDescribeCol(fHstmt, field+1, columnName, 1024, - &nameLength, &dataType, - &columnSize, &decimalDigits, &nullable); - - if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) return nullptr; - - fNameBuffer = (const char*) columnName; - - return fNameBuffer; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get next query result row. The returned object must be -/// deleted by the user. - -TSQLRow *TODBCResult::Next() -{ - if (!fHstmt) return nullptr; - - SQLRETURN retcode = SQLFetch(fHstmt); - - if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) - return new TODBCRow(fHstmt, fFieldCount); - - return nullptr; -} diff --git a/sql/odbc/src/TODBCRow.cxx b/sql/odbc/src/TODBCRow.cxx deleted file mode 100644 index f1648ee239aed..0000000000000 --- a/sql/odbc/src/TODBCRow.cxx +++ /dev/null @@ -1,131 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TODBCRow.h" - -#include -#include "strlcpy.h" - -ClassImp(TODBCRow); - -//////////////////////////////////////////////////////////////////////////////// -/// Single row of query result. - -TODBCRow::TODBCRow(SQLHSTMT stmt, Int_t fieldcount) -{ - fHstmt = stmt; - fFieldCount = fieldcount; - - fBuffer = nullptr; - fLengths = nullptr; - - if (fFieldCount>0) { - fBuffer = new char*[fFieldCount]; - fLengths = new ULong_t[fFieldCount]; - for (Int_t n = 0; n < fFieldCount; n++) { - fBuffer[n] = nullptr; - fLengths[n] = 0; - CopyFieldValue(n); - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destroy row object. - -TODBCRow::~TODBCRow() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close row. - -void TODBCRow::Close(Option_t *) -{ - if (fBuffer) { - for (Int_t n = 0; n < fFieldCount; n++) - delete[] fBuffer[n]; - delete[] fBuffer; - fBuffer = nullptr; - } - - if (fLengths) { - delete[] fLengths; - fLengths = nullptr; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Extracts field value from statement. -/// First allocates 128 bytes for buffer. -/// If there is not enouth space, bigger buffer is allocated and -/// request is repeated - -void TODBCRow::CopyFieldValue(Int_t field) -{ - #define buffer_len 128 - - fBuffer[field] = new char[buffer_len]; - - SQLLEN ressize; - - SQLRETURN retcode = SQLGetData(fHstmt, field+1, SQL_C_CHAR, fBuffer[field], buffer_len, &ressize); - - if (ressize==SQL_NULL_DATA) { - delete[] fBuffer[field]; - fBuffer[field] = nullptr; - return; - } - - fLengths[field] = ressize; - - if (retcode==SQL_SUCCESS_WITH_INFO) { - SQLINTEGER code; - SQLCHAR state[ 7 ]; - SQLGetDiagRec(SQL_HANDLE_STMT, fHstmt, 1, state, &code, nullptr, 0, nullptr); - - if (strcmp((char*)state,"01004")==0) { -// Info("CopyFieldValue","Before %d %s", ressize, fBuffer[field]); - - char* newbuf = new char[ressize+10]; - strlcpy(newbuf, fBuffer[field], buffer_len); - delete fBuffer[field]; - fBuffer[field] = newbuf; - newbuf+=(buffer_len-1); // first data will not be read again - retcode = SQLGetData(fHstmt, field+1, SQL_C_CHAR, newbuf, ressize+10-buffer_len, &ressize); - -// Info("CopyFieldValue","After %d %s", ressize, fBuffer[field]); - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get length in bytes of specified field. - -ULong_t TODBCRow::GetFieldLength(Int_t field) -{ - if ((field < 0) || (field >= fFieldCount)) - return 0; - - return fLengths[field]; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get specified field from row (0 <= field < GetFieldCount()). - -const char *TODBCRow::GetField(Int_t field) -{ - if ((field < 0) || (field >= fFieldCount)) - return nullptr; - - return fBuffer[field]; -} diff --git a/sql/odbc/src/TODBCServer.cxx b/sql/odbc/src/TODBCServer.cxx deleted file mode 100644 index bf507093f84f7..0000000000000 --- a/sql/odbc/src/TODBCServer.cxx +++ /dev/null @@ -1,871 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TODBCServer.h" - -#include "TODBCRow.h" -#include "TODBCResult.h" -#include "TODBCStatement.h" -#include "TSQLColumnInfo.h" -#include "TSQLTableInfo.h" -#include "TUrl.h" -#include "TString.h" -#include "TObjString.h" -#include "TList.h" -#include "strlcpy.h" - -#include - - -#include - - -ClassImp(TODBCServer); - -//////////////////////////////////////////////////////////////////////////////// -/// Open a connection to a ODBC server. The db arguments can be: -/// 1. Form "odbc://[user[:passwd]@][:][/][?Driver]", -/// e.g.: "odbc://pcroot.cern.ch:3306/test?MySQL". -/// Driver argument specifies ODBC driver, which should be used for -/// connection. By default, MyODBC driver name is used. -/// The uid is the username and pw the password that should be used -/// for the connection. -/// If uid and pw are not specified (==0), user and passwd arguments from -/// URL will be used. Works only with MySQL ODBC, probably with PostrSQL -/// ODBC. -/// 2. Form "odbcd://DRIVER={MyODBC};SERVER=pcroot.cern.ch;DATABASE=test;USER=user;PASSWORD=pass;OPTION=3;PORT=3306;" -/// This is a form, which is accepted by SQLDriverConnect function of ODBC. -/// Here some other arguments can be specified, which are not included -/// in standard URL format. -/// 3. Form "odbcn://MySpecialConfig", where MySpecialConfig is entry, -/// defined in user DSN (user data source). Here uid and pw should be -/// always specified. -/// -/// Configuring unixODBC under Linux: http://www.unixodbc.org/odbcinst.html -/// Remarks: for variants 1 & 2 it is enough to create/configure -/// odbcinst.ini file. For variant 3 file odbc.ini should be created. -/// Path to this files can be specified in environmental variables like -/// export ODBCINI=/home/my/unixODBC/etc/odbc.ini -/// export ODBCSYSINI=/home/my/unixODBC/etc -/// -/// Configuring MySQL ODBC under Windows. -/// Installing ODBC driver for MySQL is enough to use it under Windows. -/// Afer odbcd:// variant can be used with DRIVER={MySQL ODBC 3.51 Driver}; -/// To configure User DSN, go into Start menu -> Settings -> -/// Control panel -> Administrative tools-> Data Sources (ODBC). -/// -/// To install Oracle ODBC driver for Windows, one should download -/// and install either complete Oracle client (~500 MB), or so-called -/// Instant Client Basic and Instant Client ODBC (~20 MB together). -/// Some remark about Instant Client: -/// 1) Two additional DLLs are required: mfc71.dll & msver71.dll -/// They can be found either in MS VC++ 7.1 Free Toolkit or -/// download from other Internet sites -/// 2) ORACLE_HOME environment variable should be specified and point to -/// location, where Instant Client files are extracted -/// 3) Run odbc_install.exe from account with administrative rights -/// 3) In $ORACLE_HOME/network/admin/ directory appropriate *.ora files -/// like ldap.ora, sqlnet.ora, tnsnames.ora should be installed. -/// Contact your Oracle administrator to get these files. -/// After Oracle ODBC driver is installed, appropriate entry in ODBC drivers -/// list like "Oracle in instantclient10_2" should appear. Connection -/// string example: -/// "odbcd://DRIVER={Oracle in instantclient10_2};DBQ=db-test;UID=user_name;PWD=user_pass;"; - -TODBCServer::TODBCServer(const char *db, const char *uid, const char *pw) : - TSQLServer() -{ - TString connstr; - Bool_t simpleconnect = kTRUE; - - SQLRETURN retcode; - SQLHWND hwnd; - - fPort = 1; // indicate that we are connected - - if ((strncmp(db, "odbc", 4)!=0) || (strlen(db)<8)) { - SetError(-1, "db argument should be started from odbc...","TODBCServer"); - goto zombie; - } - - if (strncmp(db, "odbc://", 7)==0) { - TUrl url(db); - if (!url.IsValid()) { - SetError(-1, Form("not valid URL: %s", db), "TODBCServer"); - goto zombie; - } - const char* driver = "MyODBC"; - const char* dbase = url.GetFile(); - if (dbase) - if (*dbase=='/') dbase++; //skip leading "/" if appears - - if ((!uid || (*uid==0)) && (strlen(url.GetUser())>0)) { - uid = url.GetUser(); - pw = url.GetPasswd(); - } - - if (strlen(url.GetOptions()) != 0) driver = url.GetOptions(); - - connstr.Form("DRIVER={%s};" - "SERVER=%s;" - "DATABASE=%s;" - "USER=%s;" - "PASSWORD=%s;" - "OPTION=3;", - driver, url.GetHost(), dbase, uid, pw); - if (url.GetPort()>0) - connstr += Form("PORT=%d;", url.GetPort()); - - fHost = url.GetHost(); - fPort = url.GetPort()>0 ? url.GetPort() : 1; - fDB = dbase; - simpleconnect = kFALSE; - } else - if (strncmp(db, "odbcd://", 8)==0) { - connstr = db+8; - simpleconnect = kFALSE; - } else - if (strncmp(db, "odbcn://", 8)==0) { - connstr = db+8; - simpleconnect = kTRUE; - } else { - SetError(-1, "db argument is invalid", "TODBCServer"); - goto zombie; - } - - retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &fHenv); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - - /* Set the ODBC version environment attribute */ - retcode = SQLSetEnvAttr(fHenv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - - /* Allocate connection handle */ - retcode = SQLAllocHandle(SQL_HANDLE_DBC, fHenv, &fHdbc); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - - /* Set login timeout to 5 seconds. */ - retcode = SQLSetConnectAttr(fHdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER) 5, 0); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - - char sbuf[2048]; - - SQLSMALLINT reslen; - SQLINTEGER reslen1; - - hwnd = nullptr; - - if (simpleconnect) - retcode = SQLConnect(fHdbc, (SQLCHAR*) connstr.Data(), SQL_NTS, - (SQLCHAR*) uid, SQL_NTS, - (SQLCHAR*) pw, SQL_NTS); - else - retcode = SQLDriverConnect(fHdbc, hwnd, - (SQLCHAR*) connstr.Data(), SQL_NTS, - (SQLCHAR*) sbuf, sizeof(sbuf), &reslen, SQL_DRIVER_NOPROMPT); - - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - - fType = "ODBC"; - - retcode = SQLGetInfo(fHdbc, SQL_USER_NAME, sbuf, sizeof(sbuf), &reslen); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - fUserId = sbuf; - - retcode = SQLGetInfo(fHdbc, SQL_DBMS_NAME, sbuf, sizeof(sbuf), &reslen); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - fServerInfo = sbuf; - fType = sbuf; - - retcode = SQLGetInfo(fHdbc, SQL_DBMS_VER, sbuf, sizeof(sbuf), &reslen); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - fServerInfo += " "; - fServerInfo += sbuf; - - // take current catalog - database name - retcode = SQLGetConnectAttr(fHdbc, SQL_ATTR_CURRENT_CATALOG, sbuf, sizeof(sbuf), &reslen1); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - if (fDB.Length()==0) fDB = sbuf; - - retcode = SQLGetInfo(fHdbc, SQL_SERVER_NAME, sbuf, sizeof(sbuf), &reslen); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - if (fHost.Length()==0) fHost = sbuf; - -/* - - SQLUINTEGER iinfo; - retcode = SQLGetInfo(fHdbc, SQL_PARAM_ARRAY_ROW_COUNTS, &iinfo, sizeof(iinfo), 0); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - Info("Constr", "SQL_PARAM_ARRAY_ROW_COUNTS = %u", iinfo); - - retcode = SQLGetInfo(fHdbc, SQL_PARAM_ARRAY_SELECTS, &iinfo, sizeof(iinfo), 0); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - Info("Constr", "SQL_PARAM_ARRAY_SELECTS = %u", iinfo); - - retcode = SQLGetInfo(fHdbc, SQL_BATCH_ROW_COUNT, &iinfo, sizeof(iinfo), 0); - if (ExtractErrors(retcode, "TODBCServer")) goto zombie; - Info("Constr", "SQL_BATCH_ROW_COUNT = %u", iinfo); -*/ - - return; - -zombie: - fPort = -1; - fHost = ""; - MakeZombie(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to MySQL DB server. - -TODBCServer::~TODBCServer() -{ - if (IsConnected()) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TList object with list of available -/// ODBC drivers (isdrivers = kTRUE) or data sources (isdrivers = kFALSE) - -TList* TODBCServer::ListData(Bool_t isdrivers) -{ - SQLHENV henv; - SQLRETURN retcode; - - retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); - if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO)) return nullptr; - - retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); - if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO)) return nullptr; - - TList* lst = nullptr; - - char namebuf[2048], optbuf[2048]; - SQLSMALLINT reslen1, reslen2; - - do { - strlcpy(namebuf, "",2048); - strlcpy(optbuf, "",2048); - if (isdrivers) - retcode = SQLDrivers(henv, (!lst ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), - (SQLCHAR*) namebuf, sizeof(namebuf), &reslen1, - (SQLCHAR*) optbuf, sizeof(optbuf), &reslen2); - else - retcode = SQLDataSources(henv, (!lst ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), - (SQLCHAR*) namebuf, sizeof(namebuf), &reslen1, - (SQLCHAR*) optbuf, sizeof(optbuf), &reslen2); - - if (retcode==SQL_NO_DATA) break; - if ((retcode==SQL_SUCCESS) || (retcode==SQL_SUCCESS_WITH_INFO)) { - if (!lst) { - lst = new TList; - lst->SetOwner(kTRUE); - } - for (int n = 0; n < reslen2 - 1; n++) - if (optbuf[n] == '\0') - optbuf[n] = ';'; - - lst->Add(new TNamed(namebuf, optbuf)); - } - } while ((retcode==SQL_SUCCESS) || (retcode==SQL_SUCCESS_WITH_INFO)); - - SQLFreeHandle(SQL_HANDLE_ENV, henv); - - return lst; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TList object with list of available ODBC drivers -/// User must delete TList object afterwards -/// Name of driver can be used in connecting to data base in form -/// TSQLServer::Connect("odbcd://DRIVER={};DBQ=;UID=user;PWD=pass;", 0, 0); - -TList* TODBCServer::GetDrivers() -{ - return ListData(kTRUE); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print list of ODBC drivers in form: -/// ` : `` - -void TODBCServer::PrintDrivers() -{ - TList* lst = GetDrivers(); - std::cout << "List of ODBC drivers:" << std::endl; - TIter iter(lst); - while (auto n = dynamic_cast(iter())) - std::cout << " " << n->GetName() << " : " << n->GetTitle() << std::endl; - delete lst; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TList object with list of available ODBC data sources -/// User must delete TList object afterwards -/// Name of data source can be used later for connection: -/// TSQLServer::Connect("odbcn://", "user", "pass"); - -TList* TODBCServer::GetDataSources() -{ - return ListData(kFALSE); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print list of ODBC data sources in form: -/// `` : `` - -void TODBCServer::PrintDataSources() -{ - TList* lst = GetDataSources(); - std::cout << "List of ODBC data sources:" << std::endl; - TIter iter(lst); - while (auto n = dynamic_cast(iter())) - std::cout << " " << n->GetName() << " : " << n->GetTitle() << std::endl; - delete lst; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Extract errors, produced by last ODBC function call - -Bool_t TODBCServer::ExtractErrors(SQLRETURN retcode, const char* method) -{ - if ((retcode==SQL_SUCCESS) || (retcode==SQL_SUCCESS_WITH_INFO)) return kFALSE; - - SQLINTEGER i = 0; - SQLINTEGER native; - SQLCHAR state[7]; - SQLCHAR text[256]; - SQLSMALLINT len; - - while (SQLGetDiagRec(SQL_HANDLE_ENV, fHenv, ++i, state, &native, text, - sizeof(text), &len ) == SQL_SUCCESS) - SetError(native, (const char *) text, method); - - i = 0; - - while (SQLGetDiagRec(SQL_HANDLE_DBC, fHdbc, ++i, state, &native, text, - sizeof(text), &len ) == SQL_SUCCESS) - SetError(native, (const char *) text, method); - - return kTRUE; -} - -// Reset error and check that server connected -#define CheckConnect(method, res) \ - { \ - ClearError(); \ - if (!IsConnected()) { \ - SetError(-1,"ODBC driver is not connected",method); \ - return res; \ - } \ - } - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to MySQL DB server. - -void TODBCServer::Close(Option_t *) -{ - SQLDisconnect(fHdbc); - SQLFreeHandle(SQL_HANDLE_DBC, fHdbc); - SQLFreeHandle(SQL_HANDLE_ENV, fHenv); - fPort = -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SQL command. Result object must be deleted by the user. -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TODBCServer::Query(const char *sql) -{ - CheckConnect("Query", nullptr); - - SQLRETURN retcode; - SQLHSTMT hstmt; - - SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - - retcode = SQLExecDirect(hstmt, (SQLCHAR*) sql, SQL_NTS); - if (ExtractErrors(retcode, "Query")) { - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - return nullptr; - } - - return new TODBCResult(hstmt); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Executes query which does not produce any results set -/// Return kTRUE if successful - -Bool_t TODBCServer::Exec(const char* sql) -{ - CheckConnect("Exec", 0); - - SQLRETURN retcode; - SQLHSTMT hstmt; - - SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - - retcode = SQLExecDirect(hstmt, (SQLCHAR*) sql, SQL_NTS); - - Bool_t res = !ExtractErrors(retcode, "Exec"); - - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Select a database. Returns 0 if successful, non-zero otherwise. -/// Not all RDBMS support selecting of database (catalog) after connecting -/// Normally user should specify database name at time of connection - -Int_t TODBCServer::SelectDataBase(const char *db) -{ - CheckConnect("SelectDataBase", -1); - - SQLRETURN retcode = SQLSetConnectAttr(fHdbc, SQL_ATTR_CURRENT_CATALOG, (SQLCHAR*) db, SQL_NTS); - if (ExtractErrors(retcode, "SelectDataBase")) return -1; - - fDB = db; - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all available databases. Wild is for wildcarding "t%" list all -/// databases starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TODBCServer::GetDataBases(const char *) -{ - CheckConnect("GetDataBases", nullptr); - - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all tables in the specified database. Wild is for wildcarding -/// "t%" list all tables starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TODBCServer::GetTables(const char*, const char* wild) -{ - CheckConnect("GetTables", nullptr); - - SQLRETURN retcode; - SQLHSTMT hstmt; - - SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - - SQLCHAR* schemaName = nullptr; - SQLSMALLINT schemaNameLength = 0; - -/* - TString schemabuf; - // schema is used by Oracle to specify to which user belong table - // therefore, to see correct tables, schema name is set to user name - if ((fUserId.Length()>0) && (fServerInfo.Contains("Oracle"))) { - schemabuf = fUserId; - schemabuf.ToUpper(); - schemaName = (SQLCHAR*) schemabuf.Data(); - schemaNameLength = schemabuf.Length(); - } -*/ - - SQLCHAR* tableName = nullptr; - SQLSMALLINT tableNameLength = 0; - - if (wild && *wild) { - tableName = (SQLCHAR*) wild; - tableNameLength = strlen(wild); - SQLSetStmtAttr(hstmt, SQL_ATTR_METADATA_ID, (SQLPOINTER) SQL_FALSE, 0); - } - - retcode = SQLTables(hstmt, nullptr, 0, schemaName, schemaNameLength, tableName, tableNameLength, (SQLCHAR*) "TABLE", 5); - if (ExtractErrors(retcode, "GetTables")) { - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - return nullptr; - } - - return new TODBCResult(hstmt); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return list of tables in database -/// See TSQLServer::GetTablesList() for details. - -TList* TODBCServer::GetTablesList(const char* wild) -{ - CheckConnect("GetTablesList", nullptr); - - TSQLResult* res = GetTables(nullptr, wild); - if (!res) return nullptr; - - TList* lst = nullptr; - - TSQLRow* row = nullptr; - - while ((row = res->Next()) != nullptr) { - const char* tablename = row->GetField(2); - if (tablename) { -// Info("List","%s %s %s %s %s", tablename, row->GetField(0), row->GetField(1), row->GetField(3), row->GetField(4)); - if (!lst) { - lst = new TList; - lst->SetOwner(kTRUE); - } - lst->Add(new TObjString(tablename)); - } - delete row; - } - - delete res; - - return lst; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Produces SQL table info -/// Object must be deleted by user - -TSQLTableInfo* TODBCServer::GetTableInfo(const char* tablename) -{ - CheckConnect("GetTableInfo", nullptr); - - #define STR_LEN 128+1 - #define REM_LEN 254+1 - - /* Declare buffers for result set data */ - - SQLCHAR szCatalog[STR_LEN], szSchema[STR_LEN]; - SQLCHAR szTableName[STR_LEN], szColumnName[STR_LEN]; - SQLCHAR szTypeName[STR_LEN], szRemarks[REM_LEN]; - SQLCHAR szColumnDefault[STR_LEN], szIsNullable[STR_LEN]; - SQLLEN columnSize, bufferLength, charOctetLength, ordinalPosition; - SQLSMALLINT dataType, decimalDigits, numPrecRadix, nullable; - SQLSMALLINT sqlDataType, datetimeSubtypeCode; - SQLRETURN retcode; - SQLHSTMT hstmt; - - /* Declare buffers for bytes available to return */ - - SQLLEN cbCatalog, cbSchema, cbTableName, cbColumnName; - SQLLEN cbDataType, cbTypeName, cbColumnSize, cbBufferLength; - SQLLEN cbDecimalDigits, cbNumPrecRadix, cbNullable, cbRemarks; - SQLLEN cbColumnDefault, cbSQLDataType, cbDatetimeSubtypeCode, cbCharOctetLength; - SQLLEN cbOrdinalPosition, cbIsNullable; - - - SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - - retcode = SQLColumns(hstmt, nullptr, 0, nullptr, 0, (SQLCHAR*) tablename, SQL_NTS, nullptr, 0); - if (ExtractErrors(retcode, "GetTableInfo")) { - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - return nullptr; - } - - TList* lst = nullptr; - - /* Bind columns in result set to buffers */ - - SQLBindCol(hstmt, 1, SQL_C_CHAR, szCatalog, STR_LEN,&cbCatalog); - SQLBindCol(hstmt, 2, SQL_C_CHAR, szSchema, STR_LEN, &cbSchema); - SQLBindCol(hstmt, 3, SQL_C_CHAR, szTableName, STR_LEN,&cbTableName); - SQLBindCol(hstmt, 4, SQL_C_CHAR, szColumnName, STR_LEN, &cbColumnName); - SQLBindCol(hstmt, 5, SQL_C_SSHORT, &dataType, 0, &cbDataType); - SQLBindCol(hstmt, 6, SQL_C_CHAR, szTypeName, STR_LEN, &cbTypeName); - SQLBindCol(hstmt, 7, SQL_C_SLONG, &columnSize, 0, &cbColumnSize); - SQLBindCol(hstmt, 8, SQL_C_SLONG, &bufferLength, 0, &cbBufferLength); - SQLBindCol(hstmt, 9, SQL_C_SSHORT, &decimalDigits, 0, &cbDecimalDigits); - SQLBindCol(hstmt, 10, SQL_C_SSHORT, &numPrecRadix, 0, &cbNumPrecRadix); - SQLBindCol(hstmt, 11, SQL_C_SSHORT, &nullable, 0, &cbNullable); - SQLBindCol(hstmt, 12, SQL_C_CHAR, szRemarks, REM_LEN, &cbRemarks); - SQLBindCol(hstmt, 13, SQL_C_CHAR, szColumnDefault, STR_LEN, &cbColumnDefault); - SQLBindCol(hstmt, 14, SQL_C_SSHORT, &sqlDataType, 0, &cbSQLDataType); - SQLBindCol(hstmt, 15, SQL_C_SSHORT, &datetimeSubtypeCode, 0, &cbDatetimeSubtypeCode); - SQLBindCol(hstmt, 16, SQL_C_SLONG, &charOctetLength, 0, &cbCharOctetLength); - SQLBindCol(hstmt, 17, SQL_C_SLONG, &ordinalPosition, 0, &cbOrdinalPosition); - SQLBindCol(hstmt, 18, SQL_C_CHAR, szIsNullable, STR_LEN, &cbIsNullable); - - retcode = SQLFetch(hstmt); - - while ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) { - - Int_t sqltype = kSQL_NONE; - - Int_t data_size = -1; // size in bytes - Int_t data_length = -1; // declaration like VARCHAR(n) or NUMERIC(n) - Int_t data_scale = -1; // second argument in declaration - Int_t data_sign = -1; // no info about sign - - switch (dataType) { - case SQL_CHAR: - sqltype = kSQL_CHAR; - data_size = columnSize; - data_length = charOctetLength; - break; - case SQL_VARCHAR: - case SQL_LONGVARCHAR: - sqltype = kSQL_VARCHAR; - data_size = columnSize; - data_length = charOctetLength; - break; - case SQL_DECIMAL: - case SQL_NUMERIC: - sqltype = kSQL_NUMERIC; - data_size = columnSize; // size of column in database - data_length = columnSize; - data_scale = decimalDigits; - break; - case SQL_INTEGER: - case SQL_TINYINT: - case SQL_BIGINT: - sqltype = kSQL_INTEGER; - data_size = columnSize; - break; - case SQL_REAL: - case SQL_FLOAT: - sqltype = kSQL_FLOAT; - data_size = columnSize; - data_sign = 1; - break; - case SQL_DOUBLE: - sqltype = kSQL_DOUBLE; - data_size = columnSize; - data_sign = 1; - break; - case SQL_BINARY: - case SQL_VARBINARY: - case SQL_LONGVARBINARY: - sqltype = kSQL_BINARY; - data_size = columnSize; - break; - case SQL_TYPE_TIMESTAMP: - sqltype = kSQL_TIMESTAMP; - data_size = columnSize; - break; - } - - if (!lst) lst = new TList; - - lst->Add(new TSQLColumnInfo((const char *) szColumnName, - (const char *) szTypeName, - nullable != 0, - sqltype, - data_size, - data_length, - data_scale, - data_sign)); - - retcode = SQLFetch(hstmt); - } - - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - - return new TSQLTableInfo(tablename, lst); -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all columns in specified table in the specified database. -/// Wild is for wildcarding "t%" list all columns starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TODBCServer::GetColumns(const char*, const char *table, const char*) -{ - CheckConnect("GetColumns", nullptr); - - SQLRETURN retcode; - SQLHSTMT hstmt; - - SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - - retcode = SQLColumns(hstmt, nullptr, 0, nullptr, 0, (SQLCHAR*) table, SQL_NTS, nullptr, 0); - if (ExtractErrors(retcode, "GetColumns")) { - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - return nullptr; - } - - return new TODBCResult(hstmt); -} - -//////////////////////////////////////////////////////////////////////////////// -/// returns maximum allowed length of identifier (table name, column name, index name) - -Int_t TODBCServer::GetMaxIdentifierLength() -{ - CheckConnect("GetMaxIdentifierLength", 20); - - SQLUINTEGER info = 0; - SQLRETURN retcode; - - retcode = SQLGetInfo(fHdbc, SQL_MAX_IDENTIFIER_LEN, (SQLPOINTER)&info, sizeof(info), nullptr); - - if (ExtractErrors(retcode, "GetMaxIdentifierLength")) return 20; - - return info; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a database. Returns 0 if successful, non-zero otherwise. - -Int_t TODBCServer::CreateDataBase(const char*) -{ - CheckConnect("CreateDataBase", -1); - - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Drop (i.e. delete) a database. Returns 0 if successful, non-zero -/// otherwise. - -Int_t TODBCServer::DropDataBase(const char*) -{ - CheckConnect("DropDataBase", -1); - - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Reload permission tables. Returns 0 if successful, non-zero -/// otherwise. User must have reload permissions. - -Int_t TODBCServer::Reload() -{ - CheckConnect("Reload", -1); - - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shutdown the database server. Returns 0 if successful, non-zero -/// otherwise. User must have shutdown permissions. - -Int_t TODBCServer::Shutdown() -{ - CheckConnect("Shutdown", -1); - - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return server info. - -const char *TODBCServer::ServerInfo() -{ - CheckConnect("ServerInfo", nullptr); - - return fServerInfo; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Creates ODBC statement for provided query. -/// See TSQLStatement class for more details. - -TSQLStatement *TODBCServer::Statement(const char *sql, Int_t bufsize) -{ - CheckConnect("Statement", nullptr); - - if (!sql || !*sql) { - SetError(-1, "no query string specified", "Statement"); - return nullptr; - } - -// SQLUINTEGER info = 0; -// SQLGetInfo(fHdbc, SQL_PARAM_ARRAY_ROW_COUNTS, (SQLPOINTER)&info, sizeof(info), nullptr); -// if (info==SQL_PARC_BATCH) Info("Statement","info==SQL_PARC_BATCH"); else -// if (info==SQL_PARC_NO_BATCH) Info("Statement","info==SQL_PARC_NO_BATCH"); else -// Info("Statement","info==%u", info); - - - SQLRETURN retcode; - SQLHSTMT hstmt; - - retcode = SQLAllocHandle(SQL_HANDLE_STMT, fHdbc, &hstmt); - if (ExtractErrors(retcode, "Statement")) return nullptr; - - retcode = SQLPrepare(hstmt, (SQLCHAR*) sql, SQL_NTS); - if (ExtractErrors(retcode, "Statement")) { - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - return nullptr; - } - - return new TODBCStatement(hstmt, bufsize, fErrorOut); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Starts transaction. -/// Check for transaction support. -/// Switch off autocommitment mode. - -Bool_t TODBCServer::StartTransaction() -{ - CheckConnect("StartTransaction", kFALSE); - - SQLUINTEGER info = 0; - SQLRETURN retcode; - - retcode = SQLGetInfo(fHdbc, SQL_TXN_CAPABLE, (SQLPOINTER)&info, sizeof(info), nullptr); - if (ExtractErrors(retcode, "StartTransaction")) return kFALSE; - - if (info == 0) { - SetError(-1,"Transactions not supported","StartTransaction"); - return kFALSE; - } - - if (!Commit()) return kFALSE; - - retcode = SQLSetConnectAttr(fHdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER) SQL_AUTOCOMMIT_OFF, 0); - if (ExtractErrors(retcode, "StartTransaction")) return kFALSE; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Complete current transaction (commit = kTRUE) or rollback -/// Switches on autocommit mode of ODBC driver - -Bool_t TODBCServer::EndTransaction(Bool_t commit) -{ - const char* method = commit ? "Commit" : "Rollback"; - - CheckConnect(method, kFALSE); - - SQLRETURN retcode = SQLEndTran(SQL_HANDLE_DBC, fHdbc, commit ? SQL_COMMIT : SQL_ROLLBACK); - if (ExtractErrors(retcode, method)) return kFALSE; - - retcode = SQLSetConnectAttr(fHdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER) SQL_AUTOCOMMIT_ON, 0); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Commit transaction - -Bool_t TODBCServer::Commit() -{ - return EndTransaction(kTRUE); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Rollback transaction - -Bool_t TODBCServer::Rollback() -{ - return EndTransaction(kFALSE); -} diff --git a/sql/odbc/src/TODBCStatement.cxx b/sql/odbc/src/TODBCStatement.cxx deleted file mode 100644 index 3741ba8b4c798..0000000000000 --- a/sql/odbc/src/TODBCStatement.cxx +++ /dev/null @@ -1,1166 +0,0 @@ -// @(#)root/odbc:$Id$ -// Author: Sergey Linev 6/02/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - - -//________________________________________________________________________ -// -// SQL statement class for ODBC -// -// See TSQLStatement class documentation for more details -// -//________________________________________________________________________ - - -#include "TODBCStatement.h" -#include "TODBCServer.h" -#include "TDataType.h" -#include "strlcpy.h" -#include "snprintf.h" - -#include -#include -#include - -#define kSqlTime 123781 -#define kSqlDate 123782 -#define kSqlTimestamp 123783 -#define kSqlBinary 123784 - - -ClassImp(TODBCStatement); - -//////////////////////////////////////////////////////////////////////////////// -///constructor - -TODBCStatement::TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout) : - TSQLStatement(errout) -{ - fHstmt = stmt; - fBufferPreferredSize = rowarrsize; - - fBuffer = nullptr; - fStatusBuffer = nullptr; - fNumBuffers = 0; - fBufferLength = 0; - fBufferCounter = 0; - - fWorkingMode = 0; - - fNumParsProcessed = 0; - fNumRowsFetched = 0; - - SQLSMALLINT paramsCount = 0; - SQLRETURN retcode = SQLNumParams(fHstmt, ¶msCount); - if (ExtractErrors(retcode,"Constructor")) - paramsCount = 0; - - if (paramsCount>0) { - - fWorkingMode = 1; // we are now using buffers for parameters - fNumParsProcessed = 0; - - SQLSetStmtAttr(fHstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0); - - SQLUINTEGER setsize = fBufferPreferredSize; - retcode = SQLSetStmtAttr(fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) (long) setsize, 0); - ExtractErrors(retcode,"Constructor"); - - SQLUINTEGER getsize = 0; - - retcode = SQLGetStmtAttr(fHstmt, SQL_ATTR_PARAMSET_SIZE, &getsize, 0, nullptr); - ExtractErrors(retcode,"Constructor"); - - Int_t bufferlen = fBufferPreferredSize; - - // MySQL is not yet support array of parameters - if (getsize<=1) bufferlen=1; else - if (getsize!=setsize) { - SQLSetStmtAttr(fHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) 1, 0); - bufferlen = 1; - } - - SetNumBuffers(paramsCount, bufferlen); - - SQLSetStmtAttr(fHstmt, SQL_ATTR_PARAM_STATUS_PTR, fStatusBuffer, 0); - SQLSetStmtAttr(fHstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &fNumParsProcessed, 0); - - // indicates that we are starting - fBufferCounter = -1; - } - - fNumRowsFetched = 0; - fLastResultRow = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -///destructor - -TODBCStatement::~TODBCStatement() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close statement - -void TODBCStatement::Close(Option_t *) -{ - FreeBuffers(); - - SQLFreeHandle(SQL_HANDLE_STMT, fHstmt); - - fHstmt = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// process statement - -Bool_t TODBCStatement::Process() -{ - ClearError(); - - SQLRETURN retcode = SQL_SUCCESS; - - if (IsParSettMode()) { - - // check if we start filling buffers, but not complete it - if (fBufferCounter>=0) { - // if buffer used not fully, set smaller size of buffer arrays - if ((fBufferCounter>0) && (fBufferCounter0) { - fBuffer[n].fBnamebuffer = new char[nameLength+1]; - strlcpy(fBuffer[n].fBnamebuffer, (const char*) columnName, nameLength+1); - } - } - - fNumRowsFetched = 0; - fLastResultRow = 0; - - fWorkingMode = 2; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///return number of fields - -Int_t TODBCStatement::GetNumFields() -{ - return IsResultSet() ? fNumBuffers : -1; -} - -//////////////////////////////////////////////////////////////////////////////// -///return field name - -const char* TODBCStatement::GetFieldName(Int_t nfield) -{ - ClearError(); - - if (!IsResultSet() || (nfield<0) || (nfield>=fNumBuffers)) return nullptr; - - return fBuffer[nfield].fBnamebuffer; -} - - -//////////////////////////////////////////////////////////////////////////////// -///next result row - -Bool_t TODBCStatement::NextResultRow() -{ - ClearError(); - - if (!IsResultSet()) return kFALSE; - - if ((fNumRowsFetched==0) || - (1.*fBufferCounter >= 1.*(fNumRowsFetched-1))) { - - fBufferCounter = 0; - fNumRowsFetched = 0; - - SQLRETURN retcode = SQLFetchScroll(fHstmt, SQL_FETCH_NEXT, 0); - if (retcode==SQL_NO_DATA) fNumRowsFetched=0; else - ExtractErrors(retcode,"NextResultRow"); - - // this is workaround of Oracle Linux ODBC driver - // it does not returns number of fetched lines, therefore one should - // calculate it from current row number - if (!IsError() && (retcode!=SQL_NO_DATA) && (fNumRowsFetched==0)) { - SQLULEN rownumber = 0; - SQLRETURN retcode2 = SQLGetStmtAttr(fHstmt, SQL_ATTR_ROW_NUMBER, &rownumber, 0, nullptr); - ExtractErrors(retcode2, "NextResultRow"); - - if (!IsError()) { - fNumRowsFetched = rownumber - fLastResultRow; - fLastResultRow = rownumber; - } - } - - if (1.*fNumRowsFetched>fBufferLength) - SetError(-1, "Missmatch between buffer length and fetched rows number", "NextResultRow"); - - if (IsError() || (fNumRowsFetched==0)) { - fWorkingMode = 0; - FreeBuffers(); - } - - } else - fBufferCounter++; - - return IsResultSet(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Extract errors, produced by last ODBC function call - -Bool_t TODBCStatement::ExtractErrors(SQLRETURN retcode, const char* method) -{ - if ((retcode== SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) return kFALSE; - - SQLINTEGER i = 0; - SQLINTEGER native; - SQLCHAR state[ 7 ]; - SQLCHAR text[256]; - SQLSMALLINT len; - SQLRETURN ret; - do { - ret = SQLGetDiagRec(SQL_HANDLE_STMT, fHstmt, ++i, state, &native, text, - sizeof(text), &len ); - if (ret == SQL_SUCCESS) SetError(native, (const char*) text, method); -// Error(method, "%s:%ld:%ld:%s\n", state, i, native, text); - } - while( ret == SQL_SUCCESS ); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///run next iteration - -Bool_t TODBCStatement::NextIteration() -{ - ClearError(); - - if (!IsParSettMode() || !fBuffer || (fBufferLength <= 0)) return kFALSE; - - if (fBufferCounter >= fBufferLength-1) { - SQLRETURN retcode = SQLExecute(fHstmt); - if (ExtractErrors(retcode,"NextIteration")) return kFALSE; - fBufferCounter = 0; - } else - fBufferCounter++; - - // probably, we do not need it, but anyway - fStatusBuffer[fBufferCounter] = SQL_ROW_SUCCESS; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///return number of parameters - -Int_t TODBCStatement::GetNumParameters() -{ - return IsParSettMode() ? fNumBuffers : 0; -} - -//////////////////////////////////////////////////////////////////////////////// -///set number of buffers - -void TODBCStatement::SetNumBuffers(Int_t isize, Int_t ilen) -{ - FreeBuffers(); - - fNumBuffers = isize; - fBufferLength = ilen; - fBufferCounter = 0; - - fBuffer = new ODBCBufferRec_t[fNumBuffers]; - for (Int_t n=0;n=fNumBuffers)) { - SetError(-1,"Internal error. Column number invalid","BindColumn"); - return kFALSE; - } - - if (fBuffer[ncol].fBsqltype!=0) { - SetError(-1,"Internal error. Bind for column already done","BindColumn"); - return kFALSE; - } - - SQLSMALLINT sqlctype = 0; - switch (sqltype) { - case SQL_CHAR: - case SQL_VARCHAR: sqlctype = SQL_C_CHAR; break; - case SQL_BINARY: - case SQL_LONGVARBINARY: - case SQL_VARBINARY: sqlctype = SQL_C_BINARY; break; - case SQL_LONGVARCHAR: Info("BindColumn","BIG VARCHAR not supported yet"); return kFALSE; break; - - case SQL_DECIMAL: sqlctype = SQL_C_DOUBLE; break; - case SQL_NUMERIC: sqlctype = SQL_C_DOUBLE; break; - case SQL_SMALLINT: sqlctype = SQL_C_SLONG; break; - case SQL_INTEGER: sqlctype = SQL_C_SLONG; break; - case SQL_FLOAT: sqlctype = SQL_C_FLOAT; break; - case SQL_REAL: - case SQL_DOUBLE: sqlctype = SQL_C_DOUBLE; break; - case SQL_TINYINT: sqlctype = SQL_C_STINYINT; break; - case SQL_BIGINT: sqlctype = SQL_C_SBIGINT; break; - case SQL_TYPE_DATE: sqlctype = SQL_C_TYPE_DATE; break; - case SQL_TYPE_TIME: sqlctype = SQL_C_TYPE_TIME; break; - case SQL_TYPE_TIMESTAMP: sqlctype = SQL_C_TYPE_TIMESTAMP; break; - default: { - SetError(-1, Form("SQL type %d not supported",sqltype), "BindColumn"); - return kFALSE; - } - } - - int elemsize = 0; - - switch (sqlctype) { - case SQL_C_ULONG: elemsize = sizeof(SQLUINTEGER); break; - case SQL_C_SLONG: elemsize = sizeof(SQLINTEGER); break; - case SQL_C_UBIGINT: elemsize = sizeof(ULong64_t); break; // should be SQLUBIGINT, but it is 64-bit structure on some platforms - case SQL_C_SBIGINT: elemsize = sizeof(Long64_t); break; // should be SQLBIGINT, but it is 64-bit structure on some platforms - case SQL_C_USHORT: elemsize = sizeof(SQLUSMALLINT); break; - case SQL_C_SSHORT: elemsize = sizeof(SQLSMALLINT); break; - case SQL_C_UTINYINT: elemsize = sizeof(SQLCHAR); break; - case SQL_C_STINYINT: elemsize = sizeof(SQLSCHAR); break; - case SQL_C_FLOAT: elemsize = sizeof(SQLREAL); break; - case SQL_C_DOUBLE: elemsize = sizeof(SQLDOUBLE); break; - case SQL_C_CHAR: elemsize = size; break; - case SQL_C_BINARY: elemsize = size; break; - case SQL_C_TYPE_DATE: elemsize = sizeof(DATE_STRUCT); break; - case SQL_C_TYPE_TIME: elemsize = sizeof(TIME_STRUCT); break; - case SQL_C_TYPE_TIMESTAMP: elemsize = sizeof(TIMESTAMP_STRUCT); break; - - default: { - SetError(-1, Form("SQL C Type %d is not supported",sqlctype), "BindColumn"); - return kFALSE; - } - } - - fBuffer[ncol].fBroottype = 0; - fBuffer[ncol].fBsqltype = sqltype; - fBuffer[ncol].fBsqlctype = sqlctype; - fBuffer[ncol].fBbuffer = malloc(elemsize * fBufferLength); - fBuffer[ncol].fBelementsize = elemsize; - fBuffer[ncol].fBlenarray = new SQLLEN[fBufferLength]; - - SQLRETURN retcode = - SQLBindCol(fHstmt, ncol+1, sqlctype, fBuffer[ncol].fBbuffer, - elemsize, - fBuffer[ncol].fBlenarray); - - return !ExtractErrors(retcode, "BindColumn"); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Bind query parameter with buffer. Creates buffer of appropriate type - -Bool_t TODBCStatement::BindParam(Int_t npar, Int_t roottype, Int_t size) -{ - ClearError(); - - if ((npar<0) || (npar>=fNumBuffers)) return kFALSE; - - if (fBuffer[npar].fBroottype!=0) { - SetError(-1,Form("ParameterType for par %d already specified", npar),"BindParam"); - return kFALSE; - } - - SQLSMALLINT sqltype = 0, sqlctype = 0; - int elemsize = 0; - - switch (roottype) { - case kUInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize = sizeof(SQLUINTEGER); break; - case kInt_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize = sizeof(SQLINTEGER); break; - case kULong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_ULONG; elemsize = sizeof(SQLUINTEGER); break; - case kLong_t: sqltype = SQL_INTEGER; sqlctype = SQL_C_SLONG; elemsize = sizeof(SQLINTEGER); break; - - // here SQLUBIGINT/SQLBIGINT types should be used, - // but on 32-bit platforms it is structures, which makes its usage inconvinient - case kULong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_UBIGINT; elemsize = sizeof(ULong64_t); break; - case kLong64_t: sqltype = SQL_BIGINT; sqlctype = SQL_C_SBIGINT; elemsize = sizeof(Long64_t); break; - - case kUShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_USHORT; elemsize = sizeof(SQLUSMALLINT); break; - case kShort_t: sqltype = SQL_SMALLINT;sqlctype = SQL_C_SSHORT; elemsize = sizeof(SQLSMALLINT); break; - case kUChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize = sizeof(SQLCHAR); break; - case kChar_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_STINYINT; elemsize = sizeof(SQLSCHAR); break; - case kBool_t: sqltype = SQL_TINYINT; sqlctype = SQL_C_UTINYINT; elemsize = sizeof(SQLCHAR); break; - case kFloat_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize = sizeof(SQLREAL); break; - case kFloat16_t: sqltype = SQL_FLOAT; sqlctype = SQL_C_FLOAT; elemsize = sizeof(SQLREAL); break; - case kDouble_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize = sizeof(SQLDOUBLE); break; - case kDouble32_t: sqltype = SQL_DOUBLE; sqlctype = SQL_C_DOUBLE; elemsize = sizeof(SQLDOUBLE); break; - case kCharStar: sqltype = SQL_CHAR; sqlctype = SQL_C_CHAR; elemsize = size; break; - case kSqlBinary: sqltype = SQL_BINARY; sqlctype = SQL_C_BINARY; elemsize = size; break; - case kSqlDate: sqltype = SQL_TYPE_DATE; sqlctype = SQL_C_TYPE_DATE; elemsize = sizeof(DATE_STRUCT); break; - case kSqlTime: sqltype = SQL_TYPE_TIME; sqlctype = SQL_C_TYPE_TIME; elemsize = sizeof(TIME_STRUCT); break; - case kSqlTimestamp: sqltype = SQL_TYPE_TIMESTAMP; sqlctype = SQL_C_TYPE_TIMESTAMP; elemsize = sizeof(TIMESTAMP_STRUCT); break; - default: { - SetError(-1, Form("Root type %d is not supported", roottype), "BindParam"); - return kFALSE; - } - } - - void* buffer = malloc(elemsize * fBufferLength); - SQLLEN* lenarray = new SQLLEN[fBufferLength]; - SQLRETURN retcode = - SQLBindParameter(fHstmt, npar+1, SQL_PARAM_INPUT, - sqlctype, sqltype, 0, 0, - buffer, elemsize, lenarray); - - if (ExtractErrors(retcode, "BindParam")) { - free(buffer); - delete[] lenarray; - return kFALSE; - } - - fBuffer[npar].fBroottype = roottype; - fBuffer[npar].fBsqlctype = sqlctype; - fBuffer[npar].fBsqltype = sqltype; - fBuffer[npar].fBbuffer = buffer; - fBuffer[npar].fBelementsize = elemsize; - fBuffer[npar].fBlenarray = lenarray; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get parameter address - -void* TODBCStatement::GetParAddr(Int_t npar, Int_t roottype, Int_t length) -{ - ClearError(); - - if (!fBuffer || (npar < 0) || (npar >= fNumBuffers) || (fBufferCounter < 0)) { - SetError(-1, "Invalid parameter number","GetParAddr"); - return nullptr; - } - - if (!fBuffer[npar].fBbuffer) { - if (IsParSettMode() && (roottype != 0) && (fBufferCounter == 0)) - if (!BindParam(npar, roottype, length)) return nullptr; - - if (!fBuffer[npar].fBbuffer) return nullptr; - } - - if (roottype!=0) - if (fBuffer[npar].fBroottype!=roottype) return nullptr; - - return (char*)fBuffer[npar].fBbuffer + fBufferCounter*fBuffer[npar].fBelementsize; -} - -//////////////////////////////////////////////////////////////////////////////// -///convert to numeric type - -long double TODBCStatement::ConvertToNumeric(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - switch (fBuffer[npar].fBsqlctype) { - case SQL_C_ULONG: return *((SQLUINTEGER*) addr); break; - case SQL_C_SLONG: return *((SQLINTEGER*) addr); break; - case SQL_C_UBIGINT: return *((ULong64_t*) addr); break; - case SQL_C_SBIGINT: return *((Long64_t*) addr); break; - case SQL_C_USHORT: return *((SQLUSMALLINT*) addr); break; - case SQL_C_SSHORT: return *((SQLSMALLINT*) addr); break; - case SQL_C_UTINYINT: return *((SQLCHAR*) addr); break; - case SQL_C_STINYINT: return *((SQLSCHAR*) addr); break; - case SQL_C_FLOAT: return *((SQLREAL*) addr); break; - case SQL_C_DOUBLE: return *((SQLDOUBLE*) addr); break; - case SQL_C_TYPE_DATE: { - DATE_STRUCT* dt = (DATE_STRUCT*) addr; - TDatime rtm(dt->year, dt->month, dt->day, 0, 0, 0); - return rtm.GetDate(); - break; - } - case SQL_C_TYPE_TIME: { - TIME_STRUCT* tm = (TIME_STRUCT*) addr; - TDatime rtm(2000, 1, 1, tm->hour, tm->minute, tm->second); - return rtm.GetTime(); - break; - } - case SQL_C_TYPE_TIMESTAMP: { - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - TDatime rtm(tm->year, tm->month, tm->day, - tm->hour, tm->minute, tm->second); - return rtm.Get(); - break; - } - } - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -///convert to string - -const char* TODBCStatement::ConvertToString(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return nullptr; - if (!fBuffer[npar].fBstrbuffer) - fBuffer[npar].fBstrbuffer = new char[100]; - - char* buf = fBuffer[npar].fBstrbuffer; - - switch(fBuffer[npar].fBsqlctype) { -#if (SIZEOF_LONG == 8) - case SQL_C_SLONG: snprintf(buf, 100, "%d", *((SQLINTEGER*) addr)); break; - case SQL_C_ULONG: snprintf(buf, 100, "%u", *((SQLUINTEGER*) addr)); break; -#else - case SQL_C_SLONG: snprintf(buf, 100, "%ld", (long)*((SQLINTEGER*) addr)); break; - case SQL_C_ULONG: snprintf(buf, 100, "%lu", (unsigned long)*((SQLUINTEGER*) addr)); break; -#endif - case SQL_C_SBIGINT: snprintf(buf, 100, "%lld", *((Long64_t*) addr)); break; - case SQL_C_UBIGINT: snprintf(buf, 100, "%llu", *((ULong64_t*) addr)); break; - case SQL_C_SSHORT: snprintf(buf, 100, "%hd", *((SQLSMALLINT*) addr)); break; - case SQL_C_USHORT: snprintf(buf, 100, "%hu", *((SQLUSMALLINT*) addr)); break; - case SQL_C_STINYINT:snprintf(buf, 100, "%d", *((SQLSCHAR*) addr)); break; - case SQL_C_UTINYINT:snprintf(buf, 100, "%u", *((SQLCHAR*) addr)); break; - case SQL_C_FLOAT: snprintf(buf, 100, TSQLServer::GetFloatFormat(), *((SQLREAL*) addr)); break; - case SQL_C_DOUBLE: snprintf(buf, 100, TSQLServer::GetFloatFormat(), *((SQLDOUBLE*) addr)); break; - case SQL_C_TYPE_DATE: { - DATE_STRUCT* dt = (DATE_STRUCT*) addr; - snprintf(buf,100,"%4.4d-%2.2d-%2.2d", - dt->year, dt->month, dt->day); - break; - } - case SQL_C_TYPE_TIME: { - TIME_STRUCT* tm = (TIME_STRUCT*) addr; - snprintf(buf,100,"%2.2d:%2.2d:%2.2d", - tm->hour, tm->minute, tm->second); - break; - } - case SQL_C_TYPE_TIMESTAMP: { - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - snprintf(buf,100,"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", - tm->year, tm->month, tm->day, - tm->hour, tm->minute, tm->second); - break; - } - default: return nullptr; - } - - return buf; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Verifies if field value is NULL - -Bool_t TODBCStatement::IsNull(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return kTRUE; - - return fBuffer[npar].fBlenarray[fBufferCounter] == SQL_NULL_DATA; -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as integer - -Int_t TODBCStatement::GetInt(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_SLONG) - return (Int_t) *((SQLINTEGER*) addr); - - return (Int_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as unsigned integer - -UInt_t TODBCStatement::GetUInt(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_ULONG) - return (UInt_t) *((SQLUINTEGER*) addr); - - return (UInt_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as Long_t - -Long_t TODBCStatement::GetLong(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_SLONG) - return (Long_t) *((SQLINTEGER*) addr); - - return (Long_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as Long64_t - -Long64_t TODBCStatement::GetLong64(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_SBIGINT) - return *((Long64_t*) addr); - - return (Long64_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as ULong64_t - -ULong64_t TODBCStatement::GetULong64(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_UBIGINT) - return *((ULong64_t*) addr); - - return (ULong64_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as Double_t - -Double_t TODBCStatement::GetDouble(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return 0; - - if (fBuffer[npar].fBsqlctype==SQL_C_DOUBLE) - return *((SQLDOUBLE*) addr); - - return (Double_t) ConvertToNumeric(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -///get parameter as string - -const char* TODBCStatement::GetString(Int_t npar) -{ - void* addr = GetParAddr(npar); - if (!addr) return nullptr; - - if (fBuffer[npar].fBsqlctype==SQL_C_CHAR) { - // first check if string is null - - int len = fBuffer[npar].fBlenarray[fBufferCounter]; - - if ((len == SQL_NULL_DATA) || (len==0)) return nullptr; - - char* res = (char*) addr; - if (len < fBuffer[npar].fBelementsize) { - *(res + len) = 0; - return res; - } - - if (len > fBuffer[npar].fBelementsize) { - SetError(-1, Form("Problems with string size %d", len), "GetString"); - return nullptr; - } - - if (!fBuffer[npar].fBstrbuffer) - fBuffer[npar].fBstrbuffer = new char[len+1]; - - strlcpy(fBuffer[npar].fBstrbuffer, res, len+1); - - res = fBuffer[npar].fBstrbuffer; - *(res + len) = 0; - return res; - } - - return ConvertToString(npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// return parameter as binary data - -Bool_t TODBCStatement::GetBinary(Int_t npar, void* &mem, Long_t& size) -{ - mem = nullptr; - size = 0; - - void* addr = GetParAddr(npar); - if (!addr) return kFALSE; - - if ((fBuffer[npar].fBsqlctype==SQL_C_BINARY) || - (fBuffer[npar].fBsqlctype==SQL_C_CHAR)) { - - // first check if data length is null - int len = fBuffer[npar].fBlenarray[fBufferCounter]; - - if ((len == SQL_NULL_DATA) || (len==0)) return kTRUE; - - size = len; - - if (!fBuffer[npar].fBstrbuffer) - fBuffer[npar].fBstrbuffer = new char[size]; - - memcpy(fBuffer[npar].fBstrbuffer, addr, size); - - mem = fBuffer[npar].fBstrbuffer; - - return kTRUE; - } - - return kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// return field value as date - -Bool_t TODBCStatement::GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) -{ - void* addr = GetParAddr(npar); - if (!addr) return kFALSE; - - if (fBuffer[npar].fBsqlctype!=SQL_C_TYPE_DATE) return kFALSE; - - DATE_STRUCT* dt = (DATE_STRUCT*) addr; - year = dt->year; - month = dt->month; - day = dt->day; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// return field value as time - -Bool_t TODBCStatement::GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) -{ - void* addr = GetParAddr(npar); - if (!addr) return kFALSE; - - if (fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIME) return kFALSE; - - TIME_STRUCT* tm = (TIME_STRUCT*) addr; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// return field value as date & time - -Bool_t TODBCStatement::GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) -{ - void* addr = GetParAddr(npar); - if (!addr) return kFALSE; - - if (fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP) return kFALSE; - - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - - year = tm->year; - month = tm->month; - day = tm->day; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// return field value as time stamp - -Bool_t TODBCStatement::GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t& frac) -{ - void* addr = GetParAddr(npar); - if (!addr) return kFALSE; - - if (fBuffer[npar].fBsqlctype!=SQL_C_TYPE_TIMESTAMP) return kFALSE; - - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - - year = tm->year; - month = tm->month; - day = tm->day; - hour = tm->hour; - min = tm->minute; - sec = tm->second; - frac = tm->fraction; - return kTRUE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Set NULL as parameter value -/// If NULL should be set for statement parameter during first iteration, -/// one should call before proper Set... method to identify type of argument for -/// the future. For instance, if one suppose to have double as type of parameter, -/// code should look like: -/// stmt->SetDouble(2, 0.); -/// stmt->SetNull(2); - -Bool_t TODBCStatement::SetNull(Int_t npar) -{ - void* addr = GetParAddr(npar, kInt_t); - if (addr) - *((SQLINTEGER*) addr) = 0; - - if ((npar >= 0) && (npar < fNumBuffers)) - fBuffer[npar].fBlenarray[fBufferCounter] = SQL_NULL_DATA; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as Int_t - -Bool_t TODBCStatement::SetInt(Int_t npar, Int_t value) -{ - void* addr = GetParAddr(npar, kInt_t); - if (!addr) return kFALSE; - - *((SQLINTEGER*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as UInt_t - -Bool_t TODBCStatement::SetUInt(Int_t npar, UInt_t value) -{ - void* addr = GetParAddr(npar, kUInt_t); - if (!addr) return kFALSE; - - *((SQLUINTEGER*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as Long_t - -Bool_t TODBCStatement::SetLong(Int_t npar, Long_t value) -{ - void* addr = GetParAddr(npar, kLong_t); - if (!addr) return kFALSE; - - *((SQLINTEGER*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as Long64_t - -Bool_t TODBCStatement::SetLong64(Int_t npar, Long64_t value) -{ - void* addr = GetParAddr(npar, kLong64_t); - if (!addr) return kFALSE; - - *((Long64_t*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as ULong64_t - -Bool_t TODBCStatement::SetULong64(Int_t npar, ULong64_t value) -{ - void* addr = GetParAddr(npar, kULong64_t); - if (!addr) return kFALSE; - - *((ULong64_t*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as Double_t - -Bool_t TODBCStatement::SetDouble(Int_t npar, Double_t value) -{ - void* addr = GetParAddr(npar, kDouble_t); - if (!addr) return kFALSE; - - *((SQLDOUBLE*) addr) = value; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter as string - -Bool_t TODBCStatement::SetString(Int_t npar, const char* value, Int_t maxsize) -{ - void* addr = GetParAddr(npar, kCharStar, maxsize); - if (!addr) return kFALSE; - - if (value) { - int len = strlen(value); - - if (len>=fBuffer[npar].fBelementsize) { - len = fBuffer[npar].fBelementsize; - strlcpy((char*) addr, value, len+1); - fBuffer[npar].fBlenarray[fBufferCounter] = len; - - } else if (len>0) { - strlcpy((char*) addr, value, maxsize); - fBuffer[npar].fBlenarray[fBufferCounter] = SQL_NTS; - } else { - *((char*) addr) = 0; - fBuffer[npar].fBlenarray[fBufferCounter] = SQL_NTS; - } - } else { - *((char*) addr) = 0; - fBuffer[npar].fBlenarray[fBufferCounter] = SQL_NTS; - } - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -///set parameter value as binary data - -Bool_t TODBCStatement::SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize) -{ - void* addr = GetParAddr(npar, kSqlBinary, maxsize); - if (!addr) return kFALSE; - - if (size>fBuffer[npar].fBelementsize) - size = fBuffer[npar].fBelementsize; - - memcpy(addr, mem, size); - fBuffer[npar].fBlenarray[fBufferCounter] = size; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// set parameter value as date - -Bool_t TODBCStatement::SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) -{ - void* addr = GetParAddr(npar, kSqlDate); - if (!addr) return kFALSE; - - DATE_STRUCT* dt = (DATE_STRUCT*) addr; - dt->year = year; - dt->month = month; - dt->day = day; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// set parameter value as time - -Bool_t TODBCStatement::SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) -{ - void* addr = GetParAddr(npar, kSqlTime); - if (!addr) return kFALSE; - - TIME_STRUCT* tm = (TIME_STRUCT*) addr; - tm->hour = hour; - tm->minute = min; - tm->second = sec; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// set parameter value as date & time - -Bool_t TODBCStatement::SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) -{ - void* addr = GetParAddr(npar, kSqlTimestamp); - if (!addr) return kFALSE; - - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - tm->year = year; - tm->month = month; - tm->day = day; - tm->hour = hour; - tm->minute = min; - tm->second = sec; - tm->fraction = 0; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// set parameter value as timestamp - -Bool_t TODBCStatement::SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac) -{ - void* addr = GetParAddr(npar, kSqlTimestamp); - if (!addr) return kFALSE; - - TIMESTAMP_STRUCT* tm = (TIMESTAMP_STRUCT*) addr; - tm->year = year; - tm->month = month; - tm->day = day; - tm->hour = hour; - tm->minute = min; - tm->second = sec; - tm->fraction = frac; - - fBuffer[npar].fBlenarray[fBufferCounter] = 0; - - return kTRUE; -} diff --git a/sql/pgsql/CMakeLists.txt b/sql/pgsql/CMakeLists.txt deleted file mode 100644 index 38c31c4e6f34e..0000000000000 --- a/sql/pgsql/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. -# All rights reserved. -# -# For the licensing terms see $ROOTSYS/LICENSE. -# For the list of contributors see $ROOTSYS/README/CREDITS. - -############################################################################ -# CMakeLists.txt file for building ROOT sql/pgsql package -############################################################################ - -ROOT_STANDARD_LIBRARY_PACKAGE(PgSQL - HEADERS - TPgSQLResult.h - TPgSQLRow.h - TPgSQLServer.h - TPgSQLStatement.h - SOURCES - TPgSQLResult.cxx - TPgSQLRow.cxx - TPgSQLServer.cxx - TPgSQLStatement.cxx - DEPENDENCIES - Core - Net - RIO - MathCore -) - -target_include_directories(PgSQL PRIVATE ${PostgreSQL_INCLUDE_DIRS}) -target_link_libraries(PgSQL PRIVATE ${PostgreSQL_LIBRARIES}) diff --git a/sql/pgsql/inc/LinkDef.h b/sql/pgsql/inc/LinkDef.h deleted file mode 100644 index 11edd53db6073..0000000000000 --- a/sql/pgsql/inc/LinkDef.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifdef __CLING__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class TPgSQLServer; -#pragma link C++ class TPgSQLResult; -#pragma link C++ class TPgSQLRow; -#pragma link C++ class TPgSQLStatement; - -#endif diff --git a/sql/pgsql/inc/TPgSQLResult.h b/sql/pgsql/inc/TPgSQLResult.h deleted file mode 100644 index de782409510ec..0000000000000 --- a/sql/pgsql/inc/TPgSQLResult.h +++ /dev/null @@ -1,40 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TPgSQLResult -#define ROOT_TPgSQLResult - -#include "TSQLResult.h" - -struct pg_result; -typedef struct pg_result PGresult; - -class TPgSQLResult : public TSQLResult { - -private: - PGresult *fResult{nullptr}; // query result (rows) - ULong_t fCurrentRow{0}; // info to result row - - Bool_t IsValid(Int_t field); - -public: - TPgSQLResult(PGresult *result); - ~TPgSQLResult(); - - void Close(Option_t *opt="") final; - Int_t GetFieldCount() final; - const char *GetFieldName(Int_t field) final; - TSQLRow *Next() final; - - ClassDefOverride(TPgSQLResult, 0) // PgSQL query result -}; - -#endif diff --git a/sql/pgsql/inc/TPgSQLRow.h b/sql/pgsql/inc/TPgSQLRow.h deleted file mode 100644 index 801d67906a10c..0000000000000 --- a/sql/pgsql/inc/TPgSQLRow.h +++ /dev/null @@ -1,39 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TPgSQLRow -#define ROOT_TPgSQLRow - -#include "TSQLRow.h" - -struct pg_result; -typedef struct pg_result PGresult; - -class TPgSQLRow : public TSQLRow { - -private: - PGresult *fResult{nullptr}; // current result set - ULong_t fRowNum{0}; // row number - - Bool_t IsValid(Int_t field); - -public: - TPgSQLRow(PGresult *result, ULong_t rowHandle); - ~TPgSQLRow(); - - void Close(Option_t *opt="") final; - ULong_t GetFieldLength(Int_t field) final; - const char *GetField(Int_t field) final; - - ClassDefOverride(TPgSQLRow,0) // One row of PgSQL query result -}; - -#endif diff --git a/sql/pgsql/inc/TPgSQLServer.h b/sql/pgsql/inc/TPgSQLServer.h deleted file mode 100644 index 4f185afc6dd61..0000000000000 --- a/sql/pgsql/inc/TPgSQLServer.h +++ /dev/null @@ -1,51 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TPgSQLServer -#define ROOT_TPgSQLServer - -#include "TSQLServer.h" - -#include -#include - -struct pg_conn; -typedef struct pg_conn PGconn; - -class TPgSQLServer : public TSQLServer { - -private: - PGconn *fPgSQL{nullptr}; // connection to PgSQL server - TString fSrvInfo; // Server info - std::map fOidTypNameMap; // Map of oid to typname, used in GetTableInfo() -public: - TPgSQLServer(const char *db, const char *uid, const char *pw); - ~TPgSQLServer(); - - void Close(Option_t *opt="") final; - TSQLResult *Query(const char *sql) final; - TSQLStatement *Statement(const char *sql, Int_t = 100) final; - Bool_t HasStatement() const final; - Int_t SelectDataBase(const char *dbname) final; - TSQLResult *GetDataBases(const char *wild = nullptr) final; - TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) final; - TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) final; - TSQLTableInfo *GetTableInfo(const char* tablename) final; - Int_t CreateDataBase(const char *dbname) final; - Int_t DropDataBase(const char *dbname) final; - Int_t Reload() final; - Int_t Shutdown() final; - const char *ServerInfo() final; - - ClassDefOverride(TPgSQLServer,0) // Connection to PgSQL server -}; - -#endif diff --git a/sql/pgsql/inc/TPgSQLStatement.h b/sql/pgsql/inc/TPgSQLStatement.h deleted file mode 100644 index 2316b6f672643..0000000000000 --- a/sql/pgsql/inc/TPgSQLStatement.h +++ /dev/null @@ -1,111 +0,0 @@ -// @(#)root/mysql:$Id$ -// Author: Dennis Box (dbox@fnal.gov) 3/12/2007 - -/************************************************************************* - * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TPgSQLStatement -#define ROOT_TPgSQLStatement - -#include "TSQLStatement.h" - -struct pg_conn; -typedef struct pg_conn PGconn; - -struct pg_result; -typedef struct pg_result PGresult; - - -struct PgSQL_Stmt_t { - PGconn *fConn; - PGresult *fRes; -}; - -class TPgSQLStatement : public TSQLStatement { - -private: - - PgSQL_Stmt_t *fStmt{nullptr}; //! executed statement - Int_t fNumBuffers{0}; //! number of statement parameters - char **fBind{nullptr}; //! array of data for input - char **fFieldName{nullptr}; //! array of column names - Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results - Int_t fIterationCount{0}; //! number of iteration - int *fParamLengths{nullptr}; //! length of column - int *fParamFormats{nullptr}; //! data type (OID) - Int_t fNumResultRows{0}; - Int_t fNumResultCols{0}; - - Bool_t IsSetParsMode() const { return fWorkingMode==1; } - Bool_t IsResultSetMode() const { return fWorkingMode==2; } - - Bool_t SetSQLParamType(Int_t npar, Bool_t isbinary = kFALSE, Int_t param_len = 0, Int_t maxsize = 0); - - long double ConvertToNumeric(Int_t npar); - const char *ConvertToString(Int_t npar); - - void FreeBuffers(); - void SetBuffersNumber(Int_t n); - - void ConvertTimeToUTC(const TString &PQvalue, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec); - -public: - TPgSQLStatement(PgSQL_Stmt_t* stmt, Bool_t errout = kTRUE); - virtual ~TPgSQLStatement(); - - void Close(Option_t * = "") final; - - Int_t GetBufferLength() const final { return 1; } - Int_t GetNumParameters() final; - - Bool_t SetNull(Int_t npar) final; - Bool_t SetInt(Int_t npar, Int_t value) final; - Bool_t SetUInt(Int_t npar, UInt_t value) final; - Bool_t SetLong(Int_t npar, Long_t value) final; - Bool_t SetLong64(Int_t npar, Long64_t value) final; - Bool_t SetULong64(Int_t npar, ULong64_t value) final; - Bool_t SetDouble(Int_t npar, Double_t value) final; - Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final; - Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final; - Bool_t SetLargeObject(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final; - Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final; - Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final; - Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final; - Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac = 0) final; - Bool_t SetTimestamp(Int_t npar, const TTimeStamp& tm) final; - - Bool_t NextIteration() final; - - Bool_t Process() final; - Int_t GetNumAffectedRows() final; - - Bool_t StoreResult() final; - Int_t GetNumFields() final; - const char *GetFieldName(Int_t nfield) final; - Bool_t NextResultRow() final; - - Bool_t IsNull(Int_t npar) final; - Int_t GetInt(Int_t npar) final; - UInt_t GetUInt(Int_t npar) final; - Long_t GetLong(Int_t npar) final; - Long64_t GetLong64(Int_t npar) final; - ULong64_t GetULong64(Int_t npar) final; - Double_t GetDouble(Int_t npar) final; - const char *GetString(Int_t npar) final; - Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final; - Bool_t GetLargeObject(Int_t npar, void* &mem, Long_t& size) final; - Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final; - Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final; - Bool_t GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) final; - Bool_t GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t&) final; - Bool_t GetTimestamp(Int_t npar, TTimeStamp& tm) final; - - ClassDefOverride(TPgSQLStatement, 0); // SQL statement class for PgSQL DB -}; - -#endif diff --git a/sql/pgsql/src/TPgSQLResult.cxx b/sql/pgsql/src/TPgSQLResult.cxx deleted file mode 100644 index 6e473d3ab4c2b..0000000000000 --- a/sql/pgsql/src/TPgSQLResult.cxx +++ /dev/null @@ -1,107 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TPgSQLResult.h" -#include "TPgSQLRow.h" - -#include - -ClassImp(TPgSQLResult); - -//////////////////////////////////////////////////////////////////////////////// -/// PgSQL query result. - -TPgSQLResult::TPgSQLResult(PGresult *result) -{ - fResult = (PGresult *) result; - fRowCount = fResult ? PQntuples(fResult) : 0; - fCurrentRow = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup PgSQL query result. - -TPgSQLResult::~TPgSQLResult() -{ - if (fResult) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close query result. - -void TPgSQLResult::Close(Option_t *) -{ - if (!fResult) - return; - - PQclear(fResult); - fResult = nullptr; - fRowCount = 0; - fCurrentRow = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if result set is open and field index within range. - -Bool_t TPgSQLResult::IsValid(Int_t field) -{ - if (!fResult) { - Error("IsValid", "result set closed"); - return kFALSE; - } - if (field < 0 || field >= GetFieldCount()) { - Error("IsValid", "field index out of bounds"); - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get number of fields in result. - -Int_t TPgSQLResult::GetFieldCount() -{ - if (!fResult) { - Error("GetFieldCount", "result set closed"); - return 0; - } - return PQnfields(fResult); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get name of specified field. - -const char *TPgSQLResult::GetFieldName(Int_t field) -{ - if (!fResult) { - Error("GetFieldName", "result set closed"); - return nullptr; - } - return PQfname(fResult, field); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get next query result row. The returned object must be -/// deleted by the user. - -TSQLRow *TPgSQLResult::Next() -{ - if (!fResult) { - Error("Next", "result set closed"); - return nullptr; - } - ULong_t row = fCurrentRow++; - if ((Int_t) row >= fRowCount) - return nullptr; - - return new TPgSQLRow(fResult, row); -} diff --git a/sql/pgsql/src/TPgSQLRow.cxx b/sql/pgsql/src/TPgSQLRow.cxx deleted file mode 100644 index 4ca7d304013ad..0000000000000 --- a/sql/pgsql/src/TPgSQLRow.cxx +++ /dev/null @@ -1,88 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TPgSQLRow.h" - -#include - - -ClassImp(TPgSQLRow); - -//////////////////////////////////////////////////////////////////////////////// -/// Single row of query result. - -TPgSQLRow::TPgSQLRow(PGresult *res, ULong_t rowHandle) -{ - fResult = res; - fRowNum = rowHandle; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destroy row object. - -TPgSQLRow::~TPgSQLRow() -{ - if (fRowNum) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close row. - -void TPgSQLRow::Close(Option_t *) -{ - if (!fRowNum) - return; - - fResult = nullptr; - fRowNum = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if row is open and field index within range. - -Bool_t TPgSQLRow::IsValid(Int_t field) -{ - if (field < 0 || field >= (Int_t)PQnfields(fResult)) { - Error("IsValid", "field index out of bounds"); - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get length in bytes of specified field. - -ULong_t TPgSQLRow::GetFieldLength(Int_t field) -{ - if (!IsValid(field)) - return 0; - - ULong_t fieldLength = (ULong_t) PQfsize(fResult, field); - - if (!fieldLength) { - Error("GetFieldLength", "cannot get field length"); - return 0; - } - - return fieldLength; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get specified field from row (0 <= field < GetFieldCount()). - -const char *TPgSQLRow::GetField(Int_t field) -{ - if (!IsValid(field)) - return nullptr; - - return PQgetvalue(fResult, fRowNum, field); -} diff --git a/sql/pgsql/src/TPgSQLServer.cxx b/sql/pgsql/src/TPgSQLServer.cxx deleted file mode 100644 index cced273915adc..0000000000000 --- a/sql/pgsql/src/TPgSQLServer.cxx +++ /dev/null @@ -1,564 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: g.p.ciceri 01/06/2001 - -/************************************************************************* - * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TPgSQLServer.h" -#include "TPgSQLResult.h" -#include "TPgSQLStatement.h" - -#include "TSQLColumnInfo.h" -#include "TSQLTableInfo.h" -#include "TSQLRow.h" -#include "TUrl.h" -#include "TList.h" - -#include // to get PG_VERSION_NUM - -#define pgsql_success(x) (((x) == PGRES_EMPTY_QUERY) \ - || ((x) == PGRES_COMMAND_OK) \ - || ((x) == PGRES_TUPLES_OK)) - -#include - -//////////////////////////////////////////////////////////////////////////////// -/// PluginManager generator function - -TSQLServer* ROOT_Plugin_TPgSQLServer(const char* db, const char* uid, const char* pw) { - return new TPgSQLServer(db, uid, pw); -} - - -ClassImp(TPgSQLServer); - -//////////////////////////////////////////////////////////////////////////////// -/// Open a connection to a PgSQL DB server. The db arguments should be -/// of the form "pgsql://[:][/]", e.g.: -/// "pgsql://pcroot.cern.ch:3456/test". The uid is the username and pw -/// the password that should be used for the connection. - -TPgSQLServer::TPgSQLServer(const char *db, const char *uid, const char *pw) -{ - fPgSQL = nullptr; - fSrvInfo = ""; - - TUrl url(db); - - if (!url.IsValid()) { - Error("TPgSQLServer", "malformed db argument %s", db); - MakeZombie(); - return; - } - - if (strncmp(url.GetProtocol(), "pgsql", 5)) { - Error("TPgSQLServer", "protocol in db argument should be pgsql it is %s", - url.GetProtocol()); - MakeZombie(); - return; - } - - const char *dbase = url.GetFile(); - - if (url.GetPort()) { - TString port; - port += url.GetPort(); - fPgSQL = PQsetdbLogin(url.GetHost(), port.Data(), nullptr, nullptr, dbase, uid, pw); - } else { - fPgSQL = PQsetdbLogin(url.GetHost(), nullptr, nullptr, nullptr, dbase, uid, pw); - } - - if (PQstatus(fPgSQL) != CONNECTION_BAD) { - fType = "PgSQL"; - fHost = url.GetHost(); - fDB = dbase; - fPort = url.GetPort(); - - // Populate server-info - fSrvInfo = "postgres "; - static const char *sql = "select setting from pg_settings where name='server_version'"; - PGresult *res = PQexec(fPgSQL, sql); - int stat = PQresultStatus(res); - if (stat == PGRES_TUPLES_OK && PQntuples(res)) { - char *vers = PQgetvalue(res,0,0); - fSrvInfo += vers; - PQclear(res); - } else { - fSrvInfo += "unknown version number"; - } - } else { - Error("TPgSQLServer", "connection to %s failed", url.GetHost()); - MakeZombie(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to PgSQL DB server. - -TPgSQLServer::~TPgSQLServer() -{ - if (IsConnected()) - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close connection to PgSQL DB server. - -void TPgSQLServer::Close(Option_t *) -{ - if (!fPgSQL) - return; - - PQfinish(fPgSQL); - fPort = -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SQL command. Result object must be deleted by the user. -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TPgSQLServer::Query(const char *sql) -{ - if (!IsConnected()) { - Error("Query", "not connected"); - return nullptr; - } - - PGresult *res = PQexec(fPgSQL, sql); - - if ((PQresultStatus(res) != PGRES_COMMAND_OK) && - (PQresultStatus(res) != PGRES_TUPLES_OK)) { - Error("Query", "%s",PQresultErrorMessage(res)); - PQclear(res); - return nullptr; - } - - return new TPgSQLResult(res); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Select a database. Returns 0 if successful, non-zero otherwise. - -Int_t TPgSQLServer::SelectDataBase(const char *dbname) -{ - TString usr; - TString pwd; - TString port; - TString opts; - - if (!IsConnected()) { - Error("SelectDataBase", "not connected"); - return -1; - } - - if (dbname == fDB) { - return 0; - } else { - usr = PQuser(fPgSQL); - pwd = PQpass(fPgSQL); - port = PQport(fPgSQL); - opts = PQoptions(fPgSQL); - - Close(); - fPgSQL = PQsetdbLogin(fHost.Data(), port.Data(), - opts.Data(), nullptr, dbname, - usr.Data(), pwd.Data()); - - if (PQstatus(fPgSQL) == CONNECTION_OK) { - fDB=dbname; - fPort=port.Atoi(); - } else { - Error("SelectDataBase", "%s",PQerrorMessage(fPgSQL)); - return -1; - } - } - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all available databases. Wild is for wildcarding "t%" list all -/// databases starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TPgSQLServer::GetDataBases(const char *wild) -{ - if (!IsConnected()) { - Error("GetDataBases", "not connected"); - return nullptr; - } - - TString sql = "SELECT pg_database.datname FROM pg_database"; - if (wild && *wild) - sql += TString::Format(" WHERE pg_database.datname LIKE '%s'", wild); - - return Query(sql.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all tables in the specified database. Wild is for wildcarding -/// "t%" list all tables starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TPgSQLServer::GetTables(const char *dbname, const char *wild) -{ - if (!IsConnected()) { - Error("GetTables", "not connected"); - return nullptr; - } - - if (SelectDataBase(dbname) != 0) { - Error("GetTables", "no such database %s", dbname); - return nullptr; - } - - TString sql = "SELECT relname FROM pg_class where relkind='r'"; - if (wild && *wild) - sql += TString::Format(" AND relname LIKE '%s'", wild); - - return Query(sql.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// List all columns in specified table in the specified database. -/// Wild is for wildcarding "t%" list all columns starting with "t". -/// Returns a pointer to a TSQLResult object if successful, 0 otherwise. -/// The result object must be deleted by the user. - -TSQLResult *TPgSQLServer::GetColumns(const char *dbname, const char *table, - const char *wild) -{ - if (!IsConnected()) { - Error("GetColumns", "not connected"); - return nullptr; - } - - if (SelectDataBase(dbname) != 0) { - Error("GetColumns", "no such database %s", dbname); - return nullptr; - } - - TString sql; - if (wild && *wild) - sql.Form("select a.attname,t.typname,a.attnotnull \ - from pg_attribute a, pg_class c, pg_type t \ - where c.oid=a.attrelid and c.relname='%s' and \ - a.atttypid=t.oid and a.attnum>0 \ - and a.attname like '%s' order by a.attnum ", table, wild); - else - sql.Form("select a.attname,t.typname,a.attnotnull \ - from pg_attribute a, pg_class c, pg_type t \ - where c.oid=a.attrelid and c.relname='%s' and \ - a.atttypid=t.oid and a.attnum>0 order by a.attnum", table); - - return Query(sql.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a database. Returns 0 if successful, non-zero otherwise. - -Int_t TPgSQLServer::CreateDataBase(const char *dbname) -{ - if (!IsConnected()) { - Error("CreateDataBase", "not connected"); - return -1; - } - TString sql; - sql.Form("CREATE DATABASE %s", dbname); - PGresult *res = PQexec(fPgSQL, sql.Data()); - PQclear(res); - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Drop (i.e. delete) a database. Returns 0 if successful, non-zero -/// otherwise. - -Int_t TPgSQLServer::DropDataBase(const char *dbname) -{ - if (!IsConnected()) { - Error("DropDataBase", "not connected"); - return -1; - } - TString sql; - sql.Form("DROP DATABASE %s", dbname); - PGresult *res = PQexec(fPgSQL, sql.Data()); - PQclear(res); - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Reload permission tables. Returns 0 if successful, non-zero -/// otherwise. User must have reload permissions. - -Int_t TPgSQLServer::Reload() -{ - if (!IsConnected()) { - Error("Reload", "not connected"); - return -1; - } - - Error("Reload", "not implemented"); - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shutdown the database server. Returns 0 if successful, non-zero -/// otherwise. User must have shutdown permissions. - -Int_t TPgSQLServer::Shutdown() -{ - if (!IsConnected()) { - Error("Shutdown", "not connected"); - return -1; - } - - Error("Shutdown", "not implemented"); - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return server info. - -const char *TPgSQLServer::ServerInfo() -{ - if (!IsConnected()) { - Error("ServerInfo", "not connected"); - return nullptr; - } - - return fSrvInfo.Data(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// PG_VERSION_NUM conveniently only started being #%defined at 8.2.3 -/// which is the first version of libpq which explicitly supports prepared -/// statements - -Bool_t TPgSQLServer::HasStatement() const -{ -#ifdef PG_VERSION_NUM - return kTRUE; -#else - return kFALSE; -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TPgSQLStatement. - -#ifdef PG_VERSION_NUM -TSQLStatement* TPgSQLServer::Statement(const char *sql, Int_t) -#else -TSQLStatement* TPgSQLServer::Statement(const char *, Int_t) -#endif -{ -#ifdef PG_VERSION_NUM - if (!sql || !*sql) { - SetError(-1, "no query string specified","Statement"); - return nullptr; - } - - PgSQL_Stmt_t *stmt = new PgSQL_Stmt_t; - if (!stmt){ - SetError(-1, "cannot allocate PgSQL_Stmt_t", "Statement"); - return nullptr; - } - stmt->fConn = fPgSQL; - stmt->fRes = PQprepare(fPgSQL, "preparedstmt", sql, 0, (const Oid*)0); - - ExecStatusType stat = PQresultStatus(stmt->fRes); - if (pgsql_success(stat)) { - fErrorOut = stat; - return new TPgSQLStatement(stmt, fErrorOut); - } else { - SetError(stat, PQresultErrorMessage(stmt->fRes), "Statement"); - stmt->fConn = nullptr; - delete stmt; - return nullptr; - } -#else - Error("Statement", "not implemented for pgsql < 8.2"); -#endif - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Produce TSQLTableInfo. - -TSQLTableInfo *TPgSQLServer::GetTableInfo(const char* tablename) -{ - if (!IsConnected()) { - Error("GetColumns", "not connected"); - return nullptr; - } - - // Check table name - if (!tablename || (*tablename==0)) - return nullptr; - - // Query first row ( works same way as MySQL) - PGresult *res = PQexec(fPgSQL, TString::Format("SELECT * FROM %s LIMIT 1;", tablename)); - - if ((PQresultStatus(res) != PGRES_COMMAND_OK) && - (PQresultStatus(res) != PGRES_TUPLES_OK)) { - Error("Query", "%s",PQresultErrorMessage(res)); - PQclear(res); - return nullptr; - } - - if (fOidTypNameMap.empty()) { - // Oid-TypNameMap empty, populate it, stays valid at least for connection - // lifetime. - PGresult *res_type = PQexec(fPgSQL, "SELECT OID, TYPNAME FROM PG_TYPE;"); - - if ((PQresultStatus(res_type) != PGRES_COMMAND_OK) && - (PQresultStatus(res_type) != PGRES_TUPLES_OK)) { - Error("Query", "%s", PQresultErrorMessage(res_type)); - PQclear(res); - PQclear(res_type); - return nullptr; - } - - Int_t nOids = PQntuples(res_type); - for (Int_t oid=0; oid::iterator lookupOid = fOidTypNameMap.find(oid_code); - if (lookupOid == fOidTypNameMap.end()) { - // Not found. - //default - sqltype = kSQL_NUMERIC; - type_name = "NUMERIC"; - data_size=-1; - } else if (lookupOid->second == "int2"){ - sqltype = kSQL_INTEGER; - type_name = "INT"; - data_size=2; - } else if (lookupOid->second == "int4"){ - sqltype = kSQL_INTEGER; - type_name = "INT"; - data_size=4; - } else if (lookupOid->second == "int8"){ - sqltype = kSQL_INTEGER; - type_name = "INT"; - data_size=8; - } else if (lookupOid->second == "float4"){ - sqltype = kSQL_FLOAT; - type_name = "FLOAT"; - data_size=4; - } else if (lookupOid->second == "float8"){ - sqltype = kSQL_DOUBLE; - type_name = "DOUBLE"; - data_size=8; - } else if (lookupOid->second == "bool"){ - sqltype = kSQL_INTEGER; - type_name = "INT"; - data_size=1; - } else if (lookupOid->second == "char"){ - sqltype = kSQL_CHAR; - type_name = "CHAR"; - data_size=1; - } else if (lookupOid->second == "varchar"){ - sqltype = kSQL_VARCHAR; - type_name = "VARCHAR"; - data_size=imod; - } else if (lookupOid->second == "text"){ - sqltype = kSQL_VARCHAR; - type_name = "VARCHAR"; - data_size=imod; - } else if (lookupOid->second == "name"){ - sqltype = kSQL_VARCHAR; - type_name = "VARCHAR"; - data_size=imod; - } else if (lookupOid->second == "date"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "time"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "timetz"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "timestamp"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "timestamptz"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "interval"){ - sqltype = kSQL_TIMESTAMP; - type_name = "TIMESTAMP"; - data_size=8; - } else if (lookupOid->second == "bytea"){ - sqltype = kSQL_BINARY; - type_name = "BINARY"; - data_size=-1; - } else if (lookupOid->second == ""){ - sqltype = kSQL_NONE; - type_name = "UNKNOWN"; - data_size=-1; - } else{ - //default - sqltype = kSQL_NUMERIC; - type_name = "NUMERIC"; - data_size=-1; - } - - if (!lst) - lst = new TList; - - lst->Add(new TSQLColumnInfo(column_name, - type_name, - nullable, - sqltype, - data_size, - data_length, - data_scale, - data_sign)); - } //! ( cols) - - PQclear(res); - return (new TSQLTableInfo(tablename,lst)); -} diff --git a/sql/pgsql/src/TPgSQLStatement.cxx b/sql/pgsql/src/TPgSQLStatement.cxx deleted file mode 100644 index 725d2c25f05f7..0000000000000 --- a/sql/pgsql/src/TPgSQLStatement.cxx +++ /dev/null @@ -1,1319 +0,0 @@ -// @(#)root/pgsql:$Id$ -// Author: Dennis Box (dbox@fnal.gov) 3/12/2007 - -/************************************************************************* - * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// SQL statement class for PgSQL // -// // -// See TSQLStatement class documentation for more details. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TPgSQLStatement.h" -#include "TDataType.h" -#include "TDatime.h" -#include "TTimeStamp.h" -#include "TMath.h" -#include "strlcpy.h" -#include "snprintf.h" - -#include - -#include // to get PG_VERSION_NUM - -#define pgsql_success(x) (((x) == PGRES_EMPTY_QUERY) \ - || ((x) == PGRES_COMMAND_OK) \ - || ((x) == PGRES_TUPLES_OK)) - -#include - -ClassImp(TPgSQLStatement); - -#ifdef PG_VERSION_NUM - -#include "libpq/libpq-fs.h" - -static const Int_t kBindStringSize = 30; // big enough to handle text rep. of 64 bit number and timestamp (e.g. "1970-01-01 01:01:01.111111+00") - -//////////////////////////////////////////////////////////////////////////////// -/// Normal constructor. -/// Checks if statement contains parameters tags. - -TPgSQLStatement::TPgSQLStatement(PgSQL_Stmt_t *stmt, Bool_t errout): - TSQLStatement(errout), - fStmt(stmt), - fNumBuffers(0), - fBind(nullptr), - fFieldName(nullptr), - fWorkingMode(0), - fIterationCount(0), - fParamLengths(nullptr), - fParamFormats(nullptr), - fNumResultRows(0), - fNumResultCols(0) -{ - // Given fRes not used, we retrieve the statement using the connection. - if (fStmt->fRes != nullptr) { - PQclear(fStmt->fRes); - } - - fStmt->fRes = PQdescribePrepared(fStmt->fConn,"preparedstmt"); - unsigned long paramcount = PQnparams(fStmt->fRes); - fNumResultCols = PQnfields(fStmt->fRes); - fIterationCount = -1; - - if (paramcount>0) { - fWorkingMode = 1; - SetBuffersNumber(paramcount); - } else { - fWorkingMode = 2; - SetBuffersNumber(fNumResultCols); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor. - -TPgSQLStatement::~TPgSQLStatement() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close statement. - -void TPgSQLStatement::Close(Option_t *) -{ - if (fStmt->fRes) - PQclear(fStmt->fRes); - - fStmt->fRes = nullptr; - - PGresult *res=PQexec(fStmt->fConn,"DEALLOCATE preparedstmt;"); - PQclear(res); - - FreeBuffers(); - //TPgSQLServers responsibility to free connection - fStmt->fConn = nullptr; - delete fStmt; -} - - -// Reset error and check that statement exists -#define CheckStmt(method, res) \ - { \ - ClearError(); \ - if (!fStmt) { \ - SetError(-1,"Statement handle is 0",method); \ - return res; \ - } \ - } - -#define CheckErrNo(method, force, wtf) \ - { \ - int stmterrno = PQresultStatus(fStmt->fRes); \ - if ((stmterrno!=0) || force) { \ - const char* stmterrmsg = PQresultErrorMessage(fStmt->fRes); \ - if (stmterrno==0) { stmterrno = -1; stmterrmsg = "PgSQL statement error"; } \ - SetError(stmterrno, stmterrmsg, method); \ - return wtf; \ - } \ - } - -#define CheckErrResult(method, pqresult, retVal) \ - { \ - ExecStatusType stmterrno=PQresultStatus(pqresult); \ - if (!pgsql_success(stmterrno)) { \ - const char* stmterrmsg = PQresultErrorMessage(fStmt->fRes); \ - SetError(stmterrno, stmterrmsg, method); \ - PQclear(res); \ - return retVal; \ - } \ - } - -#define RollBackTransaction(method) \ - { \ - PGresult *resnum=PQexec(fStmt->fConn,"COMMIT"); \ - CheckErrResult("RollBackTransaction", resnum, kFALSE); \ - PQclear(res); \ - } - -// check last pgsql statement error code -#define CheckGetField(method, res) \ - { \ - ClearError(); \ - if (!IsResultSetMode()) { \ - SetError(-1,"Cannot get statement parameters",method); \ - return res; \ - } \ - if ((npar<0) || (npar>=fNumBuffers)) { \ - SetError(-1,Form("Invalid parameter number %d", npar),method); \ - return res; \ - } \ - } - -//////////////////////////////////////////////////////////////////////////////// -/// Process statement. - -Bool_t TPgSQLStatement::Process() -{ - CheckStmt("Process",kFALSE); - - // We create the prepared statement below, MUST delete the old one - // from our constructor first! - if (fStmt->fRes != NULL) { - PQclear(fStmt->fRes); - } - - if (IsSetParsMode()) { - fStmt->fRes= PQexecPrepared(fStmt->fConn,"preparedstmt",fNumBuffers, - (const char* const*)fBind, - fParamLengths, - fParamFormats, - 0); - - } else { //result set mode - fStmt->fRes= PQexecPrepared(fStmt->fConn,"preparedstmt",0,(const char* const*) nullptr, nullptr, nullptr,0); - } - ExecStatusType stat = PQresultStatus(fStmt->fRes); - if (!pgsql_success(stat)) - CheckErrNo("Process",kTRUE, kFALSE); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of affected rows after statement is processed. - -Int_t TPgSQLStatement::GetNumAffectedRows() -{ - CheckStmt("GetNumAffectedRows", -1); - - return (Int_t) atoi(PQcmdTuples(fStmt->fRes)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of statement parameters. - -Int_t TPgSQLStatement::GetNumParameters() -{ - CheckStmt("GetNumParameters", -1); - - if (IsSetParsMode()) { - return fNumBuffers; - } else { - return 0; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Store result of statement processing to access them -/// via GetInt(), GetDouble() and so on methods. - -Bool_t TPgSQLStatement::StoreResult() -{ - int i; - for (i=0;ifRes,i); - fParamFormats[i]=PQftype(fStmt->fRes,i); - fParamLengths[i]=PQfsize(fStmt->fRes,i); - - } - fNumResultRows=PQntuples(fStmt->fRes); - ExecStatusType stat = PQresultStatus(fStmt->fRes); - fWorkingMode = 2; - if (!pgsql_success(stat)) - CheckErrNo("StoreResult",kTRUE, kFALSE); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of fields in result set. - -Int_t TPgSQLStatement::GetNumFields() -{ - if (fWorkingMode==1) - return fNumBuffers; - if (fWorkingMode==2) - return fNumResultCols; - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns field name in result set. - -const char* TPgSQLStatement::GetFieldName(Int_t nfield) -{ - if (!IsResultSetMode() || (nfield < 0) || (nfield >= fNumBuffers)) return nullptr; - - return fFieldName[nfield]; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shift cursor to nect row in result set. - -Bool_t TPgSQLStatement::NextResultRow() -{ - if (!fStmt || !IsResultSetMode()) return kFALSE; - - Bool_t res = kTRUE; - - fIterationCount++; - if (fIterationCount>=fNumResultRows) - res = kFALSE; - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Increment iteration counter for statement, where parameter can be set. -/// Statement with parameters of previous iteration -/// automatically will be applied to database. - -Bool_t TPgSQLStatement::NextIteration() -{ - ClearError(); - - if (!IsSetParsMode() || !fBind) { - SetError(-1,"Cannot call for that statement","NextIteration"); - return kFALSE; - } - - fIterationCount++; - - if (fIterationCount==0) return kTRUE; - - fStmt->fRes= PQexecPrepared(fStmt->fConn,"preparedstmt",fNumBuffers, - (const char* const*)fBind, - fParamLengths, - fParamFormats, - 0); - ExecStatusType stat = PQresultStatus(fStmt->fRes); - if (!pgsql_success(stat) ){ - CheckErrNo("NextIteration", kTRUE, kFALSE) ; - return kFALSE; - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Release all buffers, used by statement. - -void TPgSQLStatement::FreeBuffers() -{ - //individual field names free()'ed by PQclear of fStmt->fRes - if (fFieldName) - delete[] fFieldName; - - if (fBind){ - for (Int_t i=0;ifRes, fIterationCount, npar); - return buf; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field to numeric. - -long double TPgSQLStatement::ConvertToNumeric(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (long double)0; - - return (long double) atof(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Checks if field value is null. - -Bool_t TPgSQLStatement::IsNull(Int_t npar) -{ - CheckGetField("IsNull", kTRUE); - - return PQgetisnull(fStmt->fRes,fIterationCount,npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get integer. - -Int_t TPgSQLStatement::GetInt(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (Int_t)0; - - return (Int_t) atoi(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get unsigned integer. - -UInt_t TPgSQLStatement::GetUInt(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (UInt_t)0; - - return (UInt_t) atoi(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get long. - -Long_t TPgSQLStatement::GetLong(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (Long_t)0; - - return (Long_t) atol(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get long64. - -Long64_t TPgSQLStatement::GetLong64(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (Long64_t)0; - -#ifndef R__WIN32 - return (Long64_t) atoll(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -#else - return (Long64_t) _atoi64(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned 64-bit integer - -ULong64_t TPgSQLStatement::GetULong64(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (ULong64_t)0; - -#ifndef R__WIN32 - return (ULong64_t) atoll(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -#else - return (ULong64_t) _atoi64(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as double. - -Double_t TPgSQLStatement::GetDouble(Int_t npar) -{ - if (PQgetisnull(fStmt->fRes,fIterationCount,npar)) - return (Double_t)0; - return (Double_t) atof(PQgetvalue(fStmt->fRes,fIterationCount,npar)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as string. - -const char *TPgSQLStatement::GetString(Int_t npar) -{ - return PQgetvalue(fStmt->fRes,fIterationCount,npar); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as binary array. -/// Note PQgetvalue mallocs/frees and ROOT classes expect new/delete. - -Bool_t TPgSQLStatement::GetBinary(Int_t npar, void* &mem, Long_t& size) -{ - size_t sz; - char *cptr = PQgetvalue(fStmt->fRes,fIterationCount,npar); - unsigned char * mptr = PQunescapeBytea((const unsigned char*)cptr,&sz); - if ((Long_t)sz>size) { - delete [] (unsigned char*) mem; - mem = (void*) new unsigned char[sz]; - } - size=sz; - memcpy(mem,mptr,sz); - PQfreemem(mptr); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return large object whose oid is in the given field. - -Bool_t TPgSQLStatement::GetLargeObject(Int_t npar, void* &mem, Long_t& size) -{ - Int_t objID = atoi(PQgetvalue(fStmt->fRes,fIterationCount,npar)); - - // All this needs to happen inside a transaction, or it will NOT work. - PGresult *res=PQexec(fStmt->fConn,"BEGIN"); - - CheckErrResult("GetLargeObject", res, kFALSE); - PQclear(res); - - Int_t lObjFD = lo_open(fStmt->fConn, objID, INV_READ); - - if (lObjFD<0) { - Error("GetLargeObject", "SQL Error on lo_open: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - // Object size is not known beforehand. - // Possible fast ways to get it are: - // (1) Create a function that does fopen, fseek, ftell on server - // (2) Query large object table with size() - // Both can not be expected to work in general, - // as (1) needs permissions and changes DB, - // and (2) needs permission. - // So we use - // (3) fopen, fseek and ftell locally. - - lo_lseek(fStmt->fConn, lObjFD, 0, SEEK_END); - Long_t sz = lo_tell(fStmt->fConn, lObjFD); - lo_lseek(fStmt->fConn, lObjFD, 0, SEEK_SET); - - if ((Long_t)sz>size) { - delete [] (unsigned char*) mem; - mem = (void*) new unsigned char[sz]; - size=sz; - } - - Int_t readBytes = lo_read(fStmt->fConn, lObjFD, (char*)mem, size); - - if (readBytes != sz) { - Error("GetLargeObject", "SQL Error on lo_read: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - if (lo_close(fStmt->fConn, lObjFD) != 0) { - Error("GetLargeObject", "SQL Error on lo_close: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - res=PQexec(fStmt->fConn,"COMMIT"); - - ExecStatusType stat = PQresultStatus(res); - if (!pgsql_success(stat)) { - Error("GetLargeObject", "SQL Error on COMMIT: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - PQclear(res); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date, in UTC. - -Bool_t TPgSQLStatement::GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) -{ - TString val=PQgetvalue(fStmt->fRes,fIterationCount,npar); - TDatime d = TDatime(val.Data()); - year = d.GetYear(); - month = d.GetMonth(); - day= d.GetDay(); - Int_t hour = d.GetHour(); - Int_t min = d.GetMinute(); - Int_t sec = d.GetSecond(); - ConvertTimeToUTC(val, year, month, day, hour, min, sec); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field as time, in UTC. - -Bool_t TPgSQLStatement::GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) -{ - TString val=PQgetvalue(fStmt->fRes,fIterationCount,npar); - TDatime d = TDatime(val.Data()); - hour = d.GetHour(); - min = d.GetMinute(); - sec= d.GetSecond(); - Int_t year = d.GetYear(); - Int_t month = d.GetMonth(); - Int_t day = d.GetDay(); - ConvertTimeToUTC(val, year, month, day, hour, min, sec); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date & time, in UTC. - -Bool_t TPgSQLStatement::GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) -{ - TString val=PQgetvalue(fStmt->fRes,fIterationCount,npar); - TDatime d = TDatime(val.Data()); - year = d.GetYear(); - month = d.GetMonth(); - day= d.GetDay(); - hour = d.GetHour(); - min = d.GetMinute(); - sec= d.GetSecond(); - ConvertTimeToUTC(val, year, month, day, hour, min, sec); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert timestamp value to UTC if a zone is included. - -void TPgSQLStatement::ConvertTimeToUTC(const TString &PQvalue, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) -{ - Ssiz_t p = PQvalue.Last(':'); - // Check if timestamp has timezone - TSubString *s_zone = nullptr; - Bool_t hasZone = kFALSE; - Ssiz_t tzP = PQvalue.Last('+'); - if ((tzP != kNPOS) && (tzP > p) ) { - s_zone = new TSubString(PQvalue(tzP+1,PQvalue.Length()-tzP)); - hasZone=kTRUE; - } else { - Ssiz_t tzM = PQvalue.Last('-'); - if ((tzM != kNPOS) && (tzM > p) ) { - s_zone = new TSubString(PQvalue(tzM+1,PQvalue.Length()-tzM)); - hasZone = kTRUE; - } - } - if (hasZone == kTRUE) { - // Parse timezone, might look like e.g. +00 or -00:00 - Int_t hourOffset, minuteOffset = 0; - Int_t conversions=sscanf(s_zone->Data(), "%2d:%2d", &hourOffset, &minuteOffset); - Int_t secondOffset = hourOffset*3600; - if (conversions>1) { - // Use sign from hour also for minute - secondOffset += (TMath::Sign(minuteOffset, hourOffset))*60; - } - // Use TTimeStamp so we do not have to take care of over-/underflows - TTimeStamp ts(year, month, day, hour, min, sec, 0, kTRUE, -secondOffset); - UInt_t uyear, umonth, uday, uhour, umin, usec; - ts.GetDate(kTRUE, 0, &uyear, &umonth, &uday); - ts.GetTime(kTRUE, 0, &uhour, &umin, &usec); - year=uyear; - month=umonth; - day=uday; - hour=uhour; - min=umin; - sec=usec; - delete s_zone; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field as timestamp, in UTC. -/// Second fraction is to be interpreted as in the following example: -/// 2013-01-12 12:10:23.093854+02 -/// Fraction is '93854', precision is fixed in this method to 6 decimal places. -/// This means the returned frac-value is always in microseconds. - -Bool_t TPgSQLStatement::GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t& frac) -{ - TString val=PQgetvalue(fStmt->fRes,fIterationCount,npar); - TDatime d(val.Data()); - year = d.GetYear(); - month = d.GetMonth(); - day= d.GetDay(); - hour = d.GetHour(); - min = d.GetMinute(); - sec= d.GetSecond(); - - ConvertTimeToUTC(val, year, month, day, hour, min, sec); - - Ssiz_t p = val.Last('.'); - TSubString s_frac = val(p,val.Length()-p+1); - - // atoi ignores timezone part. - // We MUST use atof here to correctly convert the fraction of - // "12:23:01.093854" and put a limitation on precision, - // as we can only return an Int_t. - frac=(Int_t) (atof(s_frac.Data())*1.E6); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return value of parameter in form of TTimeStamp -/// Be aware, that TTimeStamp does not allow dates before 1970-01-01 - -Bool_t TPgSQLStatement::GetTimestamp(Int_t npar, TTimeStamp& tm) -{ - Int_t year, month, day, hour, min, sec, microsec; - GetTimestamp(npar, year, month, day, hour, min, sec, microsec); - - if (year < 1970) { - SetError(-1, "Date before year 1970 does not supported by TTimeStamp type", "GetTimestamp"); - return kFALSE; - } - - tm.Set(year, month, day, hour, min, sec, microsec*1000, kTRUE, 0); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter type to be used as buffer. -/// Also verifies parameter index and memory allocation - -Bool_t TPgSQLStatement::SetSQLParamType(Int_t npar, Bool_t isbinary, Int_t param_len, Int_t maxsize) -{ - if ((npar < 0) || (npar >= fNumBuffers)) return kFALSE; - - if (maxsize < 0) { - if (fBind[npar]) delete [] fBind[npar]; - fBind[npar] = nullptr; - } else if (maxsize > kBindStringSize) { - if (fBind[npar]) delete [] fBind[npar]; - fBind[npar] = new char[maxsize]; - } else if (!fBind[npar]) { - fBind[npar] = new char[kBindStringSize]; - } - fParamFormats[npar] = isbinary ? 1 : 0; - fParamLengths[npar] = isbinary ? param_len : 0; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set NULL as parameter value. - -Bool_t TPgSQLStatement::SetNull(Int_t npar) -{ - if (!SetSQLParamType(npar, kFALSE, 0, -1)) return kFALSE; - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as integer. - -Bool_t TPgSQLStatement::SetInt(Int_t npar, Int_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%d",value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsinged integer. - -Bool_t TPgSQLStatement::SetUInt(Int_t npar, UInt_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%u",value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as long. - -Bool_t TPgSQLStatement::SetLong(Int_t npar, Long_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%ld",value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as 64-bit integer. - -Bool_t TPgSQLStatement::SetLong64(Int_t npar, Long64_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%lld",(Long64_t)value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsinged 64-bit integer. - -Bool_t TPgSQLStatement::SetULong64(Int_t npar, ULong64_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%llu",(ULong64_t)value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as double value. - -Bool_t TPgSQLStatement::SetDouble(Int_t npar, Double_t value) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar],kBindStringSize,"%lf",value); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as string. - -Bool_t TPgSQLStatement::SetString(Int_t npar, const char* value, Int_t maxsize) -{ - if (!SetSQLParamType(npar, kFALSE, 0, maxsize)) return kFALSE; - - if (fBind[npar] && value) - strlcpy(fBind[npar], value, (maxsize > kBindStringSize) ? maxsize : kBindStringSize); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as binary data. - -Bool_t TPgSQLStatement::SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize) -{ - if (size > maxsize) maxsize = size; - - if (!SetSQLParamType(npar, kTRUE, size, maxsize)) return kFALSE; - - if (fBind[npar] && mem) - memcpy(fBind[npar], mem, size); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value to large object and immediately insert the large object into DB. - -Bool_t TPgSQLStatement::SetLargeObject(Int_t npar, void* mem, Long_t size, Long_t /*maxsize*/) -{ - // All this needs to happen inside a transaction, or it will NOT work. - PGresult *res=PQexec(fStmt->fConn,"BEGIN"); - - CheckErrResult("GetLargeObject", res, kFALSE); - PQclear(res); - - Int_t lObjID = lo_creat(fStmt->fConn, INV_READ | INV_WRITE); - if (lObjID<0) { - Error("SetLargeObject", "Error in SetLargeObject: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - Int_t lObjFD = lo_open(fStmt->fConn, lObjID, INV_READ | INV_WRITE); - if (lObjFD<0) { - Error("SetLargeObject", "Error in SetLargeObject: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - Int_t writtenBytes = lo_write(fStmt->fConn, lObjFD, (char*)mem, size); - - if (writtenBytes != size) { - Error("SetLargeObject", "SQL Error on lo_write: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - if (lo_close(fStmt->fConn, lObjFD) != 0) { - Error("SetLargeObject", "SQL Error on lo_close: %s", PQerrorMessage(fStmt->fConn)); - RollBackTransaction("GetLargeObject"); - return kFALSE; - } - - res=PQexec(fStmt->fConn,"COMMIT"); - ExecStatusType stat = PQresultStatus(res); - if (!pgsql_success(stat)) { - Error("SetLargeObject", "SQL Error on COMMIT: %s", PQerrorMessage(fStmt->fConn)); - PQclear(res); - return kFALSE; - } - PQclear(res); - - snprintf(fBind[npar],kBindStringSize,"%d",lObjID); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date. - -Bool_t TPgSQLStatement::SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - TDatime d(year,month,day,0,0,0); - snprintf(fBind[npar],kBindStringSize,"%s",(char*)d.AsSQLString()); - - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as time. - -Bool_t TPgSQLStatement::SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - TDatime d(2000,1,1,hour,min,sec); - snprintf(fBind[npar],kBindStringSize,"%s",(char*)d.AsSQLString()); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date & time, in UTC. - -Bool_t TPgSQLStatement::SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - TDatime d(year,month,day,hour,min,sec); - snprintf(fBind[npar],kBindStringSize,"%s+00",(char*)d.AsSQLString()); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp, in UTC. -/// Second fraction is assumed as value in microseconds, -/// i.e. as a fraction with six decimal places. -/// See GetTimestamp() for an example. - -Bool_t TPgSQLStatement::SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - TDatime d(year,month,day,hour,min,sec); - snprintf(fBind[npar],kBindStringSize,"%s.%06d+00",(char*)d.AsSQLString(),frac); - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp from TTimeStamp object - -Bool_t TPgSQLStatement::SetTimestamp(Int_t npar, const TTimeStamp& tm) -{ - if (!SetSQLParamType(npar)) return kFALSE; - - snprintf(fBind[npar], kBindStringSize, "%s.%06d+00", (char*)tm.AsString("s"), TMath::Nint(tm.GetNanoSec() / 1000.0)); - return kTRUE; -} - -#else - -//////////////////////////////////////////////////////////////////////////////// -/// Normal constructor. -/// For PgSQL version < 8.2 no statement is supported. - -TPgSQLStatement::TPgSQLStatement(PgSQL_Stmt_t*, Bool_t) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor. - -TPgSQLStatement::~TPgSQLStatement() -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close statement. - -void TPgSQLStatement::Close(Option_t *) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Process statement. - -Bool_t TPgSQLStatement::Process() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of affected rows after statement is processed. - -Int_t TPgSQLStatement::GetNumAffectedRows() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of statement parameters. - -Int_t TPgSQLStatement::GetNumParameters() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Store result of statement processing to access them -/// via GetInt(), GetDouble() and so on methods. - -Bool_t TPgSQLStatement::StoreResult() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return number of fields in result set. - -Int_t TPgSQLStatement::GetNumFields() -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns field name in result set. - -const char* TPgSQLStatement::GetFieldName(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Shift cursor to nect row in result set. - -Bool_t TPgSQLStatement::NextResultRow() -{ - return kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Increment iteration counter for statement, where parameter can be set. -/// Statement with parameters of previous iteration -/// automatically will be applied to database. - -Bool_t TPgSQLStatement::NextIteration() -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Release all buffers, used by statement. - -void TPgSQLStatement::FreeBuffers() -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Allocate buffers for statement parameters/ result fields. - -void TPgSQLStatement::SetBuffersNumber(Int_t) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field value to string. - -const char* TPgSQLStatement::ConvertToString(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Convert field to numeric value. - -long double TPgSQLStatement::ConvertToNumeric(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Checks if field value is null. - -Bool_t TPgSQLStatement::IsNull(Int_t) -{ - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as integer. - -Int_t TPgSQLStatement::GetInt(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned integer. - -UInt_t TPgSQLStatement::GetUInt(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as long integer. - -Long_t TPgSQLStatement::GetLong(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as 64-bit integer. - -Long64_t TPgSQLStatement::GetLong64(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as unsigned 64-bit integer. - -ULong64_t TPgSQLStatement::GetULong64(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as double. - -Double_t TPgSQLStatement::GetDouble(Int_t) -{ - return 0.; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as string. - -const char *TPgSQLStatement::GetString(Int_t) -{ - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as binary array. - -Bool_t TPgSQLStatement::GetBinary(Int_t, void* &, Long_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return large object whose oid is in the given field. - -Bool_t TPgSQLStatement::GetLargeObject(Int_t, void* &, Long_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date. - -Bool_t TPgSQLStatement::GetDate(Int_t, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time. - -Bool_t TPgSQLStatement::GetTime(Int_t, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as date & time. - -Bool_t TPgSQLStatement::GetDatime(Int_t, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return field value as time stamp. - -Bool_t TPgSQLStatement::GetTimestamp(Int_t, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return value of parameter in form of TTimeStamp -/// Be aware, that TTimeStamp does not allow dates before 1970-01-01 - -Bool_t TPgSQLStatement::GetTimestamp(Int_t npar, TTimeStamp& tm) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter type to be used as buffer. - -Bool_t TPgSQLStatement::SetSQLParamType(Int_t, Bool_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set NULL as parameter value. - -Bool_t TPgSQLStatement::SetNull(Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as integer. - -Bool_t TPgSQLStatement::SetInt(Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsigned integer. - -Bool_t TPgSQLStatement::SetUInt(Int_t, UInt_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as long integer. - -Bool_t TPgSQLStatement::SetLong(Int_t, Long_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as 64-bit integer. - -Bool_t TPgSQLStatement::SetLong64(Int_t, Long64_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as unsigned 64-bit integer. - -Bool_t TPgSQLStatement::SetULong64(Int_t, ULong64_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as double. - -Bool_t TPgSQLStatement::SetDouble(Int_t, Double_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as string. - -Bool_t TPgSQLStatement::SetString(Int_t, const char*, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as binary data. - -Bool_t TPgSQLStatement::SetBinary(Int_t, void*, Long_t, Long_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value to large object and immediately insert the large object into DB. - -Bool_t TPgSQLStatement::SetLargeObject(Int_t, void*, Long_t, Long_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date. - -Bool_t TPgSQLStatement::SetDate(Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as time. - -Bool_t TPgSQLStatement::SetTime(Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as date & time. - -Bool_t TPgSQLStatement::SetDatime(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp. - -Bool_t TPgSQLStatement::SetTimestamp(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Int_t) -{ - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set parameter value as timestamp from TTimeStamp object - -Bool_t TPgSQLStatement::SetTimestamp(Int_t, const TTimeStamp&) -{ - return kFALSE; -} - -#endif //PG_VERSION_NUM diff --git a/tree/tree/src/TBufferSQL.cxx b/tree/tree/src/TBufferSQL.cxx index 4d04c7da88b24..cbaeca9f2373a 100644 --- a/tree/tree/src/TBufferSQL.cxx +++ b/tree/tree/src/TBufferSQL.cxx @@ -940,39 +940,3 @@ void TBufferSQL::ResetOffset() { fIter = fColumnVec->begin(); } - -#if 0 -//////////////////////////////////////////////////////////////////////////////// - -void TBufferSQL::insert_test(const char* dsn, const char* usr, - const char* pwd, const TString& tblname) -{ - TString str; - TString select = "select * from "; - TString sql; - TSQLStatement* stmt; - sql = select + "ins"; - - con = gSQLDriverManager->GetConnection(dsn,usr,pwd); - - if(!con) - printf("\n\n\nConnection NOT Successful\n\n\n"); - else - printf("\n\n\nConnection Sucessful\n\n\n"); - - stmt = con->CreateStatement(0, odbc::ResultSet::CONCUR_READ_ONLY); - - ptr = stmt->ExecuteQuery(sql.Data()); - if(!ptr) printf("No recorSet found!"); - - ptr->Next(); - ptr->MoveToInsertRow(); - std::cerr << "IsAfterLast(): " << ptr->IsAfterLast() << std::endl; - ptr->UpdateInt(1, 5555); - ptr->InsertRow(); - con->Commit(); - - ptr1 = stmt->ExecuteQuery(sql.Data()); - -} -#endif