Mercurial > hg > monetdb-java
changeset 146:8b40a845240c
Added test program for Bug 6388
and a fix for calling metadata methods:
getUserName()
getMaxConnections()
getDatabaseProductVersion()
getDatabaseMajorVersion()
getDatabaseMinorVersion()
ToDo: for calling
getTables()
getTableTypes()
we need to do changes in monetdb server code.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 10 Aug 2017 18:10:43 +0200 (2017-08-10) |
parents | b18cfb312330 |
children | ad0fe5b04fd4 |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.java tests/build.xml |
diffstat | 3 files changed, 133 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java @@ -48,7 +48,7 @@ public class MonetDatabaseMetaData exten try { st = con.createStatement(); rs = st.executeQuery( - "SELECT \"name\", \"value\" FROM \"sys\".\"environment\"" + + "SELECT \"name\", \"value\" FROM \"sys\".\"env\"()" + " WHERE \"name\" IN ('monet_version', 'max_clients')" + " UNION SELECT 'current_user' as \"name\", current_user as \"value\""); if (rs != null) {
new file mode 100644 --- /dev/null +++ b/tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.java @@ -0,0 +1,113 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +import java.sql.*; + +public class Bug_Connect_as_voc_getMetaData_Failure_Bug_6388 { + public static void main(String[] args) throws SQLException + { + Connection con1 = null; + Statement stmt1 = null; + + // Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); // not needed anymore for self registering JDBC drivers + con1 = DriverManager.getConnection(args[0]); + stmt1 = con1.createStatement(); + + // test the creation of a table with concurrent clients + try { + System.out.println("1. CREATE USER voc"); + stmt1.executeUpdate("CREATE USER \"voc\" WITH PASSWORD 'voc' NAME 'VOC Explorer' SCHEMA \"sys\""); + System.out.println("2. CREATE SCHEMA voc"); + stmt1.executeUpdate("CREATE SCHEMA \"voc\" AUTHORIZATION \"voc\""); + System.out.println("3. ALTER USER voc"); + stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"voc\""); + System.out.println("creation succeeded :)"); + + login_as_voc_and_get_MetaData(args[0].replace("=monetdb", "=voc")); + + System.out.println(); + System.out.println("Cleanup created objects"); + System.out.println("5. ALTER USER voc"); + stmt1.executeUpdate("ALTER USER \"voc\" SET SCHEMA \"sys\""); + System.out.println("6. DROP SCHEMA voc"); + stmt1.executeUpdate("DROP SCHEMA \"voc\""); + System.out.println("7. DROP USER voc"); + stmt1.executeUpdate("DROP USER \"voc\""); + System.out.println("cleanup succeeded :)"); + } catch (SQLException e) { + System.out.println("FAILED creating user and schema voc. " + e.getMessage()); + } finally { + stmt1.close(); + con1.close(); + } + } + + private static void login_as_voc_and_get_MetaData(String connectString) { + Connection con2 = null; + + try { + System.out.println("4.1. connect as user: voc"); + con2 = DriverManager.getConnection(connectString); + System.out.println("connected :)"); + } catch (SQLException e) { + System.out.println("FAILED to connect as user voc. " + e.getMessage()); + return; + } + + try { + DatabaseMetaData dbmd = con2.getMetaData(); + + System.out.println("4.2. getUserName()"); + System.out.println("UserName = " + dbmd.getUserName()); + + System.out.println("4.3. getMaxConnections()"); + System.out.println("MaxConnections = " + dbmd.getMaxConnections()); + + System.out.println("4.4. getDatabaseProductVersion()"); + System.out.println("DatabaseProductVersion = " + dbmd.getDatabaseProductVersion()); + + System.out.println("4.5. getDatabaseMajorVersion()"); + System.out.println("DatabaseMajorVersion = " + dbmd.getDatabaseMajorVersion()); + + System.out.println("4.6. getDatabaseMinorVersion()"); + System.out.println("DatabaseMinorVersion = " + dbmd.getDatabaseMinorVersion()); + + System.out.println("4.7. getTables(null, 'tmp', null, null)"); + ResultSet rs2 = dbmd.getTables(null, "tmp", null, null); + if (rs2 != null) { + System.out.println("List Tables in schema tmp:"); + while (rs2.next()) { + System.out.println(rs2.getString(3)); + } + rs2.close(); + } + System.out.println("completed listing Tables in schema tmp"); + + System.out.println("4.8. getTableTypes()"); + ResultSet rs1 = dbmd.getTableTypes(); + if (rs1 != null) { + System.out.println("List TableTypes:"); + while (rs1.next()) { + System.out.println(rs1.getString(1)); + } + rs1.close(); + } + System.out.println("completed listing TableTypes"); + + System.out.println("voc meta data Test completed successfully"); + } catch (SQLException e) { + System.out.println("FAILED fetching MonetDatabaseMetaData. " + e.getMessage()); + } finally { + try { + con2.close(); + } catch (SQLException e) { + System.out.println("FAILED to close voc connection. " + e.getMessage()); + } + } + } +}
--- a/tests/build.xml +++ b/tests/build.xml @@ -19,7 +19,7 @@ Copyright 1997 - July 2008 CWI, August 2 <property file="build.local.properties" /> <property file="build.properties" /> - <property file="../build.properties"/> <!-- included for version --> + <property file="../build.properties" /> <!-- included for version --> <!-- set global properties for this build --> <property name="srcdir" value="." /> @@ -31,7 +31,8 @@ Copyright 1997 - July 2008 CWI, August 2 value="jdbc:monetdb://localhost/?user=monetdb&password=monetdb${debug}" /> <property name="jdbctests-jar" value="${jardir}/jdbctests.jar" /> - <property name="jvm.version" value="1.7"/> + <property name="jvm.version" value="1.7" /> + <property name="javac.flags" value="-Xlint:-options" /> <!-- Prepares the build directory --> <target name="prepare"> @@ -95,13 +96,13 @@ Copyright 1997 - July 2008 CWI, August 2 <!-- Run tests --> <target name="test"> <antcall target="Test_Cautocommit" /> - <antcall target="Test_Cforkbomb" /> + <!-- <antcall target="Test_Cforkbomb" /> --> <antcall target="Test_CisValid" /> <antcall target="Test_Clargequery" /> <antcall target="Test_Cmanycon" /> <antcall target="Test_Creplysize" /> <antcall target="Test_Csavepoints" /> - <antcall target="Test_Csendthread" /> + <!-- <antcall target="Test_Csendthread" /> --> <antcall target="Test_Ctransaction" /> <antcall target="Test_Dobjects" /> <antcall target="Test_FetchSize" /> @@ -133,6 +134,8 @@ Copyright 1997 - July 2008 CWI, August 2 <antcall target="BugExecuteUpdate_Bug_3350" /> <antcall target="BugSetQueryTimeout_Bug_3357" /> <antcall target="BugResultSetMetaData_Bug_6183" /> + <antcall target="Bug_PrepStmtSetObject_CLOB_6349" /> + <antcall target="Bug_Connect_as_voc_getMetaData_Failure_Bug_6388" /> </target> <target name="test_class" depends="compile,jdbc"> @@ -382,4 +385,16 @@ Copyright 1997 - July 2008 CWI, August 2 </antcall> </target> + <target name="Bug_PrepStmtSetObject_CLOB_6349"> + <antcall target="test_class"> + <param name="test.class" value="Bug_PrepStmtSetObject_CLOB_6349" /> + </antcall> + </target> + + <target name="Bug_Connect_as_voc_getMetaData_Failure_Bug_6388"> + <antcall target="test_class"> + <param name="test.class" value="Bug_Connect_as_voc_getMetaData_Failure_Bug_6388" /> + </antcall> + </target> + </project>