├── cmake ├── ConfigureFile.cmake ├── SetValueMacro.cmake ├── SearchLibrary.cmake ├── resources │ └── macos │ │ ├── README.html │ │ └── WELCOME.html.in ├── COPYING-CMAKE-SCRIPTS ├── connector_c.cmake ├── symlink.cmake ├── ConnectorName.cmake └── build_depends.cmake ├── src ├── maconncpp.def.in ├── stringinfo.h ├── Identifier.h ├── CArray.cpp ├── Charset.cpp ├── parameters │ ├── ParameterHolder.cpp │ ├── OffsetTimeParameter.h │ ├── ZonedDateTimeParameter.h │ ├── BooleanParameter.h │ ├── SerializableParameter.h │ ├── IntParameter.h │ ├── ShortParameter.h │ ├── BigDecimalParameter.h │ ├── FloatParameter.h │ ├── LongParameter.h │ ├── DefaultParameter.h │ ├── DoubleParameter.h │ ├── LocalTimeParameter.h │ ├── ReaderParameter.h │ ├── ULongParameter.h │ ├── ByteParameter.h │ ├── NullParameter.h │ ├── ByteArrayParameter.h │ ├── StreamParameter.h │ ├── StringParameter.h │ ├── TimestampParameter.h │ ├── ParameterHolder.h │ ├── TimeParameter.h │ ├── DateParameter.h │ └── NullParameter.cpp ├── util │ ├── StateChange.h │ ├── ServerStatus.h │ ├── LogQueryTool.h │ ├── ServerPrepareStatementCache.h │ └── String.h ├── Identifier.cpp ├── StringImp.cpp ├── credential │ ├── Credential.h │ ├── CredentialPluginLoader.h │ ├── Credential.cpp │ └── CredentialPlugin.h ├── PrepareResult.h ├── Charset.h ├── logger │ ├── LoggerFactory.h │ ├── NoLogger.h │ ├── Logger.h │ ├── NoLogger.cpp │ └── LoggerFactory.cpp ├── options │ └── DriverPropertyInfo.h ├── Dll.c ├── MariaDbSavepoint.h ├── io │ ├── SocketHandlerFunction.h │ └── PacketInputStream.h ├── StringImp.h ├── com │ ├── ColumnNameMap.h │ ├── Packet.cpp │ ├── CmdInformationSingle.h │ ├── CmdInformationMultiple.h │ ├── CmdInformationBatch.h │ └── Packet.h ├── cache │ ├── CallableStatementCacheKey.cpp │ ├── CallableStatementCacheKey.h │ ├── CallableStatementCache.cpp │ └── CallableStatementCache.h ├── SimpleParameterMetaData.h ├── Version.h.in ├── MariaDbDriver.h ├── Consts.cpp ├── CallableParameterMetaData.h ├── protocol │ └── MasterProtocol.h ├── MariaDbConnCpp.h ├── MariaDbSavepoint.cpp ├── Parameters.h ├── pool │ └── GlobalStateInfo.h ├── MariaDbParameterMetaData.h ├── MariaDBWarning.h ├── SqlStates.h └── ColumnDefinition.cpp ├── .gitmodules ├── wininstall ├── mdb-connector-cpp.png ├── mdb-dialog-popup.png └── binaries_dir.xml.in ├── appveyor-download.bat ├── benchmark ├── installation.sh ├── launch.sh └── build.sh ├── .travis.yml ├── .gitignore ├── include ├── conncpp │ ├── compat │ │ ├── Array.hpp │ │ ├── Struct.hpp │ │ ├── Object.hpp │ │ ├── Executor.hpp │ │ └── SQLType.hpp │ ├── Savepoint.hpp │ ├── Warning.hpp │ ├── buildconf.hpp │ ├── DriverManager.hpp │ ├── Types.hpp │ ├── Driver.hpp │ └── ParameterMetaData.hpp └── conncpp.hpp ├── BUILD.md ├── test ├── unit │ ├── bugs │ │ └── CMakeLists.txt │ ├── classes │ │ └── art_resultset.h │ ├── performance │ │ ├── CMakeLists.txt │ │ └── perf_statement.h │ └── example │ │ └── CMakeLists.txt ├── CJUnitTestsPort │ ├── compliance │ │ ├── UnbufferedRsStmtTest.h │ │ └── UnbufferedRsStmtTest.cpp │ └── regression │ │ ├── PreparedStatementRegressionTest.cpp │ │ └── PreparedStatementRegressionTest.h ├── common │ └── singleton.h └── framework │ ├── test_container.cpp │ └── test_container.h └── install_test └── CMakeLists.txt.in /cmake/ConfigureFile.cmake: -------------------------------------------------------------------------------- 1 | CONFIGURE_FILE(${FILE_IN} ${FILE_OUT} @ONLY) 2 | -------------------------------------------------------------------------------- /src/maconncpp.def.in: -------------------------------------------------------------------------------- 1 | LIBRARY @LIBRARY_NAME@.dll 2 | EXPORTS 3 | DllMain 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libmariadb"] 2 | path = libmariadb 3 | url = https://github.com/MariaDB/mariadb-connector-c.git 4 | -------------------------------------------------------------------------------- /wininstall/mdb-connector-cpp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariadb-corporation/mariadb-connector-cpp/HEAD/wininstall/mdb-connector-cpp.png -------------------------------------------------------------------------------- /wininstall/mdb-dialog-popup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariadb-corporation/mariadb-connector-cpp/HEAD/wininstall/mdb-dialog-popup.png -------------------------------------------------------------------------------- /wininstall/binaries_dir.xml.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/stringinfo.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | 4 | #ifdef APSTUDIO_INVOKED 5 | #ifndef APSTUDIO_READONLY_SYMBOLS 6 | #define _APS_NEXT_RESOURCE_VALUE 101 7 | #define _APS_NEXT_COMMAND_VALUE 40001 8 | #define _APS_NEXT_CONTROL_VALUE 1001 9 | #define _APS_NEXT_SYMED_VALUE 101 10 | #endif 11 | #endif 12 | -------------------------------------------------------------------------------- /cmake/SetValueMacro.cmake: -------------------------------------------------------------------------------- 1 | # Macro that checks if variable is defined, otherwise checks env for same name, otherwise uses default value 2 | MACRO(SET_VALUE _variable _default_value _descr) 3 | IF (NOT ${_variable}) 4 | IF(DEFINED ENV{${_variable}}) 5 | SET(${_variable} $ENV{${_variable}} CACHE STRING "${_descr}") 6 | ELSE() 7 | SET(${_variable} ${_default_value} CACHE STRING "${_descr}") 8 | ENDIF() 9 | ENDIF() 10 | ENDMACRO(SET_VALUE) 11 | 12 | -------------------------------------------------------------------------------- /appveyor-download.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set archive=http://ftp.hosteurope.de/mirror/archive.mariadb.org/mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi 3 | set last=http://mirror.i3d.net/pub/mariadb/mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi 4 | 5 | curl -fLsS -o server.msi %archive% 6 | 7 | if %ERRORLEVEL% == 0 goto end 8 | 9 | curl -fLsS -o server.msi %last% 10 | if %ERRORLEVEL% == 0 goto end 11 | 12 | echo Failure Reason Given is %errorlevel% 13 | exit /b %errorlevel% 14 | 15 | :end 16 | echo "File found". 17 | -------------------------------------------------------------------------------- /benchmark/installation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | # Check out the library. 6 | git clone https://github.com/google/benchmark.git 7 | # Go to the library root directory 8 | cd benchmark 9 | # Make a build directory to place the build output. 10 | cmake -E make_directory "build" 11 | # Generate build system files with cmake, and download any dependencies. 12 | cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ 13 | # or, starting with CMake 3.13, use a simpler form: 14 | # cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build" 15 | # Build the library. 16 | cmake --build "build" --config Release 17 | 18 | -------------------------------------------------------------------------------- /cmake/SearchLibrary.cmake: -------------------------------------------------------------------------------- 1 | INCLUDE(CheckFunctionExists) 2 | INCLUDE(CheckLibraryExists) 3 | 4 | FUNCTION(SEARCH_LIBRARY library_name function liblist) 5 | IF(${${library_name}}) 6 | RETURN() 7 | ENDIF() 8 | CHECK_FUNCTION_EXISTS(${function} ${function}_IS_SYS_FUNC) 9 | # check if function is part of libc 10 | IF(HAVE_${function}_IS_SYS_FUNC) 11 | SET(${library_name} "" PARENT_SCOPE) 12 | RETURN() 13 | ENDIF() 14 | FOREACH(lib ${liblist}) 15 | CHECK_LIBRARY_EXISTS(${lib} ${function} "" HAVE_${function}_IN_${lib}) 16 | IF(HAVE_${function}_IN_${lib}) 17 | SET(${library_name} ${lib} PARENT_SCOPE) 18 | SET(HAVE_${library_name} 1 PARENT_SCOPE) 19 | RETURN() 20 | ENDIF() 21 | ENDFOREACH() 22 | ENDFUNCTION() 23 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | version: ~> 1.0 3 | sudo: true 4 | 5 | cache: 6 | apt: true 7 | ccache: true 8 | 9 | env: 10 | global: local=0 PROFILE=default DB=testcpp CLEAR_TEXT=0 11 | 12 | import: mariadb-corporation/connector-test-machine:common-build.yml@master 13 | 14 | jobs: 15 | allow_failures: 16 | - env: srv=build 17 | - os: osx 18 | - os: linux 19 | arch: s390x 20 | dist: focal 21 | include: 22 | - stage: Community 23 | os: osx 24 | compiler: clang 25 | before_script: 26 | - brew install openssl 27 | - brew install libiodbc 28 | name: "osx" 29 | - os: linux 30 | arch: s390x 31 | dist: focal 32 | env: srv=mariadb v=10.11 local=1 33 | name: "s390x" 34 | 35 | script: ./travis.sh 36 | -------------------------------------------------------------------------------- /benchmark/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | sudo cpupower frequency-set --governor performance || true 6 | 7 | g++ main-benchmark.cc -std=c++11 -isystem benchmark/include -Lbenchmark/build/src -L/usr/local/lib/mariadb/ -lbenchmark -lpthread -lmariadbcpp -o main-benchmark 8 | ./main-benchmark --benchmark_repetitions=30 --benchmark_time_unit=us --benchmark_min_warmup_time=10 --benchmark_counters_tabular=true --benchmark_format=json --benchmark_out=mariadb.json 9 | 10 | g++ main-benchmark.cc -std=c++11 -isystem benchmark/include -Lbenchmark/build/src -lbenchmark -lpthread -DMYSQL -lmysqlcppconn -o main-benchmark 11 | ./main-benchmark --benchmark_repetitions=30 --benchmark_time_unit=us --benchmark_min_warmup_time=10 --benchmark_counters_tabular=true --benchmark_format=json --benchmark_out=mysql.json 12 | 13 | 14 | pip3 install -r benchmark/requirements.txt 15 | benchmark/tools/compare.py -a --no-utest benchmarksfiltered ./mysql.json MySQL ./mariadb.json MariaDB -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | cmake_install.cmake 4 | 5 | Testing 6 | CTestTestfile.cmake 7 | 8 | ma_odbc_version.h 9 | wininstall/mariadb_conncpp.xml 10 | marconncpp.def 11 | maconncpp.rc 12 | 13 | *.vcxproj 14 | *.vcxproj.* 15 | *.sln 16 | *.suo 17 | *.sdf 18 | *.dir 19 | Debug 20 | Win32 21 | ipch 22 | 23 | *.msi 24 | *.wixobj 25 | *.wixpdb 26 | 27 | *.*~ 28 | *.swp 29 | *.diff 30 | *.bak 31 | *.so 32 | *.dylib 33 | .idea/ 34 | Makefile 35 | CPackConfig.cmake 36 | CPackSourceConfig.cmake 37 | benchmark/benchmark/ 38 | benchmark/mysql-connector-cpp/ 39 | benchmark/mariadb.json 40 | benchmark/mysql.json 41 | benchmark/main-benchmark 42 | 43 | # Prerequisites 44 | *.d 45 | 46 | # Compiled Object files 47 | *.slo 48 | *.lo 49 | *.o 50 | *.obj 51 | 52 | # Precompiled Headers 53 | *.gch 54 | *.pch 55 | 56 | # Compiled Dynamic libraries 57 | *.so 58 | *.dylib 59 | *.dll 60 | 61 | # Fortran module files 62 | *.mod 63 | *.smod 64 | 65 | # Compiled Static libraries 66 | *.lai 67 | *.la 68 | *.a 69 | *.lib 70 | 71 | # Executables 72 | *.exe 73 | *.out 74 | *.app 75 | -------------------------------------------------------------------------------- /cmake/resources/macos/README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | Readme for MariaDB Connector/C++ 9 | 10 | 11 |

MariaDB Connector/C++ files will be installed in /Library/MariaDB/MariaDB-Connector-Cpp.

12 |

Warning:The driver library requires latest versions of openssl libraries, that are not available natively, and can be obtained with Homebrew

13 |

Homebrew installation instructions can be found here. The short version at the moment is to run the following command in the terminal: 14 |

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

15 |

The command to install openssl is:

brew install openssl@1.1

16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cmake/resources/macos/WELCOME.html.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | Welcome to MariaDB Connector/C++ Installer 9 | 10 | 11 |

This is going to install MariaDB Connector/C++ 64bit version @CPACK_PACKAGE_VERSION@ - a database driver that implements JDBC-based API.

12 |

Warning: The driver library requires the latest version of the openssl libraries.These are not natively available in macOS, but can be obtained using Homebrew

13 |

Homebrew installation instructions can be found here. The short version at the moment is to run the following command in the terminal: 14 |

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

15 |

The command to install openssl is:

brew install openssl@1.1

