Mercurial > hg > monetdb-java
changeset 462:bc7e42f9e147
Remove no longer needed individual java JDBC test programs as they are migrated and converted to JDBC_API_Tester program.
Note: program SQLcopyinto.java may NOT be removed as it referred to from https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 24 Mar 2021 19:22:30 +0100 (2021-03-24) |
parents | 805fd920a36f |
children | cde144382233 f20f0a0044bf |
files | tests/BugConcurrent_clients_SF_1504657.java tests/BugConcurrent_sequences.java tests/BugDatabaseMetaData_Bug_3356.java tests/BugDecimalRound_Bug_3561.java tests/BugExecuteUpdate_Bug_3350.java tests/BugResultSetMetaData_Bug_6183.java tests/BugSetQueryTimeout_Bug_3357.java tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.java tests/Bug_IsValid_Timeout_Bug_6782.java tests/Bug_LargeQueries_6571_6693.java tests/Bug_PrepStmtSetObject_CLOB_6349.java tests/Bug_PrepStmtSetString_6382.java tests/Bug_PrepStmt_With_Errors_Jira292.java tests/Test_CallableStmt.java tests/Test_Cautocommit.java tests/Test_CisValid.java tests/Test_Clargequery.java tests/Test_Cmanycon.java tests/Test_Creplysize.java tests/Test_Csavepoints.java tests/Test_Ctransaction.java tests/Test_Dobjects.java tests/Test_FetchSize.java tests/Test_Int128.java tests/Test_PSgeneratedkeys.java tests/Test_PSgetObject.java tests/Test_PSlargebatchval.java tests/Test_PSlargeresponse.java tests/Test_PSmanycon.java tests/Test_PSmetadata.java tests/Test_PSsomeamount.java tests/Test_PSsqldata.java tests/Test_PStimedate.java tests/Test_PStimezone.java tests/Test_PStypes.java tests/Test_Rbooleans.java tests/Test_Rmetadata.java tests/Test_Rpositioning.java tests/Test_Rsqldata.java tests/Test_Rtimedate.java tests/Test_Sbatching.java tests/Test_Smoreresults.java tests/Test_Wrapper.java |
diffstat | 43 files changed, 0 insertions(+), 3729 deletions(-) [+] |
line wrap: on
line diff
deleted file mode 100644 --- a/tests/BugConcurrent_clients_SF_1504657.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugConcurrent_clients_SF_1504657 { - public static void main(String[] args) throws Exception{ - Connection con1 = null, con2 = null, con3 = null; - Statement stmt1 = null, stmt2 = null, stmt3 = null; - ResultSet rs1 = null, rs2= null, rs3 = null; - con1 = DriverManager.getConnection(args[0]); - con2 = DriverManager.getConnection(args[0]); - con3 = DriverManager.getConnection(args[0]); - stmt1 = con1.createStatement(); - stmt2 = con2.createStatement(); - stmt3 = con3.createStatement(); - //DatabaseMetaData dbmd = con.getMetaData(); - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con1.getAutoCommit()); - System.out.println("0. true\t" + con2.getAutoCommit()); - System.out.println("0. true\t" + con3.getAutoCommit()); - - // test the creation of a table with concurrent clients - try { - System.out.println("1.1. create table t1 using client 1..."); - stmt1.executeUpdate("CREATE TABLE t1 ( id int, name varchar(1024) )"); - System.out.println("passed :)"); - System.out.println("1.2. check table existence in client 2..."); - rs2 = stmt2.executeQuery("SELECT name FROM tables where name LIKE 't1'"); - while (rs2.next()) - System.out.println(rs2.getString("name")); - System.out.println("passed :)"); - System.out.println("1.3. check table existence in client 3..."); - rs3 = stmt3.executeQuery("SELECT name FROM tables where name LIKE 't1'"); - while (rs3.next()) - System.out.println(rs3.getString("name")); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 1 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - con1.close(); - con2.close(); - con3.close(); - System.exit(-1); - } - - // test the insertion of values with concurrent clients - try { - System.out.println("2 insert into t1 using client 1..."); - stmt1.executeUpdate("INSERT INTO t1 values( 1, 'monetdb' )"); - System.out.println("passed :)"); - stmt1.executeUpdate("INSERT INTO t1 values( 2, 'monet' )"); - System.out.println("passed :)"); - stmt1.executeUpdate("INSERT INTO t1 values( 3, 'mon' )"); - System.out.println("passed :)"); - System.out.println("2.1. check table status with client 1..."); - rs1 = stmt1.executeQuery("SELECT * FROM t1"); - while (rs1.next()) - System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); - System.out.println("passed :)"); - System.out.println("2.2. check table status with client 2..."); - rs2 = stmt2.executeQuery("SELECT * FROM t1"); - while (rs2.next()) - System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); - System.out.println("passed :)"); - System.out.println("2.3. check table status with client 3..."); - rs3 = stmt3.executeQuery("SELECT * FROM t1"); - while (rs3.next()) - System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 2 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - if (rs3 != null) rs3.close(); - con1.close(); - con2.close(); - con3.close(); - System.exit(-1); - } - - // test the insertion of values with concurrent clients - try { - System.out.println("3 insert into t1 using client 2..."); - stmt2.executeUpdate("INSERT INTO t1 values( 4, 'monetdb' )"); - System.out.println("passed :)"); - stmt2.executeUpdate("INSERT INTO t1 values( 5, 'monet' )"); - System.out.println("passed :)"); - stmt2.executeUpdate("INSERT INTO t1 values( 6, 'mon' )"); - System.out.println("passed :)"); - System.out.println("3.1. check table status with client 1..."); - rs1 = stmt1.executeQuery("SELECT * FROM t1"); - while (rs1.next()) - System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); - System.out.println("passed :)"); - System.out.println("3.2. check table status with client 2..."); - rs2 = stmt2.executeQuery("SELECT * FROM t1"); - while (rs2.next()) - System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); - System.out.println("passed :)"); - System.out.println("3.3. check table status with client 3..."); - rs3 = stmt3.executeQuery("SELECT * FROM t1"); - while (rs3.next()) - System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 3 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - if (rs3 != null) rs3.close(); - con1.close(); - con2.close(); - con3.close(); - System.exit(-1); - } - - // test the insertion of values with concurrent clients - try { - System.out.println("4 insert into t1 using client 3..."); - stmt3.executeUpdate("INSERT INTO t1 values( 7, 'monetdb' )"); - System.out.println("passed :)"); - stmt3.executeUpdate("INSERT INTO t1 values( 8, 'monet' )"); - System.out.println("passed :)"); - stmt3.executeUpdate("INSERT INTO t1 values( 9, 'mon' )"); - System.out.println("passed :)"); - System.out.println("4.1. check table status with client 1..."); - rs1 = stmt1.executeQuery("SELECT * FROM t1"); - while (rs1.next()) - System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); - System.out.println("passed :)"); - System.out.println("4.2. check table status with client 2..."); - rs2 = stmt2.executeQuery("SELECT * FROM t1"); - while (rs2.next()) - System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); - System.out.println("passed :)"); - System.out.println("4.3. check table status with client 3..."); - rs3 = stmt3.executeQuery("SELECT * FROM t1"); - while (rs3.next()) - System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 4 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - if (rs3 != null) rs3.close(); - con1.close(); - con2.close(); - con3.close(); - System.exit(-1); - } - - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - if (rs3 != null) rs3.close(); - - // cleanup - try { - stmt3.executeUpdate("DROP TABLE t1"); - } catch (SQLException e) { - System.out.println("FAILED to clean up! :( " + e.getMessage()); - } - - con1.close(); - con2.close(); - con3.close(); - } -}
deleted file mode 100644 --- a/tests/BugConcurrent_sequences.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugConcurrent_sequences { - public static void main(String[] args) throws Exception { - Connection con1 = null, con2 = null; - Statement stmt1 = null, stmt2 = null; - ResultSet rs1 = null, rs2 = null; - con1 = DriverManager.getConnection(args[0]); - con2 = DriverManager.getConnection(args[0]); - stmt1 = con1.createStatement(); - stmt2 = con2.createStatement(); - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con1.getAutoCommit()); - System.out.println("0. true\t" + con2.getAutoCommit()); - - // create a table - try { - System.out.print("1. create table t1 using client 1... "); - stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )"); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (that sux) - System.out.println("FAILED 1 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - con1.close(); - con2.close(); - System.exit(-1); - } - - // test the insertion of values with concurrent clients - try { - System.out.print("2. insert into t1 using client 1 and 2... "); - stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); - System.out.println("client 1 passed :)"); - con2.setAutoCommit(false); - stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); - System.out.println("transaction on client 2 :)"); - stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); - System.out.println("client 1 passed :)"); - try { - con2.commit(); - System.out.println("transaction client 2 PASSED :("); - System.exit(-1); - } catch (SQLException e) { - System.out.println("transaction client 2 failed :)"); - } - con2.setAutoCommit(true); - stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); - System.out.println("passed :)"); - System.out.println("2.1. check table status with client 1..."); - rs1 = stmt1.executeQuery("SELECT * FROM t1"); - while (rs1.next()) - System.out.println(rs1.getInt("id") + ", " + - rs1.getString("who")); - System.out.println("passed :)"); - System.out.println("2.2. check table status with client 2..."); - rs2 = stmt2.executeQuery("SELECT * FROM t1"); - while (rs2.next()) - System.out.println(rs2.getInt("id") + ", " + - rs2.getString("who")); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 2 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - con1.close(); - con2.close(); - System.exit(-1); - } - - // drop the table (not dropping the sequence) from client 1 - try { - System.out.print("3.1. drop table t1 using client 1... "); - stmt1.executeUpdate("DROP TABLE t1"); - System.out.println("passed :)"); - System.out.print("3.1. recreate t1 using client 1... "); - stmt1.executeUpdate("CREATE TABLE t1 ( id serial, who varchar(12) )"); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 3 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - con1.close(); - con2.close(); - System.exit(-1); - } - - // re-establish connection - try { - System.out.print("x. Reconnecting client 1 and 2... "); - con1.close(); - con2.close(); - con1 = DriverManager.getConnection(args[0]); - con2 = DriverManager.getConnection(args[0]); - stmt1 = con1.createStatement(); - stmt2 = con2.createStatement(); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED x :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - con1.close(); - con2.close(); - System.exit(-1); - } - - // insert and print, should get 1,2 - try { - System.out.println("4. insert into t1 using client 1 and 2..."); - stmt1.executeUpdate("INSERT INTO t1(who) VALUES('client1')"); - System.out.println("passed :)"); - con2.setAutoCommit(false); - stmt2.executeUpdate("INSERT INTO t1(who) VALUES('client2')"); - con2.commit(); - con2.setAutoCommit(true); - System.out.println("passed :)"); - System.out.println("4.1. check table status with client 1..."); - rs1 = stmt1.executeQuery("SELECT * FROM t1 ORDER BY who"); - for (int cntr = 1; rs1.next(); cntr++) { - int id = rs1.getInt("id"); - System.out.println(id + ", " + - rs1.getString("who")); - if (id != cntr) - throw new SQLException("expected " + cntr + ", got " + id); - } - System.out.println("passed :)"); - System.out.println("4.2. check table status with client 2..."); - rs2 = stmt2.executeQuery("SELECT * FROM t1 ORDER BY who"); - for (int cntr = 1; rs2.next(); cntr++) { - int id = rs2.getInt("id"); - System.out.println(id + ", " + - rs2.getString("who")); - if (id != cntr) - throw new SQLException("expected " + cntr + ", got " + id); - } - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED 4 :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - con1.close(); - con2.close(); - System.exit(-1); - } - - if (rs1 != null) rs1.close(); - if (rs2 != null) rs2.close(); - - // cleanup - try { - stmt1.executeUpdate("DROP TABLE t1"); - } catch (SQLException e) { - System.out.println("FAILED to clean up! :( " + e.getMessage()); - } - - con1.close(); - con2.close(); - } -}
deleted file mode 100644 --- a/tests/BugDatabaseMetaData_Bug_3356.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugDatabaseMetaData_Bug_3356 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - DatabaseMetaData dbmd = con.getMetaData(); - ResultSet rs = dbmd.getColumns("", "sys", "_tables", "id"); - rs.next(); - String tableName1 = rs.getString("TABLE_NAME"); - String tableName2 = rs.getString(3); - String isNullable1 = rs.getString("IS_NULLABLE"); - String isNullable2 = rs.getString(18); - System.out.println(tableName1); - System.out.println(tableName2); - System.out.println(isNullable1); - System.out.println(isNullable2); - rs.close(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/BugDecimalRound_Bug_3561.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import java.math.BigDecimal; - -public class BugDecimalRound_Bug_3561 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - - Statement stmt1 = con.createStatement(); - stmt1.executeUpdate("CREATE TABLE bug3561 (d decimal(14,4))"); - - PreparedStatement st = con.prepareStatement("INSERT INTO bug3561 VALUES (?)"); - st.setBigDecimal(1, new BigDecimal("112.125")); - st.executeUpdate(); - st.setBigDecimal(1, new BigDecimal("212.12345")); - st.executeUpdate(); - st.setBigDecimal(1, new BigDecimal("0.012345")); - st.executeUpdate(); - st.close(); - - Statement stmt2 = con.createStatement(); - ResultSet rs = stmt2.executeQuery("SELECT d FROM bug3561"); - while (rs.next()) - System.out.println(rs.getString(1)); - rs.close(); - stmt2.close(); - - stmt1.executeUpdate("DROP TABLE bug3561"); - stmt1.close(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/BugExecuteUpdate_Bug_3350.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugExecuteUpdate_Bug_3350 { - public static void main(String[] args) throws Exception { - final Connection con = DriverManager.getConnection(args[0]); - con.setAutoCommit(false); // disable auto commit, so we can roll back the transaction - - final Statement stmt = con.createStatement(); - try { - stmt.execute("CREATE TABLE t3350 (keyword VARCHAR(30) PRIMARY KEY)"); - con.commit(); - - executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // should insert 1 row - executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // this will result in an SQLException due to PK uniqueness violation - con.rollback(); - - executeDML(stmt, "INSERT INTO t3350 VALUES ('Bug_3350')"); // should insert 1 row - executeDML(stmt, "INSERT INTO t3350 VALUES ('1'), ('x'), ('3'), ('y')"); // should insert 4 rows - executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 1 row - executeDML(stmt, "DELETE FROM t3350 WHERE \"keyword\" = 'Bug_3350'"); // should delete 0 rows - executeDML(stmt, "UPDATE t3350 set \"keyword\" = keyword||'_ext'"); // should update 4 rows - executeDML(stmt, "DELETE FROM t3350"); // should delete 4 rows - con.commit(); - - stmt.execute("DROP TABLE t3350"); - con.commit(); - } catch (SQLException se) { - System.out.println(se.getMessage()); - } finally { - stmt.close(); - } - con.close(); - } - - private static void executeDML(Statement st, String sql) { - try { - int upd_count = st.executeUpdate(sql); - System.out.println("executeUpdate(" + sql.substring(0, 6) + " ...) returned: " + upd_count); - } catch (SQLException se) { - System.out.println(se.getMessage()); - } - - try { - System.out.println("getUpdateCount() returned: " + st.getUpdateCount()); - } catch (SQLException se) { - System.out.println(se.getMessage()); - } - } -}
deleted file mode 100644 --- a/tests/BugResultSetMetaData_Bug_6183.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugResultSetMetaData_Bug_6183 { - static final String dqTblName = "\"my dq_table\""; - static final String[] dqColNames = { "\"my space\"", "\"my, comma_space\"", "\"my$dollar\"", "\"my#hash\"", "\"my tab\"" - , "\"my ,tab_comma\"", "\"my, comma_tab\"", "\"my\"\"double_doublequote\"", "\"Abc\"", "\" \"", "\"123\"" }; - - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - try { - System.out.println("1. create table " + dqTblName); - StringBuilder sb = new StringBuilder(30 + (dqColNames.length * (30 + 15))); - sb.append("CREATE TABLE ").append(dqTblName).append(" ("); - for (int n = 0; n < dqColNames.length; n++) { - sb.append(dqColNames[n]); - sb.append(" varchar(").append(31 + n).append(')'); - if (n < (dqColNames.length -1)) - sb.append(", "); - } - sb.append(')'); - int ret = stmt.executeUpdate(sb.toString()); - System.out.println(" returned: " + ret + " (expected -2)"); - System.out.println(); - - String tblName = dqTblName.substring(1, dqTblName.length() -1); // trim the leading and trailing double quote characters - System.out.println("2. show column names of this new table (" + tblName + ") via sys.columns query"); - rs = stmt.executeQuery("SELECT number, name, type from sys.columns where table_id in (select id from sys._tables where name = '" + tblName + "') order by number"); - showResultAndClose(rs); - - System.out.println("3. insert 1 row of data with values same as column names"); - sb.setLength(0); - sb.append("INSERT INTO ").append(dqTblName).append(" VALUES ("); - for (int n = 0; n < dqColNames.length; n++) { - sb.append('\''); - sb.append(dqColNames[n]); - sb.append('\''); - if (n < (dqColNames.length -1)) - sb.append(", "); - } - sb.append(')'); - ret = stmt.executeUpdate(sb.toString()); - System.out.println(" returned: " + ret + " (expected 1)"); - System.out.println(); - - System.out.println("4. insert 1 row of data with values same as column names but without enclosing double quotes"); - sb.setLength(0); - sb.append("INSERT INTO ").append(dqTblName).append(" VALUES ("); - for (int n = 0; n < dqColNames.length; n++) { - sb.append('\''); - // remove enclosing double quotes - sb.append(dqColNames[n].substring(1, dqColNames[n].length() -1)); - sb.append('\''); - if (n < (dqColNames.length -1)) - sb.append(", "); - } - sb.append(')'); - ret = stmt.executeUpdate(sb.toString()); - System.out.println(" returned: " + ret + " (expected 1)"); - System.out.println(); - - // query each column separately - for (int n = 0; n < dqColNames.length; n++) { - executeQueryAndShowResult(stmt, dqColNames[n], 5 + n); - } - // query all columns - executeQueryAndShowResult(stmt, "*", 5 + dqColNames.length); - - System.out.println("Finally drop table " + dqTblName); - ret = stmt.executeUpdate("DROP TABLE " + dqTblName); - System.out.println(" returned: " + ret + " (expected -2)"); - System.out.println(); - } catch (SQLException se) { - System.out.println("Failure occurred: " + se); - } finally { - if (rs != null) - rs.close(); - stmt.close(); - } - con.close(); - } - - private static void executeQueryAndShowResult(Statement st, String col_list, int query_count) throws SQLException { - System.out.print(query_count); - System.out.println(". show content of column(s): " + col_list); - ResultSet rs = st.executeQuery("SELECT " + col_list + " from " + dqTblName); - showResultAndClose(rs); - } - - private static void showResultAndClose(ResultSet rs) throws SQLException { - ResultSetMetaData rsmd = rs.getMetaData(); - int rs_col_count = rsmd.getColumnCount(); - System.out.println("Resultset with " + rs_col_count + " columns"); - System.out.println("\tColumn Name, Column Label:"); - for (int col = 1; col <= rs_col_count; col++) { - System.out.println(col + "\t" + rsmd.getColumnName(col) + "\t" +rsmd.getColumnLabel(col)); - } - - System.out.println("Data rows:"); - long row_count = 0; - while (rs.next()) { - row_count++; - for (int col = 1; col <= rs_col_count; col++) { - if (col > 1) - System.out.print("\t"); - System.out.print(rs.getString(col)); - } - System.out.println(); - } - rs.close(); - System.out.println("Listed " + row_count + " rows"); - System.out.println(); - } -}
deleted file mode 100644 --- a/tests/BugSetQueryTimeout_Bug_3357.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class BugSetQueryTimeout_Bug_3357 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement st = con.createStatement(); - try { - System.out.println("QueryTimeout = " + st.getQueryTimeout()); - - testTimeout(st, 123); - testTimeout(st, 123); - testTimeout(st, 2134567890); - testTimeout(st, 0); - testTimeout(st, 0); - testTimeout(st, -1); // to generate an SQLException as negative timeouts are invalid - } catch (SQLException se) { - System.out.println("setQueryTimeout(timeout_value) throws: " + se); - } finally { - st.close(); - } - con.close(); - } - - private static void testTimeout(Statement st, int secs) throws SQLException { - st.setQueryTimeout(secs); - // as the call to set the timeout is delayed till a statement is executed, issue a select statment - ResultSet rs = st.executeQuery("SELECT " + secs); - if (rs != null) - rs.close(); - System.out.println("QueryTimeout = " + st.getQueryTimeout()); - } -}
deleted file mode 100644 --- a/tests/Bug_Connect_as_voc_getMetaData_Failure_Bug_6388.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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 - 2021 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; - - 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 :)"); - System.out.println(); - - 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()"); - String dbmsVersion = dbmd.getDatabaseProductVersion(); // should be 11.27.1 or higher - boolean postJul2017 = ("11.27.1".compareTo(dbmsVersion) <= 0); - System.out.println("DatabaseProductVersion = " + (postJul2017 ? "11.27.+" : dbmsVersion)); - - System.out.println("4.5. getDatabaseMajorVersion()"); - System.out.println("DatabaseMajorVersion = " + dbmd.getDatabaseMajorVersion()); // should be 11 - - System.out.println("4.6. getDatabaseMinorVersion()"); - int dbmsMinorVersion = dbmd.getDatabaseMinorVersion(); // should be 27 or higher - System.out.println("DatabaseMinorVersion = " + (dbmsMinorVersion >= 27 ? "27+" : dbmsMinorVersion)); - - System.out.println("4.7. getTables(null, 'tmp', null, null)"); - ResultSet rs1 = dbmd.getTables(null, "tmp", null, null); - if (rs1 != null) { - System.out.println("List Tables in schema tmp:"); - while (rs1.next()) { - System.out.println(rs1.getString(3)); - } - rs1.close(); - } - System.out.println("completed listing Tables in schema tmp"); - - System.out.println("4.8. getTableTypes()"); - 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()); - } - } - } -}
deleted file mode 100644 --- a/tests/Bug_IsValid_Timeout_Bug_6782.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Bug_IsValid_Timeout_Bug_6782 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement st = null; - - st = con.createStatement(); - st.setQueryTimeout(5); - System.out.println("getQueryTimeout must give 5: " + st.getQueryTimeout()); - st.close(); - - con.isValid(3); - - st = con.createStatement(); - System.out.println("getQueryTimeout must give 0: " + st.getQueryTimeout()); - - con.isValid(3); - System.out.println("getQueryTimeout must give 0: " + st.getQueryTimeout()); - st.close(); - - st.setQueryTimeout(5); - con.isValid(3); - System.out.println("getQueryTimeout must give 5: " + st.getQueryTimeout()); - st.close(); - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Bug_LargeQueries_6571_6693.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; -import java.sql.SQLException; - -public class Bug_LargeQueries_6571_6693 { - final static String tbl_nm = "tbl6693"; - final static String largedata = createLargedata(9216); - - private static String createLargedata(int num) { - String repeatValue = "*"; - StringBuilder sb = new StringBuilder(num * repeatValue.length()); - for (int i = 0; i < num; i++) - sb.append(repeatValue); - String largedata = sb.toString(); - if (largedata.length() <= 8192) - System.out.println("Length (" + largedata.length() + ") of largedata value is too small! Should be larger than 8192!"); - return largedata; - } - - // To execute this test program: start a local MonetDB server (mserver5 process) and next execute command: - // java -cp monetdb-jdbc-2.29.jar:. Bug_LargeQueries_6571_6693 "jdbc:monetdb://localhost:50000/demo?user=monetdb&password=monetdb" - - public static void main(String[] args) throws SQLException { - int script_iterations = 10; - String conURL = args.length > 0 ? args[0] : ""; - - if (args.length > 1) { - try { - script_iterations = Integer.parseInt(args[1]); - } catch (NumberFormatException nfe) { - System.err.println("Cannot convert 2nd argumnent to an integer. Ignoring it."); - } - } - - try (Connection con = DriverManager.getConnection(conURL)) { - try (Statement stmt = con.createStatement()) { - // create a test table. - stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tbl_nm + " (attribute CLOB, value CLOB);"); - System.out.print("Created table: " + tbl_nm); - System.out.print(" Inserting rows. "); - String insertCmd = "INSERT INTO " + tbl_nm + " VALUES ('activeset_default_fiets', '" + largedata + "');"; - int ins = stmt.executeUpdate(insertCmd); - ins += stmt.executeUpdate(insertCmd); - ins += stmt.executeUpdate(insertCmd); - System.out.println(ins + " rows inserted"); - } - - run_tests(conURL, script_iterations); - - try (Statement stmt = con.createStatement()) { - System.out.println("Cleanup TABLE " + tbl_nm); - stmt.executeUpdate("DROP TABLE IF EXISTS " + tbl_nm); - } - } - - System.out.println("Test completed without hanging"); - } - - private static void run_tests(String conURL, int iterations) throws SQLException { - String script = - "delete from " + tbl_nm + " where attribute='activeset_default_fiets';\n" - + "insert into " + tbl_nm + " values ('activeset_default_fiets', '" + largedata + "');\n" - + "insert into " + tbl_nm + " values ('activeset_default_fiets', '" + largedata + "');\n" - + "insert into " + tbl_nm + " values ('activeset_default_fiets', '" + largedata + "');\n" - + "select value from " + tbl_nm + " where attribute='activeset_default_fiets';\n"; - System.out.println("Script size is " + script.length()); - - // first try to make the execution hang after many iterations of sending large data queries within one connection - System.out.println("First test repeat " + iterations + " times"); - try (Connection con = DriverManager.getConnection(conURL)) { - System.out.print("Iteration: "); - for (int i = 1; i <= iterations; i++) { - System.out.print(i + " "); - try (Statement stmt = con.createStatement()) { - process_script(stmt, script, 1, 3, 6); - } - } - System.out.println(); - } - System.out.println("Completed first test"); - - // also try to make the execution hang after many iterations of making connections (each their own socket) and sending large scripts - System.out.println("Second test repeat " + iterations + " times"); - System.out.print("Iteration: "); - for (int i = 1; i <= iterations; i++) { - try (Connection con = DriverManager.getConnection(conURL)) { - System.out.print(i + " "); - try (Statement stmt = con.createStatement()) { - process_script(stmt, script, 1, 3, 6); - process_script(stmt, script, 1, 3, 6); - process_script(stmt, script, 1, 3, 6); - process_script(stmt, script, 1, 3, 6); - } - } - } - System.out.println(); - System.out.println("Completed second test"); - - // next try to make the execution hang by sending very many queries combined in 1 large script - final int queries = 100; - StringBuilder sb = new StringBuilder(queries * 13); - for (int i = 1; i <= queries; i++) - sb.append(" SELECT ").append(i).append(';'); - script = sb.toString(); - System.out.println("Script size is " + script.length()); - iterations = 3; - System.out.println("Third test repeat " + iterations + " times"); - try (Connection con = DriverManager.getConnection(conURL)) { - System.out.print("Iteration: "); - for (int i = 1; i <= iterations; i++) { - System.out.print(i + " "); - try (Statement stmt = con.createStatement()) { - process_script(stmt, script, queries, queries, 0); - } - } - System.out.println(); - } - System.out.println("Completed third test"); - } - - private static void process_script(Statement stmt, String script, - int expectedResults, int expectedTotalRows, int expectedUpdates) throws SQLException { - int results = 0; - int rows = 0; - int updates = 0; - stmt.execute(script); - do { - ResultSet rs = stmt.getResultSet(); - if (rs != null) { - results++; - while(rs.next()) { - String val = rs.getString(1); - rows++; - } - rs.close(); - } else { - int uc = stmt.getUpdateCount(); - if (uc > 0) - updates += uc; - } - } while (stmt.getMoreResults() || stmt.getUpdateCount() != -1); - - /* verify nr of processed resultsets and retrieved rows are as expected */ - if (results != expectedResults) - System.out.print(results + "!=" + expectedResults + " "); - if (rows != expectedTotalRows) - System.out.print(rows + "!=" + expectedTotalRows + " "); - if (updates != expectedUpdates) - System.out.print(updates + "!=" + expectedUpdates + " "); - } -}
deleted file mode 100644 --- a/tests/Bug_PrepStmtSetObject_CLOB_6349.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Bug_PrepStmtSetObject_CLOB_6349 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt = null; - ParameterMetaData pmd = null; - ResultSet rs = null; - ResultSetMetaData rsmd = null; - - System.out.println("0. true\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE PrepStmtSetObject_CLOB (myint INT, myvarchar VARCHAR(15), myclob CLOB)"); - stmt.executeUpdate("INSERT INTO PrepStmtSetObject_CLOB VALUES (123, 'A string', 'A longer string')"); - stmt.executeUpdate("INSERT INTO PrepStmtSetObject_CLOB VALUES (NULL, NULL, NULL)"); // all NULLs - - pstmt = con.prepareStatement("SELECT myclob, myvarchar, myint FROM PrepStmtSetObject_CLOB WHERE myclob = ?"); - pmd = pstmt.getParameterMetaData(); - System.out.println("Prepared Query has " + pmd.getParameterCount() + " parameters. Type of first is: " + pmd.getParameterTypeName(1)); - rsmd = pstmt.getMetaData(); - System.out.println("Prepared Query has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)); - - pstmt.setObject(1, "A longer string"); - rs = pstmt.executeQuery(); - rsmd = rs.getMetaData(); - System.out.println("Query ResultSet has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)); - - boolean has_row = rs.next(); - boolean has_rows = rs.next(); - if (has_row == false || has_rows == true) - System.out.println("Fetching Query ResultSet failed"); - - stmt.executeUpdate("DROP TABLE PrepStmtSetObject_CLOB"); - - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } finally { - if (rs != null) rs.close(); - if (pstmt != null) pstmt.close(); - stmt.close(); - } - - con.close(); - } -} -
deleted file mode 100644 --- a/tests/Bug_PrepStmtSetString_6382.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import org.monetdb.jdbc.types.INET; -import org.monetdb.jdbc.types.URL; - -public class Bug_PrepStmtSetString_6382 { - public static void main(String[] args) throws Exception { - Connection con = null; - Statement stmt = null; - PreparedStatement pstmt = null; - ResultSet rs = null; - final String tableName = "PrepStmtSetString_6382"; - try { - con = DriverManager.getConnection(args[0]); - System.out.println("0. true\t" + con.getAutoCommit()); - - stmt = con.createStatement(); - System.out.println("Creating table " + tableName); - stmt.executeUpdate("CREATE TABLE " + tableName + " (myint INT, myvarchar VARCHAR(15), myjson JSON, myuuid UUID, myurl URL, myinet INET)"); - - System.out.println("Inserting row 1"); - stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (1, 'row 1', '{}', uuid '34c8deb5-e608-406b-beda-6a951f73d455', 'https://www.monetdb.org/', '128.0.0.1')"); - - System.out.println("Inserting row 2"); - stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (2, 'row 2', '[]', NULL, NULL, NULL)"); - - - System.out.println("Creating a prepared statement with 6 parameters and inserting rows using setInt(), setString(), setNull(), setNString(), setURL(), setObject()."); - pstmt = con.prepareStatement("INSERT INTO " + tableName + " VALUES (?,?, ? ,?,? , ?)"); - ParameterMetaData pmd = pstmt.getParameterMetaData(); - int pcount = pmd.getParameterCount(); - System.out.println("Prepared Statement has " + pcount + " parameters:" + (pcount != 6 ? " ERROR: Expected 6 parameters!" : "")); - for (int p = 1; p <= pcount; p++) { - System.out.println(" Parameter " + p + " type is: " + pmd.getParameterTypeName(p) + ". JDBC SQL type: " + pmd.getParameterType(p)); - } - - int row = 3; - pstmt.setInt(1, row); - pstmt.setString(2, "row " + row); - pstmt.setString(3, "{\"menu\": {\n \"id\": \"file\",\n \"value\": \"File\",\n \"popup\": {\n \"menuitem\": [\n {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n ]\n }\n}}"); - pstmt.setNull(4, 0); - pstmt.setNull(5, 0); - pstmt.setNull(6, 0); - System.out.println("Inserting row " + row); - int inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - row++; // row 4 - pstmt.setShort(1, (short)row); - pstmt.setNString(2, "row " + row); - pstmt.setNull(3, 0); - pstmt.setString(4, "4a148b7d-8d47-4e1e-a21e-09a71abf2215"); - System.out.println("Inserting row " + row); - inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - row++; // row 5 - pstmt.setLong(1, (long)row); - pstmt.setString(2, "row " + row); - pstmt.setNull(4, 0); - pstmt.setURL(5, new java.net.URL("https://www.cwi.nl/")); - System.out.println("Inserting row " + row); - inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - row++; // row 6 - pstmt.setBigDecimal(1, new java.math.BigDecimal(row)); - pstmt.setNString(2, "row " + row); - pstmt.setNull(5, 0); - pstmt.setString(6, "127.255.255.255"); - System.out.println("Inserting row " + row); - inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - /* also test generic setObject(int, String) */ - row++; // row 7 - pstmt.setObject(1, Integer.valueOf(row)); - pstmt.setObject(2, "row " + row); - pstmt.setObject(3, "{\"menu\": {\n \"header\": \"SVG Viewer\",\n \"items\": [\n {\"id\": \"Open\"},\n {\"id\": \"OpenNew\", \"label\": \"Open New\"},\n null,\n {\"id\": \"ZoomIn\", \"label\": \"Zoom In\"},\n {\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"},\n {\"id\": \"OriginalView\", \"label\": \"Original View\"},\n null,\n {\"id\": \"Quality\"},\n {\"id\": \"Pause\"},\n {\"id\": \"Mute\"},\n null,\n {\"id\": \"Help\"},\n {\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}\n ]\n}}"); - pstmt.setObject(4, "b39dc76e-4faf-4fd9-bc1e-17df48acf764"); - pstmt.setObject(5, "https://en.wikipedia.org/wiki/IP_address"); - pstmt.setObject(6, "223.255.255.255"); - System.out.println("Inserting row " + row); - inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - row++; // row 8 - pstmt.setObject(1, new java.math.BigDecimal(row)); - pstmt.setObject(2, "row " + row); - pstmt.setObject(3, null); - pstmt.setObject(4, java.util.UUID.fromString("ff125769-b63c-4c3c-859f-5b84a9349e24")); - URL myURL = new URL(); - myURL.fromString("https://en.wikipedia.org/wiki/IP_address"); - pstmt.setObject(5, myURL); - INET myINET = new INET(); - myINET.fromString("223.234.245.255"); - pstmt.setObject(6, myINET); - System.out.println("Inserting row " + row); - inserted = pstmt.executeUpdate(); - System.out.println("Inserted " + inserted + " row"); - - - System.out.println("List contents of TABLE " + tableName + " after " + row + " rows inserted"); - rs = stmt.executeQuery("SELECT * FROM " + tableName + " ORDER BY 1"); - ResultSetMetaData rsmd = rs.getMetaData(); - int colcount = rsmd.getColumnCount(); - System.out.println("Query has " + colcount + " output columns." + (colcount != 6 ? " ERROR: Expected 6 columns!" : "")); - row = 0; - while (rs.next()) { - System.out.print("row " + ++row); - for (int c = 1; c <= colcount; c++) { - System.out.print("\t" + rs.getString(c)); - } - System.out.println(); - } - - System.out.println(); - System.out.println("Cleanup TABLE " + tableName); - stmt.executeUpdate("DROP TABLE " + tableName); - System.out.println("Test completed successfully"); - } catch (SQLException e) { - System.err.println("FAILED :( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.err.println("FAILED :( " + e.getMessage()); - System.err.println("ABORTING TEST!!!"); - } finally { - try { if (rs != null) rs.close(); } catch (SQLException e) { /* ignore */ } - try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { /* ignore */ } - try { if (stmt != null) stmt.close(); } catch (SQLException e) { /* ignore */ } - try { if (con != null) con.close(); } catch (SQLException e) { /* ignore */ } - } - } -} -
deleted file mode 100644 --- a/tests/Bug_PrepStmt_With_Errors_Jira292.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Bug_PrepStmt_With_Errors_Jira292 { - public static void main(String[] args) throws Exception { - Connection con = null; - Statement stmt = null; - PreparedStatement pstmt = null; - ParameterMetaData pmd = null; - ResultSet rs = null; - ResultSetMetaData rsmd = null; - - try { - con = DriverManager.getConnection(args[0]); - System.out.println("0. true\t" + con.getAutoCommit()); - con.setNetworkTimeout(null, (10 *1000)); - - stmt = con.createStatement(); - stmt.executeUpdate("drop table if exists abacus;"); - stmt.executeUpdate("create table abacus ( \"'Zeitachse'\" date,\"'Abo_ID'\" int,\"'description'\" varchar(256),\"'Klassierungs-Typ'\" clob,\"'KlassierungApplikation'\" clob,\"'EP Netto'\" decimal,\"'Nettoumsatz'\" decimal,\"'validfrom'\" date,\"'validuntil'\" date,\"'Abo_aufgeschaltet'\" int,\"'Abo_deaktiviert'\" int,\"'Differenz'\" decimal,\"'User_ID'\" int,\"'UserName'\" varchar(256),\"'client'\" varchar(256),\"'Installations_ID'\" int,\"'InstallationsName'\" varchar(256),\"'Installationsprovider_ID'\" int,\"'InstallationsproviderName'\" varchar(256),\"'INR'\" bigint,\"'NAME'\" varchar(256),\"'PLZ'\" varchar(256),\"'ORT'\" varchar(256),\"'STAAT'\" varchar(256),\"'Reseller_ID'\" int,\"'ResellerName'\" varchar(256),\"'ET_ABO'\" clob,\"'UserName_1'\" varchar(256),\"'Anzahl_Abos'\" decimal,\"'Anzahl_User'\" decimal,\"'Jahr'\" decimal,\"'Monat'\" decimal,\"'Jahr_Monat'\" clob,\"'IFJ'\" clob,\"'RECNUM$'\" int,\"'InlineCalc_Year_Zeitachse'\" int);"); - stmt.executeUpdate("insert into abacus values ('2019-10-30',2239,'description','Klassierungs-Typ','Klassierung-Applikation',73.28,68.29,'2018-01-01','2018-12-01',563,63,56.3,852,'UserName','client',134,'InstallationsName',892,'InstallationsproviderName',9348,'NAME','PLZ','ORT','STAAT',934,'ResellerName','ET_ABO','UserName_1',849.2739,1742.718,395.824,39.824,'Jahr_Monat','IFJ',395824,3789);"); - - System.out.println("1. table created and inserted 1 row"); - - String qry = "SELECT \"'ResellerName'\" FROM abacus WHERE ( ( (\"'InstallationsproviderName'\"='Bienz Pius Treuhand- und Revisions AG')) AND ( (\"'validuntil'\"='2018-01-01' AND \"'description'\"='ABEA 2' AND (EXTRACT(YEAR FROM \"'Zeitachse'\")*100 + EXTRACT(MONTH FROM \"'Zeitachse'\"))/100.0='2019.010' AND \"'UserName'\"='AL - Astrid Lincke (Delphys)' AND \"'validfrom'\"='2016-12-01')) AND ( (\"'IFJ'\"='ohne IFJ')) AND ( (\"'InlineCalc_Year_Zeitachse'\"='2019'))) GROUP BY \"'ResellerName'\" LIMIT 1001 OFFSET 0;"; - try { - System.out.println("2. before select query execution"); - rs = stmt.executeQuery(qry); - System.out.println("2a. select query executed"); - if (rs != null) { - if (rs.next()) { - System.out.println("2b. select query returned: " + rs.getString(1)); - } - rs.close(); - rs = null; - System.out.println("2c. closed select query resultset"); - } - System.out.println("2d. normal end of select query"); - } catch (SQLException se) { - System.out.println("select query Exception: "+ se.getMessage()); - while ((se = se.getNextException()) != null) - System.out.println("next Exception: "+ se.getMessage()); - } - - try { - System.out.println("3. before creating a prepared select query"); - pstmt = con.prepareStatement(qry); - System.out.println("3a. prepared select query"); - - pmd = pstmt.getParameterMetaData(); - System.out.println("3b. Prepared Query has " + pmd.getParameterCount() + " parameters."); // "Type of first is: " + pmd.getParameterTypeName(1)); - rsmd = pstmt.getMetaData(); - System.out.println("3c. Prepared Query has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)); - - System.out.println("3d. before executing the prepared select query"); - rs = pstmt.executeQuery(); - System.out.println("3e. prepared select query executed"); - if (rs != null) { - rsmd = rs.getMetaData(); - System.out.println("3f. prepared Query ResultSet has " + rsmd.getColumnCount() + " columns. Type of first is: " + rsmd.getColumnTypeName(1)); - - if (rs.next()) { - System.out.println("3g. prepared select query returned: " + rs.getString(1)); - } - rs.close(); - rs = null; - System.out.println("3h. closed prepared select query resultset"); - } - System.out.println("3i. normal end of prepared select query"); - } catch (SQLException se) { - System.out.println("prepared select query Exception: "+ se.getMessage()); - while ((se = se.getNextException()) != null) - System.out.println("next Exception: "+ se.getMessage()); - } - - System.out.println("4. drop table"); - stmt.executeUpdate("drop table abacus"); - - System.out.println("5. normal end of test"); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } finally { - if (rs != null) try { rs.close(); } catch (SQLException e) { /* ignore */ } - if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { /* ignore */ } - if (stmt != null) try { stmt.close(); } catch (SQLException e) { /* ignore */ } - if (con != null) try { con.close(); } catch (SQLException e) { /* ignore */ } - } - } -} -
deleted file mode 100644 --- a/tests/Test_CallableStmt.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_CallableStmt { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0] + "&treat_clob_as_varchar=false"); - Statement stmt = null; - CallableStatement cstmt = null; - try { - String tbl_nm = "tbl6402"; - String proc_nm = "proc6402"; - - stmt = con.createStatement(); - - // create a test table. - stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tbl_nm + " (tint int, tdouble double, tbool boolean, tvarchar varchar(15), tclob clob, turl url, tclen int);"); - System.out.println("Created table: " + tbl_nm); - - // create a procedure with multiple different IN parameters which inserts a row into a table of which one column is computed. - stmt.executeUpdate("CREATE PROCEDURE " + proc_nm + " (myint int, mydouble double, mybool boolean, myvarchar varchar(15), myclob clob, myurl url) BEGIN" + - " INSERT INTO " + tbl_nm + " (tint, tdouble, tbool, tvarchar, tclob, turl, tclen) VALUES (myint, mydouble, mybool, myvarchar, myclob, myurl, LENGTH(myvarchar) + LENGTH(myclob)); " + - "END;"); - System.out.println("Created procedure: " + proc_nm); - - // make sure we can call the procedure the old way (as string) - stmt.executeUpdate("call " + proc_nm + "(1, 1.1, true,'one','ONE', 'www.monetdb.org');"); - System.out.println("Called procedure (1): " + proc_nm); - showContents(con, tbl_nm); - - - // now use a CallableStament object - cstmt = con.prepareCall(" { call " + proc_nm + " (?,?, ?, ? , ?,?) } ;"); - System.out.println("Prepared Callable procedure: " + proc_nm); - - // specify first set of params - cstmt.setInt(1, 2); - cstmt.setDouble(2, 2.02); - cstmt.setBoolean(3, true); - cstmt.setString(4, "Two"); - Clob myclob = con.createClob(); - myclob.setString(1, "TWOs"); - cstmt.setClob(5, myclob); - cstmt.setString(6, "http://www.monetdb.org/"); - cstmt.execute(); - System.out.println("Called Prepared procedure (1): " + proc_nm); - showParams(cstmt); - showContents(con, tbl_nm); - - myclob.setString(1, "TREEs"); - // specify second set of params (some (1 and 3 and 5) are left the same) - cstmt.setDouble(2, 3.02); - cstmt.setString(4, "Tree"); - cstmt.setURL(6, new java.net.URL("https://www.monetdb.org/")); - cstmt.execute(); - System.out.println("Called Prepared procedure (2): " + proc_nm); - // showParams(cstmt); - showContents(con, tbl_nm); - - // specify third set of params (some (1 and 2) are left the same) - cstmt.setInt(1, 4); - cstmt.setBoolean(3, false); - cstmt.setString(4, "Four"); - cstmt.executeUpdate(); - System.out.println("Called Prepared procedure (3): " + proc_nm); - showContents(con, tbl_nm); - - // test setNull() also - cstmt.setNull(3, Types.BOOLEAN); - cstmt.setNull(5, Types.CLOB); - cstmt.setNull(2, Types.DOUBLE); - cstmt.setNull(4, Types.VARCHAR); - cstmt.setNull(1, Types.INTEGER); - cstmt.executeUpdate(); - System.out.println("Called Prepared procedure (with NULLs): " + proc_nm); - showContents(con, tbl_nm); - - - System.out.println("Test completed. Cleanup procedure and table."); - stmt.execute("DROP PROCEDURE IF EXISTS " + proc_nm + ";"); - stmt.execute("DROP TABLE IF EXISTS " + tbl_nm + ";"); - - } catch (SQLException e) { - System.out.println("main failed: " + e.getMessage()); - System.out.println("ABORTING TEST"); - } finally { - try { - if (cstmt != null) - cstmt.close(); - if (stmt != null) - stmt.close(); - } catch (SQLException e) { /* ignore */ } - } - - con.close(); - } - - - // some utility methods for showing table content and params meta data - static void showContents(Connection con, String tblnm) { - Statement stmt = null; - ResultSet rs = null; - try { - stmt = con.createStatement(); - rs = stmt.executeQuery("SELECT * FROM " + tblnm); - if (rs != null) { - ResultSetMetaData rsmd = rs.getMetaData(); - System.out.println("Table " + tblnm + " has " + rsmd.getColumnCount() + " columns:"); - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.print("\t" + rsmd.getColumnLabel(col)); - } - System.out.println(); - while (rs.next()) { - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.print("\t" + rs.getString(col)); - } - System.out.println(); - } - } else - System.out.println("failed to execute query: SELECT * FROM " + tblnm); - } catch (SQLException e) { - System.out.println("showContents failed: " + e.getMessage()); - } finally { - try { - if (rs != null) - rs.close(); - if (stmt != null) - stmt.close(); - } catch (SQLException e) { /* ignore */ } - } - } - - static void showParams(PreparedStatement stmt) { - try { - ParameterMetaData pmd = stmt.getParameterMetaData(); - System.out.println(pmd.getParameterCount() + " parameters reported:"); - for (int parm = 1; parm <= pmd.getParameterCount(); parm++) { - System.out.print(parm + "."); - int nullable = pmd.isNullable(parm); - System.out.println("\tnullable " + nullable + " (" + paramNullableName(nullable) + ")"); - System.out.println("\tsigned " + pmd.isSigned(parm)); - System.out.println("\tprecision " + pmd.getPrecision(parm)); - System.out.println("\tscale " + pmd.getScale(parm)); - System.out.println("\ttype " + pmd.getParameterType(parm)); - System.out.println("\ttypename " + pmd.getParameterTypeName(parm)); - System.out.println("\tclassname " + pmd.getParameterClassName(parm)); - int mode = pmd.getParameterMode(parm); - System.out.println("\tmode " + mode + " (" + paramModeName(mode) + ")"); - } - } catch (SQLException e) { - System.out.println("showParams failed: " + e.getMessage()); - } - } - - static String paramNullableName(int nullable) { - if (nullable == ParameterMetaData.parameterNoNulls) - return "NO"; - if (nullable == ParameterMetaData.parameterNullable) - return "YA"; - if (nullable == ParameterMetaData.parameterNullableUnknown) - return "UNKNOWN"; - return "INVALID" + nullable; - } - - static String paramModeName(int mode) { - if (mode == ParameterMetaData.parameterModeIn) - return "IN"; - if (mode == ParameterMetaData.parameterModeInOut) - return "INOUT"; - if (mode == ParameterMetaData.parameterModeOut) - return "OUT"; - if (mode == ParameterMetaData.parameterModeUnknown) - return "UNKNOWN"; - return "INVALID" + mode; - } -}
deleted file mode 100644 --- a/tests/Test_Cautocommit.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Cautocommit { - public static void main(String[] args) throws Exception { - Connection con1 = DriverManager.getConnection(args[0]); - Connection con2 = DriverManager.getConnection(args[0]); - Statement stmt1 = con1.createStatement(); - Statement stmt2 = con2.createStatement(); - ResultSet rs = null; - //DatabaseMetaData dbmd = con.getMetaData(); - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con1.getAutoCommit()); - System.out.println("0. true\t" + con2.getAutoCommit()); - - // test commit by checking if a change is visible in another connection - try { - System.out.print("1. create..."); - stmt1.executeUpdate("CREATE TABLE table_Test_Cautocommit ( id int )"); - System.out.println("passed :)"); - System.out.print("2. select..."); - rs = stmt2.executeQuery("SELECT * FROM table_Test_Cautocommit"); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - con1.close(); - con2.close(); - System.exit(-1); - } - - // turn off auto commit - con1.setAutoCommit(false); - con2.setAutoCommit(false); - - // >> false: we just disabled it - System.out.println("3. false\t" + con1.getAutoCommit()); - System.out.println("4. false\t" + con2.getAutoCommit()); - - // a change would not be visible now - try { - System.out.print("5. drop..."); - stmt2.executeUpdate("DROP TABLE table_Test_Cautocommit"); - System.out.println("passed :)"); - System.out.print("6. select..."); - rs = stmt1.executeQuery("SELECT * FROM table_Test_Cautocommit"); - System.out.println("passed :)"); - System.out.print("7. commit..."); - con2.commit(); - System.out.println("passed :)"); - System.out.print("8. select..."); - rs = stmt1.executeQuery("SELECT * FROM table_Test_Cautocommit"); - System.out.println("passed :)"); - System.out.print("9. commit..."); - con1.commit(); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :("); - System.out.println("ABORTING TEST!!!"); - } - - if (rs != null) rs.close(); - - con1.close(); - con2.close(); - } -}
deleted file mode 100644 --- a/tests/Test_CisValid.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_CisValid { - /* Test that after an error has occurred during a transaction, one can - * still test if the connection is valid or not. - * The function Connection.isValid() should only return TRUE or FALSE. It - * shall never alter the state of this connection */ - public static void main(String[] args) throws Exception { - Connection conn = DriverManager.getConnection(args[0]); - Statement stmt = conn.createStatement(); - - try { - conn.setAutoCommit(false); // start a transaction - stmt.execute("SELECT COUNT(*) FROM doesnotexist;"); // let's trigger an error - } catch (SQLException e) { - // e.printStackTrace(); - System.err.println("Expected error: " + e); - - try { - // test calling conn.isValid() - System.out.println("Validating connection: conn.isValid? " + conn.isValid(30)); - // Can we rollback on this connection without causing an error? - conn.rollback(); - } catch (SQLException e2) { - System.err.println("UnExpected error: " + e2); - } - } - - stmt.close(); - conn.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Clargequery.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Clargequery { - public static void main(String[] args) throws Exception { - Connection con1 = DriverManager.getConnection(args[0]); - Statement stmt1 = con1.createStatement(); - ResultSet rs = null; - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con1.getAutoCommit()); - - final String query = - "-- When a query larger than the send buffer is being " + - "sent, a deadlock situation can occur when the server writes " + - "data back, blocking because we as client are sending as well " + - "and not reading. Hence, to avoid this deadlock, in JDBC a " + - "separate thread is started in the background such that results " + - "from the server can be read, while data is still being sent to " + - "the server. To test this, we need to trigger the SendThread " + - "being started, which we do with a quite large query. We " + - "construct it by repeating some stupid query plus a comment " + - "a lot of times. And as you're guessing by now, you're reading " + - "this stupid comment that we use :)\n" + - "select 1;\n"; - - int size = 1000; - StringBuilder bigq = new StringBuilder(query.length() * size); - for (int i = 0; i < size; i++) { - bigq.append(query); - } - - // test commit by checking if a change is visible in another connection - try { - System.out.print("1. sending"); - stmt1.execute(bigq.toString()); - int i = 1; // we skip the first "getResultSet()" - while (stmt1.getMoreResults() != false) { - i++; - } - if (stmt1.getUpdateCount() != -1) { - System.out.println("found an update count for a SELECT query"); - throw new SQLException("boo"); - } - if (i != size) { - System.out.println("expecting " + size + " tuples, only got " + i); - throw new SQLException("boo"); - } - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :("); - System.out.println("ABORTING TEST!!!"); - } - - if (rs != null) - rs.close(); - - con1.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Cmanycon.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import java.util.*; - -public class Test_Cmanycon { - public static void main(String[] args) throws Exception { - List<Connection> cons = new ArrayList<Connection>(100); // Connections go in here - - try { - // spawn a lot of Connections, just for fun... - int i; - for (i = 0; i < 50; i++) { - System.out.print("Establishing Connection " + i + "..."); - Connection con = DriverManager.getConnection(args[0]); - System.out.print(" done..."); - - // do something with the connection to test if it works - con.setAutoCommit(false); - System.out.println(" alive"); - - cons.add(con); - } - - // now try to nicely close them - i = 0; - for (Iterator<Connection> it = cons.iterator(); it.hasNext(); i++) { - Connection con = it.next(); - - // see if the connection still works - System.out.print("Closing Connection " + i + "..."); - con.setAutoCommit(true); - System.out.print(" still alive..."); - con.close(); - System.out.println(" done"); - } - } catch (SQLException e) { - System.out.println("FAILED! " + e.getMessage()); - } - } -}
deleted file mode 100644 --- a/tests/Test_Creplysize.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Creplysize { - public static void main(String[] args) throws Exception { - Connection con1 = DriverManager.getConnection(args[0]); - Statement stmt1 = con1.createStatement(); - ResultSet rs = null; - - con1.setAutoCommit(false); - // >> true: auto commit should be off by now - System.out.println("0. true\t" + con1.getAutoCommit()); - - // test commit by checking if a change is visible in another connection - try { - System.out.print("1. create... "); - stmt1.executeUpdate("CREATE TABLE table_Test_Creplysize ( id int )"); - System.out.println("passed :)"); - - System.out.print("2. populating with 21 records... "); - for (int i = 0; i < 21; i++) - stmt1.executeUpdate("INSERT INTO table_Test_Creplysize (id) values (" + (i + 1) + ")"); - System.out.println("passed :)"); - - System.out.print("3. hinting the driver to use fetchsize 10... "); - stmt1.setFetchSize(10); - System.out.println("passed :)"); - - System.out.print("4. selecting all values... "); - rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); - int i = 0; - while (rs.next()) i++; - rs.close(); - if (i == 21) { - System.out.println("passed :)"); - } else { - throw new SQLException("got " + i + " records!!!"); - } - - System.out.print("5. resetting driver fetchsize hint... "); - stmt1.setFetchSize(0); - System.out.println("passed :)"); - - System.out.print("6. instructing the driver to return at max 10 rows... "); - stmt1.setMaxRows(10); - System.out.println("passed :)"); - - System.out.print("7. selecting all values... "); - rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); - i = 0; - while (rs.next()) i++; - rs.close(); - if (i == 10) { - System.out.println("passed :)"); - } else { - throw new SQLException("got " + i + " records!!!"); - } - - System.out.print("8. hinting the driver to use fetchsize 5... "); - stmt1.setFetchSize(5); - System.out.println("passed :)"); - - System.out.print("9. selecting all values... "); - rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); - i = 0; - while (rs.next()) i++; - rs.close(); - if (i == 10) { - System.out.println("passed :)"); - } else { - throw new SQLException("got " + i + " records!!!"); - } - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - con1.close(); - System.exit(-1); - } - - con1.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Csavepoints.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Csavepoints { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con.getAutoCommit()); - - // savepoints require a non-autocommit connection - try { - System.out.print("1. savepoint..."); - con.setSavepoint(); - System.out.println("PASSED :("); - System.out.println("ABORTING TEST!!!"); - con.close(); - System.exit(-1); - } catch (SQLException e) { - System.out.println("failed :) " + e.getMessage()); - } - - con.setAutoCommit(false); - // >> true: auto commit should be on by default - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - System.out.print("2. savepoint..."); - /* make a savepoint, and discard it */ - con.setSavepoint(); - System.out.println("passed :)"); - - stmt.executeUpdate("CREATE TABLE table_Test_Csavepoints ( id int, PRIMARY KEY (id) )"); - - System.out.print("3. savepoint..."); - Savepoint sp2 = con.setSavepoint("empty table"); - System.out.println("passed :)"); - - rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); - int i = 0; - int items = 0; - System.out.print("4. table " + items + " items"); - while (rs.next()) { - System.out.print(", " + rs.getString("id")); - i++; - } - if (i != items) { - System.out.println(" FAILED (" + i + ") :("); - System.out.println("ABORTING TEST!!!"); - con.close(); - System.exit(-1); - } - System.out.println(" passed :)"); - - stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (1)"); - stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (2)"); - stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (3)"); - - System.out.print("5. savepoint..."); - Savepoint sp3 = con.setSavepoint("three values"); - System.out.println("passed :)"); - - rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); - i = 0; - items = 3; - System.out.print("6. table " + items + " items"); - while (rs.next()) { - System.out.print(", " + rs.getString("id")); - i++; - } - if (i != items) { - System.out.println(" FAILED (" + i + ") :("); - System.out.println("ABORTING TEST!!!"); - con.close(); - System.exit(-1); - } - System.out.println(" passed :)"); - - System.out.print("7. release..."); - con.releaseSavepoint(sp3); - System.out.println("passed :)"); - - rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); - i = 0; - items = 3; - System.out.print("8. table " + items + " items"); - while (rs.next()) { - System.out.print(", " + rs.getString("id")); - i++; - } - if (i != items) { - System.out.println(" FAILED (" + i + ") :("); - System.out.println("ABORTING TEST!!!"); - con.close(); - System.exit(-1); - } - System.out.println(" passed :)"); - - System.out.print("9. rollback..."); - con.rollback(sp2); - System.out.println("passed :)"); - - rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); - i = 0; - items = 0; - System.out.print("10. table " + items + " items"); - while (rs.next()) { - System.out.print(", " + rs.getString("id")); - i++; - } - if (i != items) { - System.out.println(" FAILED (" + i + ") :("); - System.out.println("ABORTING TEST!!!"); - con.close(); - System.exit(-1); - } - System.out.println(" passed :)"); - - con.rollback(); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Ctransaction.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Ctransaction { - public static void main(String[] args) throws Exception { - Connection con1 = DriverManager.getConnection(args[0]); - Statement stmt1 = con1.createStatement(); - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con1.getAutoCommit()); - - // test commit by checking if a change is visible in another connection - try { - System.out.print("1. commit..."); - con1.commit(); - System.out.println("PASSED :("); - con1.close(); - System.exit(-1); - } catch (SQLException e) { - // this means we get what we expect - System.out.println("failed :) " + e.getMessage()); - } - - // turn off auto commit - con1.setAutoCommit(false); - - // >> false: we just disabled it - System.out.println("2. false\t" + con1.getAutoCommit()); - - // a change would not be visible now - try { - System.out.print("3. commit..."); - con1.commit(); - System.out.println("passed :)"); - System.out.print("4. commit..."); - con1.commit(); - System.out.println("passed :)"); - System.out.print("5. rollback..."); - con1.rollback(); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - con1.close(); - System.exit(-1); - } - - // turn off auto commit - con1.setAutoCommit(true); - - // >> false: we just disabled it - System.out.println("6. true\t" + con1.getAutoCommit()); - - try { - System.out.print("7. start transaction..."); - stmt1.executeUpdate("START TRANSACTION"); - System.out.println("passed :)"); - System.out.print("8. commit..."); - con1.commit(); - System.out.println("passed :)"); - System.out.println("9. true\t" + con1.getAutoCommit()); - System.out.print("10. start transaction..."); - stmt1.executeUpdate("START TRANSACTION"); - System.out.println("passed :)"); - System.out.print("11. rollback..."); - con1.rollback(); - System.out.println("passed :)"); - System.out.println("12. true\t" + con1.getAutoCommit()); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :("); - System.out.println("ABORTING TEST!!!"); - } - - try { - // a commit now should fail - System.out.print("13. commit..."); - con1.commit(); - System.out.println("PASSED :("); - } catch (SQLException e) { - // this means we get what we expect - System.out.println("failed :) " + e.getMessage()); - } - - con1.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Dobjects.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Dobjects { - private static void dumpResultSet(ResultSet rs) throws SQLException { - ResultSetMetaData rsmd = rs.getMetaData(); - int columnCount = rsmd.getColumnCount(); - System.out.println("Resultset with " + columnCount + " columns"); - for (int col = 1; col <= columnCount; col++) { - System.out.print(rsmd.getColumnName(col) + "\t"); - } - System.out.println(); - while (rs.next()) { - for (int col = 1; col <= columnCount; col++) { - System.out.print(rs.getString(col) + "\t"); - } - System.out.println(); - } - rs.close(); - } - - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - DatabaseMetaData dbmd = con.getMetaData(); - try { - // inspect the catalog by use of dbmd functions - dumpResultSet(dbmd.getCatalogs()); -// dumpResultSet(dbmd.getSchemas()); // this produces different outputs on different platforms due to dependency on SAMTOOLS and NETCDF. so exclude it - dumpResultSet(dbmd.getSchemas(null, "sys")); -// dumpResultSet(dbmd.getTables(null, "sys", null, null)); // this produces different outputs on different platforms due to dependency on Geom and NETCDF. - dumpResultSet(dbmd.getTables(null, "tmp", null, null)); // schema tmp has 6 tables - dumpResultSet(dbmd.getUDTs(null, "sys", null, null)); - int[] UDTtypes = { Types.STRUCT, Types.DISTINCT }; - dumpResultSet(dbmd.getUDTs(null, "sys", null, UDTtypes)); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_FetchSize.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_FetchSize { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT * FROM _tables"); - - System.out.println("Statement fetch size before set: " + stmt.getFetchSize()); - System.out.println("ResultSet fetch size before set: " + rs.getFetchSize()); - - rs.setFetchSize(16384); - - System.out.println("Statement fetch size before set: " + stmt.getFetchSize()); - System.out.println("ResultSet fetch size before set: " + rs.getFetchSize()); - - rs.close(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Int128.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/* Test whether we can represent a full-size int128 as JDBC results */ -public class Test_Int128 { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - BigInteger bi = new BigInteger( - "123456789012345678909876543210987654321"); - BigDecimal bd = new BigDecimal( - "1234567890123456789.9876543210987654321"); - try { - con.setAutoCommit(false); - Statement s = con.createStatement(); - s.executeUpdate("CREATE TABLE HUGEINTT (I HUGEINT)"); - s.executeUpdate("CREATE TABLE HUGEDECT (I DECIMAL(38,19))"); - - PreparedStatement insertStatement = con - .prepareStatement("INSERT INTO HUGEINTT VALUES (?)"); - insertStatement.setBigDecimal(1, new BigDecimal(bi)); - insertStatement.executeUpdate(); - insertStatement.close(); - - s.executeUpdate("INSERT INTO HUGEDECT VALUES ("+bd+");"); - - ResultSet rs = s.executeQuery("SELECT I FROM HUGEINTT"); - rs.next(); - BigInteger biRes = rs.getBigDecimal(1).toBigInteger(); - rs.close(); - rs = s.executeQuery("SELECT I FROM HUGEDECT"); - rs.next(); - BigDecimal bdRes = rs.getBigDecimal(1); - rs.close(); - s.close(); - - System.out.println("Expecting " + bi + ", got " + biRes); - if (!bi.equals(biRes)) { - throw new RuntimeException(); - } - - System.out.println("Expecting " + bd + ", got " + bdRes); - if (!bd.equals(bdRes)) { - throw new RuntimeException(); - } - System.out.println("SUCCESS"); - - } catch (SQLException e) { - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PSgeneratedkeys.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PSgeneratedkeys { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - con.setAutoCommit(false); - // >> false: auto commit was just switched off - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - Statement stmt = con.createStatement(); - stmt.executeUpdate( - "CREATE TABLE psgenkey (" + - " id serial," + - " val varchar(20)" + - ")"); - stmt.close(); - } catch (SQLException e) { - System.out.println(e); - System.out.println("Creation of test table failed! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - try { - PreparedStatement pstmt = con.prepareStatement( - "INSERT INTO psgenkey (val) VALUES ('this is a test')", - Statement.RETURN_GENERATED_KEYS); - - System.out.print("1. inserting a record..."); - pstmt.executeUpdate(); - System.out.println("success :)"); - - // now get the generated keys - System.out.print("2. getting generated keys..."); - ResultSet keys = pstmt.getGeneratedKeys(); - if (keys == null || !keys.next()) { - System.out.println("there are no keys! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - System.out.println("generated key index: " + keys.getInt(1)); - while (keys.next()) { - System.out.println("generated key index: " + keys.getInt(1)); - } - - if (keys.getStatement() == null) { - System.out.println("ResultSet.getStatement() should never return null!"); - } - - keys.close(); - pstmt.close(); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PSgetObject.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PSgetObject { - public static void main(String[] args) throws Exception { - final Connection con = DriverManager.getConnection(args[0]); - con.setAutoCommit(false); - // >> false: auto commit was just switched off - System.out.println("0. false\t" + con.getAutoCommit()); - - final Statement stmt = con.createStatement(); - try { - System.out.print("1. creating test table..."); - stmt.executeUpdate("CREATE TABLE table_Test_PSgetObject (ti tinyint, si smallint, i int, bi bigint)"); - stmt.close(); - System.out.println(" passed :)"); - } catch (SQLException e) { - System.out.println(e); - System.out.println("Creation of test table failed! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - PreparedStatement pstmt; - try { - System.out.print("2a. inserting 3 records as batch..."); - pstmt = con.prepareStatement("INSERT INTO table_Test_PSgetObject (ti,si,i,bi) VALUES (?,?,?,?)"); - pstmt.setShort(1, (short)1); - pstmt.setShort(2, (short)1); - pstmt.setInt (3, 1); - pstmt.setLong(4, (long)1); - pstmt.addBatch(); - - pstmt.setShort(1, (short)127); - pstmt.setShort(2, (short)12700); - pstmt.setInt (3, 1270000); - pstmt.setLong(4, (long)127000000); - pstmt.addBatch(); - - pstmt.setShort(1, (short)-127); - pstmt.setShort(2, (short)-12700); - pstmt.setInt (3, -1270000); - pstmt.setLong(4, (long)-127000000); - pstmt.addBatch(); - - pstmt.executeBatch(); - System.out.println(" passed :)"); - - System.out.print("2b. closing PreparedStatement..."); - pstmt.close(); - System.out.println(" passed :)"); - } catch (SQLException e) { - System.out.println("FAILED to INSERT data:( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - try { - System.out.print("3a. selecting records..."); - pstmt = con.prepareStatement("SELECT ti,si,i,bi FROM table_Test_PSgetObject ORDER BY ti,si,i,bi"); - ResultSet rs = pstmt.executeQuery(); - System.out.println(" passed :)"); - - while (rs.next()) { - // test fix for https://www.monetdb.org/bugzilla/show_bug.cgi?id=4026 - Short ti = (Short) rs.getObject(1); - Short si = (Short) rs.getObject(2); - Integer i = (Integer) rs.getObject(3); - Long bi = (Long) rs.getObject(4); - - System.out.println(" Retrieved row data: ti=" + ti + " si=" + si + " i=" + i + " bi=" + bi); - } - - System.out.print("3b. closing ResultSet..."); - rs.close(); - System.out.println(" passed :)"); - - System.out.print("3c. closing PreparedStatement..."); - pstmt.close(); - System.out.println(" passed :)"); - } catch (SQLException e) { - System.out.println("FAILED to RETRIEVE data:( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - System.out.print("4. Rollback changes..."); - con.rollback(); - System.out.println(" passed :)"); - - System.out.print("5. Close connection..."); - con.close(); - System.out.println(" passed :)"); - } -}
deleted file mode 100644 --- a/tests/Test_PSlargebatchval.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import java.io.StringReader; -import java.nio.charset.Charset; - -public class Test_PSlargebatchval { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - - // >> true: auto commit should be on - System.out.println("0. true\t" + con.getAutoCommit()); - - byte[] errorBytes = new byte[] { (byte) 0xe2, (byte) 0x80, (byte) 0xa7 }; - String errorStr = new String(errorBytes, Charset.forName("UTF-8")); - StringBuilder repeatedErrorStr = new StringBuilder(); - for (int i = 0; i < 8170;i++) { - repeatedErrorStr.append(errorStr); - } - String largeStr = repeatedErrorStr.toString(); - - try { - stmt.execute("CREATE TABLE x (c INT, a CLOB, b DOUBLE)"); - pstmt = con.prepareStatement("INSERT INTO x VALUES (?,?,?)"); - - pstmt.setLong(1, 1L); - pstmt.setString(2, largeStr); - pstmt.setDouble(3, 1.0); - pstmt.addBatch(); - pstmt.executeBatch(); - System.out.println("1. inserted 1 large string"); - - /* test issue reported at https://www.monetdb.org/bugzilla/show_bug.cgi?id=3470 */ - pstmt.setLong(1, -2L); - pstmt.setClob(2, new StringReader(largeStr)); - pstmt.setDouble(3, -2.0); - pstmt.addBatch(); - pstmt.executeBatch(); - System.out.println("2. inserted 1 large clob via StringReader() object"); - - Clob myClob = con.createClob(); - myClob.setString(1L, largeStr); - - pstmt.setLong(1, 123456789L); - pstmt.setClob(2, myClob); - pstmt.setDouble(3, 12345678901.98765); - pstmt.addBatch(); - pstmt.executeBatch(); - System.out.println("3. inserted 1 large clob via createClob() object"); - - pstmt.close(); - - ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM x"); - if (rs.next()) - System.out.println(rs.getInt(1) + " rows inserted."); - rs.close(); - - stmt.execute("DROP TABLE x"); - stmt.close(); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PSlargeresponse.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PSlargeresponse { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - // retrieve this to simulate a bug report - DatabaseMetaData dbmd = con.getMetaData(); - - // >> true: auto commit should be on - System.out.println("0. true\t" + con.getAutoCommit()); - - try { - System.out.print("1. DatabaseMetadata environment retrieval... "); - if (args[0].startsWith(dbmd.getURL())) - System.out.println("oke"); - else - System.out.println("not oke " + dbmd.getURL()); - - pstmt = con.prepareStatement("select * from columns"); - System.out.print("2. empty call..."); - try { - // should succeed (no arguments given) - pstmt.execute(); - System.out.println(" passed :)"); - } catch (SQLException e) { - System.out.println(" FAILED :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PSmanycon.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import java.util.*; - -public class Test_PSmanycon { - public static void main(String[] args) throws Exception { - List<PreparedStatement> pss = new ArrayList<PreparedStatement>(100); // PreparedStatements go in here - - try { - // spawn a lot of Connections with 1 PreparedStatement, just for fun... - int i; - for (i = 0; i < 50; i++) { - System.out.print("Establishing Connection " + i + "..."); - Connection con = DriverManager.getConnection(args[0]); - System.out.print(" done..."); - - // do something with the connection to test if it works - PreparedStatement pstmt = con.prepareStatement("select " + i); - System.out.println(" alive"); - - pss.add(pstmt); - } - - // now try to nicely execute them - i = 0; - for (Iterator<PreparedStatement> it = pss.iterator(); it.hasNext(); i++) { - PreparedStatement pstmt = it.next(); - - // see if the connection still works - System.out.print("Executing PreparedStatement " + i + "..."); - if (!pstmt.execute()) - throw new Exception("should have seen a ResultSet!"); - - ResultSet rs = pstmt.getResultSet(); - if (!rs.next()) - throw new Exception("ResultSet is empty"); - System.out.print(" result: " + rs.getString(1)); - - // close the connection and associated resources - pstmt.getConnection().close(); - System.out.println(", done"); - - if ((i + 1) % 23 == 0) { - // inject a failed transaction - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - try { - int affrows = stmt.executeUpdate("update foo where bar is wrong"); - System.out.println("oops, faulty statement just got through :("); - } catch (SQLException e) { - System.out.println("Forced transaction failure"); - } - } - } - } catch (SQLException e) { - System.out.println("FAILED! " + e.getMessage()); - } - } -}
deleted file mode 100644 --- a/tests/Test_PSmetadata.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PSmetadata { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0] + "&treat_clob_as_varchar=false"); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - ResultSet rs = null; - ResultSetMetaData rsmd = null; - ParameterMetaData pmd = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_PSmetadata ( myint int, mydouble double, mybool boolean, myvarchar varchar(15), myclob clob )"); - - // all NULLs - stmt.executeUpdate("INSERT INTO table_Test_PSmetadata VALUES (NULL, NULL, NULL, NULL, NULL)"); - // all filled in - stmt.executeUpdate("INSERT INTO table_Test_PSmetadata VALUES (2 , 3.0, true, 'A string', 'bla bla bla')"); - - pstmt = con.prepareStatement("SELECT CASE WHEN myint IS NULL THEN 0 ELSE 1 END AS intnull, * FROM table_Test_PSmetadata WHERE myint = ?"); - - rsmd = pstmt.getMetaData(); - - System.out.println("0. 6 columns:\t" + rsmd.getColumnCount()); - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.println("" + col + ".\t" + rsmd.getCatalogName(col)); - System.out.println("\tclassname " + rsmd.getColumnClassName(col)); - System.out.println("\tdisplaysize " + rsmd.getColumnDisplaySize(col)); - System.out.println("\tlabel " + rsmd.getColumnLabel(col)); - System.out.println("\tname " + rsmd.getColumnName(col)); - System.out.println("\ttype " + rsmd.getColumnType(col)); - System.out.println("\ttypename " + rsmd.getColumnTypeName(col)); - System.out.println("\tprecision " + rsmd.getPrecision(col)); - System.out.println("\tscale " + rsmd.getScale(col)); - System.out.println("\tschemaname " + rsmd.getSchemaName(col)); - System.out.println("\ttablename " + rsmd.getTableName(col)); - System.out.println("\tautoincrement " + rsmd.isAutoIncrement(col)); - System.out.println("\tcasesensitive " + rsmd.isCaseSensitive(col)); - System.out.println("\tcurrency " + rsmd.isCurrency(col)); - System.out.println("\tdefwritable " + rsmd.isDefinitelyWritable(col)); - System.out.println("\tnullable " + rsmd.isNullable(col)); - System.out.println("\treadonly " + rsmd.isReadOnly(col)); - System.out.println("\tsearchable " + rsmd.isSearchable(col)); - System.out.println("\tsigned " + rsmd.isSigned(col)); - System.out.println("\twritable " + rsmd.isWritable(col)); - } - - showParams(pstmt); - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } - - // some utility methods for showing table content and params meta data - static void showParams(PreparedStatement stmt) { - try { - ParameterMetaData pmd = stmt.getParameterMetaData(); - System.out.println(pmd.getParameterCount() + " parameters reported:"); - for (int parm = 1; parm <= pmd.getParameterCount(); parm++) { - System.out.print(parm + "."); - int nullable = pmd.isNullable(parm); - System.out.println("\tnullable " + nullable + " (" + paramNullableName(nullable) + ")"); - System.out.println("\tsigned " + pmd.isSigned(parm)); - System.out.println("\tprecision " + pmd.getPrecision(parm)); - System.out.println("\tscale " + pmd.getScale(parm)); - System.out.println("\ttype " + pmd.getParameterType(parm)); - System.out.println("\ttypename " + pmd.getParameterTypeName(parm)); - System.out.println("\tclassname " + pmd.getParameterClassName(parm)); - int mode = pmd.getParameterMode(parm); - System.out.println("\tmode " + mode + " (" + paramModeName(mode) + ")"); - } - } catch (SQLException e) { - System.out.println("showParams failed: " + e.getMessage()); - } - } - - static String paramNullableName(int nullable) { - if (nullable == ParameterMetaData.parameterNoNulls) - return "NO"; - if (nullable == ParameterMetaData.parameterNullable) - return "YA"; - if (nullable == ParameterMetaData.parameterNullableUnknown) - return "UNKNOWN"; - return "INVALID" + nullable; - } - - static String paramModeName(int mode) { - if (mode == ParameterMetaData.parameterModeIn) - return "IN"; - if (mode == ParameterMetaData.parameterModeInOut) - return "INOUT"; - if (mode == ParameterMetaData.parameterModeOut) - return "OUT"; - if (mode == ParameterMetaData.parameterModeUnknown) - return "UNKNOWN"; - return "INVALID" + mode; - } -}
deleted file mode 100644 --- a/tests/Test_PSsomeamount.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -/* Create a lot of PreparedStatements, to emulate webloads such as those - * from Hibernate. */ - -public class Test_PSsomeamount { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - - // >> true: auto commit should be on - System.out.println("0. true\t" + con.getAutoCommit()); - - try { - System.out.println("1. Preparing and executing a unique statement"); - for (int i = 0; i < 100; i++) { - pstmt = con.prepareStatement("select " + i + ", " + i + " = ?"); - pstmt.setInt(1, i); - ResultSet rs = pstmt.executeQuery(); - if (rs.next() && i % 20 == 0) { - System.out.println(rs.getInt(1) + ", " + rs.getBoolean(2)); - } - /* this call should cause resources on the server to be - * freed */ - pstmt.close(); - } - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - stmt.close(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PSsqldata.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import org.monetdb.jdbc.types.INET; -import org.monetdb.jdbc.types.URL; - -public class Test_PSsqldata { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - ResultSet rs = null; - ResultSetMetaData rsmd = null; - ParameterMetaData pmd = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_PSsqldata ( myinet inet, myurl url )"); - - pstmt = con.prepareStatement("INSERT INTO table_Test_PSsqldata VALUES (?, ?)"); - - pmd = pstmt.getParameterMetaData(); - System.out.println("1. 2 parameters:\t" + pmd.getParameterCount()); - for (int col = 1; col <= pmd.getParameterCount(); col++) { - System.out.println("" + col + "."); - System.out.println("\ttype " + pmd.getParameterType(col)); - System.out.println("\ttypename " + pmd.getParameterTypeName(col)); - System.out.println("\tclassname " + pmd.getParameterClassName(col)); - } - - INET tinet = new INET(); - URL turl = new URL(); - - tinet.fromString("172.5.5.5/24"); - turl.fromString("http://www.monetdb.org/"); - pstmt.setObject(1, tinet); - pstmt.setObject(2, turl); - pstmt.execute(); - - tinet.setNetmaskBits(16); - pstmt.execute(); - - rs = stmt.executeQuery("SELECT * FROM table_Test_PSsqldata"); - rsmd = rs.getMetaData(); - - for (int i = 1; rs.next(); i++) { - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - Object x = rs.getObject(col); - if (x == null) { - System.out.println("" + i + ".\t<null>"); - } else { - System.out.println("" + i + ".\t" + x.toString()); - if (x instanceof INET) { - INET inet = (INET)x; - System.out.println("\t" + inet.getAddress() + "/" + inet.getNetmaskBits()); - System.out.println("\t" + inet.getInetAddress().toString()); - } else if (x instanceof URL) { - URL url = (URL)x; - System.out.println("\t" + url.getURL().toString()); - } - } - } - } - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PStimedate.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PStimedate { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - ResultSet rs = null; - - con.setAutoCommit(false); - // >> false: auto commit was just switched off - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_PStimedate (t time, ts timestamp, d date)"); - stmt.close(); - } catch (SQLException e) { - System.out.println(e); - System.out.println("Creation of test table failed! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - try { - pstmt = con.prepareStatement("INSERT INTO table_Test_PStimedate VALUES (?, ?, ?)"); - System.out.print("1. empty call..."); - try { - // should fail (no arguments given) - pstmt.execute(); - System.out.println(" PASSED :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } catch (SQLException e) { - System.out.println(" failed :)"); - } - - System.out.print("2. inserting a record..."); - java.util.Date d = new java.util.Date(); - pstmt.setTime(1, new java.sql.Time(d.getTime())); - pstmt.setTimestamp(2, new java.sql.Timestamp(d.getTime())); - pstmt.setDate(3, new java.sql.Date(d.getTime())); - - pstmt.executeUpdate(); - System.out.println(" passed :)"); - System.out.print("3. closing PreparedStatement..."); - pstmt.close(); - System.out.println(" passed :)"); - - System.out.print("4. selecting record..."); - pstmt = con.prepareStatement("SELECT * FROM table_Test_PStimedate"); - rs = pstmt.executeQuery(); - System.out.println(" passed :)"); - - while (rs.next()) { - for (int j = 1; j <= 3; j++) { - System.out.print((j + 4) + ". retrieving..."); - java.util.Date x = (java.util.Date)(rs.getObject(j)); - boolean matches = false; - if (x instanceof Time) { - System.out.print(" (Time)"); - matches = (new Time(d.getTime())).toString().equals(x.toString()); - } else if (x instanceof Date) { - System.out.print(" (Date)"); - matches = (new Date(d.getTime())).toString().equals(x.toString()); - } else if (x instanceof Timestamp) { - System.out.print(" (Timestamp)"); - matches = (new Timestamp(d.getTime())).toString().equals(x.toString()); - } - if (matches) { - System.out.println(" passed :)"); - } else { - System.out.println(" FAILED :( (" + x + " is not " + d + ")"); - } - } - } - - con.rollback(); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PStimezone.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import java.util.*; -import java.text.*; - -public class Test_PStimezone { - public static void main(String[] args) throws Exception { - // make sure this test is reproducable regardless timezone - // setting, by overriding the VM's default - // we have to make sure that one doesn't have daylight - // savings corrections - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - ResultSet rs = null; - - con.setAutoCommit(false); - // >> false: auto commit was just switched off - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_PStimezone (ts timestamp, tsz timestamp with time zone, t time, tz time with time zone)"); - stmt.close(); - } catch (SQLException e) { - System.out.println(e); - System.out.println("Creation of test table failed! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - try { - pstmt = con.prepareStatement("INSERT INTO table_Test_PStimezone VALUES (?, ?, ?, ?)"); - System.out.print("1. empty call..."); - try { - // should fail (no arguments given) - pstmt.execute(); - System.out.println(" PASSED :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } catch (SQLException e) { - System.out.println(" failed :)"); - } - - System.out.println("2. inserting records..."); - - SimpleDateFormat tsz = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); - SimpleDateFormat tz = - new SimpleDateFormat("HH:mm:ss.SSSZ"); - - java.sql.Timestamp ts = new java.sql.Timestamp(0L); - java.sql.Time t = new java.sql.Time(0L); - - Calendar c = Calendar.getInstance(); - tsz.setTimeZone(c.getTimeZone()); - tz.setTimeZone(tsz.getTimeZone()); - System.out.println("inserting (" + c.getTimeZone().getID() + ") " + tsz.format(ts) + ", " + tz.format(t)); - - pstmt.setTimestamp(1, ts); - pstmt.setTimestamp(2, ts); - pstmt.setTime(3, t); - pstmt.setTime(4, t); - pstmt.executeUpdate(); - - c.setTimeZone(TimeZone.getTimeZone("UTC")); - - System.out.println("inserting with calendar timezone " + c.getTimeZone().getID()); - pstmt.setTimestamp(1, ts, c); - pstmt.setTimestamp(2, ts, c); - pstmt.setTime(3, t, c); - pstmt.setTime(4, t, c); - pstmt.executeUpdate(); - - c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); - System.out.println("inserting with calendar timezone " + c.getTimeZone().getID()); - pstmt.setTimestamp(1, ts, c); - pstmt.setTimestamp(2, ts); - pstmt.setTime(3, t, c); - pstmt.setTime(4, t); - pstmt.executeUpdate(); - - c.setTimeZone(TimeZone.getTimeZone("GMT+04:15")); - System.out.println("inserting with calendar timezone " + c.getTimeZone().getID()); - pstmt.setTimestamp(1, ts); - pstmt.setTimestamp(2, ts, c); - pstmt.setTime(3, t); - pstmt.setTime(4, t, c); - pstmt.executeUpdate(); - - System.out.println("done"); - System.out.print("3. closing PreparedStatement..."); - pstmt.close(); - System.out.println(" passed :)"); - - System.out.print("4. selecting records..."); - pstmt = con.prepareStatement("SELECT * FROM table_Test_PStimezone"); - rs = pstmt.executeQuery(); - System.out.println(" passed :)"); - - // The tz fields should basically always be the same - // (exactly 1st Jan 1970) since whatever timezone is used, - // the server retains it, and Java restores it. - // The zoneless fields will show differences since the time - // is inserted translated to the given timezones, and - // retrieved as in they were given in those timezones. When - // the insert zone matches the retrieve zone, Java should - // eventually see 1st Jan 1970. - while (rs.next()) { - System.out.println("retrieved row (String):\n\t" + - rs.getString("ts") + " \t" + - rs.getString("tsz") + "\t" + - rs.getString("t") + " \t" + - rs.getString("tz")); - - tsz.setTimeZone(TimeZone.getDefault()); - tz.setTimeZone(tsz.getTimeZone()); - System.out.println("default (" + tsz.getTimeZone().getID() + "):\n\t" + - tsz.format(rs.getTimestamp("ts")) + "\t" + - tsz.format(rs.getTimestamp("tsz")) + " \t" + - tz.format(rs.getTime("t")) + "\t" + - tz.format(rs.getTime("tz"))); - - c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); - System.out.println(c.getTimeZone().getID() + ":\n\t" + - rs.getTimestamp("ts", c) + " \t" + - rs.getTimestamp("tsz", c) + " \t" + - rs.getTime("t", c) + " \t" + - rs.getTime("tz", c) + " "); - - c.setTimeZone(TimeZone.getTimeZone("Africa/Windhoek")); - System.out.println(c.getTimeZone().getID() + ":\n\t" + - rs.getTimestamp("ts", c) + " \t" + - rs.getTimestamp("tsz", c) + " \t" + - rs.getTime("t", c) + " \t" + - rs.getTime("tz", c) + " "); - - System.out.println(); - SQLWarning w = rs.getWarnings(); - while (w != null) { - System.out.println(w.getMessage()); - w = w.getNextWarning(); - } - } - - con.rollback(); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_PStypes.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_PStypes { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - PreparedStatement pstmt; - - con.setAutoCommit(false); - // >> false: auto commit was just switched off - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate( -"CREATE TABLE htmtest (" + -" htmid bigint NOT NULL," + -" ra double ," + -" decl double ," + -" dra double ," + -" ddecl double ," + -" flux double ," + -" dflux double ," + -" freq double ," + -" bw double ," + -" type decimal(1,0)," + -" imageurl varchar(100)," + -" comment varchar(100)," + -" CONSTRAINT htmtest_htmid_pkey PRIMARY KEY (htmid)" + -")" -); - // index is not used, but the original bug had it too - stmt.executeUpdate("CREATE INDEX htmid ON htmtest (htmid)"); - stmt.close(); - } catch (SQLException e) { - System.out.println(e); - System.out.println("Creation of test table failed! :("); - System.out.println("ABORTING TEST!!!"); - System.exit(-1); - } - - try { - pstmt = con.prepareStatement( -"INSERT INTO HTMTEST (HTMID,RA,DECL,FLUX,COMMENT) VALUES (?,?,?,?,?)" -); - System.out.print("1. inserting a record..."); - - pstmt.setLong(1, 1L); - pstmt.setFloat(2, (float)1.2); - pstmt.setDouble(3, 2.4); - pstmt.setDouble(4, 3.2); - pstmt.setString(5, "vlavbla"); - pstmt.executeUpdate(); - - System.out.println("success :)"); - - // try an update like bug #1757923 - pstmt = con.prepareStatement( -"UPDATE HTMTEST set COMMENT=?, TYPE=? WHERE HTMID=?" -); - System.out.print("2. updating record..."); - - pstmt.setString(1, "some update"); - pstmt.setObject(2, (float)3.2); - pstmt.setLong(3, 1L); - pstmt.executeUpdate(); - - System.out.println("success :)"); - } catch (SQLException e) { - System.out.println("FAILED :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Rbooleans.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Rbooleans { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_Rbooleans ( id int, tiny_int tinyint, small_int smallint, medium_int mediumint, \"integer\" int, big_int bigint, a_real real, a_float float, a_double double, a_decimal decimal(8,2), a_numeric numeric(8), bool boolean, a_char char(4), b_char char(5), a_varchar varchar(20), PRIMARY KEY (id) )"); - - // all falses - stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (1, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, false, 'fals', 'false', 'false')"); - // all trues - stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (2, 1, 1, 1, 1, 1, 1.0, 1.0, 1.0, 1.0, 1, true, 'true', 'true ', 'true')"); - // sneakier - stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (3, 2, 3, 4, 5, 6, 7.1, 8.2, 9.3, 10.4, 11, true, 'TrUe', 'fAlSe', 'true/false')"); - stmt.executeUpdate("INSERT INTO table_Test_Rbooleans VALUES (4, 2, 3, 4, 5, 6, 7.1, 8.2, 9.3, 10.4, 11, true, 't ', 'f ', 'TRUE ')"); - - rs = stmt.executeQuery("SELECT * FROM table_Test_Rbooleans ORDER BY id ASC"); - - // all should give false - rs.next(); - System.out.println("1. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar")); - // all should give true except the one before last - rs.next(); - System.out.println("2. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar")); - // should give true for all but the last two - rs.next(); - System.out.println("3. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar")); - // should give true for all but the last three - rs.next(); - System.out.println("4. " + rs.getInt("id") + ", " + rs.getBoolean("tiny_int") + ", " + rs.getBoolean("small_int") + ", " + rs.getBoolean("medium_int") + ", " + rs.getBoolean("integer") + ", " + rs.getBoolean("big_int") + ", " + rs.getBoolean("a_real") + ", " + rs.getBoolean("a_double") + ", " + rs.getBoolean("a_decimal") + ", " + rs.getBoolean("a_numeric") + ", " + rs.getBoolean("bool") + ", " + rs.getBoolean("a_char") + ", " + rs.getBoolean("b_char") + ", " + rs.getBoolean("a_varchar")); - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Rmetadata.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Rmetadata { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0] + "&treat_clob_as_varchar=false"); - Statement stmt = con.createStatement(); - ResultSet rs = null; - ResultSetMetaData rsmd = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_Rmetadata ( myint int, mydouble double, mybool boolean, myvarchar varchar(15), myclob clob )"); - - // all NULLs - stmt.executeUpdate("INSERT INTO table_Test_Rmetadata VALUES (NULL, NULL, NULL, NULL, NULL)"); - // all filled in - stmt.executeUpdate("INSERT INTO table_Test_Rmetadata VALUES (2 , 3.0, true, 'A string', 'bla bla bla')"); - - rs = stmt.executeQuery("SELECT * FROM table_Test_Rmetadata"); - rsmd = rs.getMetaData(); - - System.out.println("0. 4 columns:\t" + rsmd.getColumnCount()); - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.println("Colnr " + col + "."); - System.out.println("\tclassname " + rsmd.getColumnClassName(col)); - System.out.println("\tdisplaysize " + rsmd.getColumnDisplaySize(col)); - System.out.println("\tlabel " + rsmd.getColumnLabel(col)); - System.out.println("\tname " + rsmd.getColumnName(col)); - System.out.println("\ttype " + rsmd.getColumnType(col)); - System.out.println("\ttypename " + rsmd.getColumnTypeName(col)); - System.out.println("\tprecision " + rsmd.getPrecision(col)); - System.out.println("\tscale " + rsmd.getScale(col)); - System.out.println("\tcatalogname " + rsmd.getCatalogName(col)); - System.out.println("\tschemaname " + rsmd.getSchemaName(col)); - System.out.println("\ttablename " + rsmd.getTableName(col)); - System.out.println("\tautoincrement " + rsmd.isAutoIncrement(col)); - System.out.println("\tcasesensitive " + rsmd.isCaseSensitive(col)); - System.out.println("\tcurrency " + rsmd.isCurrency(col)); - System.out.println("\tdefwritable " + rsmd.isDefinitelyWritable(col)); - System.out.println("\tnullable " + rsmd.isNullable(col)); - System.out.println("\treadonly " + rsmd.isReadOnly(col)); - System.out.println("\tsearchable " + rsmd.isSearchable(col)); - System.out.println("\tsigned " + rsmd.isSigned(col)); - System.out.println("\twritable " + rsmd.isWritable(col)); - } - - for (int i = 5; rs.next(); i++) { - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.println("" + i + ".\t" + - isInstance(rs.getObject(col), rsmd.getColumnClassName(col)) - ); - } - } - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } - - private static String isInstance(Object obj, String type) { - if (obj == null || type == null) - return("(null)"); - try { - Class<?> c = Class.forName(type); - if (c.isInstance(obj)) { - return(obj.getClass().getName() + " is an instance of " + type); - } else { - return(obj.getClass().getName() + " is NOT an instance of " + type); - } - } catch (ClassNotFoundException e) { - return("No such class: " + type); - } - } -}
deleted file mode 100644 --- a/tests/Test_Rpositioning.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Rpositioning { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - DatabaseMetaData dbmd = con.getMetaData(); - - // get a one rowed resultset - ResultSet rs = stmt.executeQuery("SELECT 1"); - - // >> true: we should be before the first result now - System.out.println("1. true\t" + rs.isBeforeFirst()); - // >> false: we're not at the first result - System.out.println("2. false\t" + rs.isFirst()); - // >> true: there is one result, so we can call next once - System.out.println("3. true\t" + rs.next()); - // >> false: we're not before the first row anymore - System.out.println("4. false\t" + rs.isBeforeFirst()); - // >> true: we're at the first result - System.out.println("5. true\t" + rs.isFirst()); - // >> false: we're on the last row - System.out.println("6. false\t" + rs.isAfterLast()); - // >> true: see above - System.out.println("7. true\t" + rs.isLast()); - // >> false: there is one result, so this is it - System.out.println("8. false\t" + rs.next()); - // >> true: yes, we're at the end - System.out.println("9. true\t" + rs.isAfterLast()); - // >> false: no we're one over it - System.out.println("10. false\t" + rs.isLast()); - // >> false: another try to move on should still fail - System.out.println("11. false\t" + rs.next()); - // >> true: and we should stay positioned after the last - System.out.println("12.true\t" + rs.isAfterLast()); - - rs.close(); - - // try the same with a 'virtual' result set - rs = dbmd.getTableTypes(); - - // >> true: we should be before the first result now - System.out.println("1. true\t" + rs.isBeforeFirst()); - // >> false: we're not at the first result - System.out.println("2. false\t" + rs.isFirst()); - // >> true: there is one result, so we can call next once - System.out.println("3. true\t" + rs.next()); - // >> false: we're not before the first row anymore - System.out.println("4. false\t" + rs.isBeforeFirst()); - // >> true: we're at the first result - System.out.println("5. true\t" + rs.isFirst()); - // move to last row - rs.last(); - // >> false: we're on the last row - System.out.println("6. false\t" + rs.isAfterLast()); - // >> true: see above - System.out.println("7. true\t" + rs.isLast()); - // >> false: there is one result, so this is it - System.out.println("8. false\t" + rs.next()); - // >> true: yes, we're at the end - System.out.println("9. true\t" + rs.isAfterLast()); - // >> false: no we're one over it - System.out.println("10. false\t" + rs.isLast()); - // >> false: another try to move on should still fail - System.out.println("11. false\t" + rs.next()); - // >> true: and we should stay positioned after the last - System.out.println("12. true\t" + rs.isAfterLast()); - - rs.close(); - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Rsqldata.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; -import org.monetdb.jdbc.types.INET; -import org.monetdb.jdbc.types.URL; - -public class Test_Rsqldata { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - ResultSetMetaData rsmd = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("0. false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_Rsqldata ( myinet inet, myurl url )"); - - // all NULLs - stmt.executeUpdate("INSERT INTO table_Test_Rsqldata VALUES (NULL, NULL)"); - // all filled in - stmt.executeUpdate("INSERT INTO table_Test_Rsqldata VALUES ('172.5.5.5' , 'http://www.monetdb.org/')"); - stmt.executeUpdate("INSERT INTO table_Test_Rsqldata VALUES ('172.5.5.5/32' , 'http://www.monetdb.org/Home')"); - stmt.executeUpdate("INSERT INTO table_Test_Rsqldata VALUES ('172.5.5.5/16' , 'http://www.monetdb.org/Home#someanchor')"); - stmt.executeUpdate("INSERT INTO table_Test_Rsqldata VALUES ('172.5.5.5/26' , 'http://www.monetdb.org/?query=bla')"); - - rs = stmt.executeQuery("SELECT * FROM table_Test_Rsqldata"); - rsmd = rs.getMetaData(); - - System.out.println("0. 4 columns:\t" + rsmd.getColumnCount()); - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - System.out.println("" + col + ".\t" + rsmd.getCatalogName(col)); - System.out.println("\tclassname " + rsmd.getColumnClassName(col)); - System.out.println("\tschemaname " + rsmd.getSchemaName(col)); - System.out.println("\ttablename " + rsmd.getTableName(col)); - System.out.println("\tname " + rsmd.getColumnName(col)); - } - - for (int i = 1; rs.next(); i++) { - for (int col = 1; col <= rsmd.getColumnCount(); col++) { - Object x = rs.getObject(col); - if (x == null) { - System.out.println("" + i + ".\t<null>"); - } else { - System.out.println("" + i + ".\t" + x.toString()); - if (x instanceof INET) { - INET inet = (INET)x; - System.out.println("\t" + inet.getAddress() + "/" + inet.getNetmaskBits()); - System.out.println("\t" + inet.getInetAddress().toString()); - } else if (x instanceof URL) { - URL url = (URL)x; - System.out.println("\t" + url.getURL().toString()); - } - } - } - } - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Rtimedate.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Rtimedate { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - - con.setAutoCommit(false); - // >> false: auto commit should be off now - System.out.println("false\t" + con.getAutoCommit()); - - try { - stmt.executeUpdate("CREATE TABLE table_Test_Rtimedate ( id int PRIMARY KEY, ts timestamp, t time, d date, vc varchar(30) )"); - - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (1, timestamp '2004-04-24 11:43:53.123')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, t) VALUES (2, time '11:43:53.123')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (3, date '2004-04-24')"); - // same values but now as strings to test string to timestamp / time / date object conversions - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (4, '2004-04-24 11:43:53.654321')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (5, '11:43:53')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (6, '2004-04-24')"); - - // test also with small years (< 1000) (see bug 6468) - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (11, timestamp '904-04-24 11:43:53.567')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (12, timestamp '74-04-24 11:43:53.567')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (13, timestamp '4-04-24 11:43:53.567')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (14, date '904-04-24')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (15, date '74-04-24')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (16, date '4-04-24')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (17, '904-04-24 11:43:53.567')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (18, '74-04-24 11:43:53.567')"); - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (19, '4-04-24 11:43:53.567')"); - - // test also with negative years (see bug 6468) - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (21, timestamp '-4-04-24 11:43:53.567')"); // negative year - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, ts) VALUES (22, timestamp '-2004-04-24 11:43:53.567')"); // negative year - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (23, date '-4-04-24')"); // negative year - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, d) VALUES (24, date '-3004-04-24')"); // negative year - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (25, '-2004-04-24 11:43:53.654321')"); // negative year - stmt.executeUpdate("INSERT INTO table_Test_Rtimedate(id, vc) VALUES (26, '-3004-04-24')"); // negative year - - rs = stmt.executeQuery("SELECT * FROM table_Test_Rtimedate"); - - readNextRow(rs, 1, "ts"); - readNextRow(rs, 2, "t"); - readNextRow(rs, 3, "d"); - - readNextRow(rs, 4, "vc"); - readNextRow(rs, 5, "vc"); - readNextRow(rs, 6, "vc"); - - readNextRow(rs, 11, "ts"); - readNextRow(rs, 12, "ts"); - readNextRow(rs, 13, "ts"); - readNextRow(rs, 14, "d"); - readNextRow(rs, 15, "d"); - readNextRow(rs, 16, "d"); - readNextRow(rs, 17, "vc"); - readNextRow(rs, 18, "vc"); - readNextRow(rs, 19, "vc"); - - readNextRow(rs, 21, "ts"); - readNextRow(rs, 22, "ts"); - readNextRow(rs, 23, "d"); - readNextRow(rs, 24, "d"); - readNextRow(rs, 25, "vc"); - readNextRow(rs, 26, "vc"); - - readWarnings(stmt.getWarnings()); - readWarnings(con.getWarnings()); - } catch (SQLException e) { - System.out.println("failed :( "+ e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - con.rollback(); - con.close(); - } - - private static void readNextRow(ResultSet rs, int rowseq, String colnm) throws SQLException { - rs.next(); - readWarnings(rs.getWarnings()); - rs.clearWarnings(); - - // fetch the column value using multiple methods: getString(), getTimestamp(), getTime() and getDate() - // to test proper conversion and error reporting - String data = rs.getString("id") + ". " + colnm + " " + rs.getString(colnm) + " to "; - - // getTimestamp() may raise a conversion warning when the value is of type Time or a String which doesn't match format yyyy-mm-dd hh:mm:ss - try { - System.out.println(data + "ts: " + rs.getTimestamp(colnm)); - } catch (SQLException e) { - System.out.println("rs.getTimestamp(colnm) failed with error: " + e.getMessage()); - } - readWarnings(rs.getWarnings()); - rs.clearWarnings(); - - // getTime() may raise a conversion warning when the value is of type Date or a String which doesn't match format hh:mm:ss - try { - System.out.println(data + "tm: " + rs.getTime(colnm)); - } catch (SQLException e) { - System.out.println("rs.getTime(colnm) failed with error: " + e.getMessage()); - } - readWarnings(rs.getWarnings()); - rs.clearWarnings(); - - // getDate() may raise a conversion warning when the value is of type Time or a String which doesn't match format yyyy-mm-dd - try { - System.out.println(data + "dt: " + rs.getDate(colnm)); - } catch (SQLException e) { - System.out.println("rs.getDate(colnm) failed with error: " + e.getMessage()); - } - readWarnings(rs.getWarnings()); - rs.clearWarnings(); - } - - private static void readWarnings(SQLWarning w) { - while (w != null) { - System.out.println("Warning: " + w.toString()); - w = w.getNextWarning(); - } - } -}
deleted file mode 100644 --- a/tests/Test_Sbatching.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Sbatching { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con.getAutoCommit()); - - try { - System.out.print("1. create..."); - if (stmt.executeUpdate("CREATE TABLE table_Test_Sbatching ( id int )") != Statement.SUCCESS_NO_INFO) - throw new SQLException("Wrong return status"); - System.out.println("passed :)"); - - // start batching a large amount of inserts - for (int i = 1; i <= 150; i++) { - stmt.addBatch("INSERT INTO table_Test_Sbatching VALUES (" + i + ")"); - if (i % 50 == 0) { - System.out.print("2. executing batch (50 inserts)..."); - int[] cnts = stmt.executeBatch(); - System.out.println("passed :)"); - System.out.print("3. checking number of update counts..."); - if (cnts.length != 50) - throw new SQLException("Invalid size: " + cnts.length); - System.out.println(cnts.length + " passed :)"); - System.out.print("4. checking update counts (should all be 1)..."); - for (int j = 0; j < cnts.length; j++) { - if (cnts[j] != 1) - throw new SQLException("Unexpected value: " + cnts[j]); - } - System.out.println("passed :)"); - } - } - System.out.print("5. executing batch..."); - stmt.executeBatch(); - System.out.println("passed :)"); - - System.out.print("6. clearing the batch..."); - stmt.clearBatch(); - System.out.println("passed :)"); - - System.out.print("7. checking table count..."); - rs = stmt.executeQuery("SELECT COUNT(*) FROM table_Test_Sbatching"); - rs.next(); - System.out.println(rs.getInt(1) + " passed :)"); - - System.out.print("8. clean up mess we made..."); - if (stmt.executeUpdate("DROP TABLE table_Test_Sbatching") != Statement.SUCCESS_NO_INFO) - throw new SQLException("Wrong return status"); - System.out.println("passed :)"); - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - if (rs != null) rs.close(); - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Smoreresults.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Smoreresults { - public static void main(String[] args) throws Exception { - Connection con = DriverManager.getConnection(args[0]); - Statement stmt = con.createStatement(); - ResultSet rs = null; - - // >> true: auto commit should be on by default - System.out.println("0. true\t" + con.getAutoCommit()); - - try { - System.out.print("1. more results?..."); - if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) - throw new SQLException("more results on an unitialised Statement, how can that be?"); - System.out.println(" nope :)"); - - System.out.print("2. SELECT 1..."); - if (stmt.execute("SELECT 1;") == false) - throw new SQLException("SELECT 1 returns update or no results"); - System.out.println(" ResultSet :)"); - - System.out.print("3. more results?..."); - if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) - throw new SQLException("more results after SELECT 1 query, how can that be?"); - System.out.println(" nope :)"); - - System.out.print("4. even more results?..."); - if (stmt.getMoreResults() != false || stmt.getUpdateCount() != -1) - throw new SQLException("more results after SELECT 1 query, how can that be?"); - System.out.println(" nope :)"); - - } catch (SQLException e) { - // this means we failed (table not there perhaps?) - System.out.println("FAILED :( " + e.getMessage()); - System.out.println("ABORTING TEST!!!"); - } - - if (rs != null) rs.close(); - - con.close(); - } -}
deleted file mode 100644 --- a/tests/Test_Wrapper.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 - 2021 MonetDB B.V. - */ - -import java.sql.*; - -public class Test_Wrapper { - public static void main(String[] args) throws Exception { - final Connection con = DriverManager.getConnection(args[0]); - System.out.println("Connected. Auto commit is: " + con.getAutoCommit()); - - try { - final String jdbc_pkg = "java.sql."; - final String monetdb_jdbc_pkg = "org.monetdb.jdbc."; - - checkIsWrapperFor("Connection", con, jdbc_pkg, "Connection"); - checkIsWrapperFor("Connection", con, monetdb_jdbc_pkg, "MonetConnection"); - checkIsWrapperFor("Connection", con, jdbc_pkg, "Statement"); - checkIsWrapperFor("Connection", con, monetdb_jdbc_pkg, "MonetStatement"); - - DatabaseMetaData dbmd = con.getMetaData(); - checkIsWrapperFor("DatabaseMetaData", dbmd, jdbc_pkg, "DatabaseMetaData"); - checkIsWrapperFor("DatabaseMetaData", dbmd, monetdb_jdbc_pkg, "MonetDatabaseMetaData"); - checkIsWrapperFor("DatabaseMetaData", dbmd, jdbc_pkg, "Statement"); - checkIsWrapperFor("DatabaseMetaData", dbmd, monetdb_jdbc_pkg, "MonetStatement"); - - ResultSet rs = dbmd.getSchemas(); - checkIsWrapperFor("ResultSet", rs, jdbc_pkg, "ResultSet"); - checkIsWrapperFor("ResultSet", rs, monetdb_jdbc_pkg, "MonetResultSet"); - checkIsWrapperFor("ResultSet", rs, jdbc_pkg, "Statement"); - checkIsWrapperFor("ResultSet", rs, monetdb_jdbc_pkg, "MonetStatement"); - - ResultSetMetaData rsmd = rs.getMetaData(); - checkIsWrapperFor("ResultSetMetaData", rsmd, jdbc_pkg, "ResultSetMetaData"); - checkIsWrapperFor("ResultSetMetaData", rsmd, monetdb_jdbc_pkg, "MonetResultSet"); - checkIsWrapperFor("ResultSetMetaData", rsmd, monetdb_jdbc_pkg, "MonetResultSet$rsmdw"); // it is a private class of MonetResultSet - checkIsWrapperFor("ResultSetMetaData", rsmd, jdbc_pkg, "Statement"); - checkIsWrapperFor("ResultSetMetaData", rsmd, monetdb_jdbc_pkg, "MonetStatement"); - - rs.close(); - - Statement stmt = con.createStatement(); - checkIsWrapperFor("Statement", stmt, jdbc_pkg, "Statement"); - checkIsWrapperFor("Statement", stmt, monetdb_jdbc_pkg, "MonetStatement"); - checkIsWrapperFor("Statement", stmt, jdbc_pkg, "Connection"); - checkIsWrapperFor("Statement", stmt, monetdb_jdbc_pkg, "MonetConnection"); - - stmt.close(); - - PreparedStatement pstmt = con.prepareStatement("SELECT name FROM sys.tables WHERE system AND name like ?"); - checkIsWrapperFor("PreparedStatement", pstmt, jdbc_pkg, "PreparedStatement"); - checkIsWrapperFor("PreparedStatement", pstmt, monetdb_jdbc_pkg, "MonetPreparedStatement"); - checkIsWrapperFor("PreparedStatement", pstmt, jdbc_pkg, "Statement"); - checkIsWrapperFor("PreparedStatement", pstmt, monetdb_jdbc_pkg, "MonetStatement"); - checkIsWrapperFor("PreparedStatement", pstmt, jdbc_pkg, "Connection"); - checkIsWrapperFor("PreparedStatement", pstmt, monetdb_jdbc_pkg, "MonetConnection"); - - ParameterMetaData pmd = pstmt.getParameterMetaData(); - checkIsWrapperFor("ParameterMetaData", pmd, jdbc_pkg, "ParameterMetaData"); - checkIsWrapperFor("ParameterMetaData", pmd, monetdb_jdbc_pkg, "MonetPreparedStatement"); - checkIsWrapperFor("ParameterMetaData", pmd, monetdb_jdbc_pkg, "MonetPreparedStatement$pmdw"); // it is a private class of MonetPreparedStatement - checkIsWrapperFor("ParameterMetaData", pmd, jdbc_pkg, "Connection"); - checkIsWrapperFor("ParameterMetaData", pmd, monetdb_jdbc_pkg, "MonetConnection"); - - ResultSetMetaData psrsmd = pstmt.getMetaData(); - checkIsWrapperFor("PrepStmt ResultSetMetaData", psrsmd, jdbc_pkg, "ResultSetMetaData"); - checkIsWrapperFor("PrepStmt ResultSetMetaData", psrsmd, monetdb_jdbc_pkg, "MonetPreparedStatement"); - checkIsWrapperFor("PrepStmt ResultSetMetaData", psrsmd, monetdb_jdbc_pkg, "MonetPreparedStatement$rsmdw"); // it is a private class of MonetPreparedStatement - checkIsWrapperFor("PrepStmt ResultSetMetaData", psrsmd, jdbc_pkg, "Connection"); - checkIsWrapperFor("PrepStmt ResultSetMetaData", psrsmd, monetdb_jdbc_pkg, "MonetConnection"); - - pstmt.close(); - - } catch (SQLException e) { - while ((e = e.getNextException()) != null) - System.out.println("FAILED :( " + e.getMessage()); - } - con.close(); - } - - private static void checkIsWrapperFor(String objnm, Wrapper obj, String pkgnm, String classnm) { - try { - Class<?> clazz = Class.forName(pkgnm + classnm); - boolean isWrapper = obj.isWrapperFor(clazz); - System.out.print(objnm + ". isWrapperFor(" + classnm + ") returns: " + isWrapper); - if (isWrapper) { - Object wobj = obj.unwrap(clazz); - System.out.print("\tCalled unwrap(). Returned object is " + (wobj != null ? "not null, so oke" : "null !!")); - } - System.out.println(); - } catch (ClassNotFoundException cnfe) { - System.out.println(cnfe.toString()); - } catch (SQLException se) { - System.out.println(se.getMessage()); - } - } -}