List:Commits« Previous MessageNext Message »
From:andrey.hristov Date:November 20 2008 12:24pm
Subject:bzr commit into connector-cpp-bzr branch (andrey.hristov:273)
View as plain text  
#At bzr+ssh://ahristov@stripped/bzrroot/public/connector-cpp-bzr/trunk/

  273 andrey.hristov@stripped	2008-11-20
      Introduce a new exception InvalidInstanceException and change some of the uses of MySQL_SQLException to it.
      The other cases were converted to SQLException.
      Removed MySQL_SQLException
removed:
  driver/mysql_exception.cpp
  driver/mysql_exception.h
modified:
  cppconn/exception.h
  driver/CMakeLists.txt
  driver/mysql_connection.cpp
  driver/mysql_constructed_resultset.cpp
  driver/mysql_prepared_statement.cpp
  driver/mysql_ps_resultset.cpp
  driver/mysql_resultset.cpp
  driver/mysql_statement.cpp

=== modified file 'cppconn/exception.h'
--- a/cppconn/exception.h	2008-11-19 10:04:45 +0000
+++ b/cppconn/exception.h	2008-11-20 12:24:33 +0000
@@ -100,6 +100,15 @@ private:
   virtual SQLException* copy() { return new InvalidArgumentException(*this); }
 };
 
+struct InvalidInstanceException : public SQLException
+{
+ 	InvalidInstanceException(const InvalidInstanceException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
+ 	InvalidInstanceException(const std::string& reason) : SQLException(reason, "", 0) {}
+
+private:
+  virtual SQLException* copy() { return new InvalidInstanceException(*this); }
+};
+
 }; /* namespace sql */
 
 #endif /* _SQL_EXCEPTION_H_ */

