Changeset: 1850e0dfb5f7 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=1850e0dfb5f7
Modified Files:
tests/JDBC_API_Tester.java
Branch: default
Log Message:
Implemented some more tests
diffs (truncated from 779 to 300 lines):
diff --git a/tests/JDBC_API_Tester.java b/tests/JDBC_API_Tester.java
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -7,9 +7,15 @@
*/
import java.sql.*;
-import java.util.*;
+
import java.io.StringReader;
import java.nio.charset.Charset;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TimeZone;
import org.monetdb.jdbc.types.INET;
import org.monetdb.jdbc.types.URL;
@@ -453,7 +459,7 @@ final public class JDBC_API_Tester {
int items = 0;
sb.append("4. table " + items + " items");
while (rs.next()) {
- System.out.print(", " + rs.getString("id"));
+ sb.append(", ").append(rs.getString("id"));
i++;
}
if (i != items) {
@@ -1216,37 +1222,7 @@ final public class JDBC_API_Tester {
sb.append(" writable
").append(rsmd.isWritable(col)).append("\n");
}
- // testing and showing parameter meta data
- ParameterMetaData pmd = pstmt.getParameterMetaData();
- sb.append("pmd.
").append(pmd.getParameterCount()).append(" parameters:\n");
- for (int parm = 1; parm <= pmd.getParameterCount();
parm++) {
- sb.append("Param ").append(parm).append("\n");
- int nullable = pmd.isNullable(parm);
- sb.append(" nullable
").append(nullable).append(" (");
- switch (nullable) {
- case
ParameterMetaData.parameterNoNulls: sb.append("NO"); break;
- case
ParameterMetaData.parameterNullable: sb.append("YA"); break;
- case
ParameterMetaData.parameterNullableUnknown: sb.append("UNKNOWN"); break;
- // default: sb.append("INVALID " +
nullable); break;
- }
- sb.append(")\n");
- sb.append(" signed
").append(pmd.isSigned(parm)).append("\n");
- sb.append(" precision
").append(pmd.getPrecision(parm)).append("\n");
- sb.append(" scale
").append(pmd.getScale(parm)).append("\n");
- sb.append(" type
").append(pmd.getParameterType(parm)).append("\n");
- sb.append(" typename
").append(pmd.getParameterTypeName(parm)).append("\n");
- sb.append(" classname
").append(pmd.getParameterClassName(parm)).append("\n");
- int mode = pmd.getParameterMode(parm);
- sb.append(" mode ").append(mode).append("
(");
- switch (mode) {
- case ParameterMetaData.parameterModeIn:
sb.append("IN"); break;
- case
ParameterMetaData.parameterModeInOut: sb.append("INOUT"); break;
- case
ParameterMetaData.parameterModeOut: sb.append("OUT"); break;
- case
ParameterMetaData.parameterModeUnknown: sb.append("UNKNOWN"); break;
- // default: sb.append("INVALID " +
mode); break;
- }
- sb.append(")\n");
- }
+ showParams(pstmt);
con.rollback();
con.setAutoCommit(true);
@@ -1543,75 +1519,615 @@ final public class JDBC_API_Tester {
sb.setLength(0); // clear the output log buffer
Statement stmt = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try {
+ con.setAutoCommit(false);
+ // >> false: auto commit should be off now
+ sb.append("0. false\t" +
con.getAutoCommit()).append("\n");
+
stmt = con.createStatement();
+ int updates = stmt.executeUpdate("CREATE TABLE
Test_PStimedate (t time, ts timestamp, d date)");
+ if (updates != -2)
+ sb.append("1. Expected -2 got
").append(updates).append(" instead\n");
+
+ pstmt = con.prepareStatement("INSERT INTO
Test_PStimedate VALUES (?, ?, ?)");
+ sb.append("1. empty call...");
+ try {
+ // should fail (as no parameters set)
+ pstmt.execute();
+ sb.append(" UNexpected PASS!\n");
+ } catch (SQLException e) {
+ sb.append(" expected exception\n");
+ }
+
+ sb.append("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();
+ sb.append(" passed\n");
+
+ sb.append("3. closing PreparedStatement...");
+ pstmt.close();
+ sb.append(" passed\n");
+
+ sb.append("4. selecting record...");
+ pstmt = con.prepareStatement("SELECT * FROM
Test_PStimedate");
+ rs = pstmt.executeQuery();
+ sb.append(" passed\n");
+
+ while (rs.next()) {
+ for (int j = 1; j <= 3; j++) {
+ sb.append((j + 4) + ". retrieving...");
+ java.util.Date x =
(java.util.Date)(rs.getObject(j));
+ boolean matches = false;
+ if (x instanceof Time) {
+ sb.append(" (Time)");
+ matches = (new
Time(d.getTime())).toString().equals(x.toString());
+ } else if (x instanceof Date) {
+ sb.append(" (Date)");
+ matches = (new
Date(d.getTime())).toString().equals(x.toString());
+ } else if (x instanceof Timestamp) {
+ sb.append(" (Timestamp)");
+ matches = (new
Timestamp(d.getTime())).toString().equals(x.toString());
+ }
+ if (matches) {
+ sb.append(" passed\n");
+ } else {
+ sb.append(" FAILED (" + x + "
is not " + d + ")\n");
+ }
+ }
+ }
+
+ con.rollback();
+ con.setAutoCommit(true);
+ // >> true: auto commit was just switched on
+ sb.append("0. true\t" +
con.getAutoCommit()).append("\n");
} catch (SQLException e) {
sb.append("FAILED:
").append(e.getMessage()).append("\n");
}
closeStmtResSet(stmt, null);
+ closeStmtResSet(pstmt, rs);
- compareExpectedOutput("Test_PStimedate", "");
+ compareExpectedOutput("Test_PStimedate",
+ "0. false false\n" +
+ "1. empty call... expected exception\n" +
+ "2. inserting a record... passed\n" +
+ "3. closing PreparedStatement... passed\n" +
+ "4. selecting record... passed\n" +
+ "5. retrieving... (Time) passed\n" +
+ "6. retrieving... (Timestamp) passed\n" +
+ "7. retrieving... (Date) passed\n" +
+ "0. true true\n");
}
private void Test_PStimezone() {
sb.setLength(0); // clear the output log buffer
+ // 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"));
+
Statement stmt = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try {
+ con.setAutoCommit(false);
+ // >> false: auto commit should be off now
+ sb.append("0. false\t" +
con.getAutoCommit()).append("\n");
+
stmt = con.createStatement();
+ int updates = stmt.executeUpdate("CREATE TABLE
Test_PStimezone (ts timestamp, tsz timestamp with time zone, t time, tz time
with time zone)");
+ if (updates != -2)
+ sb.append("1. Expected -2 got
").append(updates).append(" instead\n");
+
+ pstmt = con.prepareStatement("INSERT INTO
Test_PStimezone VALUES (?, ?, ?, ?)");
+ sb.append("1. empty call...");
+ try {
+ // should fail (as no parameters set)
+ pstmt.execute();
+ sb.append(" UNexpected PASS!\n");
+ } catch (SQLException e) {
+ sb.append(" expected exception\n");
+ }
+
+ sb.append("2. inserting records...\n");
+ java.sql.Timestamp ts = new java.sql.Timestamp(0L);
+ java.sql.Time t = new java.sql.Time(0L);
+ Calendar c = Calendar.getInstance();
+ SimpleDateFormat tsz = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss.SSSZ");
+ SimpleDateFormat tz = new
SimpleDateFormat("HH:mm:ss.SSSZ");
+
+ tsz.setTimeZone(c.getTimeZone());
+ tz.setTimeZone(tsz.getTimeZone());
+ sb.append("inserting
(").append(c.getTimeZone().getID()).append(")
").append(tsz.format(ts)).append(", ").append(tz.format(t)).append("\n");
+
+ pstmt.setTimestamp(1, ts);
+ pstmt.setTimestamp(2, ts);
+ pstmt.setTime(3, t);
+ pstmt.setTime(4, t);
+ pstmt.executeUpdate();
+
+ c.setTimeZone(TimeZone.getTimeZone("UTC"));
+ sb.append("inserting with calendar timezone
").append(c.getTimeZone().getID()).append("\n");
+ 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"));
+ sb.append("inserting with calendar timezone " +
c.getTimeZone().getID()).append("\n");
+ 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"));
+ sb.append("inserting with calendar timezone " +
c.getTimeZone().getID()).append("\n");
+ pstmt.setTimestamp(1, ts);
+ pstmt.setTimestamp(2, ts, c);
+ pstmt.setTime(3, t);
+ pstmt.setTime(4, t, c);
+ pstmt.executeUpdate();
+ sb.append(" done\n");
+
+ sb.append("3. closing PreparedStatement...");
+ pstmt.close();
+ sb.append(" passed\n");
+
+ sb.append("4. selecting records...");
+ pstmt = con.prepareStatement("SELECT * FROM
Test_PStimezone");
+ rs = pstmt.executeQuery();
+ sb.append(" passed\n");
+
+ // 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()) {
+ sb.append("retrieved row (String):\n").append(
+ rs.getString("ts")).append(" |
").append(
+ rs.getString("tsz")).append(" |
").append(
+ rs.getString("t")).append(" |
").append(
+
rs.getString("tz")).append("\n");
+
+ tsz.setTimeZone(TimeZone.getDefault());
+ tz.setTimeZone(tsz.getTimeZone());
+ sb.append("default
(").append(tsz.getTimeZone().getID()).append("):\n").append(
+
tsz.format(rs.getTimestamp("ts"))).append(" | ").append(
+
tsz.format(rs.getTimestamp("tsz"))).append(" | ").append(
+
tz.format(rs.getTime("t"))).append(" | ").append(
+
tz.format(rs.getTime("tz"))).append("\n");
+
+
c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
+
sb.append(c.getTimeZone().getID()).append(":\n").append(
+ rs.getTimestamp("ts",
c)).append(" | ").append(
+ rs.getTimestamp("tsz",
c)).append(" | ").append(
+ rs.getTime("t", c)).append(" |
").append(
+ rs.getTime("tz",
c)).append("\n");
+
+
c.setTimeZone(TimeZone.getTimeZone("Africa/Windhoek"));
+
sb.append(c.getTimeZone().getID()).append(":\n").append(
+ rs.getTimestamp("ts",
c)).append(" | ").append(
+ rs.getTimestamp("tsz",
c)).append(" | ").append(
+ rs.getTime("t", c)).append(" |
").append(
+ rs.getTime("tz",
c)).append("\n");
+
+ SQLWarning w = rs.getWarnings();
+ while (w != null) {
+ sb.append(w.getMessage()).append("\n");
+ w = w.getNextWarning();
+ }
+ }
+
+ con.rollback();
+ con.setAutoCommit(true);
+ // >> true: auto commit was just switched on
+ sb.append("0. true\t" +
con.getAutoCommit()).append("\n");
} catch (SQLException e) {
sb.append("FAILED:
").append(e.getMessage()).append("\n");
}
closeStmtResSet(stmt, null);
+ closeStmtResSet(pstmt, rs);
- compareExpectedOutput("Test_PStimezone", "");
+ compareExpectedOutput("Test_PStimezone",
+ "0. false false\n" +
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list