From 3a8e187b628710760a2f1c34f9cce238661318a6 Mon Sep 17 00:00:00 2001 From: Alexander Soklakov Date: Wed, 17 Feb 2021 13:27:29 +0400 Subject: [PATCH] Fix for Bug#102131 (32338451), UPDATABLERESULTSET NPE WHEN USING DERIVED QUERIES OR VIEWS. --- CHANGES | 2 ++ .../cj/jdbc/result/UpdatableResultSet.java | 2 +- .../regression/ResultSetRegressionTest.java | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 53f08eed0..72372da30 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ Version 8.0.24 + - Fix for Bug#102131 (32338451), UPDATABLERESULTSET NPE WHEN USING DERIVED QUERIES OR VIEWS. + - Fix for Bug#101596 (32151143), GET THE 'HOST' PROPERTY ERROR AFTER CALLING TRANSFORMPROPERTIES() METHOD. - Fix for Bug#20391832, SETOBJECT() FOR TYPES.TIME RESULTS IN EXCEPTION WHEN VALUE HAS FRACTIONAL PART. diff --git a/src/main/user-impl/java/com/mysql/cj/jdbc/result/UpdatableResultSet.java b/src/main/user-impl/java/com/mysql/cj/jdbc/result/UpdatableResultSet.java index afbd69b83..ef561d1a4 100644 --- a/src/main/user-impl/java/com/mysql/cj/jdbc/result/UpdatableResultSet.java +++ b/src/main/user-impl/java/com/mysql/cj/jdbc/result/UpdatableResultSet.java @@ -284,7 +284,7 @@ public void checkUpdatability() throws SQLException { } // Can't reference more than one database - if ((dbName == null) || !otherDbName.equals(dbName)) { + if ((dbName == null) || !dbName.equals(otherDbName)) { this.isUpdatable = false; this.notUpdatableReason = Messages.getString("NotUpdatableReason.1"); diff --git a/src/test/java/testsuite/regression/ResultSetRegressionTest.java b/src/test/java/testsuite/regression/ResultSetRegressionTest.java index ff7d4be4f..630b7c09f 100644 --- a/src/test/java/testsuite/regression/ResultSetRegressionTest.java +++ b/src/test/java/testsuite/regression/ResultSetRegressionTest.java @@ -7802,4 +7802,27 @@ public void testBug102321() throws Exception { "Wrong ResultSetMetaData metadata for column type " + rsm.getColumnTypeName(colnum)); } } + + /** + * Tests fix for Bug#102131 (32338451), UPDATABLERESULTSET NPE WHEN USING DERIVED QUERIES OR VIEWS. + * + * @throws Exception + * if the test fails + */ + @Test + public void testBug102131() throws Exception { + createTable("testBug102131User", "(id int,name varchar(10))"); + createTable("testBug102131Age", "(id int,age int)"); + createView("testBug102131View", + "as select name,ifnull(age,0) age from testBug102131User inner join testBug102131Age on testBug102131User.id = testBug102131Age.id"); + + this.stmt.executeUpdate("INSERT INTO testBug102131User VALUES (1, 'a')"); + this.stmt.executeUpdate("INSERT INTO testBug102131Age VALUES (1, 20)"); + + Statement st1 = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + this.rs = st1.executeQuery("select * from testBug102131View"); + assertTrue(this.rs.next()); + assertEquals("a", this.rs.getString("name")); + assertEquals(20, this.rs.getInt("age")); + } }