=== modified file 'driver/CMakeLists.txt'
--- a/driver/CMakeLists.txt	2008-11-18 15:43:11 +0000
+++ b/driver/CMakeLists.txt	2008-11-20 12:24:33 +0000
@@ -35,7 +35,6 @@ SET(MYSQLCPPCONN_SOURCES
 	mysql_cset_metadata.cpp
 	mysql_debug.cpp
 	mysql_driver.cpp
-	mysql_exception.cpp
 	mysql_metadata.cpp
 	mysql_parameter_metadata.cpp
 	mysql_prepared_statement.cpp

=== modified file 'driver/mysql_connection.cpp'
--- a/driver/mysql_connection.cpp	2008-11-20 11:17:24 +0000
+++ b/driver/mysql_connection.cpp	2008-11-20 12:24:33 +0000
@@ -31,7 +31,6 @@
 #include "mysql_connection.h"
 #include "mysql_prepared_statement.h"
 #include "mysql_statement.h"
-#include "mysql_exception.h"
 #include "mysql_metadata.h"
 #include "mysql_resultset.h"
 #include "mysql_warning.h"
@@ -90,7 +89,7 @@ MySQL_Connection::MySQL_Connection(const
 	try {
 		if (!(mysql = mysql_init(NULL))) {
 			logger->freeReference();
-			throw MySQL_SQLException("Insufficient memory: cannot create MySQL handle using mysql_init()");
+			throw sql::SQLException("Insufficient memory: cannot create MySQL handle using mysql_init()", "HY000", 1000);
 		}
 #ifndef CPPDBC_WIN32
 		if (!hostName.compare(0, sizeof("unix://") - 1, "unix://")) {
@@ -184,7 +183,7 @@ MySQL_Connection::checkClosed()
 {
 	CPP_ENTER("MySQL_Connection::checkClosed");
 	if (!is_valid) {
-		throw MySQL_SQLException("Connection has been closed");
+		throw sql::SQLException("Connection has been closed", "HY000", 1000);
 	}
 }
 /* }}} */

=== modified file 'driver/mysql_constructed_resultset.cpp'
--- a/driver/mysql_constructed_resultset.cpp	2008-11-19 12:23:01 +0000
+++ b/driver/mysql_constructed_resultset.cpp	2008-11-20 12:24:33 +0000
@@ -184,7 +184,7 @@ MySQL_ConstructedResultSet::checkValid()
 {
 	CPP_ENTER("MySQL_ConstructedResultSet::checkValid");
 	if (isClosed()) {
-		throw MySQL_SQLException("Statement has been closed");
+		throw sql::InvalidInstanceException("ResultSet has been closed");
 	}
 }
 /* }}} */

=== removed file 'driver/mysql_exception.cpp'
--- a/driver/mysql_exception.cpp	2008-10-15 17:22:12 +0000
+++ b/driver/mysql_exception.cpp	1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
-/* 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
-*/
-
-#include "mysql_exception.h"
-#include <stdio.h>
-
-namespace sql
-{
-namespace mysql
-{
-
-/* {{{ MySQL_SQLException::MySQL_SQLException -I- */
-MySQL_SQLException::MySQL_SQLException(const char *error) :
-	SQLException(error) { printf("EXCEPTION=%s\n", error);}
-/* }}} */
-
-/* {{{ MySQL_SQLException::MySQL_SQLException -I- */
-MySQL_SQLException::MySQL_SQLException(const char *error, const char* sqlerror, unsigned int _errNo) :
-	SQLException(error, sqlerror, (int)_errNo) {}
-/* }}} */
-
-
-};/* namespace mysql */
-};/* namespace sql */
-
-/*
- * 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
- */

=== removed file 'driver/mysql_exception.h'
--- a/driver/mysql_exception.h	2008-11-19 10:04:45 +0000
+++ b/driver/mysql_exception.h	1970-01-01 00:00:00 +0000
@@ -1,80 +0,0 @@
-/* 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 _MYSQL_DBC_EXCECPTION_H_
-#define _MYSQL_DBC_EXCECPTION_H_
-
-#include <cppconn/exception.h>
-
-/*
-TODO - FIXME
-
-I've had a chat with Andrey. We are not sure if we need this extra type of
-exception. Client side errors cause MySQL_SQLExceptions and server side
-errors result in SQLExceptions. However, the interfaces of the exception classes
-are identical. The only purpose of the MySQL_SQLException is to transport
-the information "comes from the client".
-
-Earlier versions of C/C++ did have a driver - driver manager design. We've almost
-(99% sure) given up that design. Therefore its questionable wheter we need a deeply
-nested exceptions class structure. Nowadays sql::SQLException is modeled after
-JDBC's SQLException. We can use it for any kind of SQL errors (client and server).
-It offers all we need for the MySQL driver.
-
-Deriving from it just for the purpose of indicating a MySQL driver error
-is pointless - there is only one driver (driver - driver manager
-design is almost gone). And if we want to distinguish between server and client
-errors we can do it on the level of sql::SQLException - no need to do it on the
-sql::mysql level.
-
-Suggestion: clearify driver - driver manager situation, remove MySQL_SQLException after
-successful WB test run of C/C++.
-*/
-
-namespace sql
-{
-namespace mysql
-{
-
-class MySQL_SQLException : public sql::SQLException
-{
-public:
-	MySQL_SQLException(const MySQL_SQLException& e) : SQLException(e.what(), e.sql_state, e.errNo) { }
-	MySQL_SQLException(const char * error);
-	MySQL_SQLException(const char * error, const char * sqlerror, unsigned int errNo);
-
-private:
-	MEMORY_ALLOC_OPERATORS(MySQL_SQLException)
-};
-
-}; /* namespace mysql */
-}; /* namespace sql */
-
-#endif // _MYSQL_DBC_EXCECPTION_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
- */

=== modified file 'driver/mysql_prepared_statement.cpp'
--- a/driver/mysql_prepared_statement.cpp	2008-11-12 13:15:56 +0000
+++ b/driver/mysql_prepared_statement.cpp	2008-11-20 12:24:33 +0000
@@ -796,7 +796,7 @@ MySQL_Prepared_Statement::checkClosed()
 	CPP_ENTER("MySQL_Prepared_Statement::checkClosed");
 	if (isClosed) {
 		CPP_ERR("Statement has already been closed");
-		throw MySQL_SQLException("Statement has been closed");
+		throw sql::InvalidInstanceException("Statement has been closed");
 	}
 }
 /* }}} */

=== modified file 'driver/mysql_ps_resultset.cpp'
--- a/driver/mysql_ps_resultset.cpp	2008-11-19 12:23:01 +0000
+++ b/driver/mysql_ps_resultset.cpp	2008-11-20 12:24:33 +0000
@@ -153,7 +153,7 @@ MySQL_Prepared_ResultSet::checkValid() c
 {
 	CPP_ENTER("MySQL_Prepared_ResultSet::checkValid");
 	if (isClosed()) {
-		throw MySQL_SQLException("Statement has been closed");
+		throw sql::InvalidInstanceException("Statement has been closed");
 	}
 }
 /* }}} */

=== modified file 'driver/mysql_resultset.cpp'
--- a/driver/mysql_resultset.cpp	2008-11-19 12:23:01 +0000
+++ b/driver/mysql_resultset.cpp	2008-11-20 12:24:33 +0000
@@ -158,7 +158,7 @@ MySQL_ResultSet::checkValid() const
 {
 	CPP_ENTER("MySQL_ResultSet::checkValid");
 	if (isClosed()) {
-		throw MySQL_SQLException("Statement has been closed");
+		throw sql::InvalidInstanceException("ResultSet has been closed");
 	}
 }
 /* }}} */

=== modified file 'driver/mysql_statement.cpp'
--- a/driver/mysql_statement.cpp	2008-11-20 11:19:55 +0000
+++ b/driver/mysql_statement.cpp	2008-11-20 12:24:33 +0000
@@ -296,7 +296,7 @@ MySQL_Statement::getMoreResults()
 		} else if (next_result == 0) {
 			return mysql_field_count(conn) != 0;
 		} else if (next_result == -1) {
-			throw MySQL_SQLException("Impossible! more_results() said true, next_result says no more results");
+			throw sql::SQLException("Impossible! more_results() said true, next_result says no more results", "HY000", 1000);
 		}
 	}
 	return false;
@@ -392,7 +392,7 @@ MySQL_Statement::checkClosed()
 	CPP_ENTER("MySQL_Statement::checkClosed");
 	if (isClosed) {
 		CPP_ERR("Statement has been closed");
-		throw MySQL_SQLException("Statement has been closed");
+		throw sql::InvalidInstanceException("Statement has been closed");
 	}
 }
 /* }}} */

Thread
bzr commit into connector-cpp-bzr branch (andrey.hristov:273) andrey.hristov20 Nov