Skip to content

Commit a4471bb

Browse files
lawrinlawrin
authored andcommitted
Part of the fix of warnings problem. This patch makes statements read their warning count and return warnings only if the count >0
1 parent e7b8f43 commit a4471bb

19 files changed

+155
-48
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ ELSE(WIN32)
3636
cmake_minimum_required(VERSION 2.6)
3737
ENDIF(WIN32)
3838

39+
if(COMMAND cmake_policy)
40+
cmake_policy(SET CMP0015 NEW)
41+
endif(COMMAND cmake_policy)
42+
3943
#-----------------
4044
# CPPFLAGS, CXXFLAGS and LDFLAGS from the environment
4145
SET(MYSQLCPPCONN_COMPILE_FLAGS_ENV "$ENV{CPPFLAGS} ${MYSQL_CXXFLAGS} $ENV{CXXFLAGS}")

driver/mysql_connection_options.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
*/
2424

25-
26-
27-
28-
#ifndef _MYSQL_CONNECTION_OPTIONS_H_
29-
#define _MYSQL_CONNECTION_OPTIONS_H_
30-
31-
namespace sql
32-
{
33-
namespace mysql
34-
{
35-
36-
enum MySQL_Connection_Options
37-
{
38-
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
39-
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
40-
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
41-
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
42-
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
43-
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
44-
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
45-
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
46-
MYSQL_OPT_SSL_VERIFY_SERVER_CERT
47-
};
48-
49-
}
50-
}
51-
52-
#endif
25+
26+
27+
28+
#ifndef _MYSQL_CONNECTION_OPTIONS_H_
29+
#define _MYSQL_CONNECTION_OPTIONS_H_
30+
31+
namespace sql
32+
{
33+
namespace mysql
34+
{
35+
36+
enum MySQL_Connection_Options
37+
{
38+
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
39+
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
40+
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
41+
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
42+
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
43+
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
44+
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
45+
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
46+
MYSQL_OPT_SSL_VERIFY_SERVER_CERT
47+
};
48+
49+
}
50+
}
51+
52+
#endif

driver/mysql_prepared_statement.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ MySQL_Prepared_Statement::MySQL_Prepared_Statement(
353353
boost::shared_ptr< NativeAPI::NativeStatementWrapper > & s, sql::Connection * conn,
354354
sql::ResultSet::enum_type rset_type, boost::shared_ptr< MySQL_DebugLogger > & log
355355
)
356-
:connection(conn), proxy(s), isClosed(false), warningsHasBeenLoaded(true), logger(log),
357-
resultset_type(rset_type), result_bind(new MySQL_ResultBind(proxy, logger))
356+
:connection(conn), proxy(s), isClosed(false), warningsHaveBeenLoaded(true), logger(log),
357+
resultset_type(rset_type), result_bind(new MySQL_ResultBind(proxy, logger)),
358+
warningsCount(0)
358359

359360
{
360361
CPP_ENTER("MySQL_Prepared_Statement::MySQL_Prepared_Statement");
@@ -413,16 +414,20 @@ MySQL_Prepared_Statement::do_query()
413414
CPP_ERR("Value not set for all parameters");
414415
throw sql::SQLException("Value not set for all parameters");
415416
}
417+
416418
if (proxy->bind_param(param_bind->getBindObject())) {
417419
CPP_ERR_FMT("Couldn't bind : %d:(%s) %s", proxy->errNo(), proxy->sqlstate().c_str(), proxy->error().c_str());
418420
sql::mysql::util::throwSQLException(*proxy.get());
419421
}
422+
420423
if (!sendLongDataBeforeParamBind() || proxy->execute()) {
421424
CPP_ERR_FMT("Couldn't execute : %d:(%s) %s", proxy->errNo(), proxy->sqlstate().c_str(), proxy->error().c_str());
422425
sql::mysql::util::throwSQLException(*proxy.get());
423426
}
424427

425-
warningsHasBeenLoaded= false;
428+
warningsCount= proxy->warning_count();
429+
430+
warningsHaveBeenLoaded= false;
426431
}
427432
/* }}} */
428433

