Skip to content

Commit

Permalink
Fix for Bug#87153 (26501245), INCORRECT RESULT OF
Browse files Browse the repository at this point in the history
DBMD.GETVERSIONCOLUMNS() AGAINST MYSQL 8.0.2+.
  • Loading branch information
soklakov committed Jul 21, 2017
1 parent cfc7870 commit d067cae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 5.1.44

- Fix for Bug#87153 (26501245), INCORRECT RESULT OF DBMD.GETVERSIONCOLUMNS() AGAINST MYSQL 8.0.2+.

- Fix for Bug#26440544, CONNECTOR/J SHOULD NOT USE TX_{READ_ONLY,ISOLATION} WHICH IS PLANNED FOR REMOVAL.

Version 5.1.43
Expand Down
56 changes: 40 additions & 16 deletions src/testsuite/regression/MetaDataRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2882,19 +2882,31 @@ public void testBug63800() throws Exception {
}

private void testTimestamp(Connection con, Statement st, String dbname) throws SQLException {
boolean explicitDefaultsForTimestamp = false;
if (versionMeetsMinimum(8, 0, 2)) {
String v = getMysqlVariable("explicit_defaults_for_timestamp");
if ("ON".equals(v)) {
explicitDefaultsForTimestamp = true;
}
}

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");
DatabaseMetaData dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
if (explicitDefaultsForTimestamp) {
assertFalse("0 column must be found", this.rs.next());
} else {
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));
}

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
Expand All @@ -2913,29 +2925,29 @@ private void testTimestamp(Connection con, Statement st, String dbname) throws S
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL, f2 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f2");
assertEquals("Wrong column or single column not found", "f2", this.rs.getString(2));

// ALTER test
st.execute("ALTER TABLE testBug63800 CHANGE COLUMN `f2` `f2` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', "
+ "ADD COLUMN `f3` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP AFTER `f2`");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f3");
assertEquals("Wrong column or single column not found", "f3", this.rs.getString(2));
}

private void testDatetime(Connection con, Statement st, String dbname) throws SQLException {
Expand All @@ -2944,7 +2956,7 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
DatabaseMetaData dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 DATETIME)");
Expand All @@ -2969,14 +2981,14 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 DATETIME ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 DATETIME NULL, f2 DATETIME ON UPDATE CURRENT_TIMESTAMP)");
Expand All @@ -2985,8 +2997,8 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
int cnt = 0;
while (this.rs.next()) {
cnt++;
assertEquals("1 column must be found", cnt, 1);
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f2");
assertEquals("1 column must be found", 1, cnt);
assertEquals("Wrong column or single column not found", "f2", this.rs.getString(2));
}

// ALTER 1 test
Expand All @@ -2997,8 +3009,8 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
cnt = 0;
while (this.rs.next()) {
cnt++;
assertEquals("1 column must be found", cnt, 1);
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f3");
assertEquals("1 column must be found", 1, cnt);
assertEquals("Wrong column or single column not found", "f3", this.rs.getString(2));
}

// ALTER 2 test
Expand All @@ -3009,7 +3021,15 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
while (this.rs.next()) {
cnt++;
}
assertEquals("2 column must be found", cnt, 2);
assertEquals("2 column must be found", 2, cnt);

boolean explicitDefaultsForTimestamp = false;
if (versionMeetsMinimum(8, 0, 2)) {
String v = getMysqlVariable("explicit_defaults_for_timestamp");
if ("ON".equals(v)) {
explicitDefaultsForTimestamp = true;
}
}

st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP, f2 DATETIME ON UPDATE CURRENT_TIMESTAMP, f3 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
Expand All @@ -3019,7 +3039,11 @@ private void testDatetime(Connection con, Statement st, String dbname) throws SQ
while (this.rs.next()) {
cnt++;
}
assertEquals("3 column must be found", cnt, 3);
if (explicitDefaultsForTimestamp) {
assertEquals("2 column must be found", 2, cnt);
} else {
assertEquals("3 column must be found", 3, cnt);
}

}

Expand Down

0 comments on commit d067cae

Please sign in to comment.