update mysql client

main
HwangKC 2024-09-21 13:57:16 +08:00
parent 5b71d4c465
commit 7b48b8db7c
20 changed files with 287 additions and 2383 deletions

View File

@ -0,0 +1,80 @@
#include "mysqlutils.h"
#include <hv/hlog.h>
#include <sstream>
#include <QtSql/QSqlDatabase>
#include <QStringList>
MysqlUtils MysqlUtils::m_instance;
MysqlUtils::MysqlUtils()
:m_pDbConnection(nullptr)
{}
MysqlUtils::~MysqlUtils()
{
CloseDatabase();
}
MysqlUtils* MysqlUtils::getInstance()
{
return &m_instance;
}
bool MysqlUtils::OpenDatabase(const std::string& server, int dbport, const std::string& dbuser, const std::string& dbpasswd, const std::string& database)
{
// 打开数据库
try
{
if (m_pDbConnection!=nullptr)
{
if (m_pDbConnection->isValid())
{
hlogd("database already connected.");
return true;
}
}
using namespace sql;
// 创建连接
sql::Driver* driver;
sql::ConnectOptionsMap connection_properties;
connection_properties["hostName"] = server.c_str();
connection_properties["userName"] = dbuser.c_str();
connection_properties["password"] = dbpasswd.c_str();
connection_properties["schema"] = database.c_str();
connection_properties["port"] = dbport;
connection_properties["OPT_RECONNECT"] = true;
driver = get_driver_instance();
m_pDbConnection = driver->connect(connection_properties);
if (!m_pDbConnection)
{
hloge("Failed to connect to database.");
return false;
}
hlogd("new database connection created successfully!");
return true;
}
catch (sql::SQLException& e)
{
std::ostringstream ss;
ss << "SQLException: " << e.what();
ss<< " (MySQL error code: " << e.getErrorCode();
ss << ", SQLState: " << e.getSQLState() << " )";
hloge("Failed to connect to database: %s",ss.str().c_str());
return false;
}
}
void MysqlUtils::CloseDatabase()
{
if (m_pDbConnection)
m_pDbConnection->close();
}

View File

@ -0,0 +1,29 @@
#ifndef MYSQLUTILS_H
#define MYSQLUTILS_H
#include <string>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
class MysqlUtils
{
protected:
MysqlUtils();
public:
~MysqlUtils();
static MysqlUtils* getInstance();
void CloseDatabase();
bool OpenDatabase(const std::string& server = "tcp://127.0.0.1:3306", int dbport = 3306, const std::string& dbuser = "root", const std::string& dbpasswd = "Hj57471000", const std::string& database="hjems");
private:
sql::Connection* m_pDbConnection;
static MysqlUtils m_instance;
};
#endif // MYSQLUTILS_H

View File

@ -0,0 +1,163 @@
#include "ziputils.h"
#include <memory>
#include <zlib/zlib.h>
ZipUtils::ZipUtils()
{}
ZipUtils::~ZipUtils()
{}
#define CHUNK 16384
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
int ZipUtils::CompressString(const char* in_str, size_t in_len, std::string& out_str, int level)
{
if (!in_str)
return Z_DATA_ERROR;
int ret, flush;
unsigned have;
z_stream strm;
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
std::shared_ptr<z_stream> sp_strm(&strm, [](z_stream* strm)
{
(void)deflateEnd(strm);
});
const char* end = in_str + in_len;
//size_t pos_index = 0;
size_t distance = 0;
/* compress until end of file */
do
{
distance = end - in_str;
strm.avail_in = (distance >= CHUNK) ? CHUNK : distance;
strm.next_in = (Bytef*)in_str;
// next pos
in_str += strm.avail_in;
flush = (in_str == end) ? Z_FINISH : Z_NO_FLUSH;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do
{
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
if (ret == Z_STREAM_ERROR)
break;
have = CHUNK - strm.avail_out;
out_str.append((const char*)out, have);
}
while (strm.avail_out == 0);
if (strm.avail_in == 0)
break; /* all input will be used */
/* done when last data in file processed */
}
while (flush != Z_FINISH);
if (ret != Z_STREAM_END) /* stream will be complete */
return Z_STREAM_ERROR;
/* clean up and return */
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
int ZipUtils::DecompressString(const char* in_str, size_t in_len, std::string& out_str)
{
if (!in_str)
return Z_DATA_ERROR;
int ret;
unsigned have;
z_stream strm;
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
std::shared_ptr<z_stream> sp_strm(&strm, [](z_stream* strm)
{
(void)inflateEnd(strm);
});
const char* end = in_str + in_len;
//size_t pos_index = 0;
size_t distance = 0;
int flush = 0;
/* decompress until deflate stream ends or end of file */
do
{
distance = end - in_str;
strm.avail_in = (distance >= CHUNK) ? CHUNK : distance;
strm.next_in = (Bytef*)in_str;
// next pos
in_str += strm.avail_in;
flush = (in_str == end) ? Z_FINISH : Z_NO_FLUSH;
/* run inflate() on input until output buffer not full */
do
{
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR) /* state not clobbered */
break;
switch (ret)
{
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
return ret;
}
have = CHUNK - strm.avail_out;
out_str.append((const char*)out, have);
}
while (strm.avail_out == 0);
/* done when inflate() says it's done */
}
while (flush != Z_FINISH);
/* clean up and return */
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}

View File

@ -0,0 +1,15 @@
#ifndef ZIPUTILS_H
#define ZIPUTILS_H
#include <string>
class ZipUtils
{
public:
ZipUtils();
~ZipUtils();
static int CompressString(const char* in_str, size_t in_len, std::string& out_str, int level);
static int DecompressString(const char* in_str, size_t in_len, std::string& out_str);
};
#endif // ZIPUTILS_H

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_BUILD_CONFIG_H_
#define _SQL_BUILD_CONFIG_H_
#ifndef CPPCONN_PUBLIC_FUNC
#if defined(_WIN32)
// mysqlcppconn_EXPORTS is added by cmake and defined for dynamic lib build only
#ifdef mysqlcppconn_EXPORTS
#define CPPCONN_PUBLIC_FUNC __declspec(dllexport)
#else
// this is for static build
#ifdef CPPCONN_LIB_BUILD
#define CPPCONN_PUBLIC_FUNC
#else
// this is for clients using dynamic lib
#define CPPCONN_PUBLIC_FUNC __declspec(dllimport)
#endif
#endif
#else
#define CPPCONN_PUBLIC_FUNC
#endif
#endif //#ifndef CPPCONN_PUBLIC_FUNC
#endif //#ifndef _SQL_BUILD_CONFIG_H_

View File

