Skip to content

Commit 82b2e47

Browse files
committed
Bug#23235968: Fix not throwing errors on commit.
1 parent 436e165 commit 82b2e47

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

driver/mysql_connection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,9 @@ MySQL_Connection::commit()
12081208
{
12091209
CPP_ENTER_WL(intern->logger, "MySQL_Connection::commit");
12101210
checkClosed();
1211-
proxy->commit();
1211+
if(proxy->commit())
1212+
throw SQLException (proxy->error(), proxy->sqlstate(), proxy->errNo());
1213+
12121214
}
12131215
/* }}} */
12141216

test/unit/bugs/bugs.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,86 @@ void bugs::bug32695580()
11911191
}
11921192
}
11931193

1194+
void bugs::bug23235968()
1195+
{
1196+
logMsg("bugs::bug23235968");
1197+
1198+
stmt->executeUpdate("drop table if exists bug23235968_1");
1199+
stmt->executeUpdate("create table bug23235968_1 (id int unsigned not null)");
1200+
1201+
stmt->executeUpdate("drop table if exists bug23235968_2");
1202+
stmt->executeUpdate("create table bug23235968_2 (id int unsigned not null)");
1203+
1204+
1205+
1206+
sql::ConnectOptionsMap opt;
1207+
1208+
opt[OPT_SCHEMA] = "test";
1209+
1210+
Connection con2(getConnection(&opt));
1211+
1212+
Statement my_stmt(con2->createStatement());
1213+
1214+
res.reset(my_stmt->executeQuery("select connection_id()"));
1215+
1216+
res->next();
1217+
1218+
uint64_t connection_id = res->getUInt64(1);
1219+
1220+
con2->setAutoCommit(false);
1221+
1222+
PreparedStatement my_pstmt(con2->prepareStatement("insert into bug23235968_1 ( id ) values( ? )"));
1223+
PreparedStatement my_pstmt2(con2->prepareStatement("insert into bug23235968_2 ( id ) values( ? )"));
1224+
1225+
for (int i = 1; i <= 10; ++i)
1226+
{
1227+
my_pstmt->setInt(1, i);
1228+
my_pstmt->execute();
1229+
1230+
my_pstmt2->setInt(1, i);
1231+
my_pstmt2->execute();
1232+
}
1233+
1234+
con2->commit();
1235+
1236+
for (int i = 11; i <= 20; ++i)
1237+
{
1238+
my_pstmt->setInt(1, i);
1239+
my_pstmt->execute();
1240+
1241+
my_pstmt2->setInt(1, i);
1242+
my_pstmt2->execute();
1243+
}
1244+
1245+
//Now, lets kill the connection 2
1246+
std::string sql ("KILL CONNECTION ");
1247+
sql+= std::to_string(connection_id);
1248+
1249+
stmt->execute(sql);
1250+
1251+
try {
1252+
con2->commit();
1253+
FAIL("No Exception thrown");
1254+
} catch (const sql::SQLException &e) {
1255+
std::cout << "Expected: " << e.what() << std::endl;
1256+
}
1257+
1258+
res.reset(stmt->executeQuery("select count(*) from bug23235968_1"));
1259+
res->next();
1260+
ASSERT_EQUALS(10,res->getUInt(1));
1261+
1262+
res.reset(stmt->executeQuery("select count(*) from bug23235968_2"));
1263+
res->next();
1264+
ASSERT_EQUALS(10,res->getUInt(1));
1265+
1266+
1267+
1268+
stmt->executeUpdate("drop table bug23235968_1");
1269+
stmt->executeUpdate("drop table bug23235968_2");
1270+
1271+
1272+
}
1273+
11941274

11951275
} /* namespace regression */
11961276
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class bugs : public unit_fixture
7979
TEST_CASE(bug31399362);
8080
TEST_CASE(bug30126457);
8181
TEST_CASE(bug32695580);
82+
TEST_CASE(bug23235968);
8283
}
8384

8485
/**
@@ -148,6 +149,8 @@ class bugs : public unit_fixture
148149

149150
void bug32695580();
150151

152+
void bug23235968();
153+
151154
};
152155

153156
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)