1
1
/*
2
- Copyright (c) 2009, 2011 , Oracle and/or its affiliates. All rights reserved.
2
+ Copyright (c) 2009, 2012 , Oracle and/or its affiliates. All rights reserved.
3
3
4
4
The MySQL Connector/C++ is licensed under the terms of the GPLv2
5
5
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -63,18 +63,22 @@ void statement::getWarnings()
63
63
{
64
64
logMsg (" statement::getWarnings() - MySQL_Statement::get|clearWarnings()" );
65
65
std::stringstream msg;
66
+ unsigned int count= 0 ;
66
67
67
68
stmt.reset (con->createStatement ());
68
69
try
69
70
{
70
71
stmt->execute (" DROP TABLE IF EXISTS test" );
71
72
stmt->execute (" CREATE TABLE test(id INT UNSIGNED)" );
72
73
74
+ // Generating 2 warnings to make sure we get only the last 1 - won't hurt
75
+ stmt->execute (" INSERT INTO test(id) VALUES (-2)" );
73
76
// Lets hope that this will always cause a 1264 or similar warning
74
77
stmt->execute (" INSERT INTO test(id) VALUES (-1)" );
75
78
76
79
for (const sql::SQLWarning* warn=stmt->getWarnings (); warn; warn=warn->getNextWarning ())
77
80
{
81
+ ++count;
78
82
msg.str (" " );
79
83
msg << " ... ErrorCode = '" << warn->getErrorCode () << " ', " ;
80
84
msg << " SQLState = '" << warn->getSQLState () << " ', " ;
@@ -93,6 +97,8 @@ void statement::getWarnings()
93
97
ASSERT ((" " != warn->getMessage ()));
94
98
}
95
99
100
+ ASSERT_EQUALS (1 , count);
101
+
96
102
for (const sql::SQLWarning* warn=stmt->getWarnings (); warn; warn=warn->getNextWarning ())
97
103
{
98
104
msg.str (" " );
@@ -119,6 +125,17 @@ void statement::getWarnings()
119
125
FAIL (" There should be no more warnings!" );
120
126
}
121
127
128
+ // New warning
129
+ stmt->execute (" INSERT INTO test(id) VALUES (-3)" );
130
+ // Verifying we have warnings now
131
+ ASSERT (stmt->getWarnings () != NULL );
132
+
133
+ // Statement without tables access does not reset warnings.
134
+ stmt->execute (" SELECT 1" );
135
+ ASSERT (stmt->getWarnings () == NULL );
136
+ res.reset (stmt->getResultSet ());
137
+ res->next ();
138
+
122
139
// TODO - how to use getNextWarning() ?
123
140
stmt->execute (" DROP TABLE IF EXISTS test" );
124
141
}
0 commit comments