@ -1,117 +0,0 @@
/*
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// libmysql defines HAVE_STRTOUL (on win), so we have to follow different pattern in definitions names
// to avoid annoying warnings.
#define HAVE_FUNCTION_STRTOLD 1
#define HAVE_FUNCTION_STRTOLL 1
#define HAVE_FUNCTION_STRTOL 1
#define HAVE_FUNCTION_STRTOULL 1
#define HAVE_FUNCTION_STRTOUL 1
#define HAVE_FUNCTION_STRTOIMAX 1
#define HAVE_FUNCTION_STRTOUMAX 1
#define HAVE_STDINT_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_INT8_T 1
#define HAVE_UINT8_T 1
#define HAVE_INT16_T 1
#define HAVE_UINT16_T 1
#define HAVE_INT32_T 1
#define HAVE_UINT32_T 1
#define HAVE_INT32_T 1
#define HAVE_UINT32_T 1
#define HAVE_INT64_T 1
#define HAVE_UINT64_T 1
#define HAVE_MS_INT8 1
#define HAVE_MS_UINT8 1
#define HAVE_MS_INT16 1
#define HAVE_MS_UINT16 1
#define HAVE_MS_INT32 1
#define HAVE_MS_UINT32 1
#define HAVE_MS_INT64 1
#define HAVE_MS_UINT64 1
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#if defined(HAVE_INTTYPES_H) && !defined(_WIN32)
#include <inttypes.h>
#endif
#if defined(_WIN32)
#ifndef CPPCONN_DONT_TYPEDEF_MS_TYPES_TO_C99_TYPES
#if _MSC_VER >= 1600
#include <stdint.h>
#else
#if !defined(HAVE_INT8_T) && defined(HAVE_MS_INT8)
typedef __int8 int8_t;
#endif
#ifdef HAVE_MS_UINT8
typedef unsigned __int8 uint8_t;
#endif
#ifdef HAVE_MS_INT16
typedef __int16 int16_t;
#endif
#ifdef HAVE_MS_UINT16
typedef unsigned __int16 uint16_t;
#endif
#ifdef HAVE_MS_INT32
typedef __int32 int32_t;
#endif
#ifdef HAVE_MS_UINT32
typedef unsigned __int32 uint32_t;
#endif
#ifdef HAVE_MS_INT64
typedef __int64 int64_t;
#endif
#ifdef HAVE_MS_UINT64
typedef unsigned __int64 uint64_t;
#endif
#endif // _MSC_VER >= 1600
#endif // CPPCONN_DONT_TYPEDEF_MS_TYPES_TO_C99_TYPES
#endif // _WIN32

View File

@ -1,176 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_CONNECTION_H_
#define _SQL_CONNECTION_H_
#include <map>
#include "build_config.h"
#include "warning.h"
#include "sqlstring.h"
#include "variant.h"
namespace sql
{
typedef sql::Variant ConnectPropertyVal;
typedef std::map< sql::SQLString, ConnectPropertyVal > ConnectOptionsMap;
class DatabaseMetaData;
class PreparedStatement;
class Statement;
class Driver;
typedef enum transaction_isolation
{
TRANSACTION_NONE= 0,
TRANSACTION_READ_COMMITTED,
TRANSACTION_READ_UNCOMMITTED,
TRANSACTION_REPEATABLE_READ,
TRANSACTION_SERIALIZABLE
} enum_transaction_isolation;
enum ssl_mode
{
SSL_MODE_DISABLED= 1, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED,
SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY
};
class Savepoint
{
/* Prevent use of these */
Savepoint(const Savepoint &);
void operator=(Savepoint &);
public:
Savepoint() {};
virtual ~Savepoint() {};
virtual int getSavepointId() = 0;
virtual sql::SQLString getSavepointName() = 0;
};
class CPPCONN_PUBLIC_FUNC Connection
{
/* Prevent use of these */
Connection(const Connection &);
void operator=(Connection &);
public:
Connection() {};
virtual ~Connection() {};
virtual void clearWarnings() = 0;
virtual Statement *createStatement() = 0;
virtual void close() = 0;
virtual void commit() = 0;
virtual bool getAutoCommit() = 0;
virtual sql::SQLString getCatalog() = 0;
virtual Driver *getDriver() = 0;
virtual sql::SQLString getSchema() = 0;
virtual sql::SQLString getClientInfo() = 0;
virtual void getClientOption(const sql::SQLString & optionName, void * optionValue) = 0;
virtual sql::SQLString getClientOption(const sql::SQLString & optionName) = 0;
virtual DatabaseMetaData * getMetaData() = 0;
virtual enum_transaction_isolation getTransactionIsolation() = 0;
virtual const SQLWarning * getWarnings() = 0;
virtual bool isClosed() = 0;
virtual bool isReadOnly() = 0;
virtual bool isValid() = 0;
virtual bool reconnect() = 0;
virtual sql::SQLString nativeSQL(const sql::SQLString& sql) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql, int* columnIndexes) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) = 0;
virtual PreparedStatement * prepareStatement(const sql::SQLString& sql, sql::SQLString columnNames[]) = 0;
virtual void releaseSavepoint(Savepoint * savepoint) = 0;
virtual void rollback() = 0;
virtual void rollback(Savepoint * savepoint) = 0;
virtual void setAutoCommit(bool autoCommit) = 0;
virtual void setCatalog(const sql::SQLString& catalog) = 0;
virtual void setSchema(const sql::SQLString& catalog) = 0;
virtual sql::Connection * setClientOption(const sql::SQLString & optionName, const void * optionValue) = 0;
virtual sql::Connection * setClientOption(const sql::SQLString & optionName, const sql::SQLString & optionValue) = 0;
virtual void setHoldability(int holdability) = 0;
virtual void setReadOnly(bool readOnly) = 0;
virtual Savepoint * setSavepoint() = 0;
virtual Savepoint * setSavepoint(const sql::SQLString& name) = 0;
virtual void setTransactionIsolation(enum_transaction_isolation level) = 0;
/* virtual void setTypeMap(Map map) = 0; */
};
} /* namespace sql */
#endif // _SQL_CONNECTION_H_

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_DATATYPE_H_
#define _SQL_DATATYPE_H_
namespace sql
{
class DataType
{
DataType();
public:
enum {
UNKNOWN = 0,
BIT,
TINYINT,
SMALLINT,
MEDIUMINT,
INTEGER,
BIGINT,
REAL,
DOUBLE,
DECIMAL,
NUMERIC,
CHAR,
BINARY,
VARCHAR,
VARBINARY,
LONGVARCHAR,
LONGVARBINARY,
TIMESTAMP,
DATE,
TIME,
YEAR,
GEOMETRY,
ENUM,
SET,
SQLNULL,
JSON
};
};
} /* namespace */
#endif /* _SQL_DATATYPE_H_ */

View File