@@ -1158,10 +1163,11 @@ MySQL_Prepared_Statement::getWarnings()
11581163
CPP_INFO_FMT("this=%p", this);
11591164
checkClosed();
11601165

1161-
if (!warningsHasBeenLoaded)
1166+
if (!warningsHaveBeenLoaded)
11621167
{
1163-
warnings.reset( loadMysqlWarnings(connection) );
1164-
warningsHasBeenLoaded= true;
1168+
if (warningsCount)
1169+
warnings.reset( loadMysqlWarnings(connection, warningsCount) );
1170+
warningsHaveBeenLoaded= true;
11651171
}
11661172

11671173
return warnings.get();

driver/mysql_prepared_statement.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MySQL_Prepared_Statement : public sql::PreparedStatement
6565
boost::scoped_ptr< MySQL_Warning > warnings;
6666

6767
bool isClosed;
68-
bool warningsHasBeenLoaded;
68+
bool warningsHaveBeenLoaded;
6969

7070
boost::shared_ptr< MySQL_DebugLogger > logger;
7171

@@ -76,6 +76,8 @@ class MySQL_Prepared_Statement : public sql::PreparedStatement
7676

7777
boost::shared_ptr< MySQL_ResultBind > result_bind;
7878

79+
unsigned int warningsCount;
80+
7981
virtual void do_query();
8082
virtual void checkClosed();
8183
virtual void closeIntern();

driver/mysql_statement.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ namespace mysql
5353
/* {{{ MySQL_Statement::MySQL_Statement() -I- */
5454
MySQL_Statement::MySQL_Statement(MySQL_Connection * conn, boost::shared_ptr< NativeAPI::NativeConnectionWrapper > & _proxy,
5555
sql::ResultSet::enum_type rset_type, boost::shared_ptr< MySQL_DebugLogger > & l)
56-
: warnings(NULL), connection(conn), proxy(_proxy), isClosed(false), warningsHasBeenLoaded(true),
57-
last_update_count(UL64(~0)), logger(l), resultset_type(rset_type)
56+
: warnings(NULL), connection(conn), proxy(_proxy), isClosed(false), warningsHaveBeenLoaded(true),
57+
last_update_count(UL64(~0)), logger(l), resultset_type(rset_type), warningsCount(0)
5858
{
5959
CPP_ENTER("MySQL_Statement::MySQL_Statement");
6060
CPP_INFO_FMT("this=%p", this);
@@ -86,7 +86,9 @@ MySQL_Statement::do_query(const char *q, size_t length)
8686
sql::mysql::util::throwSQLException(*proxy.get());
8787
}
8888

89-
warningsHasBeenLoaded= false;
89+
warningsCount= proxy->warning_count();
90+
91+
warningsHaveBeenLoaded= false;
9092
}
9193
/* }}} */
9294

@@ -100,7 +102,7 @@ MySQL_Statement::get_resultset()
100102
checkClosed();
101103

