#At bzr+ssh://ahristov@stripped/bzrroot/public/connector-cpp-bzr/trunk/
186 andrey.hristov@stripped 2008-10-17
Blob support for PreparedStatement added
Cleanup in other parts -> better header protectors
Usage of the abstract classes in the definitions whenever possible
added:
cppconn/blob.h
modified:
cppconn/connection.h
cppconn/datatype.h
cppconn/driver.h
cppconn/exception.h
cppconn/metadata.h
cppconn/parameter_metadata.h
cppconn/prepared_statement.h
cppconn/resultset.h
cppconn/resultset_metadata.h
cppconn/statement.h
driver/mysql_connection.cpp
driver/mysql_connection.h
driver/mysql_prepared_statement.cpp
driver/mysql_prepared_statement.h
driver/mysql_private_iface.h
driver/mysql_statement.h
=== added file 'cppconn/blob.h'
--- a/cppconn/blob.h 1970-01-01 00:00:00 +0000
+++ b/cppconn/blob.h 2008-10-17 16:54:41 +0000
@@ -0,0 +1,41 @@
+/* Copyright (C) 2007 - 2008 MySQL AB, 2008 Sun Microsystems, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef _SQL_BLOB_H_
+#define _SQL_BLOB_H_
+
+
+namespace sql
+{
+
+class Blob
+{
+public:
+ Blob() {}
+ virtual ~Blob() {}
+
+ virtual std::string readChunk(size_t chunkSize) = 0;
+ virtual void writeChunk(const std::string & chunk) = 0;
+};
+
+}; /* namespace sql */
+
+#endif // _SQL_BLOB_H_
=== modified file 'cppconn/connection.h'
--- a/cppconn/connection.h 2008-10-17 15:28:52 +0000
+++ b/cppconn/connection.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _CONNECTION_H_
-#define _CONNECTION_H_
+#ifndef _SQL_CONNECTION_H_
+#define _SQL_CONNECTION_H_
#if defined(_WIN32)
#ifdef CPPDBC_EXPORTS
@@ -143,4 +143,4 @@ public:
}; /* namespace sql */
-#endif // _CONNECTION_H_
+#endif // _SQL_CONNECTION_H_
=== modified file 'cppconn/datatype.h'
--- a/cppconn/datatype.h 2008-10-13 09:55:26 +0000
+++ b/cppconn/datatype.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _DATATYPE_H_
-#define _DATATYPE_H_
+#ifndef _SQL_DATATYPE_H_
+#define _SQL_DATATYPE_H_
namespace sql
{
@@ -62,4 +62,4 @@ public:
}; /* namespace */
-#endif
+#endif /* _SQL_DATATYPE_H_ */
=== modified file 'cppconn/driver.h'
--- a/cppconn/driver.h 2008-10-17 10:11:08 +0000
+++ b/cppconn/driver.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _DRIVER_H_
-#define _DRIVER_H_
+#ifndef _SQL_DRIVER_H_
+#define _SQL_DRIVER_H_
#include <string>
@@ -38,18 +38,15 @@ namespace sql
{
class Connection;
-class db_mgmt_Connection;
class CPPDBC_PUBLIC_FUNC Driver
{
protected:
- virtual ~Driver() {}
+ virtual ~Driver() {}
public:
// Attempts to make a database connection to the given URL.
- virtual Connection *connect(const std::string& hostName,
- const std::string& userName,
- const std::string& password) = 0;
+ virtual Connection * connect(const std::string& hostName, const std::string& userName, const std::string& password) = 0;
virtual int getMajorVersion() = 0;
@@ -65,4 +62,4 @@ extern "C"
CPPDBC_PUBLIC_FUNC sql::Driver *get_driver_instance();
}
-#endif // _DRIVER_H_
+#endif /* _SQL_DRIVER_H_ */
=== modified file 'cppconn/exception.h'
--- a/cppconn/exception.h 2008-10-15 17:41:44 +0000
+++ b/cppconn/exception.h 2008-10-17 16:54:41 +0000
@@ -44,22 +44,14 @@ public:
next (NULL )
{}
- 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(""), errNo(0) {}
-
- SQLException() :
- std::runtime_error(""),
- sql_state(""), errNo(0) {}
+ 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(""), errNo(0) {}
+
+ SQLException() : std::runtime_error(""), sql_state(""), errNo(0) {}
/* BC - FIXME */
- SQLException(const char * /*file*/, int /*line*/, const char * /*desc*/) :
- std::runtime_error("BC - FIXME"),
- sql_state(""), errNo(0) {}
+ SQLException(const char *, int, const char *) : std::runtime_error("BC - FIXME"), sql_state(""), errNo(0) {}
const std::string& getSQLState() const
{
@@ -87,26 +79,21 @@ public:
struct MethodNotImplementedException : public SQLException
{
- MethodNotImplementedException(const std::string& reason) :
- SQLException(reason, "", 0) {}
+ MethodNotImplementedException(const std::string& reason) : SQLException(reason, "", 0) {}
/* BC - FIXME */
- MethodNotImplementedException(const char * reason) :
- SQLException(std::string(reason), "", 0) {}
+ MethodNotImplementedException(const char * reason) : SQLException(std::string(reason), "", 0) {}
};
struct InvalidArgumentException : public SQLException
{
- InvalidArgumentException(const std::string& reason) :
- SQLException(reason, "", 0) {}
+ InvalidArgumentException(const std::string& reason) : SQLException(reason, "", 0) {}
/* BC - FIXME */
- InvalidArgumentException(const char * /*func*/, int /*line*/, const char *t) :
- SQLException(std::string(t), "", 0) {}
-
+ InvalidArgumentException(const char * /*func*/, int /*line*/, const char *t) : SQLException(std::string(t), "", 0) {}
};
}; /* namespace sql */
-#endif // _SQL_EXCEPTION_H_
+#endif /* _SQL_EXCEPTION_H_ */
=== modified file 'cppconn/metadata.h'
--- a/cppconn/metadata.h 2008-10-15 17:05:45 +0000
+++ b/cppconn/metadata.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _METADATA_H_
-#define _METADATA_H_
+#ifndef _SQL_METADATA_H_
+#define _SQL_METADATA_H_
#include <string>
#include <list>
@@ -464,4 +464,4 @@ public:
}; /* namespace sql */
-#endif // _METADATA_H_
+#endif /* _SQL_METADATA_H_ */
=== modified file 'cppconn/parameter_metadata.h'
--- a/cppconn/parameter_metadata.h 2008-10-13 09:55:26 +0000
+++ b/cppconn/parameter_metadata.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _PARAMETER_METADATA_H_
-#define _PARAMETER_METADATA_H_
+#ifndef _SQL_PARAMETER_METADATA_H_
+#define _SQL_PARAMETER_METADATA_H_
#include <string>
@@ -69,4 +69,4 @@ public:
}; /* namespace sql */
-#endif // _PARAMETER_METADATA_H_
+#endif /* _SQL_PARAMETER_METADATA_H_ */
=== modified file 'cppconn/prepared_statement.h'
--- a/cppconn/prepared_statement.h 2008-10-17 10:11:08 +0000
+++ b/cppconn/prepared_statement.h 2008-10-17 16:54:41 +0000
@@ -20,10 +20,11 @@
*/
-#ifndef _PREPARED_STATEMENT_H_
-#define _PREPARED_STATEMENT_H_
+#ifndef _SQL_PREPARED_STATEMENT_H_
+#define _SQL_PREPARED_STATEMENT_H_
#include "statement.h"
+#include "blob.h"
namespace sql
@@ -53,7 +54,7 @@ public:
virtual const ParameterMetaData * getParameterMetaData() = 0;
- virtual void setBlob(unsigned int parameterIndex, const std::string& fileName) = 0;
+ virtual void setBlob(unsigned int parameterIndex, sql::Blob & blob) = 0;
virtual void setBoolean(unsigned int parameterIndex, bool value) = 0;
@@ -73,4 +74,4 @@ public:
}; /* namespace sql */
-#endif // _PREPARED_STATEMENT_H_
+#endif /* _SQL_PREPARED_STATEMENT_H_ */
=== modified file 'cppconn/resultset.h'
--- a/cppconn/resultset.h 2008-10-17 09:10:31 +0000
+++ b/cppconn/resultset.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _RESULTSET_H_
-#define _RESULTSET_H_
+#ifndef _SQL_RESULTSET_H_
+#define _SQL_RESULTSET_H_
#include "exception.h"
#include "resultset_metadata.h"
@@ -162,4 +162,4 @@ public:
}; /* namespace sql */
-#endif // _RESULTSET_H_
+#endif /* _SQL_RESULTSET_H_ */
=== modified file 'cppconn/resultset_metadata.h'
--- a/cppconn/resultset_metadata.h 2008-10-13 09:55:26 +0000
+++ b/cppconn/resultset_metadata.h 2008-10-17 16:54:41 +0000
@@ -19,12 +19,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _RESULTSET_METADATA_H_
-#define _RESULTSET_METADATA_H_
+#ifndef _SQL_RESULTSET_METADATA_H_
+#define _SQL_RESULTSET_METADATA_H_
#include <string>
-
namespace sql
{
@@ -84,4 +83,4 @@ public:
}; /* namespace sql */
-#endif // _RESULTSET_METADATA_H_
+#endif /* _SQL_RESULTSET_METADATA_H_ */
=== modified file 'cppconn/statement.h'
--- a/cppconn/statement.h 2008-10-15 17:05:45 +0000
+++ b/cppconn/statement.h 2008-10-17 16:54:41 +0000
@@ -19,8 +19,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _STATEMENT_H_
-#define _STATEMENT_H_
+#ifndef _SQL_STATEMENT_H_
+#define _SQL_STATEMENT_H_
#include <string>
@@ -81,4 +81,4 @@ public:
}; /* namespace sql */
-#endif // _STATEMENT_H_
+#endif /* _SQL_STATEMENT_H_ */
=== modified file 'driver/mysql_connection.cpp'
--- a/driver/mysql_connection.cpp 2008-10-17 15:28:52 +0000
+++ b/driver/mysql_connection.cpp 2008-10-17 16:54:41 +0000
@@ -356,7 +356,7 @@ MySQL_Connection::prepareStatement(const
throw e;
}
- return new MySQL_Prepared_Statement(stmt, this);
+ return new MySQL_Prepared_Statement(stmt, this, this->logger);
}
/* }}} */
=== modified file 'driver/mysql_connection.h'
--- a/driver/mysql_connection.h 2008-10-17 15:28:52 +0000
+++ b/driver/mysql_connection.h 2008-10-17 16:54:41 +0000
@@ -51,10 +51,8 @@ private:
void operator=(MySQL_Savepoint &);
};
-class MySQL_ConnectionMetaData;
class MySQL_DebugLogger;
-
class CPPDBC_PUBLIC_FUNC MySQL_Connection : public sql::Connection
{
public:
@@ -134,7 +132,7 @@ public:
MySQL_DebugLogger * logger;
private:
- MySQL_ConnectionMetaData * metadata;
+ sql::DatabaseMetaData * metadata;
bool closed;
bool autocommit;
=== modified file 'driver/mysql_prepared_statement.cpp'
--- a/driver/mysql_prepared_statement.cpp 2008-10-15 17:22:12 +0000
+++ b/driver/mysql_prepared_statement.cpp 2008-10-17 16:54:41 +0000
@@ -68,8 +68,8 @@ get_new_param_bind(int param_count)
/* {{{ MySQL_Prepared_Statement::MySQL_Prepared_Statement() -I- */
-MySQL_Prepared_Statement::MySQL_Prepared_Statement(MYSQL_STMT *s, MySQL_Connection * conn)
- :connection(conn), stmt(s), param_bind(NULL), isClosed(false), logger(conn->logger)
+MySQL_Prepared_Statement::MySQL_Prepared_Statement(MYSQL_STMT *s, sql::Connection * conn, MySQL_DebugLogger * log)
+ :connection(conn), stmt(s), param_bind(NULL), isClosed(false), logger(log)
{
CPP_ENTER("MySQL_Prepared_Statement::MySQL_Prepared_Statement");
param_count = mysql_stmt_param_count(s);
@@ -333,7 +333,7 @@ MySQL_Prepared_Statement::executeUpdate(
/* {{{ MySQL_Prepared_Statement::setBlob() -U- */
void
-MySQL_Prepared_Statement::setBlob(unsigned int parameterIndex, const std::string&)
+MySQL_Prepared_Statement::setBlob(unsigned int parameterIndex, sql::Blob & blob)
{
CPP_ENTER("MySQL_Prepared_Statement::setBlob");
CPP_INFO_FMT("this=%p", this);
@@ -342,7 +342,33 @@ MySQL_Prepared_Statement::setBlob(unsign
if (parameterIndex >= param_count) {
throw new InvalidArgumentException(CPPCONN_FUNC, __LINE__, "MySQL_Prepared_Statement::setBlob: invalid 'parameterIndex'");
}
- throw new sql::MethodNotImplementedException("MySQL_Prepared_Statement::setBlob");
+ do {
+ std::string chunk = blob.readChunk(1024);
+ if (!chunk.length()) {
+ break;
+ }
+ if (mysql_stmt_send_long_data(stmt, parameterIndex, chunk.c_str(), chunk.length())) {
+ switch (mysql_stmt_errno(stmt)) {
+ case CR_OUT_OF_MEMORY:
+ throw new std::bad_alloc();
+ case CR_INVALID_BUFFER_USE:
+ throw new InvalidArgumentException(CPPCONN_FUNC, __LINE__, "MySQL_Prepared_Statement::setBlob: can't set blob value on that column");
+ case CR_SERVER_GONE_ERROR:
+ case CR_COMMANDS_OUT_OF_SYNC:
+ default:
+ throw new SQLException(mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt));
+ }
+ }
+ } while (1);
+}
+/* }}} */
+
+
+/* {{{ MySQL_Prepared_Statement::setBoolean() -I- */
+void
+MySQL_Prepared_Statement::setBoolean(unsigned int parameterIndex, bool value)
+{
+ setInt(parameterIndex, value);
}
/* }}} */
=== modified file 'driver/mysql_prepared_statement.h'
--- a/driver/mysql_prepared_statement.h 2008-10-13 09:55:26 +0000
+++ b/driver/mysql_prepared_statement.h 2008-10-17 16:54:41 +0000
@@ -31,14 +31,12 @@ namespace sql
{
namespace mysql
{
-class MySQL_Connection;
-class MySQL_ParameterMetaData;
class MySQL_DebugLogger;
class MySQL_Prepared_Statement : public sql::PreparedStatement
{
protected:
- MySQL_Connection *connection;
+ sql::Connection *connection;
MYSQL_STMT *stmt;
MYSQL_BIND *param_bind;
unsigned int param_count;
@@ -46,7 +44,7 @@ protected:
int resultSetConcurrency;
int resultSetType;
- std::list<std::string> warnings;
+ std::list< std::string > warnings;
bool isClosed;
@@ -62,10 +60,10 @@ protected:
unsigned long *len;
MYSQL_BIND *result_bind;
- const MySQL_ParameterMetaData * param_meta;
+ const sql::ParameterMetaData * param_meta;
public:
- MySQL_Prepared_Statement(MYSQL_STMT *s, MySQL_Connection *conn);
+ MySQL_Prepared_Statement(MYSQL_STMT *s, sql::Connection * conn, MySQL_DebugLogger * log);
virtual ~MySQL_Prepared_Statement();
sql::Connection *getConnection();
@@ -105,9 +103,9 @@ public:
void getWarnings();/* should return differen type */
- void setBlob(unsigned int parameterIndex, const std::string& fileName);
+ void setBlob(unsigned int parameterIndex, sql::Blob & blob);
- void setBoolean(unsigned int parameterIndex, bool value) { setInt(parameterIndex, value); }
+ void setBoolean(unsigned int parameterIndex, bool value);
void setBigInt(unsigned int parameterIndex, const std::string& value);
=== modified file 'driver/mysql_private_iface.h'
--- a/driver/mysql_private_iface.h 2008-10-13 09:55:26 +0000
+++ b/driver/mysql_private_iface.h 2008-10-17 16:54:41 +0000
@@ -24,7 +24,7 @@ extern "C"
#if defined(_WIN32) || defined(_WIN64)
#include "my_global.h"
#endif
-
+#include "errmsg.h"
#include "mysql.h"
}
/* mysql.h introduces bool */
=== modified file 'driver/mysql_statement.h'
--- a/driver/mysql_statement.h 2008-10-13 09:55:26 +0000
+++ b/driver/mysql_statement.h 2008-10-17 16:54:41 +0000
@@ -33,10 +33,10 @@ class MySQL_Connection;
class MYSQL_RES_Wrapper;
class MySQL_DebugLogger;
-class MySQL_Statement : public ::sql::Statement
+class MySQL_Statement : public sql::Statement
{
protected:
- std::list<std::string> warnings;
+ std::list< std::string > warnings;
MySQL_Connection *connection;
void do_query(const char *q, size_t length);
@@ -48,7 +48,7 @@ protected:
virtual void checkClosed();
public:
- MySQL_Statement(MySQL_Connection *conn);
+ MySQL_Statement(MySQL_Connection * conn);
~MySQL_Statement();
sql::Connection *getConnection();
| Thread |
|---|
| • bzr commit into connector-cpp-bzr branch (andrey.hristov:186) | andrey.hristov | 17 Oct |