@ -1,76 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_DRIVER_H_
#define _SQL_DRIVER_H_
#include "connection.h"
#include "build_config.h"
namespace sql
{
class CPPCONN_PUBLIC_FUNC Driver
{
protected:
virtual ~Driver() {}
public:
// Attempts to make a database connection to the given URL.
virtual Connection * connect(const sql::SQLString& hostName, const sql::SQLString& userName, const sql::SQLString& password) = 0;
virtual Connection * connect(ConnectOptionsMap & options) = 0;
virtual int getMajorVersion() = 0;
virtual int getMinorVersion() = 0;
virtual int getPatchVersion() = 0;
virtual const sql::SQLString & getName() = 0;
virtual void threadInit() = 0;
virtual void threadEnd() = 0;
};
} /* namespace sql */
extern "C"
{
CPPCONN_PUBLIC_FUNC sql::Driver * get_driver_instance();
/* If dynamic loading is disabled in a driver then this function works just like get_driver_instance() */
CPPCONN_PUBLIC_FUNC sql::Driver * get_driver_instance_by_name(const char * const clientlib);
}
#endif /* _SQL_DRIVER_H_ */

View File

@ -1,168 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_EXCEPTION_H_
#define _SQL_EXCEPTION_H_
#include "build_config.h"
#include <stdexcept>
#include <string>
#include <memory>
namespace sql
{
#if (__cplusplus < 201103L)
#define MEMORY_ALLOC_OPERATORS(Class) \
void* operator new(size_t size) throw (std::bad_alloc) { return ::operator new(size); } \
void* operator new(size_t, void*) throw(); \
void* operator new(size_t, const std::nothrow_t&) throw(); \
void* operator new[](size_t) throw (std::bad_alloc); \
void* operator new[](size_t, void*) throw(); \
void* operator new[](size_t, const std::nothrow_t&) throw(); \
void* operator new(size_t N, std::allocator<Class>&);
#else
#define MEMORY_ALLOC_OPERATORS(Class) \
void* operator new(size_t size){ return ::operator new(size); } \
void* operator new(size_t, void*) noexcept; \
void* operator new(size_t, const std::nothrow_t&) noexcept; \
void* operator new[](size_t); \
void* operator new[](size_t, void*) noexcept; \
void* operator new[](size_t, const std::nothrow_t&) noexcept; \
void* operator new(size_t N, std::allocator<Class>&);
#endif
#ifdef _WIN32
#pragma warning (disable : 4290)
//warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#pragma warning(push)
#pragma warning(disable: 4275)
#endif
class CPPCONN_PUBLIC_FUNC SQLException : public std::runtime_error
{
#ifdef _WIN32
#pragma warning(pop)
#endif
protected:
const std::string sql_state;
const int errNo;
public:
SQLException(const SQLException& e) : std::runtime_error(e.what()), sql_state(e.sql_state), errNo(e.errNo) {}
SQLException(const std::string& reason, const std::string& SQLState, int vendorCode) :
std::runtime_error (reason ),
sql_state (SQLState ),
errNo (vendorCode)
{}
SQLException(const std::string& reason, const std::string& SQLState) : std::runtime_error(reason), sql_state(SQLState), errNo(0) {}
SQLException(const std::string& reason) : std::runtime_error(reason), sql_state("HY000"), errNo(0) {}
SQLException() : std::runtime_error(""), sql_state("HY000"), errNo(0) {}
const std::string & getSQLState() const
{
return sql_state;
}
const char * getSQLStateCStr() const
{
return sql_state.c_str();
}
int getErrorCode() const
{
return errNo;
}
virtual ~SQLException() throw () {};
protected:
MEMORY_ALLOC_OPERATORS(SQLException)
};
struct CPPCONN_PUBLIC_FUNC MethodNotImplementedException : public SQLException
{
MethodNotImplementedException(const MethodNotImplementedException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
MethodNotImplementedException(const std::string& reason) : SQLException(reason, "", 0) {}
};
struct CPPCONN_PUBLIC_FUNC InvalidArgumentException : public SQLException
{
InvalidArgumentException(const InvalidArgumentException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
InvalidArgumentException(const std::string& reason) : SQLException(reason, "", 0) {}
};
struct CPPCONN_PUBLIC_FUNC InvalidInstanceException : public SQLException
{
InvalidInstanceException(const InvalidInstanceException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
InvalidInstanceException(const std::string& reason) : SQLException(reason, "", 0) {}
};
struct CPPCONN_PUBLIC_FUNC NonScrollableException : public SQLException
{
NonScrollableException(const NonScrollableException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
NonScrollableException(const std::string& reason) : SQLException(reason, "", 0) {}
};
struct CPPCONN_PUBLIC_FUNC SQLUnsupportedOptionException : public SQLException
{
SQLUnsupportedOptionException(const SQLUnsupportedOptionException& e, const std::string conn_option) :
SQLException(e.what(), e.sql_state, e.errNo),
option(conn_option )
{}
SQLUnsupportedOptionException(const std::string& reason, const std::string conn_option) :
SQLException(reason, "", 0),
option(conn_option )
{}
const char *getConnectionOption() const
{
return option.c_str();
}
~SQLUnsupportedOptionException() throw () {};
protected:
const std::string option;
};
} /* namespace sql */
#endif /* _SQL_EXCEPTION_H_ */

View File

@ -1,493 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_METADATA_H_
#define _SQL_METADATA_H_
#include <string>
#include <list>
#include "datatype.h"
#include "sqlstring.h"
namespace sql
{
class ResultSet;
class DatabaseMetaData
{
protected:
virtual ~DatabaseMetaData() {}
public:
enum
{
attributeNoNulls = 0,
attributeNullable,
attributeNullableUnknown
};
enum
{
bestRowTemporary = 0,
bestRowTransaction,
bestRowSession
};
enum
{
bestRowUnknown = 0,
bestRowNotPseudo,
bestRowPseudo
};
enum
{
columnNoNulls = 0,
columnNullable,
columnNullableUnknown
};
enum
{
importedKeyCascade = 0,
importedKeyInitiallyDeferred,
importedKeyInitiallyImmediate,
importedKeyNoAction,
importedKeyNotDeferrable,
importedKeyRestrict,
importedKeySetDefault,
importedKeySetNull
};
enum
{
procedureColumnIn = 0,
procedureColumnInOut,
procedureColumnOut,
procedureColumnResult,
procedureColumnReturn,
procedureColumnUnknown,
procedureNoNulls,
procedureNoResult,
procedureNullable,
procedureNullableUnknown,
procedureResultUnknown,
procedureReturnsResult
};
enum
{
sqlStateSQL99 = 0,
sqlStateXOpen
};
enum
{
tableIndexClustered = 0,
tableIndexHashed,
tableIndexOther,
tableIndexStatistic
};
enum
{
versionColumnUnknown = 0,
versionColumnNotPseudo = 1,
versionColumnPseudo = 2
};
enum
{
typeNoNulls = 0,
typeNullable = 1,
typeNullableUnknown = 2
};
enum
{
typePredNone = 0,
typePredChar = 1,
typePredBasic= 2,
typeSearchable = 3
};
virtual bool allProceduresAreCallable() = 0;
virtual bool allTablesAreSelectable() = 0;
virtual bool dataDefinitionCausesTransactionCommit() = 0;
virtual bool dataDefinitionIgnoredInTransactions() = 0;
virtual bool deletesAreDetected(int type) = 0;
virtual bool doesMaxRowSizeIncludeBlobs() = 0;
virtual ResultSet * getAttributes(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& typeNamePattern, const sql::SQLString& attributeNamePattern) = 0;
virtual ResultSet * getBestRowIdentifier(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table, int scope, bool nullable) = 0;
virtual ResultSet * getCatalogs() = 0;
virtual const sql::SQLString& getCatalogSeparator() = 0;
virtual const sql::SQLString& getCatalogTerm() = 0;
virtual ResultSet * getColumnPrivileges(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table, const sql::SQLString& columnNamePattern) = 0;
virtual ResultSet * getColumns(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern, const sql::SQLString& columnNamePattern) = 0;
virtual Connection * getConnection() = 0;
virtual ResultSet * getCrossReference(const sql::SQLString& primaryCatalog, const sql::SQLString& primarySchema, const sql::SQLString& primaryTable, const sql::SQLString& foreignCatalog, const sql::SQLString& foreignSchema, const sql::SQLString& foreignTable) = 0;
virtual unsigned int getDatabaseMajorVersion() = 0;
virtual unsigned int getDatabaseMinorVersion() = 0;
virtual unsigned int getDatabasePatchVersion() = 0;
virtual const sql::SQLString& getDatabaseProductName() = 0;
virtual SQLString getDatabaseProductVersion() = 0;
virtual int getDefaultTransactionIsolation() = 0;
virtual unsigned int getDriverMajorVersion() = 0;
virtual unsigned int getDriverMinorVersion() = 0;
virtual unsigned int getDriverPatchVersion() = 0;
virtual const sql::SQLString& getDriverName() = 0;
virtual const sql::SQLString& getDriverVersion() = 0;
virtual ResultSet * getExportedKeys(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table) = 0;
virtual const sql::SQLString& getExtraNameCharacters() = 0;
virtual const sql::SQLString& getIdentifierQuoteString() = 0;
virtual ResultSet * getImportedKeys(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table) = 0;
virtual ResultSet * getIndexInfo(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table, bool unique, bool approximate) = 0;
virtual unsigned int getCDBCMajorVersion() = 0;
virtual unsigned int getCDBCMinorVersion() = 0;
virtual unsigned int getMaxBinaryLiteralLength() = 0;
virtual unsigned int getMaxCatalogNameLength() = 0;
virtual unsigned int getMaxCharLiteralLength() = 0;
virtual unsigned int getMaxColumnNameLength() = 0;
virtual unsigned int getMaxColumnsInGroupBy() = 0;
virtual unsigned int getMaxColumnsInIndex() = 0;
virtual unsigned int getMaxColumnsInOrderBy() = 0;
virtual unsigned int getMaxColumnsInSelect() = 0;
virtual unsigned int getMaxColumnsInTable() = 0;
virtual unsigned int getMaxConnections() = 0;
virtual unsigned int getMaxCursorNameLength() = 0;
virtual unsigned int getMaxIndexLength() = 0;
virtual unsigned int getMaxProcedureNameLength() = 0;
virtual unsigned int getMaxRowSize() = 0;
virtual unsigned int getMaxSchemaNameLength() = 0;
virtual unsigned int getMaxStatementLength() = 0;
virtual unsigned int getMaxStatements() = 0;
virtual unsigned int getMaxTableNameLength() = 0;
virtual unsigned int getMaxTablesInSelect() = 0;
virtual unsigned int getMaxUserNameLength() = 0;
virtual const sql::SQLString& getNumericFunctions() = 0;
virtual ResultSet * getPrimaryKeys(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table) = 0;
virtual ResultSet * getProcedureColumns(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& procedureNamePattern, const sql::SQLString& columnNamePattern) = 0;
virtual ResultSet * getProcedures(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& procedureNamePattern) = 0;
virtual const sql::SQLString& getProcedureTerm() = 0;
virtual int getResultSetHoldability() = 0;
virtual ResultSet * getSchemas() = 0;
virtual const sql::SQLString& getSchemaTerm() = 0;
virtual ResultSet * getSchemaCollation(const sql::SQLString& catalog, const sql::SQLString& schemaPattern) = 0;
virtual ResultSet * getSchemaCharset(const sql::SQLString& catalog, const sql::SQLString& schemaPattern) = 0;
virtual const sql::SQLString& getSearchStringEscape() = 0;
virtual const sql::SQLString& getSQLKeywords() = 0;
virtual int getSQLStateType() = 0;
virtual const sql::SQLString& getStringFunctions() = 0;
virtual ResultSet * getSuperTables(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern) = 0;
virtual ResultSet * getSuperTypes(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& typeNamePattern) = 0;
virtual const sql::SQLString& getSystemFunctions() = 0;
virtual ResultSet * getTablePrivileges(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern) = 0;
virtual ResultSet * getTables(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern, std::list<sql::SQLString> &types) = 0;
virtual ResultSet * getTableTypes() = 0;
virtual ResultSet * getTableCollation(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern) = 0;
virtual ResultSet * getTableCharset(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& tableNamePattern) = 0;
virtual const sql::SQLString& getTimeDateFunctions() = 0;
virtual ResultSet * getTypeInfo() = 0;
virtual ResultSet * getUDTs(const sql::SQLString& catalog, const sql::SQLString& schemaPattern, const sql::SQLString& typeNamePattern, std::list<int> &types) = 0;
virtual SQLString getURL() = 0;
virtual SQLString getUserName() = 0;
virtual ResultSet * getVersionColumns(const sql::SQLString& catalog, const sql::SQLString& schema, const sql::SQLString& table) = 0;
virtual bool insertsAreDetected(int type) = 0;
virtual bool isCatalogAtStart() = 0;
virtual bool isReadOnly() = 0;
virtual bool locatorsUpdateCopy() = 0;
virtual bool nullPlusNonNullIsNull() = 0;
virtual bool nullsAreSortedAtEnd() = 0;
virtual bool nullsAreSortedAtStart() = 0;
virtual bool nullsAreSortedHigh() = 0;
virtual bool nullsAreSortedLow() = 0;
virtual bool othersDeletesAreVisible(int type) = 0;
virtual bool othersInsertsAreVisible(int type) = 0;
virtual bool othersUpdatesAreVisible(int type) = 0;
virtual bool ownDeletesAreVisible(int type) = 0;
virtual bool ownInsertsAreVisible(int type) = 0;
virtual bool ownUpdatesAreVisible(int type) = 0;
virtual bool storesLowerCaseIdentifiers() = 0;
virtual bool storesLowerCaseQuotedIdentifiers() = 0;
virtual bool storesMixedCaseIdentifiers() = 0;
virtual bool storesMixedCaseQuotedIdentifiers() = 0;
virtual bool storesUpperCaseIdentifiers() = 0;
virtual bool storesUpperCaseQuotedIdentifiers() = 0;
virtual bool supportsAlterTableWithAddColumn() = 0;
virtual bool supportsAlterTableWithDropColumn() = 0;
virtual bool supportsANSI92EntryLevelSQL() = 0;
virtual bool supportsANSI92FullSQL() = 0;
virtual bool supportsANSI92IntermediateSQL() = 0;
virtual bool supportsBatchUpdates() = 0;
virtual bool supportsCatalogsInDataManipulation() = 0;
virtual bool supportsCatalogsInIndexDefinitions() = 0;
virtual bool supportsCatalogsInPrivilegeDefinitions() = 0;
virtual bool supportsCatalogsInProcedureCalls() = 0;
virtual bool supportsCatalogsInTableDefinitions() = 0;
virtual bool supportsColumnAliasing() = 0;
virtual bool supportsConvert() = 0;
virtual bool supportsConvert(int fromType, int toType) = 0;
virtual bool supportsCoreSQLGrammar() = 0;
virtual bool supportsCorrelatedSubqueries() = 0;
virtual bool supportsDataDefinitionAndDataManipulationTransactions() = 0;
virtual bool supportsDataManipulationTransactionsOnly() = 0;
virtual bool supportsDifferentTableCorrelationNames() = 0;
virtual bool supportsExpressionsInOrderBy() = 0;
virtual bool supportsExtendedSQLGrammar() = 0;
virtual bool supportsFullOuterJoins() = 0;
virtual bool supportsGetGeneratedKeys() = 0;
virtual bool supportsGroupBy() = 0;
virtual bool supportsGroupByBeyondSelect() = 0;
virtual bool supportsGroupByUnrelated() = 0;
virtual bool supportsIntegrityEnhancementFacility() = 0;
virtual bool supportsLikeEscapeClause() = 0;
virtual bool supportsLimitedOuterJoins() = 0;
virtual bool supportsMinimumSQLGrammar() = 0;
virtual bool supportsMixedCaseIdentifiers() = 0;
virtual bool supportsMixedCaseQuotedIdentifiers() = 0;
virtual bool supportsMultipleOpenResults() = 0;
virtual bool supportsMultipleResultSets() = 0;
virtual bool supportsMultipleTransactions() = 0;
virtual bool supportsNamedParameters() = 0;
virtual bool supportsNonNullableColumns() = 0;
virtual bool supportsOpenCursorsAcrossCommit() = 0;
virtual bool supportsOpenCursorsAcrossRollback() = 0;
virtual bool supportsOpenStatementsAcrossCommit() = 0;
virtual bool supportsOpenStatementsAcrossRollback() = 0;
virtual bool supportsOrderByUnrelated() = 0;
virtual bool supportsOuterJoins() = 0;
virtual bool supportsPositionedDelete() = 0;
virtual bool supportsPositionedUpdate() = 0;
virtual bool supportsResultSetConcurrency(int type, int concurrency) = 0;
virtual bool supportsResultSetHoldability(int holdability) = 0;
virtual bool supportsResultSetType(int type) = 0;
virtual bool supportsSavepoints() = 0;
virtual bool supportsSchemasInDataManipulation() = 0;
virtual bool supportsSchemasInIndexDefinitions() = 0;
virtual bool supportsSchemasInPrivilegeDefinitions() = 0;
virtual bool supportsSchemasInProcedureCalls() = 0;
virtual bool supportsSchemasInTableDefinitions() = 0;
virtual bool supportsSelectForUpdate() = 0;
virtual bool supportsStatementPooling() = 0;
virtual bool supportsStoredProcedures() = 0;
virtual bool supportsSubqueriesInComparisons() = 0;
virtual bool supportsSubqueriesInExists() = 0;
virtual bool supportsSubqueriesInIns() = 0;
virtual bool supportsSubqueriesInQuantifieds() = 0;
virtual bool supportsTableCorrelationNames() = 0;
virtual bool supportsTransactionIsolationLevel(int level) = 0;
virtual bool supportsTransactions() = 0;
virtual bool supportsTypeConversion() = 0; /* SDBC */
virtual bool supportsUnion() = 0;
virtual bool supportsUnionAll() = 0;
virtual bool updatesAreDetected(int type) = 0;
virtual bool usesLocalFilePerTable() = 0;
virtual bool usesLocalFiles() = 0;
virtual ResultSet *getSchemata(const sql::SQLString& catalogName = "") = 0;
virtual ResultSet *getSchemaObjects(const sql::SQLString& catalogName = "",
const sql::SQLString& schemaName = "",
const sql::SQLString& objectType = "",
bool includingDdl = true,
const sql::SQLString& objectName = "",
const sql::SQLString& contextTableName = "") = 0;
virtual ResultSet *getSchemaObjectTypes() = 0;
};
} /* namespace sql */
#endif /* _SQL_METADATA_H_ */

View File

@ -1,84 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_PARAMETER_METADATA_H_
#define _SQL_PARAMETER_METADATA_H_
#include <cppconn/sqlstring.h>
namespace sql
{
class ParameterMetaData
{
public:
enum
{
parameterModeIn,
parameterModeInOut,
parameterModeOut,
parameterModeUnknown
};
enum
{
parameterNoNulls,
parameterNullable,
parameterNullableUnknown
};
virtual sql::SQLString getParameterClassName(unsigned int param) = 0;
virtual int getParameterCount() = 0;
virtual int getParameterMode(unsigned int param) = 0;
virtual int getParameterType(unsigned int param) = 0;
virtual sql::SQLString getParameterTypeName(unsigned int param) = 0;
virtual int getPrecision(unsigned int param) = 0;
virtual int getScale(unsigned int param) = 0;
virtual int isNullable(unsigned int param) = 0;
virtual bool isSigned(unsigned int param) = 0;
protected:
virtual ~ParameterMetaData() {}
};
} /* namespace sql */
#endif /* _SQL_PARAMETER_METADATA_H_ */

View File

@ -1,99 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_PREPARED_STATEMENT_H_
#define _SQL_PREPARED_STATEMENT_H_
#include <iostream>
#include "statement.h"
namespace sql
{
class Connection;
class ResultSet;
class ResultSetMetaData;
class ParameterMetaData;
class PreparedStatement : public Statement
{
public:
virtual ~PreparedStatement() {}
virtual void clearParameters() = 0;
virtual bool execute(const sql::SQLString& sql) = 0;
virtual bool execute() = 0;
virtual ResultSet *executeQuery(const sql::SQLString& sql) = 0;
virtual ResultSet *executeQuery() = 0;
virtual int executeUpdate(const sql::SQLString& sql) = 0;
virtual int executeUpdate() = 0;
virtual ResultSetMetaData * getMetaData() = 0;
virtual ParameterMetaData * getParameterMetaData() = 0;
virtual bool getMoreResults() = 0;
virtual void setBigInt(unsigned int parameterIndex, const sql::SQLString& value) = 0;
virtual void setBlob(unsigned int parameterIndex, std::istream * blob) = 0;
virtual void setBoolean(unsigned int parameterIndex, bool value) = 0;
virtual void setDateTime(unsigned int parameterIndex, const sql::SQLString& value) = 0;
virtual void setDouble(unsigned int parameterIndex, double value) = 0;
virtual void setInt(unsigned int parameterIndex, int32_t value) = 0;
virtual void setUInt(unsigned int parameterIndex, uint32_t value) = 0;
virtual void setInt64(unsigned int parameterIndex, int64_t value) = 0;
virtual void setUInt64(unsigned int parameterIndex, uint64_t value) = 0;
virtual void setNull(unsigned int parameterIndex, int sqlType) = 0;
virtual void setString(unsigned int parameterIndex, const sql::SQLString& value) = 0;
virtual PreparedStatement * setResultSetType(sql::ResultSet::enum_type type) = 0;
};
} /* namespace sql */
#endif /* _SQL_PREPARED_STATEMENT_H_ */

View File

@ -1,188 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_RESULTSET_H_
#define _SQL_RESULTSET_H_
#include "config.h"
#include <list>
#include <map>
#include <iostream>
#include "sqlstring.h"
#include "resultset_metadata.h"
namespace sql
{
class Statement;
class RowID
{
public:
virtual ~RowID() {}
};
class ResultSet
{
public:
enum
{
CLOSE_CURSORS_AT_COMMIT,
HOLD_CURSORS_OVER_COMMIT
};
enum
{
CONCUR_READ_ONLY,
CONCUR_UPDATABLE
};
enum
{
FETCH_FORWARD,
FETCH_REVERSE,
FETCH_UNKNOWN
};
typedef enum
{
TYPE_FORWARD_ONLY,
TYPE_SCROLL_INSENSITIVE,
TYPE_SCROLL_SENSITIVE
} enum_type;
virtual ~ResultSet() {}
virtual bool absolute(int row) = 0;
virtual void afterLast() = 0;
virtual void beforeFirst() = 0;
virtual void cancelRowUpdates() = 0;
virtual void clearWarnings() = 0;
virtual void close() = 0;
virtual uint32_t findColumn(const sql::SQLString& columnLabel) const = 0;
virtual bool first() = 0;
virtual std::istream * getBlob(uint32_t columnIndex) const = 0;
virtual std::istream * getBlob(const sql::SQLString& columnLabel) const = 0;
virtual bool getBoolean(uint32_t columnIndex) const = 0;
virtual bool getBoolean(const sql::SQLString& columnLabel) const = 0;
virtual int getConcurrency() = 0;
virtual SQLString getCursorName() = 0;
virtual long double getDouble(uint32_t columnIndex) const = 0;
virtual long double getDouble(const sql::SQLString& columnLabel) const = 0;
virtual int getFetchDirection() = 0;
virtual size_t getFetchSize() = 0;
virtual int getHoldability() = 0;
virtual int32_t getInt(uint32_t columnIndex) const = 0;
virtual int32_t getInt(const sql::SQLString& columnLabel) const = 0;
virtual uint32_t getUInt(uint32_t columnIndex) const = 0;
virtual uint32_t getUInt(const sql::SQLString& columnLabel) const = 0;
virtual int64_t getInt64(uint32_t columnIndex) const = 0;
virtual int64_t getInt64(const sql::SQLString& columnLabel) const = 0;
virtual uint64_t getUInt64(uint32_t columnIndex) const = 0;
virtual uint64_t getUInt64(const sql::SQLString& columnLabel) const = 0;
virtual ResultSetMetaData * getMetaData() const = 0;
virtual size_t getRow() const = 0;
virtual RowID * getRowId(uint32_t columnIndex) = 0;
virtual RowID * getRowId(const sql::SQLString & columnLabel) = 0;
virtual const Statement * getStatement() const = 0;
virtual SQLString getString(uint32_t columnIndex) const = 0;
virtual SQLString getString(const sql::SQLString& columnLabel) const = 0;
virtual enum_type getType() const = 0;
virtual void getWarnings() = 0;
virtual void insertRow() = 0;
virtual bool isAfterLast() const = 0;
virtual bool isBeforeFirst() const = 0;
virtual bool isClosed() const = 0;
virtual bool isFirst() const = 0;
virtual bool isLast() const = 0;
virtual bool isNull(uint32_t columnIndex) const = 0;
virtual bool isNull(const sql::SQLString& columnLabel) const = 0;
virtual bool last() = 0;
virtual bool next() = 0;
virtual void moveToCurrentRow() = 0;
virtual void moveToInsertRow() = 0;
virtual bool previous() = 0;
virtual void refreshRow() = 0;
virtual bool relative(int rows) = 0;
virtual bool rowDeleted() = 0;
virtual bool rowInserted() = 0;
virtual bool rowUpdated() = 0;
virtual void setFetchSize(size_t rows) = 0;
virtual size_t rowsCount() const = 0;
virtual bool wasNull() const = 0;
};
} /* namespace sql */
#endif /* _SQL_RESULTSET_H_ */

View File

@ -1,107 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_RESULTSET_METADATA_H_
#define _SQL_RESULTSET_METADATA_H_
#include "sqlstring.h"
#include "datatype.h"
namespace sql
{
class ResultSetMetaData
{
public:
enum
{
columnNoNulls,
columnNullable,
columnNullableUnknown
};
virtual SQLString getCatalogName(unsigned int column) = 0;
virtual unsigned int getColumnCount() = 0;
virtual unsigned int getColumnDisplaySize(unsigned int column) = 0;
virtual SQLString getColumnLabel(unsigned int column) = 0;
virtual SQLString getColumnName(unsigned int column) = 0;
virtual int getColumnType(unsigned int column) = 0;
virtual SQLString getColumnTypeName(unsigned int column) = 0;
virtual SQLString getColumnCharset(unsigned int columnIndex) = 0;
virtual SQLString getColumnCollation(unsigned int columnIndex) = 0;
virtual unsigned int getPrecision(unsigned int column) = 0;
virtual unsigned int getScale(unsigned int column) = 0;
virtual SQLString getSchemaName(unsigned int column) = 0;
virtual SQLString getTableName(unsigned int column) = 0;
virtual bool isAutoIncrement(unsigned int column) = 0;
virtual bool isCaseSensitive(unsigned int column) = 0;
virtual bool isCurrency(unsigned int column) = 0;
virtual bool isDefinitelyWritable(unsigned int column) = 0;
virtual int isNullable(unsigned int column) = 0;
virtual bool isNumeric(unsigned int column) = 0;
virtual bool isReadOnly(unsigned int column) = 0;
virtual bool isSearchable(unsigned int column) = 0;
virtual bool isSigned(unsigned int column) = 0;
virtual bool isWritable(unsigned int column) = 0;
virtual bool isZerofill(unsigned int column) = 0;
protected:
virtual ~ResultSetMetaData() {}
};
} /* namespace sql */
#endif /* _SQL_RESULTSET_METADATA_H_ */

View File

@ -1,244 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_STRING_H_
#define _SQL_STRING_H_
#include <string>
#include <algorithm>
#include "build_config.h"
#include <iostream>
namespace sql
{
class CPPCONN_PUBLIC_FUNC SQLString
{
std::string realStr;
public:
#ifdef _WIN32
//TODO something less dirty-hackish.
static const size_t npos = static_cast<std::string::size_type>(-1);
#else
static const size_t npos = std::string::npos;
#endif
~SQLString() {}
SQLString() {}
SQLString(const SQLString & other) : realStr(other.realStr) {}
SQLString(const std::string & other) : realStr(other) {}
SQLString(const char other[]) : realStr(other) {}
SQLString(const char * s, size_t n) : realStr(s, n) {}
// Needed for stuff like SQLString str= "char * string constant"
const SQLString & operator=(const char * s)
{
realStr = s;
return *this;
}
const SQLString & operator=(const std::string & rhs)
{
realStr = rhs;
return *this;
}
const SQLString & operator=(const SQLString & rhs)
{
realStr = rhs.realStr;
return *this;
}
// Conversion to st::string. Comes in play for stuff like std::string str= SQLString_var;
operator const std::string &() const
{
return realStr;
}
/** For access std::string methods. Not sure we need it. Makes it look like some smart ptr.
possibly operator* - will look even more like smart ptr */
std::string * operator ->()
{
return & realStr;
}
int compare(const SQLString& str) const
{
return realStr.compare(str.realStr);
}
int compare(const char * s) const
{
return realStr.compare(s);
}
int compare(size_t pos1, size_t n1, const char * s) const
{
return realStr.compare(pos1, n1, s);
}
int caseCompare(const SQLString &s) const
{
std::string tmp(realStr), str(s);
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return tmp.compare(str);
}
int caseCompare(const char * s) const
{
std::string tmp(realStr), str(s);
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
return tmp.compare(str);
}
int caseCompare(size_t pos1, size_t n1, const char * s) const
{
std::string tmp(realStr.c_str() + pos1, n1), str(s);
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
return tmp.compare(str);
}
const std::string & asStdString() const
{
return realStr;
}
const char * c_str() const
{
return realStr.c_str();
}
size_t length() const
{
return realStr.length();
}
SQLString & append(const std::string & str)
{
realStr.append(str);
return *this;
}
SQLString & append(const char * s)
{
realStr.append(s);
return *this;
}
const char& operator[](size_t pos) const
{
return realStr[pos];
}
size_t find(char c, size_t pos = 0) const
{
return realStr.find(c, pos);
}
size_t find(const SQLString & s, size_t pos = 0) const
{
return realStr.find(s.realStr, pos);
}
SQLString substr(size_t pos = 0, size_t n = npos) const
{
return realStr.substr(pos, n);
}
const SQLString& replace(size_t pos1, size_t n1, const SQLString & s)
{
realStr.replace(pos1, n1, s.realStr);
return *this;
}
size_t find_first_of(char c, size_t pos = 0) const
{
return realStr.find_first_of(c, pos);
}
size_t find_last_of(char c, size_t pos = npos) const
{
return realStr.find_last_of(c, pos);
}
const SQLString & operator+=(const SQLString & op2)
{
realStr += op2.realStr;
return *this;
}
};
/*
Operators that can and have to be not a member.
*/
inline const SQLString operator+(const SQLString & op1, const SQLString & op2)
{
return sql::SQLString(op1.asStdString() + op2.asStdString());
}
inline bool operator ==(const SQLString & op1, const SQLString & op2)
{
return (op1.asStdString() == op2.asStdString());
}
inline bool operator !=(const SQLString & op1, const SQLString & op2)
{
return (op1.asStdString() != op2.asStdString());
}
inline bool operator <(const SQLString & op1, const SQLString & op2)
{
return op1.asStdString() < op2.asStdString();
}
}// namespace sql
namespace std
{
// operator << for SQLString output
inline ostream & operator << (ostream & os, const sql::SQLString & str )
{
return os << str.asStdString();
}
}
#endif

View File

@ -1,103 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_STATEMENT_H_
#define _SQL_STATEMENT_H_
#include "config.h"
#include "resultset.h"
#include <string>
namespace sql
{
class ResultSet;
class Connection;
class SQLWarning;
class Statement
{
public:
virtual ~Statement() {};
virtual Connection * getConnection() = 0;
virtual void cancel() = 0;
virtual void clearWarnings() = 0;
virtual void close() = 0;
virtual bool execute(const sql::SQLString& sql) = 0;
virtual ResultSet * executeQuery(const sql::SQLString& sql) = 0;
virtual int executeUpdate(const sql::SQLString& sql) = 0;
virtual size_t getFetchSize() = 0;
virtual unsigned int getMaxFieldSize() = 0;
virtual uint64_t getMaxRows() = 0;
virtual bool getMoreResults() = 0;
virtual unsigned int getQueryTimeout() = 0;
virtual ResultSet * getResultSet() = 0;
virtual sql::ResultSet::enum_type getResultSetType() = 0;
virtual uint64_t getUpdateCount() = 0;
virtual const SQLWarning * getWarnings() = 0;
virtual void setCursorName(const sql::SQLString & name) = 0;
virtual void setEscapeProcessing(bool enable) = 0;
virtual void setFetchSize(size_t rows) = 0;
virtual void setMaxFieldSize(unsigned int max) = 0;
virtual void setMaxRows(unsigned int max) = 0;
virtual void setQueryTimeout(unsigned int seconds) = 0;
virtual Statement * setResultSetType(sql::ResultSet::enum_type type) = 0;
};
} /* namespace sql */
#endif /* _SQL_STATEMENT_H_ */

View File

@ -1,80 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SQL_WARNING_H_
#define _SQL_WARNING_H_
#include <stdexcept>
#include <string>
#include <memory>
#include "sqlstring.h"
namespace sql
{
#ifdef _WIN32
#pragma warning (disable : 4290)
//warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
class SQLWarning
{
public:
SQLWarning(){}
virtual const sql::SQLString & getMessage() const = 0;
virtual const sql::SQLString & getSQLState() const = 0;
virtual int getErrorCode() const = 0;
virtual const SQLWarning * getNextWarning() const = 0;
virtual void setNextWarning(const SQLWarning * _next) = 0;
protected:
virtual ~SQLWarning(){};
SQLWarning(const SQLWarning&){};
private:
const SQLWarning & operator = (const SQLWarning & rhs);
};
} /* namespace sql */
#endif /* _SQL_WARNING_H_ */

View File

@ -1,206 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _MYSQL_CONNECTION_H_
#define _MYSQL_CONNECTION_H_
#include <cppconn/connection.h>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
namespace sql
{
namespace mysql
{
class MySQL_Savepoint : public sql::Savepoint
{
sql::SQLString name;
public:
MySQL_Savepoint(const sql::SQLString &savepoint);
virtual ~MySQL_Savepoint() {}
int getSavepointId();
sql::SQLString getSavepointName();
private:
/* Prevent use of these */
MySQL_Savepoint(const MySQL_Savepoint &);
void operator=(MySQL_Savepoint &);
};
class MySQL_DebugLogger;
struct MySQL_ConnectionData; /* PIMPL */
class MySQL_Statement;
namespace NativeAPI
{
class NativeConnectionWrapper;
}
class CPPCONN_PUBLIC_FUNC MySQL_Connection : public sql::Connection
{
MySQL_Statement * createServiceStmt();
public:
MySQL_Connection(Driver * _driver,
::sql::mysql::NativeAPI::NativeConnectionWrapper & _proxy,
const sql::SQLString& hostName,
const sql::SQLString& userName,
const sql::SQLString& password);
MySQL_Connection(Driver * _driver, ::sql::mysql::NativeAPI::NativeConnectionWrapper & _proxy,
std::map< sql::SQLString, sql::ConnectPropertyVal > & options);
virtual ~MySQL_Connection();
void clearWarnings();
void close();
void commit();
sql::Statement * createStatement();
sql::SQLString escapeString(const sql::SQLString &);
bool getAutoCommit();
sql::SQLString getCatalog();
Driver *getDriver();
sql::SQLString getSchema();
sql::SQLString getClientInfo();
void getClientOption(const sql::SQLString & optionName, void * optionValue);
sql::SQLString getClientOption(const sql::SQLString & optionName);
sql::DatabaseMetaData * getMetaData();
enum_transaction_isolation getTransactionIsolation();
const SQLWarning * getWarnings();
bool isClosed();
bool isReadOnly();
bool isValid();
bool reconnect();
sql::SQLString nativeSQL(const sql::SQLString& sql);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int columnIndexes[]);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability);
sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, sql::SQLString columnNames[]);
void releaseSavepoint(Savepoint * savepoint) ;
void rollback();
void rollback(Savepoint * savepoint);
void setAutoCommit(bool autoCommit);
void setCatalog(const sql::SQLString& catalog);
void setSchema(const sql::SQLString& catalog);
sql::Connection * setClientOption(const sql::SQLString & optionName, const void * optionValue);
sql::Connection * setClientOption(const sql::SQLString & optionName, const sql::SQLString & optionValue);
void setHoldability(int holdability);
void setReadOnly(bool readOnly);
sql::Savepoint * setSavepoint();
sql::Savepoint * setSavepoint(const sql::SQLString& name);
void setTransactionIsolation(enum_transaction_isolation level);
virtual sql::SQLString getSessionVariable(const sql::SQLString & varname);
virtual void setSessionVariable(const sql::SQLString & varname, const sql::SQLString & value);
virtual void setSessionVariable(const sql::SQLString & varname, unsigned int value);
virtual sql::SQLString getLastStatementInfo();
private:
/* We do not really think this class has to be subclassed*/
void checkClosed();
void init(std::map< sql::SQLString, sql::ConnectPropertyVal > & properties);
Driver * driver;
boost::shared_ptr< NativeAPI::NativeConnectionWrapper > proxy;
/* statement handle to execute queries initiated by driver. Perhaps it is
a good idea to move it to a separate helper class */
boost::scoped_ptr< ::sql::mysql::MySQL_Statement > service;
boost::scoped_ptr< ::sql::mysql::MySQL_ConnectionData > intern; /* pimpl */
/* Prevent use of these */
MySQL_Connection(const MySQL_Connection &);
void operator=(MySQL_Connection &);
};
} /* namespace mysql */
} /* namespace sql */
#endif // _MYSQL_CONNECTION_H_
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -1,110 +0,0 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2.0, as
* published by the Free Software Foundation.
*
* This program is also distributed with certain software (including
* but not limited to OpenSSL) that is licensed under separate terms,
* as designated in a particular file or component or in included license
* documentation. The authors of MySQL hereby grant you an
* additional permission to link the program and your derivative works
* with the separately licensed software that they have included with
* MySQL.
*
* Without limiting anything contained in the foregoing, this file,
* which is part of MySQL Connector/C++, is also subject to the
* Universal FOSS Exception, version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License, version 2.0, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _MYSQL_DRIVER_H_
#define _MYSQL_DRIVER_H_
#include <boost/scoped_ptr.hpp>
#include <cppconn/driver.h>
extern "C"
{
CPPCONN_PUBLIC_FUNC void * sql_mysql_get_driver_instance();
}
namespace sql
{
namespace mysql
{
namespace NativeAPI
{
class NativeDriverWrapper;
}
//class sql::mysql::NativeAPI::NativeDriverWrapper;
class CPPCONN_PUBLIC_FUNC MySQL_Driver : public sql::Driver
{
boost::scoped_ptr< ::sql::mysql::NativeAPI::NativeDriverWrapper > proxy;
public:
MySQL_Driver();
MySQL_Driver(const ::sql::SQLString & clientLib);
virtual ~MySQL_Driver();
sql::Connection * connect(const sql::SQLString& hostName, const sql::SQLString& userName, const sql::SQLString& password);
sql::Connection * connect(sql::ConnectOptionsMap & options);
int getMajorVersion();
int getMinorVersion();
int getPatchVersion();
const sql::SQLString & getName();
void threadInit();
void threadEnd();
private:
/* Prevent use of these */
MySQL_Driver(const MySQL_Driver &);
void operator=(MySQL_Driver &);
};
/** We do not hide the function if MYSQLCLIENT_STATIC_BINDING(or anything else) not defined
because the counterpart C function is declared in the cppconn and is always visible.
If dynamic loading is not enabled then its result is just like of get_driver_instance()
*/
CPPCONN_PUBLIC_FUNC MySQL_Driver * get_driver_instance_by_name(const char * const clientlib);
CPPCONN_PUBLIC_FUNC MySQL_Driver * get_driver_instance();
static inline MySQL_Driver * get_mysql_driver_instance() { return get_driver_instance(); }
} /* namespace mysql */
} /* namespace sql */
#endif // _MYSQL_DRIVER_H_
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/