102104
NativeAPI::NativeResultsetWrapper * result;
103-
//TODO: again - probably no need to catch-n-throw here. O maybe no need to throw further
105+
//TODO: again - probably no need to catch-n-throw here. Or maybe no need to throw further
104106
try {
105107
result= (resultset_type == sql::ResultSet::TYPE_FORWARD_ONLY)? proxy->use_result(): proxy->store_result();
106108
if (!result) {
@@ -412,10 +414,10 @@ MySQL_Statement::getWarnings()
412414
CPP_INFO_FMT("this=%p", this);
413415
checkClosed();
414416

415-
if (!warningsHasBeenLoaded)
417+
if (!warningsHaveBeenLoaded)
416418
{
417-
warnings.reset(loadMysqlWarnings(connection));
418-
warningsHasBeenLoaded= true;
419+
warnings.reset(loadMysqlWarnings(connection, warningsCount));
420+
warningsHaveBeenLoaded= true;
419421
}
420422

421423
return warnings.get();

driver/mysql_statement.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ class MySQL_Statement : public sql::Statement
5858

5959
void do_query(const char *q, size_t length);
6060
bool isClosed;
61-
bool warningsHasBeenLoaded;
61+
bool warningsHaveBeenLoaded;
6262

6363
uint64_t last_update_count;
6464

6565
boost::shared_ptr< MySQL_DebugLogger > logger;
6666

6767
sql::ResultSet::enum_type resultset_type;
6868

69+
unsigned int warningsCount;
70+
6971
virtual boost::shared_ptr< NativeAPI::NativeResultsetWrapper > get_resultset();
7072
virtual void checkClosed();
7173

driver/mysql_warning.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <boost/scoped_ptr.hpp>
2929
#include <cppconn/statement.h>
3030
#include <cppconn/resultset.h>
31+
#include <sstream>
3132

3233
namespace sql
3334
{
@@ -235,12 +236,14 @@ errCode2SqlState(int32_t errCode, sql::SQLString & state)
235236

236237

237238
MySQL_Warning *
238-
loadMysqlWarnings(sql::Connection * connection)
239+
loadMysqlWarnings(sql::Connection * connection, unsigned int warningsCount)
239240
{
240241
MySQL_Warning * first = NULL, * current = NULL;
241242
SQLString state;
243+
unsigned int count;
244+
242245

243-
if (connection != NULL) {
246+
if (warningsCount >0 && connection != NULL) {
244247
boost::scoped_ptr< sql::Statement > stmt(connection->createStatement());
245248
boost::scoped_ptr< sql::ResultSet > rset(stmt->executeQuery("SHOW WARNINGS"));
246249

driver/mysql_warning.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ namespace mysql
8787

8888
const sql::SQLString & errCode2SqlState(int32_t errCode, ::sql::SQLString & state);
8989

90-
MySQL_Warning * loadMysqlWarnings(sql::Connection * connection);
90+
MySQL_Warning * loadMysqlWarnings( sql::Connection * connection,
91+
unsigned int warningsCount=0);
9192

9293

9394
} /* namespace mysql */

driver/nativeapi/libmysql_dynamic_proxy.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ LibmysqlDynamicProxy::real_connect(MYSQL * mysql,
442442
unsigned long
443443
LibmysqlDynamicProxy::real_escape_string(MYSQL * mysql, char * to, const char * from, unsigned long length)
444444
{
445-
ptr2mysql_realescapestring ptr2_realescapestring = symbol_safe_cast<ptr2mysql_realescapestring>(GetProcAddr("mysql_real_escape_string"));
445+
ptr2mysql_real_escape_string ptr2_realescapestring = symbol_safe_cast<ptr2mysql_real_escape_string>(GetProcAddr("mysql_real_escape_string"));
446446

447447
return (*ptr2_realescapestring)(mysql, to, from, length);
448448
}
@@ -520,6 +520,17 @@ LibmysqlDynamicProxy::use_result(MYSQL * mysql)
520520
/* }}} */
521521

522522

523+
/* {{{ LibmysqlDynamicProxy::warning_count() */
524+
unsigned int
525+
LibmysqlDynamicProxy::warning_count(MYSQL * mysql)
526+
{
527+
ptr2mysql_warning_count ptr2_warning_count= symbol_safe_cast<ptr2mysql_warning_count>(GetProcAddr("mysql_warning_count"));
528+
529+
return (*ptr2_warning_count)(mysql);
530+
}
531+
/* }}} */
532+
533+
523534
/* Prepared Statement mysql_stmt_* functions */
524535

525536
/* {{{ LibmysqlDynamicProxy::stmt_affected_rows() */

driver/nativeapi/libmysql_dynamic_proxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class LibmysqlDynamicProxy : public sql::mysql::util::LibraryLoader, public IMyS
142142

143143
MYSQL_RES * use_result(MYSQL *);
144144

145+
unsigned int warning_count(MYSQL *);
146+
145147
/* Prepared Statement stmt_* functions */
146148
my_ulonglong stmt_affected_rows (MYSQL_STMT *);
147149

0 commit comments

Comments
 (0)