16 | 17 | 18 | -------------------------------------------------------------------------------- /benchmark/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | sudo apt-get update 6 | sudo apt-get -f -y install build-essential cmake 7 | sudo apt-get -f -y install libmariadb3 libmariadb-dev 8 | sudo apt-get -f -y install linux-tools-common linux-gcp linux-tools-$(uname -r) 9 | cmake . -DCONC_WITH_MSI=OFF -DCONC_WITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DWITH_SSL=OPENSSL 10 | sudo cmake --build . --config Release --target install 11 | sudo make install 12 | echo $LD_LIBRARY_PATH 13 | export LD_LIBRARY_PATH=/usr/local/lib 14 | sudo install /usr/local/lib/mariadb/libmariadbcpp.so /usr/lib 15 | sudo install -d /usr/lib/mariadb 16 | sudo install -d /usr/lib/mariadb/plugin 17 | 18 | sudo ldconfig -n /usr/local/lib/mariadb || true 19 | sudo ldconfig -l -v /usr/lib/libmariadbcpp.so || true 20 | 21 | ls -lrt /usr/lib/libmar* 22 | 23 | #ldconfig -p 24 | 25 | #install mysql 26 | #git clone --recurse-submodules https://github.com/mysql/mysql-connector-cpp.git 27 | #cd mysql-connector-cpp 28 | #git checkout 8.0 29 | # 30 | #sudo apt-get install libboost-all-dev 31 | # 32 | #cmake . -DCMAKE_BUILD_TYPE=Release -DWITH_JDBC=ON -DWITH_BOOST=/usr/include/boost 33 | #sudo cmake --build . --target install --config Release 34 | 35 | 36 | sudo apt-get -y install libmysqlcppconn-dev 37 | -------------------------------------------------------------------------------- /include/conncpp/compat/Array.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MariaDB C++ Connector 4 | * 5 | * Copyright (c) 2020 MariaDB Ab. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not see 19 | * or write to the Free Software Foundation, Inc., 20 | * 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 21 | * 22 | */ 23 | 24 | #ifndef _ARRAY_H_ 25 | #define _ARRAY_H_ 26 | /* Stub class for the interface, that is used in one of methods for the non-implemented functionality. */ 27 | namespace sql 28 | { 29 | class Array{ 30 | Array(const Array&); 31 | void operator=(Array &); 32 | public: 33 | Array() {} 34 | virtual ~Array(){} 35 | }; 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /include/conncpp/compat/Struct.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MariaDB C++ Connector 4 | * 5 | * Copyright (c) 2020 MariaDB Ab. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not see 19 | * or write to the Free Software Foundation, Inc., 20 | * 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 21 | * 22 | */ 23 | 24 | #ifndef _STRUCT_H_ 25 | #define _STRUCT_H_ 26 | /* Stub class for the interface, that is used in one of methods for the non-implemented functionality. */ 27 | namespace sql 28 | { 29 | class Struct{ 30 | Struct(const Struct&); 31 | void operator=(Struct &); 32 | public: 33 | Struct() {} 34 | virtual ~Struct(){} 35 | }; 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /include/conncpp/compat/Object.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MariaDB C++ Connector 4 | * 5 | * Copyright (c) 2020 MariaDB Ab. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not see 19 | * or write to the Free Software Foundation, Inc., 20 | * 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 21 | * 22 | */ 23 | 24 | #ifndef _OBJECT_H_ 25 | #define _OBJECT_H_ 26 | 27 | /* Stub class for the interface, that is used in one of methods for the non-implemented functionality. */ 28 | namespace sql 29 | { 30 | class Object{ 31 | Object(const Object&); 32 | void operator=(Object &); 33 | public: 34 | Object() {} 35 | virtual ~Object(){} 36 | }; 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /include/conncpp/compat/Executor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MariaDB C++ Connector 4 | * 5 | * Copyright (c) 2020 MariaDB Ab. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not see 19 | * or write to the Free Software Foundation, Inc., 20 | * 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 21 | * 22 | */ 23 | 24 | #ifndef _EXECUTOR_H_ 25 | #define _EXECUTOR_H_ 26 | /* Stub class for the interface, that is used in one of methods for the non-implemented functionality. */ 27 | namespace sql 28 | { 29 | class Executor{ 30 | Executor(const Executor&); 31 | void operator=(Executor &); 32 | public: 33 | Executor() {} 34 | virtual ~Executor(){} 35 | }; 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /include/conncpp/compat/SQLType.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MariaDB C++ Connector 4 | * 5 | * Copyright (c) 2020 MariaDB Ab. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Library General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Library General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Library General Public 18 | * License along with this library; if not see 19 | * or write to the Free Software Foundation, Inc., 20 | * 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 21 | * 22 | */ 23 | 24 | #ifndef _SQLTYPE_H_ 25 | #define _SQLTYPE_H_ 26 | 27 | namespace sql 28 | { 29 | class SQLType{ 30 | SQLType(const SQLType&); 31 | void operator=(SQLType &); 32 | public: 33 | SQLType() {} 34 | virtual ~SQLType(){} 35 | 36 | virtual SQLString getName()=0; 37 | virtual SQLString getVendor()=0; 38 | virtual int SQLString getVendorTypeNumber()=0; 39 | }; 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /src/Identifier.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _IDENTIFIER_H_ 22 | #define _IDENTIFIER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | struct Identifier { 32 | 33 | SQLString schema; 34 | SQLString name; 35 | SQLString toString() const; 36 | }; 37 | 38 | } 39 | } 40 | #endif -------------------------------------------------------------------------------- /src/CArray.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #include "buildconf.hpp" 21 | #include "CArrayImp.h" 22 | 23 | namespace sql 24 | { 25 | // Instantiating template classes that have to be exported 26 | template struct MARIADB_EXPORTED CArray; 27 | template struct MARIADB_EXPORTED CArray; 28 | template struct MARIADB_EXPORTED CArray; 29 | } 30 | -------------------------------------------------------------------------------- /src/Charset.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "Charset.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | Charset::Charset(const SQLString& name) : csName(name) 29 | {} 30 | 31 | Charset::~Charset() 32 | {} 33 | 34 | namespace StandardCharsets 35 | { 36 | const Charset UTF_8("utf8mb4"); 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/parameters/ParameterHolder.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "ParameterHolder.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | char ParameterHolder::BINARY_INTRODUCER[]= {'_','b','i','n','a','r','y',' ','\'','\0'}; 28 | char ParameterHolder::QUOTE= '\''; 29 | 30 | ParameterHolder::~ParameterHolder() 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cmake/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /cmake/connector_c.cmake: -------------------------------------------------------------------------------- 1 | INCLUDE(FindGit) 2 | 3 | IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libmariadb/CMakeLists.txt AND GIT_EXECUTABLE) 4 | EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" submodule init 5 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 6 | EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" submodule update 7 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") 8 | ENDIF() 9 | IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libmariadb/CMakeLists.txt) 10 | MESSAGE(FATAL_ERROR "No MariaDB Connector/C! Run 11 | git submodule init 12 | git submodule update 13 | Then restart the build. 14 | ") 15 | ENDIF() 16 | 17 | SET(OPT CONC_) 18 | 19 | IF (CMAKE_BUILD_TYPE STREQUAL "Debug") 20 | SET(CONC_WITH_RTC ON) 21 | ENDIF() 22 | 23 | SET(CONC_WITH_SIGNCODE ${SIGNCODE}) 24 | SET(SIGN_OPTIONS ${SIGNTOOL_PARAMETERS}) 25 | 26 | IF(TARGET zlib) 27 | GET_PROPERTY(ZLIB_LIBRARY_LOCATION TARGET zlib PROPERTY LOCATION) 28 | ELSE() 29 | SET(ZLIB_LIBRARY_LOCATION ${ZLIB_LIBRARY}) 30 | ENDIF() 31 | 32 | SET(CONC_WITH_CURL OFF) 33 | SET(CONC_WITH_MYSQLCOMPAT ON) 34 | 35 | IF (INSTALL_LAYOUT STREQUAL "RPM") 36 | SET(CONC_INSTALL_LAYOUT "RPM") 37 | ELSE() 38 | SET(CONC_INSTALL_LAYOUT "DEFAULT") 39 | ENDIF() 40 | 41 | SET(PLUGIN_INSTALL_DIR ${INSTALL_PLUGINDIR}) 42 | SET(MARIADB_UNIX_ADDR ${MYSQL_UNIX_ADDR}) 43 | 44 | MESSAGE("== Configuring MariaDB Connector/C") 45 | ADD_SUBDIRECTORY(libmariadb EXCLUDE_FROM_ALL) 46 | -------------------------------------------------------------------------------- /cmake/symlink.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2016 MariaDB Corporation AB 3 | # 4 | # Redistribution and use is allowed according to the terms of the New 5 | # BSD license. 6 | # For details see the COPYING-CMAKE-SCRIPTS file. 7 | # 8 | MACRO(create_symlink symlink_name target install_path) 9 | # According to cmake documentation symlinks work on unix systems only 10 | IF(UNIX) 11 | # Get target components 12 | ADD_CUSTOM_COMMAND( 13 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} 14 | COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${symlink_name} 15 | COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink $ ${symlink_name} 16 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 17 | DEPENDS ${target} 18 | ) 19 | 20 | ADD_CUSTOM_TARGET(SYM_${symlink_name} 21 | ALL 22 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name}) 23 | SET_TARGET_PROPERTIES(SYM_${symlink_name} PROPERTIES CLEAN_DIRECT_OUTPUT 1) 24 | 25 | IF(CMAKE_GENERATOR MATCHES "Xcode") 26 | # For Xcode, replace project config with install config 27 | STRING(REPLACE "${CMAKE_CFG_INTDIR}" 28 | "\${CMAKE_INSTALL_CONFIG_NAME}" output ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name}) 29 | ENDIF() 30 | 31 | # presumably this will be used for libmysql*.so symlinks 32 | INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} DESTINATION ${install_path} 33 | COMPONENT Development) 34 | ENDIF() 35 | ENDMACRO() 36 | -------------------------------------------------------------------------------- /src/util/StateChange.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _STATECHANGE_H_ 22 | #define _STATECHANGE_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | enum StateChange { 31 | 32 | SESSION_TRACK_SYSTEM_VARIABLES = 0, 33 | SESSION_TRACK_SCHEMA = 1, 34 | SESSION_TRACK_STATE_CHANGE = 2, 35 | SESSION_TRACK_GTIDS = 3, 36 | SESSION_TRACK_TRANSACTION_CHARACTERISTICS = 4, 37 | SESSION_TRACK_TRANSACTION_STATE = 5 38 | }; 39 | 40 | } 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /src/Identifier.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "Identifier.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | /** 29 | * Identifier string value. 30 | * 31 | * @return the datas. 32 | */ 33 | SQLString Identifier::toString() const 34 | { 35 | if (!schema.empty()) 36 | { 37 | SQLString result(schema); 38 | return result.append('.').append(name); 39 | } 40 | return name; 41 | } 42 | 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/StringImp.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #include "StringImp.h" 21 | 22 | namespace sql 23 | { 24 | std::string& StringImp::get(SQLString& str) { 25 | return str.theString->realStr; 26 | } 27 | 28 | 29 | const std::string& StringImp::get(const SQLString& str) { 30 | return str.theString->realStr; 31 | } 32 | 33 | 34 | StringImp::StringImp(const char* str) : realStr(str) { 35 | } 36 | 37 | 38 | StringImp::StringImp(const char* str, std::size_t count) : realStr(str, count) { 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/credential/Credential.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CREDENTIAL_H_ 22 | #define _CREDENTIAL_H_ 23 | 24 | #include "SQLString.hpp" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | class Credential { 32 | SQLString user; 33 | SQLString password; 34 | 35 | public: 36 | Credential(const SQLString& user, const SQLString& password); 37 | const SQLString& getUser() const; 38 | void setUser(const SQLString& user); 39 | const SQLString& getPassword() const; 40 | }; 41 | } 42 | } 43 | #endif -------------------------------------------------------------------------------- /include/conncpp/Savepoint.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SAVEPOINT_H_ 22 | #define _SAVEPOINT_H_ 23 | 24 | #include "SQLString.hpp" 25 | 26 | namespace sql 27 | { 28 | 29 | class Savepoint 30 | { 31 | Savepoint(const Savepoint &); 32 | void operator=(Savepoint &); 33 | 34 | public: 35 | Savepoint() {} 36 | virtual ~Savepoint(){} 37 | 38 | virtual int32_t getSavepointId() const=0; 39 | virtual const SQLString& getSavepointName() const=0; 40 | virtual SQLString toString() const=0; 41 | }; 42 | 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /src/PrepareResult.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _PREPARERESULT_H_ 22 | #define _PREPARERESULT_H_ 23 | 24 | #include "SQLString.hpp" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | class PrepareResult { 31 | PrepareResult(const PrepareResult &)=delete; 32 | void operator=(PrepareResult &)= delete; 33 | public: 34 | PrepareResult() {} 35 | virtual ~PrepareResult(){} 36 | 37 | virtual const SQLString& getSql() const=0; 38 | virtual size_t getParamCount() const=0; 39 | }; 40 | } 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /src/Charset.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CHARSET_H_ 22 | #define _CHARSET_H_ 23 | 24 | #include "StringImp.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | class Charset{ 32 | //MariaDbCharset native; 33 | SQLString csName; 34 | Charset(const Charset&)=delete; 35 | void operator=(Charset &)=delete; 36 | public: 37 | Charset() {} 38 | Charset(const SQLString& name); 39 | ~Charset(); 40 | }; 41 | 42 | namespace StandardCharsets 43 | { 44 | extern const Charset UTF_8; 45 | }; 46 | 47 | } 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/logger/LoggerFactory.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _LOGGERFACTORY_H_ 22 | #define _LOGGERFACTORY_H_ 23 | 24 | #include 25 | 26 | #include "Logger.h" 27 | #include "Consts.h" 28 | 29 | namespace sql 30 | { 31 | namespace mariadb 32 | { 33 | class LoggerFactory 34 | { 35 | static std::shared_ptr NO_LOGGER; 36 | static bool hasToLog; 37 | static bool initLoggersIfNeeded(); 38 | public: 39 | static void init(bool mustLog); 40 | static Shared::Logger getLogger(const std::type_info &typeId); 41 | }; 42 | } 43 | } 44 | #endif -------------------------------------------------------------------------------- /src/options/DriverPropertyInfo.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020, 2022 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _DRIVERPROPERTYINFO_H_ 21 | #define _DRIVERPROPERTYINFO_H_ 22 | namespace sql 23 | { 24 | namespace mariadb 25 | { 26 | struct DriverPropertyInfo { 27 | std::vector choices; 28 | SQLString description; 29 | SQLString name; 30 | SQLString value; 31 | bool required; 32 | DriverPropertyInfo(const SQLString& Name, const SQLString& Value) : name(Name), value(Value), required(false) {} 33 | }; 34 | } 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /src/Dll.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2013,2019 MariaDB Corporation AB 3 | This library is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU Library General Public 5 | License as published by the Free Software Foundation; either 6 | version 2.1 of the License, or (at your option) any later version. 7 | This library is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | Library General Public License for more details. 11 | You should have received a copy of the GNU Library General Public 12 | License along with this library; if not see 13 | or write to the Free Software Foundation, Inc., 14 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 15 | *************************************************************************************/ 16 | #include 17 | 18 | #include "mysql.h" 19 | 20 | BOOL __stdcall DllMain ( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) 21 | { 22 | switch (fdwReason) { 23 | case DLL_PROCESS_ATTACH: 24 | mysql_library_init(0, NULL, NULL); 25 | break; 26 | case DLL_PROCESS_DETACH: 27 | mysql_library_end(); 28 | break; 29 | case DLL_THREAD_ATTACH: 30 | mysql_thread_init(); 31 | break; 32 | case DLL_THREAD_DETACH: 33 | mysql_thread_end(); 34 | break; 35 | } 36 | return TRUE; 37 | } 38 | -------------------------------------------------------------------------------- /src/MariaDbSavepoint.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _MARIADBSAVEPOINT_H_ 22 | #define _MARIADBSAVEPOINT_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | class MariaDbSavepoint : public Savepoint { 32 | 33 | int32_t savepointId; 34 | const SQLString name; 35 | 36 | public: 37 | MariaDbSavepoint(const SQLString& name,int32_t savepointId); 38 | int32_t getSavepointId() const; 39 | const SQLString& getSavepointName() const; 40 | SQLString toString() const; 41 | }; 42 | 43 | } 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /cmake/ConnectorName.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2022 MariaDB Corporation AB 3 | # 4 | # Redistribution and use is allowed according to the terms of the New 5 | # BSD license. 6 | # For details see the COPYING-CMAKE-SCRIPTS file. 7 | # 8 | MACRO(GET_CONNECTOR_PACKAGE_NAME name base_name) 9 | # check if we have 64bit 10 | IF(SIZEOF_VOIDP EQUAL 8) 11 | SET(IS64 1) 12 | ENDIF() 13 | 14 | SET (PLATFORM_NAME ${SYSTEM_NAME}) 15 | SET (MACHINE_NAME ${CMAKE_SYSTEM_PROCESSOR}) 16 | SET (CONCAT_SIGN "-") 17 | 18 | IF(CMAKE_SYSTEM_NAME MATCHES "Windows") 19 | SET(PLATFORM_NAME "win") 20 | SET(CONCAT_SIGN "") 21 | IF(IS64) 22 | IF(CMAKE_C_COMPILER_ARCHITECTURE_ID) 23 | STRING(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MACHINE_NAME) 24 | ELSE() 25 | SET(MACHINE_NAME x64) 26 | ENDIF() 27 | ELSE() 28 | SET(MACHINE_NAME "32") 29 | ENDIF() 30 | ENDIF() 31 | 32 | # Get revision number 33 | IF(WITH_REVNO) 34 | EXECUTE_PROCESS(COMMAND git log -n 1 --pretty="%h" 35 | OUTPUT_VARIABLE revno) 36 | STRING(REPLACE "\n" "" revno ${revno}) 37 | ENDIF() 38 | 39 | IF(${revno}) 40 | SET(product_name "${base_name}-${CPACK_PACKAGE_VERSION}-r${revno}-${PLATFORM_NAME}${CONCAT_SIGN}${MACHINE_NAME}") 41 | ELSE() 42 | IF(PACKAGE_PLATFORM_SUFFIX) 43 | SET(product_name "${base_name}-${CPACK_PACKAGE_VERSION}${QUALITY_SUFFIX}-${PACKAGE_PLATFORM_SUFFIX}") 44 | ELSE() 45 | SET(product_name "${base_name}-${CPACK_PACKAGE_VERSION}${QUALITY_SUFFIX}-${PLATFORM_NAME}${CONCAT_SIGN}${MACHINE_NAME}") 46 | ENDIF() 47 | ENDIF() 48 | 49 | STRING(TOLOWER ${product_name} ${name}) 50 | ENDMACRO() 51 | -------------------------------------------------------------------------------- /src/io/SocketHandlerFunction.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SOCKETHANDLERFUNCTION_H_ 22 | #define _SOCKETHANDLERFUNCTION_H_ 23 | 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | 29 | class Socket; 30 | 31 | class SocketHandlerFunction 32 | { 33 | SocketHandlerFunction(const SocketHandlerFunction &); 34 | void operator=(SocketHandlerFunction &); 35 | 36 | public: 37 | SocketHandlerFunction() {} 38 | virtual ~SocketHandlerFunction(){} 39 | 40 | virtual Socket* apply(Shared::Options &options, const SQLString& host)=0; 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/credential/CredentialPluginLoader.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CREDENTIALPLUGINLOADER_H_ 22 | #define _CREDENTIALPLUGINLOADER_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "CredentialPlugin.h" 29 | 30 | namespace sql 31 | { 32 | namespace mariadb 33 | { 34 | class CredentialPluginLoader 35 | { 36 | static std::map> plugin; 37 | public: 38 | static void RegisterPlugin(CredentialPlugin *aplugin); 39 | static std::shared_ptr get(const std::string& type); 40 | }; 41 | } 42 | } 43 | #endif -------------------------------------------------------------------------------- /src/credential/Credential.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "Credential.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | Credential::Credential(const SQLString& user, const SQLString& password) 29 | : user(user) 30 | , password(password) 31 | { 32 | } 33 | 34 | const SQLString& Credential::getUser() const 35 | { 36 | return user; 37 | } 38 | 39 | void Credential::setUser(const SQLString& _user) 40 | { 41 | this->user= _user; 42 | } 43 | 44 | const SQLString& Credential::getPassword() const 45 | { 46 | return password; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/util/ServerStatus.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SERVERSTATUS_H_ 22 | #define _SERVERSTATUS_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | enum ServerStatus 32 | { 33 | IN_TRANSACTION= 1, 34 | AUTOCOMMIT= 2, 35 | MORE_RESULTS_EXISTS= 8, 36 | QUERY_NO_GOOD_INDEX_USED= 16, 37 | QUERY_NO_INDEX_USED= 32, 38 | CURSOR_EXISTS= 64, 39 | LAST_ROW_SENT= 128, 40 | DB_DROPPED= 256, 41 | NO_BACKSLASH_ESCAPES= 512, 42 | METADATA_CHANGED= 1024, 43 | QUERY_WAS_SLOW= 2048, 44 | PS_OUT_PARAMETERS= 4096, 45 | SERVER_SESSION_STATE_CHANGED_= 1 << 14 46 | }; 47 | 48 | } 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/StringImp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _STRINGIMP_H_ 21 | #define _STRINGIMP_H_ 22 | 23 | #include 24 | 25 | #include "SQLString.hpp" 26 | 27 | namespace sql 28 | { 29 | class StringImp 30 | { 31 | std::string realStr; 32 | 33 | public: 34 | static std::string& get(SQLString& str); 35 | static const std::string& get(const SQLString& str); 36 | 37 | StringImp(const char* str); 38 | StringImp(const char* str, std::size_t count); 39 | StringImp()=default; //or delete? 40 | ~StringImp()=default; 41 | 42 | std::string* operator ->() { return &realStr; } 43 | 44 | std::string& get() { return realStr; } 45 | }; 46 | 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /include/conncpp/Warning.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _WARNING_H_ 22 | #define _WARNING_H_ 23 | 24 | #include "SQLString.hpp" 25 | 26 | namespace sql 27 | { 28 | class SQLWarning 29 | { 30 | SQLWarning(const SQLWarning&)= delete; 31 | SQLWarning & operator=(const SQLWarning &)= delete; 32 | 33 | public: 34 | SQLWarning() {} 35 | virtual ~SQLWarning(){} 36 | virtual SQLWarning* getNextWarning() const=0; 37 | virtual void setNextWarning(const SQLWarning* nextWarning)=0; 38 | virtual const SQLString& getSQLState() const=0; 39 | virtual int32_t getErrorCode() const=0; 40 | virtual const SQLString& getMessage() const=0; 41 | }; 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /src/com/ColumnNameMap.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _COLUMNNAMEMAP_H_ 22 | #define _COLUMNNAMEMAP_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | class ColumnDefinition; 31 | 32 | class ColumnNameMap 33 | { 34 | std::vector* columnInfo; 35 | std::maporiginalMap; 36 | std::mapaliasMap; 37 | 38 | public: 39 | ColumnNameMap() : columnInfo(nullptr) {} 40 | ColumnNameMap(std::vector& columnInformations); 41 | void init(std::vector& columnInformations); 42 | int32_t getIndex(const SQLString& name); 43 | }; 44 | 45 | } 46 | } 47 | #endif -------------------------------------------------------------------------------- /cmake/build_depends.cmake: -------------------------------------------------------------------------------- 1 | IF(RPM) 2 | MACRO(FIND_DEP V) 3 | SET(out ${V}_DEP) 4 | IF (NOT DEFINED ${out}) 5 | IF(EXISTS ${${V}} AND NOT IS_DIRECTORY ${${V}}) 6 | EXECUTE_PROCESS(COMMAND ${ARGN} RESULT_VARIABLE res OUTPUT_VARIABLE O OUTPUT_STRIP_TRAILING_WHITESPACE) 7 | ELSE() 8 | SET(res 1) 9 | ENDIF() 10 | IF (res) 11 | SET(O) 12 | ELSE() 13 | MESSAGE(STATUS "Need ${O} for ${${V}}") 14 | ENDIF() 15 | SET(${out} ${O} CACHE INTERNAL "Package that contains ${${V}}" FORCE) 16 | ENDIF() 17 | ENDMACRO() 18 | 19 | # FindBoost.cmake doesn't leave any trace, do it here 20 | IF (Boost_INCLUDE_DIR) 21 | FIND_FILE(Boost_config_hpp boost/config.hpp PATHS ${Boost_INCLUDE_DIR}) 22 | ENDIF() 23 | 24 | GET_CMAKE_PROPERTY(ALL_VARS CACHE_VARIABLES) 25 | FOREACH (V ${ALL_VARS}) 26 | GET_PROPERTY(H CACHE ${V} PROPERTY HELPSTRING) 27 | IF (H MATCHES "^Have library [^/]" AND ${V}) 28 | STRING(REGEX REPLACE "^Have library " "" L ${H}) 29 | SET(V ${L}_LIBRARY) 30 | FIND_LIBRARY(${V} ${L}) 31 | ENDIF() 32 | GET_PROPERTY(T CACHE ${V} PROPERTY TYPE) 33 | IF ((T STREQUAL FILEPATH OR V MATCHES "^CMAKE_COMMAND$") AND ${V} MATCHES "^/") 34 | IF (RPM) 35 | FIND_DEP(${V} rpm -q --qf "%{NAME}" -f ${${V}}) 36 | ELSE() # must be DEB 37 | MESSAGE(FATAL_ERROR "Not implemented") 38 | ENDIF () 39 | SET(BUILD_DEPS ${BUILD_DEPS} ${${V}_DEP}) 40 | ENDIF() 41 | ENDFOREACH() 42 | IF (BUILD_DEPS) 43 | SET(BUILD_DEPS "${CPACK_RPM_BUILDREQUIRES}" "${BUILD_DEPS}") 44 | LIST(REMOVE_DUPLICATES BUILD_DEPS) 45 | STRING(REPLACE ";" " " CPACK_RPM_BUILDREQUIRES "${BUILD_DEPS}") 46 | ENDIF() 47 | ENDIF(RPM) 48 | -------------------------------------------------------------------------------- /src/logger/NoLogger.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020, 2021 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _NOLOGGER_H_ 21 | #define _NOLOGGER_H_ 22 | 23 | #include "Logger.h" 24 | 25 | namespace sql 26 | { 27 | namespace mariadb 28 | { 29 | struct NoLogger : public Logger { 30 | bool isTraceEnabled(); 31 | void trace(const SQLString& msg); 32 | bool isDebugEnabled(); 33 | void debug(const SQLString& msg); 34 | void debug(const SQLString& msg, std::exception& e); 35 | bool isInfoEnabled(); 36 | void info(const SQLString& msg); 37 | bool isWarnEnabled(); 38 | void warn(const SQLString& msg); 39 | bool isErrorEnabled(); 40 | void error(const SQLString& msg); 41 | void error(const SQLString& msg, SQLException& e); 42 | void error(const SQLString& msg, MariaDBExceptionThrower& e); 43 | }; 44 | } 45 | } 46 | #endif -------------------------------------------------------------------------------- /include/conncpp.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef __CONNCPP_H_ 22 | #define __CONNCPP_H_ 23 | 24 | #include "conncpp/Driver.hpp" 25 | #include "conncpp/DriverManager.hpp" 26 | #include "conncpp/Connection.hpp" 27 | #include "conncpp/ResultSet.hpp" 28 | #include "conncpp/DatabaseMetaData.hpp" 29 | #include "conncpp/ResultSetMetaData.hpp" 30 | #include "conncpp/Statement.hpp" 31 | #include "conncpp/PreparedStatement.hpp" 32 | #include "conncpp/ParameterMetaData.hpp" 33 | #include "conncpp/CallableStatement.hpp" 34 | #include "conncpp/Warning.hpp" 35 | #include "conncpp/Savepoint.hpp" 36 | #include "conncpp/Types.hpp" 37 | 38 | #include "conncpp/SQLString.hpp" 39 | #include "conncpp/Exception.hpp" 40 | #include "conncpp/jdbccompat.hpp" 41 | 42 | namespace sql 43 | { 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /src/cache/CallableStatementCacheKey.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "CallableStatementCacheKey.h" 22 | #include "Consts.h" 23 | 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | 29 | CallableStatementCacheKey::CallableStatementCacheKey(const SQLString& db, const SQLString& q) : 30 | database(db.c_str(), db.length()), query(q.c_str(), q.length()) 31 | { 32 | } 33 | 34 | size_t CallableStatementCacheKey::hashCode() const 35 | { 36 | return std::hash()(database) ^ (std::hash()(query) << 1); 37 | } 38 | 39 | 40 | bool CallableStatementCacheKey::operator==(const CallableStatementCacheKey &other) const 41 | { 42 | return database.compare(other.database) == 0 &&query.compare(other.query) == 0; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/parameters/OffsetTimeParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _OFFSETTIMEPARAMETER_H_ 22 | #define _OFFSETTIMEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class OffsetTimeParameter : public ParameterHolder { 33 | 34 | OffsetTime time; 35 | bool fractionalSeconds; 36 | 37 | public: 38 | OffsetTimeParameter( OffsetTime offsetTime,ZoneId serverZoneId,bool fractionalSeconds,Shared::Options options); 39 | void writeTo(PacketOutputStream& pos); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | const ColumnType& getColumnType(); 43 | SQLString toString(); 44 | bool isNullData(); 45 | bool isLongData(); 46 | }; 47 | } 48 | } 49 | #endif -------------------------------------------------------------------------------- /src/io/PacketInputStream.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _PacketInputStream_H_ 22 | #define _PacketInputStream_H_ 23 | 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | 29 | class PacketInputStream { 30 | PacketInputStream(const PacketInputStream &); 31 | void operator=(PacketInputStream &); 32 | 33 | public: 34 | 35 | PacketInputStream() {} 36 | virtual ~PacketInputStream(){} 37 | 38 | // virtual Buffer getPacket(bool reUsable)=0; 39 | virtual sql::bytes getPacketArray(bool reUsable)=0; 40 | virtual int32_t getLastPacketSeq()=0; 41 | virtual int32_t getCompressLastPacketSeq()=0; 42 | virtual void close()=0; 43 | virtual void setServerThreadId(int64_t serverThreadId, bool isMaster)=0; 44 | // virtual void setTraceCache(LruTraceCache traceCache)=0; 45 | }; 46 | 47 | } 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/parameters/ZonedDateTimeParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _ZONEDDATETIMEPARAMETER_H_ 22 | #define _ZONEDDATETIMEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class ZonedDateTimeParameter : public ParameterHolder { 34 | 35 | //const ZonedDateTime tz; 36 | bool fractionalSeconds; 37 | 38 | public: 39 | ZonedDateTimeParameter( ZonedDateTime tz,ZoneId serverZoneId,bool fractionalSeconds,Shared::Options options); 40 | void writeTo(PacketOutputStream& pos); 41 | int64_t getApproximateTextProtocolLength(); 42 | void writeBinary(PacketOutputStream& pos); 43 | const ColumnType& getColumnType(); 44 | SQLString toString(); 45 | bool isNullData(); 46 | bool isLongData(); 47 | }; 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Building the Connector/C++ 2 | 3 | Following are build instructions for various operating systems. In order to build you will need compiler 4 | supporting C++11 standard. 5 | 6 | ## Windows 7 | 8 | Prior to start building on Windows you need to have following tools installed: 9 | - Microsoft Visual Studio https://visualstudio.microsoft.com/downloads/ 10 | - Git https://git-scm.com/download/win 11 | - cmake https://cmake.org/download/ 12 | - WiX Toolset https://wixtoolset.org/releases/ 13 | 14 | ``` 15 | git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git 16 | cd mariadb-connector-cpp 17 | cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off -DCONC_WITH_MSI=OFF -DWITH_SSL=SCHANNEL . 18 | cmake --build . --config RelWithDebInfo 19 | msiexec.exe /i wininstall\mariadb-connector-cpp-0.9.1-win32.msi 20 | ``` 21 | Please mind msi file name - it's will be different depending on current connector version, and also architecture suffix may be different 22 | 23 | ## CentOS 24 | 25 | ``` 26 | sudo yum -y install git cmake make gcc openssl-devel 27 | git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git 28 | mkdir build && cd build 29 | cmake ../mariadb-connector-cpp/ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_SSL=OPENSSL 30 | cmake --build . --config RelWithDebInfo 31 | sudo make install 32 | ``` 33 | 34 | ## Debian & Ubuntu 35 | 36 | ``` 37 | sudo apt-get update 38 | sudo sh apt-get install -y git cmake make gcc libssl-dev 39 | git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git 40 | mkdir build && cd build 41 | cmake ../mariadb-connector-cpp/ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_SSL=OPENSSL 42 | cmake --build . --config RelWithDebInfo 43 | sudo make install 44 | ``` 45 | -------------------------------------------------------------------------------- /include/conncpp/buildconf.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020, 2023 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _BUILDCONF_H_ 21 | #define _BUILDCONF_H_ 22 | 23 | #if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__) 24 | # ifdef MARIADB_STATIC_LINK 25 | # ifdef MARIADB_EXTERN 26 | # undef MARIADB_EXTERN 27 | # endif 28 | # define MARIADB_EXTERN extern 29 | # ifdef MARIADB_EXPORTED 30 | # undef MARIADB_EXPORTED 31 | # endif 32 | # define MARIADB_EXPORTED 33 | # else 34 | # ifndef MARIADB_EXPORTED 35 | # define MARIADB_EXPORTED __declspec(dllimport) 36 | # define MARIADB_EXTERN extern 37 | # else 38 | # ifndef MARIADB_EXTERN 39 | # define MARIADB_EXTERN 40 | # endif 41 | # endif 42 | # endif 43 | #else 44 | # ifndef MARIADB_EXPORTED 45 | # define MARIADB_EXPORTED 46 | # endif 47 | # define MARIADB_EXTERN extern 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/parameters/BooleanParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _BOOLEANPARAMETER_H_ 22 | #define _BOOLEANPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class BooleanParameter : public ParameterHolder { 34 | 35 | bool value; 36 | 37 | public: 38 | BooleanParameter(bool value); 39 | void writeTo(PacketOutputStream& os); 40 | void writeTo(SQLString& str); 41 | int64_t getApproximateTextProtocolLength(); 42 | void writeBinary(PacketOutputStream& pos); 43 | uint32_t writeBinary(sql::bytes& buffer); 44 | const ColumnType& getColumnType() const; 45 | SQLString toString(); 46 | bool isNullData() const; 47 | bool isLongData(); 48 | void* getValuePtr(); 49 | unsigned long getValueBinLen() const { return 1; } 50 | }; 51 | } 52 | } 53 | #endif -------------------------------------------------------------------------------- /src/cache/CallableStatementCacheKey.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CALLABLESTATEMENTCACHEKEY_H_ 22 | #define _CALLABLESTATEMENTCACHEKEY_H_ 23 | 24 | #include "StringImp.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | class CallableStatementCacheKey 32 | { 33 | const std::string database; 34 | const std::string query; 35 | 36 | public: 37 | CallableStatementCacheKey(const SQLString& database, const SQLString& query); 38 | size_t hashCode() const; 39 | bool operator== (const CallableStatementCacheKey& other) const; 40 | }; 41 | 42 | } 43 | } 44 | 45 | namespace std 46 | { 47 | template <> 48 | struct hash 49 | { 50 | std::size_t operator()(const sql::mariadb::CallableStatementCacheKey& key) const 51 | { 52 | return key.hashCode(); 53 | } 54 | }; 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/SimpleParameterMetaData.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2021 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _SIMPLEPARAMETERMETADATA_H_ 21 | #define _SIMPLEPARAMETERMETADATA_H_ 22 | 23 | #include "Consts.h" 24 | 25 | namespace sql 26 | { 27 | namespace mariadb 28 | { 29 | 30 | class SimpleParameterMetaData : public ParameterMetaData 31 | { 32 | uint32_t parameterCount; 33 | void validateParameter(uint32_t param); 34 | 35 | public: 36 | SimpleParameterMetaData(uint32_t parameterCount); 37 | uint32_t getParameterCount(); 38 | int32_t isNullable(uint32_t param); 39 | bool isSigned(uint32_t param); 40 | int32_t getPrecision(uint32_t param); 41 | int32_t getScale(uint32_t param); 42 | int32_t getParameterType(uint32_t param); 43 | SQLString getParameterTypeName(uint32_t param); 44 | SQLString getParameterClassName(uint32_t param); 45 | int32_t getParameterMode(uint32_t param); 46 | }; 47 | } 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/parameters/SerializableParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SERIALIZABLEPARAMETER_H_ 22 | #define _SERIALIZABLEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class SerializableParameter : public ParameterHolder { 33 | 34 | bool noBackSlashEscapes; 35 | Object object; 36 | sql::bytes loadedStream ; /*NULL*/ 37 | 38 | public: 39 | SerializableParameter( const sql::Object&object,bool noBackslashEscapes); 40 | void writeTo(PacketOutputStream& pos); 41 | 42 | private: 43 | void writeObjectToBytes(); 44 | 45 | public: 46 | int64_t getApproximateTextProtocolLength(); 47 | void writeBinary(PacketOutputStream& pos); 48 | SQLString toString(); 49 | const ColumnType& getColumnType(); 50 | bool isNullData(); 51 | bool isLongData(); 52 | }; 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/parameters/IntParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _INTPARAMETER_H_ 22 | #define _INTPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class IntParameter : public ParameterHolder { 34 | 35 | int32_t value; 36 | 37 | public: 38 | IntParameter(int32_t value); 39 | void writeTo(SQLString& str); 40 | void writeTo(PacketOutputStream& str); 41 | int64_t getApproximateTextProtocolLength(); 42 | void writeBinary(PacketOutputStream& pos); 43 | uint32_t writeBinary(sql::bytes& buffer); 44 | const ColumnType& getColumnType() const; 45 | SQLString toString(); 46 | bool isNullData() const; 47 | bool isLongData(); 48 | void* getValuePtr() { return static_cast(&value); } 49 | unsigned long getValueBinLen() const { return sizeof(value); } 50 | }; 51 | } 52 | } 53 | #endif -------------------------------------------------------------------------------- /src/parameters/ShortParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SHORTPARAMETER_H_ 22 | #define _SHORTPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class ShortParameter : public ParameterHolder { 33 | 34 | int16_t value; 35 | 36 | public: 37 | ShortParameter(int16_t value); 38 | void writeTo(SQLString& str); 39 | void writeTo(PacketOutputStream& str); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | uint32_t writeBinary(sql::bytes& buffer); 43 | const ColumnType& getColumnType() const; 44 | SQLString toString(); 45 | bool isNullData() const; 46 | bool isLongData(); 47 | void* getValuePtr() { return static_cast(&value); } 48 | virtual unsigned long getValueBinLen() const { return 2; } 49 | }; 50 | } 51 | } 52 | #endif -------------------------------------------------------------------------------- /src/parameters/BigDecimalParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _BIGDECIMALPARAMETER_H_ 22 | #define _BIGDECIMALPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class BigDecimalParameter : public ParameterHolder { 34 | 35 | const BigDecimal bigDecimal; 36 | 37 | public: 38 | BigDecimalParameter(const BigDecimal& bigDecimal); 39 | void writeTo(PacketOutputStream& pos); 40 | void writeTo(SQLString& str); 41 | int64_t getApproximateTextProtocolLength(); 42 | void writeBinary(PacketOutputStream& pos); 43 | uint32_t writeBinary(sql::bytes& buffer); 44 | const ColumnType& getColumnType() const; 45 | SQLString toString(); 46 | bool isNullData() const; 47 | bool isLongData(); 48 | void* getValuePtr(); 49 | unsigned long getValueBinLen() const; 50 | }; 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/parameters/FloatParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _FLOATPARAMETER_H_ 22 | #define _FLOATPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class FloatParameter : public ParameterHolder { 33 | 34 | float value; 35 | 36 | public: 37 | FloatParameter(float value); 38 | void writeTo(SQLString& str); 39 | void writeTo(PacketOutputStream& str); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | uint32_t writeBinary(sql::bytes& buffer); 43 | const ColumnType& getColumnType() const; 44 | SQLString toString(); 45 | bool isNullData() const; 46 | bool isLongData(); 47 | void* getValuePtr() { return static_cast(&value); } 48 | unsigned long getValueBinLen() const { return sizeof(value); } 49 | }; 50 | } 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /src/parameters/LongParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _LONGPARAMETER_H_ 22 | #define _LONGPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class LongParameter : public ParameterHolder { 33 | 34 | int64_t value; 35 | 36 | public: 37 | LongParameter(int64_t value); 38 | void writeTo(SQLString& str); 39 | void writeTo(PacketOutputStream& str); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | uint32_t writeBinary(sql::bytes& buffer); 43 | const ColumnType& getColumnType() const; 44 | SQLString toString(); 45 | bool isNullData() const; 46 | bool isLongData(); 47 | void* getValuePtr() { return static_cast(&value); } 48 | unsigned long getValueBinLen() const { return sizeof(value); } 49 | }; 50 | } 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /src/parameters/DefaultParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020,2023 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _DEFAULTPARAMETER_H_ 22 | #define _DEFAULTPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class DefaultParameter : public ParameterHolder { 33 | 34 | static const char* defaultBytes ; /*"DEFAULT"*/ 35 | 36 | public: 37 | void writeTo(SQLString& str); 38 | void writeTo(PacketOutputStream& str); 39 | int64_t getApproximateTextProtocolLength(); 40 | void writeBinary(PacketOutputStream& pos); 41 | uint32_t writeBinary(sql::bytes& /*buffer*/) { return getValueBinLen(); } 42 | const ColumnType& getColumnType() const; 43 | SQLString toString(); 44 | bool isNullData() const; 45 | bool isLongData(); 46 | void* getValuePtr() { return nullptr; } 47 | unsigned long getValueBinLen() const { return 0; } 48 | }; 49 | } 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /src/parameters/DoubleParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020,2021 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _DOUBLEPARAMETER_H_ 22 | #define _DOUBLEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class DoubleParameter : public ParameterHolder { 33 | 34 | double value; 35 | 36 | public: 37 | DoubleParameter(long double value); 38 | void writeTo(SQLString& str); 39 | void writeTo(PacketOutputStream& str); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | uint32_t writeBinary(sql::bytes& buffer); 43 | const ColumnType& getColumnType() const; 44 | SQLString toString(); 45 | bool isNullData() const; 46 | bool isLongData(); 47 | void* getValuePtr() { return static_cast(&value); } 48 | unsigned long getValueBinLen() const { return sizeof(value); } 49 | }; 50 | } 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /src/parameters/LocalTimeParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _LOCALTIMEPARAMETER_H_ 22 | #define _LOCALTIMEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | typedef Time LocalTime; 34 | 35 | class LocalTimeParameter : public ParameterHolder { 36 | 37 | const LocalTime time; 38 | bool fractionalSeconds; 39 | 40 | public: 41 | LocalTimeParameter(const LocalTime& time,bool fractionalSeconds); 42 | void writeTo(SQLString& str); 43 | void writeTo(PacketOutputStream& str); 44 | int64_t getApproximateTextProtocolLength(); 45 | void writeBinary(PacketOutputStream& pos); 46 | const ColumnType& getColumnType() const; 47 | SQLString toString(); 48 | bool isNullData() const; 49 | bool isLongData(); 50 | const void* getValuePtr() const; 51 | unsigned long getValueBinLen() const; 52 | }; 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/parameters/ReaderParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _READERPARAMETER_H_ 22 | #define _READERPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class ReaderParameter : public ParameterHolder { 33 | 34 | std::istream& reader; 35 | const int64_t length; 36 | bool noBackslashEscapes; 37 | 38 | public: 39 | ReaderParameter(std::istream& reader,int64_t length,bool noBackslashEscapes); 40 | ReaderParameter(std::istream& reader,bool noBackslashEscapes); 41 | void writeTo(SQLString& str); 42 | void writeTo(PacketOutputStream& str); 43 | int64_t getApproximateTextProtocolLength(); 44 | uint32_t writeBinary(sql::bytes& buffer); 45 | void writeBinary(PacketOutputStream& pos); 46 | const ColumnType& getColumnType() const; 47 | SQLString toString(); 48 | bool isNullData() const; 49 | bool isLongData(); 50 | }; 51 | } 52 | } 53 | #endif -------------------------------------------------------------------------------- /src/parameters/ULongParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _ULONGPARAMETER_H_ 22 | #define _ULONGPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class ULongParameter : public ParameterHolder { 33 | 34 | uint64_t value; 35 | 36 | public: 37 | ULongParameter(uint64_t value); 38 | void writeTo(SQLString& str); 39 | void writeTo(PacketOutputStream& str); 40 | int64_t getApproximateTextProtocolLength(); 41 | void writeBinary(PacketOutputStream& pos); 42 | uint32_t writeBinary(sql::bytes& buffer); 43 | const ColumnType& getColumnType() const; 44 | SQLString toString(); 45 | bool isNullData() const; 46 | bool isLongData(); 47 | void* getValuePtr() { return static_cast(&value); } 48 | unsigned long getValueBinLen() const { return sizeof(value); } 49 | bool isUnsigned() const { return true; } 50 | }; 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /include/conncpp/DriverManager.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _DRIVERMANAGER_H_ 22 | #define _DRIVERMANAGER_H_ 23 | 24 | #include "buildconf.hpp" 25 | #include "SQLString.hpp" 26 | #include "Connection.hpp" 27 | #include "Driver.hpp" 28 | 29 | namespace sql 30 | { 31 | 32 | /* 33 | * Mimimalistic DriverManager manager as the more convenient way to obtain a connection. 34 | * There is no means of registsering etc drivers, as it's unlikely needed. 35 | */ 36 | class MARIADB_EXPORTED DriverManager 37 | { 38 | DriverManager(const DriverManager &); 39 | void operator=(DriverManager&)= delete; 40 | DriverManager() {} 41 | virtual ~DriverManager(){} 42 | public: 43 | 44 | static Connection* getConnection(const SQLString& url); 45 | static Connection* getConnection(const SQLString& url, Properties& props); 46 | static Connection* getConnection(const SQLString& url, const SQLString& user, const SQLString& pwd); 47 | }; 48 | 49 | } 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/parameters/ByteParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _BYTEPARAMETER_H_ 22 | #define _BYTEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class ByteParameter : public ParameterHolder { 34 | 35 | static const std::string hexArray ; /*"0123456789ABCDEF".toCharArray()*/ 36 | int8_t value; 37 | 38 | public: 39 | ByteParameter(int8_t value); 40 | void writeTo(PacketOutputStream& os); 41 | void writeTo(SQLString& os); 42 | int64_t getApproximateTextProtocolLength(); 43 | void writeBinary(PacketOutputStream& pos); 44 | uint32_t writeBinary(sql::bytes& buffer); 45 | const ColumnType& getColumnType() const; 46 | SQLString toString(); 47 | bool isNullData() const; 48 | bool isLongData(); 49 | void* getValuePtr() { return static_cast(&value); } 50 | unsigned long getValueBinLen() const { return 1; } 51 | }; 52 | } 53 | } 54 | #endif -------------------------------------------------------------------------------- /src/Version.h.in: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _VERSION_H_ 22 | #define _VERSION_H_ 23 | 24 | #define MACPP_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 25 | #define MACPP_VERSION_MINOR @PROJECT_VERSION_MINOR@ 26 | #define MACPP_VERSION_PATCH @PROJECT_VERSION_PATCH@ 27 | 28 | #define MACPP_VERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@" 29 | 30 | #define MACPP_VERSION "@MACPP_VERSION@" 31 | 32 | #define MACPP_ERR_PREFIX "[@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@]" 33 | 34 | #define MACPP_DEFAULT_PLUGINS_SUBDIR "plugin" 35 | 36 | namespace sql 37 | { 38 | namespace mariadb 39 | { 40 | 41 | struct Version final { 42 | static const char* version; 43 | static const unsigned int majorVersion= MACPP_VERSION_MAJOR; 44 | static const unsigned int minorVersion= MACPP_VERSION_MINOR; 45 | static const unsigned int patchVersion= MACPP_VERSION_PATCH; 46 | }; 47 | } 48 | } 49 | 50 | #endif /* _Version_h_ */ 51 | -------------------------------------------------------------------------------- /src/MariaDbDriver.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _MARIADBDRIVER_H_ 21 | #define _MARIADBDRIVER_H_ 22 | 23 | #include 24 | #include 25 | 26 | #include "Driver.hpp" 27 | #include "options/DriverPropertyInfo.h" 28 | #include "logger/Logger.h" 29 | 30 | namespace sql 31 | { 32 | namespace mariadb 33 | { 34 | class MariaDbDriver final : public sql::Driver { 35 | public: 36 | Connection* connect(const SQLString& url, Properties& props); 37 | Connection* connect(const SQLString& host, const SQLString& user, const SQLString& pwd); 38 | Connection* connect(const Properties& props); 39 | 40 | bool acceptsURL(const SQLString& url); 41 | std::unique_ptr> getPropertyInfo(SQLString& url, Properties& info); 42 | uint32_t getMajorVersion(); 43 | uint32_t getMinorVersion(); 44 | bool jdbcCompliant(); 45 | const SQLString& getName(); 46 | Logger* getParentLogger(); 47 | }; 48 | } 49 | } 50 | #endif -------------------------------------------------------------------------------- /src/Consts.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #include "Version.h" 21 | #include "Consts.h" 22 | #include "jdbccompat.hpp" 23 | 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | 29 | const char* Version::version= MACPP_VERSION_STR; 30 | const SQLString ParameterConstant::TYPE_MASTER("master"); 31 | const SQLString ParameterConstant::TYPE_SLAVE("slave"); 32 | const SQLString emptyStr(""); 33 | const SQLString localhost("localhost"); 34 | 35 | const char QUOTE= '\''; 36 | const char DBL_QUOTE= '"'; 37 | const char ZERO_BYTE= '\0'; 38 | const char BACKSLASH= '\\'; 39 | 40 | std::map StrHaModeMap={ {"NONE", HaMode::NONE}, 41 | {"AURORA", AURORA}, 42 | {"REPLICATION", REPLICATION}, 43 | {"SEQUENTIAL", SEQUENTIAL}, 44 | {"LOADBALANCE", LOADBALANCE} }; 45 | 46 | const char* HaModeStrMap[]= {"NONE", "AURORA", "REPLICATION", "SEQUENTIAL", "LOADBALANCE"}; 47 | 48 | //int32_t arr[]= {11, 7, 29}; 49 | //sql::chars b(32); 50 | //sql::Ints c(arr, 3); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/parameters/NullParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020,2023 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _NULLPARAMETER_H_ 22 | #define _NULLPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class NullParameter : public ParameterHolder { 33 | 34 | static const char* _NULL ; /*{'N','U','L','L'}*/ 35 | const ColumnType& type; 36 | 37 | public: 38 | NullParameter(); 39 | NullParameter(const ColumnType& type); 40 | void writeTo(SQLString& str); 41 | void writeTo(PacketOutputStream& str); 42 | int64_t getApproximateTextProtocolLength(); 43 | void writeBinary(PacketOutputStream& pos); 44 | uint32_t writeBinary(sql::bytes& /*buffer*/) { return 0; } 45 | const ColumnType& getColumnType() const; 46 | SQLString toString(); 47 | bool isNullData() const; 48 | bool isLongData(); 49 | void* getValuePtr() { return nullptr; } 50 | unsigned long getValueBinLen() const { return 0; } 51 | }; 52 | } 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /include/conncpp/Types.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _MARIADB_TYPES_H_ 22 | #define _MARIADB_TYPES_H_ 23 | 24 | namespace sql 25 | { 26 | 27 | enum Types { 28 | ARRAY= 1, 29 | BIGINT, 30 | BINARY, 31 | BIT, 32 | BLOB, 33 | BOOLEAN, 34 | CHAR, 35 | CLOB, 36 | DATALINK, 37 | DATE, //10 38 | DECIMAL, 39 | DISTINCT, 40 | DOUBLE, 41 | FLOAT, 42 | INTEGER, 43 | JAVA_OBJECT, 44 | LONGNVARCHAR, 45 | LONGVARBINARY, 46 | LONGVARCHAR, 47 | NCHAR, //20 48 | NCLOB, 49 | _NULL, 50 | SQLNULL= _NULL, 51 | NUMERIC, 52 | NVARCHAR, 53 | OTHER, 54 | REAL, 55 | REF, 56 | REF_CURSOR, 57 | ROWID, 58 | SMALLINT, //30 59 | _SQLXML, // Clash with class name 60 | STRUCT, 61 | TIME, 62 | TIME_WITH_TIMEZONE, 63 | TIMESTAMP, 64 | TIMESTAMP_WITH_TIMEZONE, 65 | TINYINT, 66 | VARBINARY, 67 | VARCHAR 68 | }; 69 | 70 | typedef enum Types DataType; 71 | } 72 | #endif 73 | -------------------------------------------------------------------------------- /src/parameters/ByteArrayParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _BYTEARRAYPARAMETER_H_ 22 | #define _BYTEARRAYPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | 34 | class ByteArrayParameter : public ParameterHolder { 35 | 36 | sql::bytes bytes; 37 | bool noBackslashEscapes; 38 | 39 | public: 40 | ByteArrayParameter(const sql::bytes &bytes, bool noBackslashEscapes); 41 | void writeTo(SQLString& str); 42 | void writeTo(PacketOutputStream& str); 43 | int64_t getApproximateTextProtocolLength(); 44 | void writeBinary(PacketOutputStream& pos); 45 | uint32_t writeBinary(sql::bytes& buf); 46 | const ColumnType& getColumnType() const; 47 | SQLString toString(); 48 | bool isNullData() const; 49 | bool isLongData(); 50 | void* getValuePtr() { return static_cast(bytes.arr); } 51 | unsigned long getValueBinLen() const { return static_cast(bytes.size()); } 52 | }; 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/CallableParameterMetaData.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CALLABLEPARAMETERMETADATA_H_ 22 | #define _CALLABLEPARAMETERMETADATA_H_ 23 | 24 | #include "CallParameter.h" 25 | #include "Consts.h" 26 | 27 | namespace sql 28 | { 29 | namespace mariadb 30 | { 31 | 32 | class CallableParameterMetaData : public ParameterMetaData 33 | { 34 | Unique::ResultSet rs; 35 | uint32_t parameterCount; 36 | bool isFunction; 37 | 38 | void setIndex(uint32_t index); 39 | 40 | public: 41 | CallableParameterMetaData(ResultSet* _rs, bool _isFunction); 42 | 43 | uint32_t getParameterCount(); 44 | int32_t isNullable(uint32_t param); 45 | bool isSigned(uint32_t param); 46 | int32_t getPrecision(uint32_t param); 47 | int32_t getScale(uint32_t param); 48 | SQLString getParameterName(int32_t index); 49 | int32_t getParameterType(uint32_t param); 50 | SQLString getParameterTypeName(uint32_t param); 51 | SQLString getParameterClassName(uint32_t param); 52 | int32_t getParameterMode(uint32_t param); 53 | }; 54 | 55 | } 56 | } 57 | #endif -------------------------------------------------------------------------------- /src/parameters/StreamParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _STREAMPARAMETER_H_ 22 | #define _STREAMPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class StreamParameter : public ParameterHolder { 33 | 34 | std::istream& is; 35 | const int64_t length; 36 | bool noBackslashEscapes; 37 | 38 | public: 39 | StreamParameter(std::istream&is,int64_t length,bool noBackslashEscapes); 40 | StreamParameter(std::istream&is,bool noBackSlashEscapes); 41 | void writeTo(SQLString& str); 42 | void writeTo(PacketOutputStream& str); 43 | int64_t getApproximateTextProtocolLength(); 44 | void writeBinary(PacketOutputStream& pos); 45 | uint32_t writeBinary(sql::bytes& buffer); 46 | SQLString toString(); 47 | const ColumnType& getColumnType() const; 48 | bool isNullData() const; 49 | bool isLongData(); 50 | void* getValuePtr() { return nullptr; } 51 | unsigned long getValueBinLen() const { return 0; } 52 | }; 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/protocol/MasterProtocol.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _MASTERPROTOCOL_H_ 22 | #define _MASTERPROTOCOL_H_ 23 | 24 | #include 25 | #include 26 | 27 | #include "Consts.h" 28 | 29 | #include "protocol/capi/QueryProtocol.h" 30 | #include "HostAddress.h" 31 | 32 | namespace sql 33 | { 34 | namespace mariadb 35 | { 36 | class Listener; 37 | class SearchFilter; 38 | 39 | class MasterProtocol : public capi::QueryProtocol 40 | { 41 | typedef capi::QueryProtocol super; 42 | 43 | static void resetHostList(Listener* listener, std::list& loopAddresses); 44 | static MasterProtocol* getNewProtocol(FailoverProxy* proxy, GlobalStateInfo* globalInfo, std::shared_ptr& urlParser); 45 | 46 | public: 47 | MasterProtocol(std::shared_ptr& urlParser, GlobalStateInfo* globalInfo, Shared::mutex& lock); 48 | static void loop(Listener* listener, GlobalStateInfo& globalInfo, const std::vector& addresses, SearchFilter* searchFilter); 49 | ~MasterProtocol() {} 50 | }; 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/MariaDbConnCpp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef __MARIADBCONNCPP_H_ 22 | #define __MARIADBCONNCPP_H_ 23 | 24 | /* Might be, that we don't really need list */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "conncpp.hpp" 38 | #include "Version.h" 39 | #include "Consts.h" 40 | #include "Protocol.h" 41 | #include "parameters/ParameterHolder.h" 42 | #include "options/Options.h" 43 | #include "options/DefaultOptions.h" 44 | #include "options/DriverPropertyInfo.h" 45 | #include "io/PacketOutputStream.h" 46 | #include "Driver.hpp" 47 | #include "UrlParser.h" 48 | #include "MariaDbDatabaseMetaData.h" 49 | #include "MariaDbConnection.h" 50 | #include "cache/CallableStatementCache.h" 51 | #include "pool/GlobalStateInfo.h" 52 | #include "logger/LoggerFactory.h" 53 | 54 | namespace sql 55 | { 56 | namespace mariadb 57 | { 58 | } 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /src/parameters/StringParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _STRINGPARAMETER_H_ 22 | #define _STRINGPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class StringParameter : public ParameterHolder { 33 | 34 | const SQLString stringValue; 35 | bool noBackslashEscapes; 36 | 37 | public: 38 | StringParameter(const SQLString& str,bool noBackslashEscapes); 39 | void writeTo(SQLString& str); 40 | void writeTo(PacketOutputStream& str); 41 | int64_t getApproximateTextProtocolLength(); 42 | void writeBinary(PacketOutputStream& pos); 43 | uint32_t writeBinary(sql::bytes& buffer); 44 | const ColumnType& getColumnType() const; 45 | SQLString toString(); 46 | bool isNullData() const; 47 | bool isLongData(); 48 | void* getValuePtr() { return const_cast(static_cast(stringValue.c_str())); } 49 | unsigned long getValueBinLen() const { return static_cast(stringValue.length()); } 50 | }; 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /src/parameters/TimestampParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _TIMESTAMPPARAMETER_H_ 22 | #define _TIMESTAMPPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class TimeZone; 33 | 34 | class TimestampParameter : public ParameterHolder { 35 | 36 | const Timestamp ts; 37 | const TimeZone* timeZone; 38 | bool fractionalSeconds; 39 | 40 | public: 41 | TimestampParameter( const Timestamp& ts, const TimeZone* timeZone, bool fractionalSeconds); 42 | void writeTo(SQLString& str); 43 | void writeTo(PacketOutputStream& str); 44 | int64_t getApproximateTextProtocolLength(); 45 | void writeBinary(PacketOutputStream& pos); 46 | uint32_t writeBinary(sql::bytes& buffer); 47 | const ColumnType& getColumnType() const; 48 | SQLString toString(); 49 | bool isNullData() const; 50 | bool isLongData(); 51 | void* getValuePtr(); 52 | unsigned long getValueBinLen() const { return static_cast(ts.length()); } 53 | }; 54 | } 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /src/cache/CallableStatementCache.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "CallableStatementCache.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | CallableStatementCache::CallableStatementCache(int32_t size) : maxSize(size) 28 | { 29 | } 30 | 31 | CallableStatementCache* CallableStatementCache::newInstance(int32_t size) 32 | { 33 | return new CallableStatementCache(size); 34 | } 35 | 36 | CallableStatementCache::iterator CallableStatementCache::find(const CallableStatementCacheKey & key) 37 | { 38 | return Cache.find(key); 39 | } 40 | 41 | void CallableStatementCache::insert(const CallableStatementCacheKey & key, CallableStatement * callable) 42 | { 43 | Shared::CallableStatement sharedCallable(callable); 44 | Cache.emplace(key, sharedCallable); 45 | } 46 | 47 | 48 | /*bool CallableStatementCache::containsKey(const CallableStatementCacheKey & key) 49 | { 50 | return Cahe.find(key) != Cache::end(); 51 | }*/ 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/logger/Logger.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _LOGGER_H_ 22 | #define _LOGGER_H_ 23 | 24 | #include "StringImp.h" 25 | #include "MariaDBException.h" 26 | 27 | namespace sql 28 | { 29 | namespace mariadb 30 | { 31 | struct Logger 32 | { 33 | Logger() {} 34 | virtual ~Logger() {} 35 | virtual bool isTraceEnabled()= 0; 36 | virtual void trace(const SQLString& msg)= 0; 37 | virtual bool isDebugEnabled()= 0; 38 | virtual void debug(const SQLString& msg)= 0; 39 | virtual void debug(const SQLString& msg, std::exception& e)= 0; 40 | virtual bool isInfoEnabled()= 0; 41 | virtual void info(const SQLString& msg)= 0; 42 | virtual bool isWarnEnabled()= 0; 43 | virtual void warn(const SQLString& msg)= 0; 44 | virtual bool isErrorEnabled()= 0; 45 | virtual void error(const SQLString& msg)= 0; 46 | virtual void error(const SQLString& msg, SQLException& e)= 0; 47 | virtual void error(const SQLString& msg, sql::MariaDBExceptionThrower& e)= 0; 48 | 49 | private: 50 | Logger(const Logger &) {} 51 | void operator=(Logger &) {} 52 | }; 53 | 54 | } 55 | } 56 | #endif -------------------------------------------------------------------------------- /src/parameters/ParameterHolder.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _PARAMETERHOLDER_H_ 22 | #define _PARAMETERHOLDER_H_ 23 | 24 | #include "io/PacketOutputStream.h" 25 | #include "ColumnType.h" 26 | 27 | namespace sql 28 | { 29 | namespace mariadb 30 | { 31 | 32 | class ParameterHolder 33 | { 34 | protected: 35 | static char BINARY_INTRODUCER[]; 36 | static char QUOTE; 37 | ParameterHolder()= default; 38 | public: 39 | virtual ~ParameterHolder(); 40 | 41 | virtual void writeTo(PacketOutputStream& os)=0; 42 | virtual void writeTo(SQLString& str)=0; 43 | virtual void writeBinary(PacketOutputStream& pos)=0; 44 | virtual uint32_t writeBinary(sql::bytes& buffer)=0; 45 | virtual int64_t getApproximateTextProtocolLength()=0; 46 | virtual SQLString toString()=0; 47 | virtual bool isNullData() const=0; 48 | virtual const ColumnType& getColumnType() const=0; 49 | virtual bool isLongData()=0; 50 | virtual void* getValuePtr()=0; 51 | virtual unsigned long getValueBinLen() const=0; 52 | virtual bool isUnsigned() const { return false; } 53 | }; 54 | } 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /test/unit/bugs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, as 5 | # published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an 11 | # additional permission to link the program and your derivative works 12 | # with the separately licensed software that they have included with 13 | # MySQL. 14 | # 15 | # Without limiting anything contained in the foregoing, this file, 16 | # which is part of MySQL Connector/C++, is also subject to the 17 | # Universal FOSS Exception, version 1.0, a copy of which can be found at 18 | # http://oss.oracle.com/licenses/universal-foss-exception. 19 | # 20 | # This program is distributed in the hope that it will be useful, but 21 | # WITHOUT ANY WARRANTY; without even the implied warranty of 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | # See the GNU General Public License, version 2.0, for more details. 24 | # 25 | # You should have received a copy of the GNU General Public License 26 | # along with this program; if not, write to the Free Software Foundation, Inc., 27 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | 29 | 30 | SET(bugs_sources 31 | ${test_common_sources} 32 | bugs.cpp) 33 | 34 | IF(WIN32) 35 | SET(bugs_sources 36 | ${bugs_sources} 37 | bugs.h) 38 | 39 | ENDIF(WIN32) 40 | 41 | ADD_EXECUTABLE(unsorted_bugs ${bugs_sources}) 42 | SET_TARGET_PROPERTIES(unsorted_bugs PROPERTIES 43 | OUTPUT_NAME "unsorted_bugs" 44 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test") 45 | TARGET_LINK_LIBRARIES(unsorted_bugs ${PLATFORM_DEPENDENCIES} test_framework ${LIBRARY_NAME} ${MY_GCOV_LINK_LIBRARIES}) 46 | 47 | MESSAGE(STATUS "Configuring bugs test cases - unsorted") 48 | -------------------------------------------------------------------------------- /src/parameters/TimeParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _TIMEPARAMETER_H_ 22 | #define _TIMEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class TimeZone; 33 | 34 | class TimeParameter : public ParameterHolder { 35 | 36 | const Time time; 37 | const TimeZone* timeZone; 38 | bool fractionalSeconds; 39 | 40 | public: 41 | TimeParameter( const Time&time, const TimeZone* timeZone,bool fractionalSeconds); 42 | void writeTo(SQLString& str); 43 | void writeTo(PacketOutputStream& str); 44 | int64_t getApproximateTextProtocolLength(); 45 | void writeBinary(PacketOutputStream& pos); 46 | uint32_t writeBinary(sql::bytes& buffer); 47 | const ColumnType& getColumnType() const; 48 | SQLString toString(); 49 | bool isNullData() const; 50 | bool isLongData(); 51 | void* getValuePtr() { return const_cast(static_cast(time.c_str())); } 52 | unsigned long getValueBinLen() const { return static_cast(time.length()); } 53 | }; 54 | } 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /src/credential/CredentialPlugin.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CREDENTIALPLUGIN_H_ 22 | #define _CREDENTIALPLUGIN_H_ 23 | 24 | #include "HostAddress.h" 25 | #include "Credential.h" 26 | #include "options/Options.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | class CredentialPlugin { 33 | 34 | /* Will later change it to be base abstract class. Using this as a stub so far */ 35 | std::string Name; 36 | std::string Type; 37 | 38 | public: 39 | virtual std::string name() {return Name;}//=0; 40 | virtual std::string type() {return Type;}//=0; 41 | 42 | virtual bool mustUseSsl() 43 | { 44 | return false; 45 | } 46 | 47 | virtual SQLString defaultAuthenticationPluginType() 48 | { 49 | return ""; 50 | } 51 | 52 | virtual CredentialPlugin* initialize(Shared::Options& /*options*/, const SQLString& userName, const HostAddress& /*hostAddress*/) 53 | { 54 | Name= StringImp::get(userName); 55 | 56 | return this; 57 | } 58 | 59 | Credential* get() 60 | { 61 | return new Credential(Name, ""); 62 | } 63 | }; 64 | 65 | } 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /test/CJUnitTestsPort/compliance/UnbufferedRsStmtTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "StatementTest.h" 34 | 35 | 36 | namespace testsuite 37 | { 38 | namespace compliance 39 | { 40 | 41 | // Same testsuite, as Statement test 42 | class UnbufferedRsStmtTest : public StatementTest 43 | { 44 | private: 45 | typedef StatementTest super; 46 | 47 | protected: 48 | 49 | public: 50 | 51 | typedef UnbufferedRsStmtTest TestSuiteClass; 52 | UnbufferedRsStmtTest( const String & name ); 53 | 54 | virtual void setUp(); 55 | 56 | }; 57 | 58 | REGISTER_FIXTURE(UnbufferedRsStmtTest); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/logger/NoLogger.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020, 2021 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "NoLogger.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | bool NoLogger::isTraceEnabled() 28 | { 29 | return false; 30 | } 31 | 32 | void NoLogger::trace(const SQLString& /*msg*/){ 33 | } 34 | 35 | bool NoLogger::isDebugEnabled(){ 36 | return false; 37 | } 38 | 39 | void NoLogger::debug(const SQLString& /*msg*/){ 40 | } 41 | 42 | void NoLogger::debug(const SQLString& /*msg*/, std::exception& /*e*/) 43 | {} 44 | 45 | bool NoLogger::isInfoEnabled(){ 46 | return false; 47 | } 48 | 49 | void NoLogger::info(const SQLString& /*msg*/){ 50 | } 51 | 52 | bool NoLogger::isWarnEnabled(){ 53 | return false; 54 | } 55 | 56 | void NoLogger::warn(const SQLString& /*msg*/){ 57 | } 58 | 59 | bool NoLogger::isErrorEnabled(){ 60 | return false; 61 | } 62 | 63 | void NoLogger::error(const SQLString& /*msg*/){ 64 | } 65 | 66 | void NoLogger::error(const SQLString& /*msg*/, SQLException& /*e*/) { 67 | } 68 | void NoLogger::error(const SQLString& /*msg*/, MariaDBExceptionThrower& /*e*/){ 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/util/LogQueryTool.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _LOGQUERYTOOL_H_ 22 | #define _LOGQUERYTOOL_H_ 23 | 24 | #include "Consts.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | class PrepareResult; 31 | class ParameterHolder; 32 | 33 | class LogQueryTool { 34 | 35 | const Shared::Options options; 36 | 37 | public: 38 | LogQueryTool(const Shared::Options& options); 39 | SQLString subQuery(const SQLString& sql); 40 | 41 | private: 42 | SQLString subQuery(SQLString& buffer); 43 | 44 | public: 45 | SQLException exceptionWithQuery(const SQLString& sql, SQLException& sqlException, bool explicitClosed); 46 | SQLException exceptionWithQuery(SQLString& buffer, SQLException& sqlEx, bool explicitClosed); 47 | SQLException exceptionWithQuery(std::vector& parameters, SQLException& sqlEx, PrepareResult* serverPrepareResult); 48 | SQLException exceptionWithQuery(SQLException& sqlEx, PrepareResult* prepareResult); 49 | 50 | private: 51 | SQLString exWithQuery(const SQLString& message, PrepareResult* serverPrepareResult, std::vector& parameters); 52 | }; 53 | } 54 | } 55 | #endif -------------------------------------------------------------------------------- /src/util/ServerPrepareStatementCache.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SERVERPREPARESTATEMENTCACHE_H_ 22 | #define _SERVERPREPARESTATEMENTCACHE_H_ 23 | 24 | #include 25 | #include 26 | 27 | #include "Consts.h" 28 | 29 | namespace sql 30 | { 31 | namespace mariadb 32 | { 33 | 34 | 35 | class ServerPrepareStatementCache final { 36 | std::mutex lock; 37 | uint32_t maxSize; 38 | const Shared::Protocol protocol; 39 | ServerPrepareStatementCache(uint32_t size, Shared::Protocol& protocol); 40 | std::unordered_map cache; 41 | typedef std::unordered_map::iterator iterator; 42 | public: 43 | typedef std::unordered_map::value_type value_type; 44 | static ServerPrepareStatementCache* newInstance(uint32_t size, Shared::Protocol& protocol); 45 | bool removeEldestEntry(value_type eldest); 46 | /*synchronized*/ ServerPrepareResult* put(const SQLString& key, ServerPrepareResult* result); 47 | /*synchronized*/ ServerPrepareResult* get(const SQLString& key); 48 | SQLString toString(); 49 | }; 50 | } 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /src/MariaDbSavepoint.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "MariaDbSavepoint.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | MariaDbSavepoint::MariaDbSavepoint(const SQLString& _name,int32_t _savepointId) : 29 | savepointId(_savepointId), name(_name) 30 | { 31 | } 32 | 33 | /** 34 | * Retrieves the generated ID for the savepoint that this Savepoint object 35 | * represents. 36 | * 37 | * @return the numeric ID of this savepoint 38 | * @since 1.4 39 | */ 40 | int32_t MariaDbSavepoint::getSavepointId() const { 41 | return savepointId; 42 | } 43 | 44 | /** 45 | * Retrieves the name of the savepoint that this Savepoint object represents. 46 | * 47 | * @return the name of this savepoint 48 | * @since 1.4 49 | */ 50 | const SQLString& MariaDbSavepoint::getSavepointName() const { 51 | return name; 52 | } 53 | 54 | SQLString MariaDbSavepoint::toString() const 55 | { 56 | SQLString res(name); 57 | return res.append(std::to_string(savepointId)); 58 | } 59 | 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Parameters.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | 22 | #ifndef _PARAMETERS_H_ 23 | #define _PARAMETERS_H_ 24 | 25 | #include "parameters/BigDecimalParameter.h" 26 | #include "parameters/BooleanParameter.h" 27 | #include "parameters/ByteArrayParameter.h" 28 | #include "parameters/ByteParameter.h" 29 | #include "parameters/DateParameter.h" 30 | #include "parameters/DefaultParameter.h" 31 | #include "parameters/DoubleParameter.h" 32 | #include "parameters/FloatParameter.h" 33 | #include "parameters/IntParameter.h" 34 | #include "parameters/LocalTimeParameter.h" 35 | #include "parameters/LongParameter.h" 36 | #include "parameters/ULongParameter.h" 37 | #include "parameters/NullParameter.h" 38 | //#include "parameters/OffsetTimeParameter.h" 39 | #include "parameters/ParameterHolder.h" 40 | #include "parameters/ReaderParameter.h" 41 | //#include "parameters/SerializableParameter.h" 42 | #include "parameters/ShortParameter.h" 43 | #include "parameters/StreamParameter.h" 44 | #include "parameters/StringParameter.h" 45 | #include "parameters/TimeParameter.h" 46 | #include "parameters/TimestampParameter.h" 47 | //#include "parameters/ZonedDateTimeParameter.h" 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/cache/CallableStatementCache.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CALLABLESTATEMENTCACHE_H_ 22 | #define _CALLABLESTATEMENTCACHE_H_ 23 | 24 | #include 25 | 26 | #include "CallableStatement.hpp" 27 | 28 | #include "CallableStatementCacheKey.h" 29 | #include "Consts.h" 30 | 31 | namespace sql 32 | { 33 | 34 | namespace mariadb 35 | { 36 | /* TODO: need means max size to enforce */ 37 | class CallableStatementCache 38 | { 39 | int32_t maxSize; 40 | 41 | std::unordered_map Cache; 42 | 43 | CallableStatementCache(int32_t size); 44 | 45 | public: 46 | 47 | typedef std::unordered_map::iterator iterator; 48 | typedef std::unordered_map::const_iterator const_iterator; 49 | 50 | static CallableStatementCache* newInstance(int32_t size); 51 | 52 | iterator find(const CallableStatementCacheKey& key); 53 | iterator end() { return Cache.end(); } 54 | void insert(const CallableStatementCacheKey& key, CallableStatement* callable); 55 | }; 56 | 57 | } 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /src/util/String.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "SQLString.hpp" 27 | 28 | namespace sql 29 | { 30 | 31 | ////////////////////// Standalone SQLString util functions ///////////////////////////// 32 | 33 | namespace mariadb 34 | { 35 | typedef std::unique_ptr> Tokens; 36 | 37 | sql::mariadb::Tokens split(const SQLString& str, const SQLString & delimiter); 38 | 39 | sql::SQLString& replace(SQLString& str, const SQLString& substr, const SQLString& subst); 40 | 41 | sql::SQLString replace(const SQLString& str, const SQLString& substr, const SQLString& substa); 42 | 43 | sql::SQLString& replaceAny(SQLString& str, const SQLString& substr, const SQLString &subst); 44 | 45 | sql::SQLString replaceAny(const SQLString& str, const SQLString& substr, const SQLString &subst); 46 | 47 | bool equalsIgnoreCase(const SQLString& str1, const SQLString& str2); 48 | 49 | uint64_t stoull(const SQLString& str, std::size_t* pos= nullptr); 50 | uint64_t stoull(const char* str, std::size_t len= -1, std::size_t* pos = nullptr); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/unit/classes/art_resultset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "../unit_fixture.h" 34 | 35 | /** 36 | * Test of mysql_art_resultset. 37 | * Actually so far - MyVal from there only 38 | */ 39 | 40 | namespace testsuite 41 | { 42 | namespace classes 43 | { 44 | 45 | class art_resultset : public unit_fixture 46 | { 47 | public: 48 | 49 | EXAMPLE_TEST_FIXTURE(art_resultset) 50 | { 51 | TEST_CASE(testMyVal); 52 | } 53 | 54 | /** 55 | * Test for MyVal interpretation methods 56 | * 57 | */ 58 | void testMyVal(); 59 | 60 | }; 61 | 62 | REGISTER_FIXTURE(art_resultset); 63 | } /* namespace classes */ 64 | } /* namespace testsuite */ 65 | -------------------------------------------------------------------------------- /src/parameters/DateParameter.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _DATEPARAMETER_H_ 22 | #define _DATEPARAMETER_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "ParameterHolder.h" 27 | 28 | namespace sql 29 | { 30 | class TimeZone; 31 | 32 | namespace mariadb 33 | { 34 | class DateParameter : public ParameterHolder { 35 | 36 | Date date; 37 | //const TimeZone timeZone; 38 | const Shared::Options options; 39 | 40 | public: 41 | DateParameter( const Date&date, TimeZone* timeZone, Shared::Options& options); 42 | void writeTo(PacketOutputStream& os); 43 | void writeTo(SQLString& os); 44 | 45 | private: 46 | const char * dateByteFormat(); 47 | 48 | public: 49 | int64_t getApproximateTextProtocolLength(); 50 | void writeBinary(PacketOutputStream& pos); 51 | uint32_t writeBinary(sql::bytes& buffer); 52 | const ColumnType& getColumnType() const; 53 | SQLString toString(); 54 | bool isNullData() const; 55 | bool isLongData(); 56 | void* getValuePtr() { return const_cast(static_cast(date.c_str())); } 57 | unsigned long getValueBinLen() const { return static_cast(date.length()); } 58 | }; 59 | } 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /src/pool/GlobalStateInfo.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _GLOBALSTATEINFO_H_ 21 | #define _GLOBALSTATEINFO_H_ 22 | #include 23 | #include "StringImp.h" 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | class GlobalStateInfo 29 | { 30 | private: int64_t maxAllowedPacket; 31 | private: int32_t waitTimeout; 32 | private: bool autocommit; 33 | private: int32_t autoIncrementIncrement; 34 | private: SQLString timeZone; 35 | private: SQLString systemTimeZone; 36 | private: int32_t defaultTransactionIsolation; 37 | public: 38 | GlobalStateInfo(); 39 | GlobalStateInfo(int64_t maxAllowedPacket, int32_t waitTimeout, bool autocommit, 40 | int32_t autoIncrementIncrement, SQLString& timeZone, SQLString& systemTimeZone, 41 | int32_t defaultTransactionIsolation); 42 | public: int64_t getMaxAllowedPacket() const; 43 | public: int32_t getWaitTimeout() const; 44 | public: bool isAutocommit() const; 45 | public: int32_t getAutoIncrementIncrement() const; 46 | public: SQLString getTimeZone() const; 47 | public: SQLString getSystemTimeZone() const; 48 | public: int32_t getDefaultTransactionIsolation() const; 49 | }; 50 | } 51 | } 52 | #endif -------------------------------------------------------------------------------- /include/conncpp/Driver.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _DRIVER_H_ 22 | #define _DRIVER_H_ 23 | 24 | #include "buildconf.hpp" 25 | #include "SQLString.hpp" 26 | #include "Connection.hpp" 27 | #include "jdbccompat.hpp" 28 | 29 | namespace sql 30 | { 31 | typedef Properties ConnectOptionsMap; 32 | 33 | class MARIADB_EXPORTED Driver { 34 | Driver(const Driver &); 35 | void operator=(Driver &); 36 | public: 37 | Driver() {} 38 | virtual ~Driver(){} 39 | 40 | virtual Connection* connect(const SQLString& url, Properties& props)=0; 41 | virtual Connection* connect(const SQLString& host, const SQLString& user, const SQLString& pwd)=0; 42 | virtual Connection* connect(const Properties& props)=0; 43 | virtual bool acceptsURL(const SQLString& url)=0; 44 | virtual uint32_t getMajorVersion()=0; 45 | virtual uint32_t getMinorVersion()=0; 46 | virtual bool jdbcCompliant()=0; 47 | //Not in the classic API 48 | virtual const SQLString& getName()=0; 49 | #ifdef JDBC_SPECIFIC_TYPES_IMPLEMENTED 50 | virtual Logger* getParentLogger()= 0; 51 | #endif 52 | }; 53 | 54 | namespace mariadb 55 | { 56 | MARIADB_EXPORTED Driver* get_driver_instance(); 57 | } 58 | } 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/conncpp/ParameterMetaData.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _PARAMETERMETADATA_H_ 22 | #define _PARAMETERMETADATA_H_ 23 | 24 | #include 25 | #include "SQLString.hpp" 26 | 27 | namespace sql 28 | { 29 | 30 | class ParameterMetaData 31 | { 32 | void operator=(ParameterMetaData &); 33 | protected: 34 | ParameterMetaData(const ParameterMetaData&) {} 35 | public: 36 | enum { 37 | parameterModeUnknown= 0, 38 | parameterModeIn, 39 | parameterModeInOut, 40 | parameterModeOut= 4 41 | }; 42 | enum { 43 | parameterNoNulls= 0, 44 | parameterNullable, 45 | parameterNullableUnknown, 46 | }; 47 | 48 | ParameterMetaData() {} 49 | virtual ~ParameterMetaData(){} 50 | 51 | virtual uint32_t getParameterCount()=0; 52 | virtual int32_t isNullable(uint32_t param)=0; 53 | virtual bool isSigned(uint32_t param)=0; 54 | virtual int32_t getPrecision(uint32_t param)=0; 55 | virtual int32_t getScale(uint32_t param)=0; 56 | virtual int32_t getParameterType(uint32_t param)=0; 57 | virtual SQLString getParameterTypeName(uint32_t param)=0; 58 | virtual SQLString getParameterClassName(uint32_t param)=0; 59 | virtual int32_t getParameterMode(uint32_t param)=0; 60 | }; 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /test/CJUnitTestsPort/compliance/UnbufferedRsStmtTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "UnbufferedRsStmtTest.h" 34 | 35 | 36 | namespace testsuite 37 | { 38 | namespace compliance 39 | { 40 | 41 | UnbufferedRsStmtTest::UnbufferedRsStmtTest( const String & name ) : StatementTest( name ) 42 | { 43 | logMsg( "UnbufferedRsStmtTest ctor called" ); 44 | } 45 | 46 | void UnbufferedRsStmtTest::setUp() 47 | { 48 | logMsg( "UnbufferedRsStmtTest setUp called" ); 49 | 50 | super::setUp(); 51 | 52 | sql::ResultSet::enum_type unbuffered= sql::ResultSet::TYPE_FORWARD_ONLY; 53 | //TODO: conn->setClientOption( "defaultStatementResultType", & unbuffered ); 54 | 55 | stmt->setResultSetType( unbuffered ); 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/common/singleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 2020 MariaDB Corporation AB 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License, version 2.0, as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is also distributed with certain software (including 10 | * but not limited to OpenSSL) that is licensed under separate terms, 11 | * as designated in a particular file or component or in included license 12 | * documentation. The authors of MySQL hereby grant you an 13 | * additional permission to link the program and your derivative works 14 | * with the separately licensed software that they have included with 15 | * MySQL. 16 | * 17 | * Without limiting anything contained in the foregoing, this file, 18 | * which is part of MySQL Connector/C++, is also subject to the 19 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 20 | * http://oss.oracle.com/licenses/universal-foss-exception. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License, version 2.0, for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program; if not, write to the Free Software Foundation, Inc., 29 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | */ 31 | 32 | 33 | #ifndef __CCPP_SINGLETON_H 34 | #define __CCPP_SINGLETON_H 35 | 36 | namespace policies 37 | { 38 | template 39 | class Singleton 40 | { 41 | Singleton(const Singleton&)=delete; 42 | Singleton& operator=(const Singleton&) = delete; 43 | protected: 44 | 45 | Singleton(){} 46 | 47 | public: 48 | 49 | static T & theInstance() 50 | { 51 | static T instance; 52 | 53 | return instance; 54 | } 55 | }; 56 | 57 | 58 | } // namespace policies 59 | 60 | // macros to use in private/protected part of singletoned class 61 | #define CCPP_SINGLETON(classname) classname();\ 62 | friend class policies::Singleton 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/com/Packet.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "Packet.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | const int8_t Packet::ERROR= (int8_t)0xff; 29 | const int8_t Packet::OK= (int8_t)0x00; 30 | const int8_t Packet::EOF_= (int8_t)0xfe; 31 | const int8_t Packet::LOCAL_INFILE= (int8_t)0xfb; 32 | // send command 33 | const int8_t Packet::COM_QUIT= (int8_t)0x01; 34 | const int8_t Packet::COM_INIT_DB= (int8_t)0x02; 35 | const int8_t Packet::COM_QUERY= (int8_t)0x03; 36 | const int8_t Packet::COM_PING= (int8_t)0x0e; 37 | const int8_t Packet::COM_STMT_PREPARE= (int8_t)0x16; 38 | const int8_t Packet::COM_STMT_EXECUTE= (int8_t)0x17; 39 | const int8_t Packet::COM_STMT_FETCH= (int8_t)0x1c; 40 | const int8_t Packet::COM_STMT_SEND_LONG_DATA= (int8_t)0x18; 41 | const int8_t Packet::COM_STMT_CLOSE= (int8_t)0x19; 42 | const int8_t Packet::COM_RESET_CONNECTION= (int8_t)0x1f; 43 | const int8_t Packet::COM_STMT_BULK_EXECUTE= (int8_t)0xfa; 44 | const int8_t Packet::COM_MULTI= (int8_t)0xfe; 45 | // prepare statement cursor flag. 46 | const int8_t Packet::CURSOR_TYPE_NO_CURSOR= (int8_t)0x00; 47 | const int8_t Packet::CURSOR_TYPE_READ_ONLY= (int8_t)0x01; 48 | const int8_t Packet::CURSOR_TYPE_FOR_UPDATE= (int8_t)0x02; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/MariaDbParameterMetaData.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _MARIADBPARAMETERMETADATA_H_ 22 | #define _MARIADBPARAMETERMETADATA_H_ 23 | 24 | #include "ParameterMetaData.hpp" 25 | 26 | #include "Consts.h" 27 | 28 | #include "ColumnDefinition.h" 29 | 30 | namespace sql 31 | { 32 | namespace mariadb 33 | { 34 | 35 | class MariaDbParameterMetaData : public ParameterMetaData { 36 | 37 | const std::vector parametersInformation; 38 | 39 | public: 40 | MariaDbParameterMetaData(const std::vector& parametersInformation); 41 | 42 | private: 43 | void checkAvailable(); 44 | 45 | public: 46 | uint32_t getParameterCount(); 47 | 48 | private: 49 | const ColumnDefinition& getParameterInformation(uint32_t param); 50 | 51 | public: 52 | int32_t isNullable(uint32_t param); 53 | bool isSigned(uint32_t param); 54 | int32_t getPrecision(uint32_t param); 55 | int32_t getScale(uint32_t param); 56 | int32_t getParameterType(uint32_t param); 57 | SQLString getParameterTypeName(uint32_t param); 58 | SQLString getParameterClassName(uint32_t param); 59 | int32_t getParameterMode(uint32_t param); 60 | // I guess we don't need it like this 61 | bool isWrapperFor(ParameterMetaData* iface); 62 | }; 63 | } 64 | } 65 | #endif -------------------------------------------------------------------------------- /src/com/CmdInformationSingle.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CMDINFORMATIONSINGLE_H_ 22 | #define _CMDINFORMATIONSINGLE_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "CmdInformation.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | 34 | class CmdInformationSingle : public CmdInformation { 35 | 36 | const int64_t insertId; 37 | int32_t autoIncrement; 38 | int64_t updateCount; 39 | 40 | public: 41 | CmdInformationSingle(int64_t insertId,int64_t updateCount,int32_t autoIncrement); 42 | std::vector& getUpdateCounts(); 43 | std::vector& getServerUpdateCounts(); 44 | std::vector& getLargeUpdateCounts(); 45 | int32_t getUpdateCount(); 46 | int64_t getLargeUpdateCount(); 47 | void addErrorStat(); 48 | void reset(); 49 | void addResultSetStat(); 50 | ResultSet* getGeneratedKeys(Protocol* protocol, const SQLString& sql); 51 | 52 | private: 53 | bool isDuplicateKeyUpdate(const SQLString& sql); 54 | 55 | public: 56 | ResultSet* getBatchGeneratedKeys(Protocol* protocol); 57 | int32_t getCurrentStatNumber(); 58 | bool moreResults(); 59 | bool isCurrentUpdateCount(); 60 | void addSuccessStat(int64_t updateCount,int64_t insertId); 61 | void setRewrite(bool rewritten); 62 | }; 63 | } 64 | } 65 | #endif -------------------------------------------------------------------------------- /test/unit/performance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 2 | # 2023 MariaDB Corportation AB 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2.0, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is also distributed with certain software (including 9 | # but not limited to OpenSSL) that is licensed under separate terms, 10 | # as designated in a particular file or component or in included license 11 | # documentation. The authors of MySQL hereby grant you an 12 | # additional permission to link the program and your derivative works 13 | # with the separately licensed software that they have included with 14 | # MySQL. 15 | # 16 | # Without limiting anything contained in the foregoing, this file, 17 | # which is part of MySQL Connector/C++, is also subject to the 18 | # Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | # http://oss.oracle.com/licenses/universal-foss-exception. 20 | # 21 | # This program is distributed in the hope that it will be useful, but 22 | # WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | # See the GNU General Public License, version 2.0, for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program; if not, write to the Free Software Foundation, Inc., 28 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | 30 | 31 | SET(perf_statement_sources 32 | ${test_common_sources} 33 | perf_statement.cpp) 34 | 35 | IF(WIN32) 36 | SET(perf_statement_sources 37 | ${perf_statement_sources} 38 | perf_statement.h) 39 | ENDIF(WIN32) 40 | 41 | ADD_EXECUTABLE(perf_statement ${perf_statement_sources}) 42 | SET_TARGET_PROPERTIES(perf_statement PROPERTIES 43 | OUTPUT_NAME "perf_statement" 44 | LINK_FLAGS "${MYSQLCPPCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}" 45 | COMPILE_FLAGS "${MYSQLCPPCONN_COMPILE_FLAGS_ENV}") 46 | TARGET_LINK_LIBRARIES(perf_statement ${PLATFORM_DEPENDENCIES} ${MY_GCOV_LINK_LIBRARIES} test_framework ${LIBRARY_NAME}) 47 | 48 | MESSAGE(STATUS "Configuring performance test - statement") 49 | -------------------------------------------------------------------------------- /test/unit/performance/perf_statement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "../unit_fixture.h" 34 | 35 | /** 36 | * Example of a collection of tests 37 | * 38 | */ 39 | 40 | namespace testsuite 41 | { 42 | namespace performance 43 | { 44 | 45 | class perf_statement : public unit_fixture 46 | { 47 | private: 48 | typedef unit_fixture super; 49 | 50 | bool realFrameworkTiming; 51 | protected: 52 | public: 53 | 54 | EXAMPLE_TEST_FIXTURE(perf_statement) 55 | { 56 | TEST_CASE(simpleSelect1k); 57 | } 58 | 59 | /** 60 | * SELECT ' ' as string 61 | */ 62 | void simpleSelect1k(); 63 | 64 | void setUp(); 65 | 66 | void tearDown(); 67 | 68 | }; 69 | 70 | REGISTER_FIXTURE(perf_statement); 71 | } /* namespace classes */ 72 | } /* namespace testsuite */ 73 | -------------------------------------------------------------------------------- /install_test/CMakeLists.txt.in: -------------------------------------------------------------------------------- 1 | # ************************************************************************************ 2 | # Copyright (C) 2021 MariaDB Corporation AB 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Library General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Library General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Library General Public 15 | # License along with this library; if not see 16 | # or write to the Free Software Foundation, Inc., 17 | # 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | # *************************************************************************************/ 19 | 20 | cmake_minimum_required(VERSION 3.1) 21 | 22 | PROJECT(mariadbcpp-example 23 | LANGUAGES CXX) 24 | IF(WIN32) 25 | MESSAGE(SEND_ERROR "Not supported on Windows") 26 | ELSE() 27 | SET(CMAKE_CXX_STANDARD 11) 28 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 29 | 30 | SET(LIBRARY_NAME "libmariadbcpp.so") 31 | 32 | EXECUTE_PROCESS(COMMAND tar zxf @CMAKE_BINARY_DIR@/@CPACK_PACKAGE_FILE_NAME@.tar.gz) 33 | ADD_CUSTOM_TARGET(LIST_CONTENTS 34 | COMMAND ls -lR ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/@INSTALL_LIB_SUFFIX@/mariadb/*.so* ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/) 35 | 36 | FILE(GLOB LIBS_IN_PACK 37 | ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/@INSTALL_LIB_SUFFIX@/mariadb/lib*.so*) 38 | MESSAGE(STATUS "Configuring to search for headers in the ${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/include") 39 | INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@/include") 40 | ADD_EXECUTABLE(example example.cpp) 41 | 42 | MESSAGE(STATUS "Configuring to link against libs in the package ${LIBS_IN_PACK}") 43 | FOREACH(PACKEDLIB ${LIBS_IN_PACK}) 44 | TARGET_LINK_LIBRARIES(example ${PACKEDLIB}) 45 | ENDFOREACH() 46 | ADD_DEPENDENCIES(example LIST_CONTENTS) 47 | ENDIF() 48 | -------------------------------------------------------------------------------- /src/MariaDBWarning.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020,2023 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | #ifndef _MARIADBWARNING_H_ 21 | #define _MARIADBWARNING_H_ 22 | 23 | #include 24 | 25 | #include "Warning.hpp" 26 | 27 | namespace sql 28 | { 29 | namespace mariadb 30 | { 31 | class MariaDBWarning : public SQLWarning 32 | { 33 | SQLString msg; 34 | SQLString sqlState; 35 | int32_t errorCode; 36 | std::unique_ptr next; 37 | 38 | void setNextWarning(const SQLWarning* /*nextWarning*/) {}//new MariaDBWarning(nextWarning->getMessage(), nextWarning->getSQLState(), nextWarning->getErrorCode());} 39 | public: 40 | MariaDBWarning() : errorCode(0) {} 41 | virtual ~MariaDBWarning(); 42 | MariaDBWarning(const MariaDBWarning&); 43 | MariaDBWarning(const SQLString& msg); 44 | //MariaDBWarning(const SQLString& msg, const SQLString& state, int32_t error= 0, const std::exception* e= nullptr); 45 | MariaDBWarning(const char* msg, const char* state= "", int32_t error= 0, const std::exception* e= nullptr); 46 | 47 | SQLWarning* getNextWarning() const; 48 | void setNextWarning(SQLWarning* nextWarning); 49 | const SQLString& getSQLState() const; 50 | int32_t getErrorCode() const; 51 | const SQLString& getMessage() const; 52 | }; 53 | } 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /test/CJUnitTestsPort/regression/PreparedStatementRegressionTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "PreparedStatementRegressionTest.h" 34 | 35 | namespace testsuite 36 | { 37 | namespace regression 38 | { 39 | 40 | void PreparedStatementRegressionTest::testStmtClose() 41 | { 42 | pstmt.reset( conn->prepareStatement( "select ?" ) ); 43 | 44 | pstmt->setString( 1, "dummy" ); 45 | 46 | ResultSet tmp(pstmt->executeQuery()); 47 | 48 | pstmt->close(); 49 | 50 | // Application crashed on the destructor if close was closed before. 51 | // prepared statement had to contain any parameter. 52 | pstmt.reset(); 53 | } 54 | 55 | 56 | void PreparedStatementRegressionTest::setUp() 57 | { 58 | super::setUp(); 59 | 60 | dbmd.reset(conn->getMetaData()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/CmdInformationMultiple.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CMDINFORMATIONMULTIPLE_H_ 22 | #define _CMDINFORMATIONMULTIPLE_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "CmdInformation.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class CmdInformationMultiple : public CmdInformation { 34 | 35 | std::vectorinsertIds; 36 | std::vectorupdateCounts; 37 | std::size_t expectedSize; 38 | int32_t autoIncrement; 39 | int64_t insertIdNumber ; /*0*/ 40 | int32_t moreResultsIdx; 41 | bool hasException; 42 | bool rewritten; 43 | 44 | public: 45 | CmdInformationMultiple(std::size_t expectedSize,int32_t autoIncrement); 46 | void addErrorStat(); 47 | void reset(); 48 | void addResultSetStat(); 49 | void addSuccessStat(int64_t updateCount,int64_t insertId); 50 | std::vector& getServerUpdateCounts(); 51 | std::vector& getUpdateCounts(); 52 | std::vector& getLargeUpdateCounts(); 53 | int32_t getUpdateCount(); 54 | int64_t getLargeUpdateCount(); 55 | ResultSet* getBatchGeneratedKeys(Protocol* protocol); 56 | ResultSet* getGeneratedKeys(Protocol* protocol, const SQLString& sql); 57 | int32_t getCurrentStatNumber(); 58 | bool moreResults(); 59 | bool isCurrentUpdateCount(); 60 | void setRewrite(bool rewritten); 61 | }; 62 | } 63 | } 64 | #endif -------------------------------------------------------------------------------- /src/parameters/NullParameter.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "NullParameter.h" 22 | 23 | namespace sql 24 | { 25 | namespace mariadb 26 | { 27 | 28 | const char* NullParameter::_NULL= "NULL";//{ 'N','U','L','L' }; 29 | 30 | NullParameter::NullParameter() : type(ColumnType::_NULL) 31 | { 32 | 33 | } 34 | 35 | NullParameter::NullParameter(const ColumnType& _type) 36 | : type(_type) 37 | { 38 | } 39 | 40 | 41 | void NullParameter::writeTo(SQLString& str) 42 | { 43 | str.append(_NULL); 44 | } 45 | 46 | 47 | void NullParameter:: writeTo(PacketOutputStream& os) 48 | { 49 | os.write(_NULL); 50 | } 51 | 52 | int64_t NullParameter::getApproximateTextProtocolLength() 53 | { 54 | return 4; 55 | } 56 | 57 | /** 58 | * Write data to socket in binary format. 59 | * 60 | * @param pos socket output stream 61 | */ 62 | void NullParameter::writeBinary(PacketOutputStream& /*pos*/) 63 | { 64 | 65 | } 66 | 67 | const ColumnType& NullParameter::getColumnType() const 68 | { 69 | return type; 70 | } 71 | 72 | SQLString NullParameter::toString() 73 | { 74 | return ""; 75 | } 76 | 77 | bool NullParameter::isNullData() const 78 | { 79 | return true; 80 | } 81 | 82 | bool NullParameter::isLongData() 83 | { 84 | return false; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /test/unit/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 2 | # 2020, 2023 MariaDB Corportation AB 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2.0, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is also distributed with certain software (including 9 | # but not limited to OpenSSL) that is licensed under separate terms, 10 | # as designated in a particular file or component or in included license 11 | # documentation. The authors of MySQL hereby grant you an 12 | # additional permission to link the program and your derivative works 13 | # with the separately licensed software that they have included with 14 | # MySQL. 15 | # 16 | # Without limiting anything contained in the foregoing, this file, 17 | # which is part of MySQL Connector/C++, is also subject to the 18 | # Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | # http://oss.oracle.com/licenses/universal-foss-exception. 20 | # 21 | # This program is distributed in the hope that it will be useful, but 22 | # WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | # See the GNU General Public License, version 2.0, for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program; if not, write to the Free Software Foundation, Inc., 28 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | 30 | 31 | SET(example_sources 32 | ../unit_fixture.cpp 33 | ../main.cpp 34 | example.cpp) 35 | 36 | IF(WIN32) 37 | SET(example_sources 38 | ${example_sources} 39 | ../unit_fixture.h 40 | example.h) 41 | ENDIF(WIN32) 42 | 43 | ADD_EXECUTABLE(example ${example_sources}) 44 | SET_TARGET_PROPERTIES(example PROPERTIES 45 | OUTPUT_NAME "example" 46 | LINK_FLAGS "${MYSQLCPPCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}" 47 | COMPILE_FLAGS "${MYSQLCPPCONN_COMPILE_FLAGS_ENV}") 48 | 49 | TARGET_LINK_LIBRARIES(example ${PLATFORM_DEPENDENCIES} test_framework ${LIBRARY_NAME} ${MY_GCOV_LINK_LIBRARIES}) 50 | 51 | # 52 | # End of the instructions for building binary example from example.cpp|h 53 | # 54 | 55 | MESSAGE(STATUS "Configuring unit tests - examples") 56 | -------------------------------------------------------------------------------- /src/logger/LoggerFactory.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #include "LoggerFactory.h" 22 | #include "NoLogger.h" 23 | 24 | namespace sql 25 | { 26 | namespace mariadb 27 | { 28 | Shared::Logger LoggerFactory::NO_LOGGER; 29 | bool LoggerFactory::hasToLog= false; 30 | 31 | void LoggerFactory::init(bool mustLog) 32 | { 33 | if ((hasToLog != mustLog ) && mustLog) 34 | { 35 | if (hasToLog != mustLog) 36 | { 37 | //try 38 | { 39 | //Class.forName("org.slf4j.LoggerFactory"); 40 | hasToLog= true; 41 | } 42 | //catch (ClassNotFoundException classNotFound) 43 | { 44 | //System.out.println("Logging cannot be activated, missing slf4j dependency"); 45 | //hasToLog= false; 46 | } 47 | } 48 | } 49 | } 50 | 51 | bool LoggerFactory::initLoggersIfNeeded() 52 | { 53 | if (!NO_LOGGER) { 54 | NO_LOGGER.reset(new NoLogger()); 55 | } 56 | return true; 57 | } 58 | 59 | Shared::Logger LoggerFactory::getLogger(const std::type_info& /*typeId*/) 60 | { 61 | static bool inited= initLoggersIfNeeded(); 62 | // Just to use inited and shut up the compiler 63 | if (inited && hasToLog) 64 | { 65 | return NO_LOGGER;//Slf4JLogger(typeId); 66 | } 67 | else 68 | { 69 | return NO_LOGGER; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/framework/test_container.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "test_case.h" 34 | #include "test_container.h" 35 | 36 | #include "../common/ccppTypes.h" 37 | 38 | 39 | namespace testsuite 40 | { 41 | namespace Private 42 | { 43 | TestContainer::StorableTest::~StorableTest() 44 | { 45 | delete test; 46 | } 47 | 48 | 49 | TestContainer::StorableTest::StorableTest( Test & test2decorate ) 50 | { 51 | test= &test2decorate; 52 | } 53 | 54 | 55 | /*Test & TestContainer::StorableTest::operator * () 56 | { 57 | return *test; 58 | } 59 | 60 | 61 | Test * TestContainer::StorableTest::operator ->() 62 | { 63 | return get(); 64 | }*/ 65 | 66 | 67 | 68 | Test * TestContainer::StorableTest::get() 69 | { 70 | //assert(test); 71 | return test; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/CJUnitTestsPort/regression/PreparedStatementRegressionTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #include "../BaseTestFixture.h" 34 | 35 | /** 36 | * @author 37 | */ 38 | 39 | namespace testsuite 40 | { 41 | namespace regression 42 | { 43 | 44 | class PreparedStatementRegressionTest : public BaseTestFixture 45 | { 46 | private: 47 | 48 | typedef BaseTestFixture super; 49 | 50 | DatabaseMetaData dbmd; 51 | 52 | protected: 53 | 54 | /** 55 | * setUp() function for tests 56 | */ 57 | /* throws std::exception * */ 58 | void setUp(); 59 | 60 | public: 61 | 62 | TEST_FIXTURE(PreparedStatementRegressionTest) 63 | { 64 | TEST_CASE( testStmtClose ); 65 | } 66 | 67 | 68 | void testStmtClose(); 69 | 70 | 71 | }; 72 | 73 | REGISTER_FIXTURE(PreparedStatementRegressionTest); 74 | 75 | } //namespace regression 76 | } //namespace testsuite 77 | -------------------------------------------------------------------------------- /src/com/CmdInformationBatch.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _CMDINFORMATIONBATCH_H_ 22 | #define _CMDINFORMATIONBATCH_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "CmdInformation.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class CmdInformationBatch : public CmdInformation { 34 | 35 | std::vectorinsertIds ; /*new ConcurrentLinkedQueue<>()*/ 36 | std::vectorupdateCounts ; /*new ConcurrentLinkedQueue<>()*/ 37 | std::size_t expectedSize; 38 | int32_t autoIncrement; 39 | int64_t insertIdNumber ; /*0*/ 40 | bool hasException= false; 41 | bool rewritten= false; 42 | 43 | public: 44 | CmdInformationBatch(std::size_t expectedSize,int32_t autoIncrement); 45 | void addErrorStat(); 46 | void reset(); 47 | void addResultSetStat(); 48 | void addSuccessStat(int64_t updateCount,int64_t insertId); 49 | std::vector& getUpdateCounts(); 50 | std::vector& getServerUpdateCounts(); 51 | std::vector& getLargeUpdateCounts(); 52 | int32_t getUpdateCount(); 53 | int64_t getLargeUpdateCount(); 54 | ResultSet* getBatchGeneratedKeys(Protocol* protocol); 55 | ResultSet* getGeneratedKeys(Protocol* protocol, const SQLString& sql); 56 | int32_t getCurrentStatNumber(); 57 | bool moreResults(); 58 | bool isCurrentUpdateCount(); 59 | void setRewrite(bool rewritten); 60 | }; 61 | } 62 | } 63 | #endif -------------------------------------------------------------------------------- /src/SqlStates.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _SQLSTATES_H_ 22 | #define _SQLSTATES_H_ 23 | 24 | #include "Consts.h" 25 | 26 | #include "StringImp.h" 27 | 28 | namespace sql 29 | { 30 | namespace mariadb 31 | { 32 | 33 | class SqlStates 34 | { 35 | SQLString sqlStateGroup; 36 | 37 | public: 38 | 39 | SqlStates(const char* stateGroup ); 40 | static SqlStates fromString(const SQLString& group); 41 | const SQLString& getSqlState() const; 42 | }; 43 | 44 | extern SqlStates WARNING;//("01"), 45 | extern SqlStates NO_DATA; //"02") 46 | extern SqlStates CONNECTION_EXCEPTION; //"08") 47 | extern SqlStates FEATURE_NOT_SUPPORTED; //"0A") 48 | extern SqlStates CARDINALITY_VIOLATION; //"21") 49 | extern SqlStates DATA_EXCEPTION; //"22") 50 | extern SqlStates CONSTRAINT_VIOLATION; //"23") 51 | extern SqlStates INVALID_CURSOR_STATE; //"24") 52 | extern SqlStates INVALID_TRANSACTION_STATE; //"25") 53 | extern SqlStates INVALID_AUTHORIZATION; //"28") 54 | extern SqlStates SQL_FUNCTION_EXCEPTION; //"2F") 55 | extern SqlStates TRANSACTION_ROLLBACK; //"40") 56 | extern SqlStates SYNTAX_ERROR_ACCESS_RULE; //"42") 57 | extern SqlStates INVALID_CATALOG; //"3D") 58 | extern SqlStates INTERRUPTED_EXCEPTION; //"70") 59 | extern SqlStates UNDEFINED_SQLSTATE; //"HY") 60 | extern SqlStates TIMEOUT_EXCEPTION; //"JZ") 61 | extern SqlStates DISTRIBUTED_TRANSACTION_ERROR;//("XA"); 62 | 63 | } 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /src/com/Packet.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | #ifndef _PACKET_H_ 22 | #define _PACKET_H_ 23 | 24 | #include "stdint.h" 25 | 26 | namespace sql 27 | { 28 | namespace mariadb 29 | { 30 | 31 | class Packet { 32 | 33 | public: 34 | static const int8_t ERROR; /*(int8_t)0xff*/ 35 | static const int8_t OK; /*(int8_t)0x00*/ 36 | static const int8_t EOF_; /*(int8_t)0xfe*/ 37 | static const int8_t LOCAL_INFILE; /*(int8_t)0xfb*/ 38 | static const int8_t COM_QUIT; /*(int8_t)0x01*/ 39 | static const int8_t COM_INIT_DB; /*(int8_t)0x02*/ 40 | static const int8_t COM_QUERY; /*(int8_t)0x03*/ 41 | static const int8_t COM_PING; /*(int8_t)0x0e*/ 42 | static const int8_t COM_STMT_PREPARE; /*(int8_t)0x16*/ 43 | static const int8_t COM_STMT_EXECUTE; /*(int8_t)0x17*/ 44 | static const int8_t COM_STMT_FETCH; /*(int8_t)0x1c*/ 45 | static const int8_t COM_STMT_SEND_LONG_DATA; /*(int8_t)0x18*/ 46 | static const int8_t COM_STMT_CLOSE; /*(int8_t)0x19*/ 47 | static const int8_t COM_RESET_CONNECTION; /*(int8_t)0x1f*/ 48 | static const int8_t COM_STMT_BULK_EXECUTE; /*(int8_t)0xfa*/ 49 | static const int8_t COM_MULTI; /*(int8_t)0xfe*/ 50 | static const int8_t CURSOR_TYPE_NO_CURSOR; /*(int8_t)0x00*/ 51 | static const int8_t CURSOR_TYPE_READ_ONLY; /*(int8_t)0x01*/ 52 | static const int8_t CURSOR_TYPE_FOR_UPDATE; /*(int8_t)0x02*/ 53 | }; 54 | } 55 | } 56 | #endif -------------------------------------------------------------------------------- /src/ColumnDefinition.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | Copyright (C) 2020 MariaDB Corporation AB 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not see 16 | or write to the Free Software Foundation, Inc., 17 | 51 Franklin St., Fifth Floor, Boston, MA 02110, USA 18 | *************************************************************************************/ 19 | 20 | 21 | 22 | #include "ColumnDefinition.h" 23 | 24 | #include "com/capi/ColumnDefinitionCapi.h" 25 | 26 | namespace sql 27 | { 28 | 29 | namespace mariadb 30 | { 31 | /** 32 | * Constructor. 33 | * 34 | * @param name column name 35 | * @param type column type 36 | * @return Shared::ColumnDefinition 37 | */ 38 | Shared::ColumnDefinition ColumnDefinition::create(const SQLString& name, const ColumnType& _type) 39 | { 40 | capi::MYSQL_FIELD* md= new capi::MYSQL_FIELD; 41 | 42 | std::memset(md, 0, sizeof(capi::MYSQL_FIELD)); 43 | 44 | md->name= (char*)name.c_str(); 45 | md->org_name= (char*)name.c_str(); 46 | md->name_length= static_cast(name.length()); 47 | md->org_name_length= static_cast(name.length()); 48 | 49 | switch (_type.getSqlType()) { 50 | case Types::VARCHAR: 51 | case Types::CHAR: 52 | md->length= 64*3; 53 | break; 54 | case Types::SMALLINT: 55 | md->length= 5; 56 | break; 57 | case Types::_NULL: 58 | md->length= 0; 59 | break; 60 | default: 61 | md->length= 1; 62 | break; 63 | } 64 | 65 | md->type= static_cast(ColumnType::toServer(_type.getSqlType()).getType()); 66 | 67 | return Shared::ColumnDefinition(new capi::ColumnDefinitionCapi(md, true)); 68 | } 69 | 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /test/framework/test_container.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2.0, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is also distributed with certain software (including 9 | * but not limited to OpenSSL) that is licensed under separate terms, 10 | * as designated in a particular file or component or in included license 11 | * documentation. The authors of MySQL hereby grant you an 12 | * additional permission to link the program and your derivative works 13 | * with the separately licensed software that they have included with 14 | * MySQL. 15 | * 16 | * Without limiting anything contained in the foregoing, this file, 17 | * which is part of MySQL Connector/C++, is also subject to the 18 | * Universal FOSS Exception, version 1.0, a copy of which can be found at 19 | * http://oss.oracle.com/licenses/universal-foss-exception. 20 | * 21 | * This program is distributed in the hope that it will be useful, but 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License, version 2.0, for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software Foundation, Inc., 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | 32 | 33 | #ifndef __TESTCONTAINER_H_ 34 | #define __TESTCONTAINER_H_ 35 | 36 | #include "../common/ccppTypes.h" 37 | 38 | namespace testsuite 39 | { 40 | 41 | class Test; 42 | 43 | namespace Private 44 | { 45 | class TestContainer 46 | { 47 | protected: 48 | 49 | class StorableTest 50 | { 51 | StorableTest() : test(nullptr) {} 52 | StorableTest(const StorableTest&)=delete; 53 | StorableTest& operator=(const StorableTest&) = delete; 54 | 55 | Test * test; 56 | 57 | public: 58 | 59 | virtual ~StorableTest(); 60 | 61 | StorableTest( Test & test2decorate ); 62 | 63 | /*Test & operator * (); 64 | Test * operator ->();*/ 65 | 66 | Test * get(); 67 | 68 | }; 69 | }; 70 | } 71 | } 72 | 73 | 74 | #endif // ifndef __TESTCONTAINER_H_ 75 | --------------------------------------------------------------------------------