0001: /*
0002:
0003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.parameterMapping
0004:
0005: Licensed to the Apache Software Foundation (ASF) under one or more
0006: contributor license agreements. See the NOTICE file distributed with
0007: this work for additional information regarding copyright ownership.
0008: The ASF licenses this file to You under the Apache License, Version 2.0
0009: (the "License"); you may not use this file except in compliance with
0010: the License. You may obtain a copy of the License at
0011:
0012: http://www.apache.org/licenses/LICENSE-2.0
0013:
0014: Unless required by applicable law or agreed to in writing, software
0015: distributed under the License is distributed on an "AS IS" BASIS,
0016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: See the License for the specific language governing permissions and
0018: limitations under the License.
0019:
0020: */
0021:
0022: package org.apache.derbyTesting.functionTests.tests.jdbcapi;
0023:
0024: import org.apache.derby.tools.ij;
0025: import org.apache.derbyTesting.functionTests.util.TestUtil;
0026: import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;
0027:
0028: import java.sql.*;
0029: import java.math.*;
0030: import java.io.*;
0031:
0032: public class parameterMapping {
0033:
0034: private static boolean HAVE_BIG_DECIMAL;
0035:
0036: static {
0037: if (BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
0038: HAVE_BIG_DECIMAL = false;
0039: else
0040: HAVE_BIG_DECIMAL = true;
0041: }
0042:
0043: private static int[] jdbcTypes = { Types.TINYINT, Types.SMALLINT,
0044: Types.INTEGER, Types.BIGINT, Types.REAL, Types.FLOAT,
0045: Types.DOUBLE, Types.DECIMAL, Types.NUMERIC,
0046: Types.BIT,
0047: Types.NULL, // Types.BOOLEAN
0048: Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR,
0049: Types.NULL, //Types.BINARY,
0050: Types.VARBINARY,
0051: Types.NULL, //Types.LONGVARBINARY,
0052: Types.DATE, Types.TIME, Types.TIMESTAMP, Types.CLOB,
0053: Types.BLOB, };
0054:
0055: private static String[] SQLTypes = { null, "SMALLINT", "INTEGER",
0056: "BIGINT", "REAL", "FLOAT", "DOUBLE", "DECIMAL(10,5)", null,
0057: null, null, "CHAR(60)", "VARCHAR(60)", "LONG VARCHAR",
0058: "CHAR(60) FOR BIT DATA", "VARCHAR(60) FOR BIT DATA",
0059: "LONG VARCHAR FOR BIT DATA", "DATE", "TIME", "TIMESTAMP",
0060: "CLOB(1k)", "BLOB(1k)",
0061:
0062: };
0063:
0064: private static Class[] B3_GET_OBJECT;
0065:
0066: static {
0067: if (HAVE_BIG_DECIMAL) {
0068: B3_GET_OBJECT = new Class[] { java.lang.Integer.class, // Types.TINYINT,
0069: java.lang.Integer.class, // Types.SMALLINT,
0070: java.lang.Integer.class, // Types.INTEGER,
0071: java.lang.Long.class, // Types.BIGINT,
0072: java.lang.Float.class, // Types.REAL,
0073: java.lang.Double.class, // Types.FLOAT,
0074: java.lang.Double.class, // Types.DOUBLE,
0075: java.math.BigDecimal.class, // Types.DECIMAL,
0076: java.math.BigDecimal.class, // Types.NUMERIC,
0077: java.lang.Boolean.class, // Types.BIT,
0078: java.lang.Boolean.class, // Types.BOOLEAN
0079: java.lang.String.class, // Types.CHAR,
0080: java.lang.String.class, // Types.VARCHAR,
0081: java.lang.String.class, // Types.LONGVARCHAR,
0082: byte[].class, // Types.NULL, //Types.BINARY,
0083: byte[].class, // Types.VARBINARY,
0084: byte[].class, // Types.LONGVARBINARY,
0085: java.sql.Date.class, // Types.DATE,
0086: java.sql.Time.class, // Types.TIME,
0087: java.sql.Timestamp.class, // Types.TIMESTAMP,
0088: java.sql.Clob.class, // Types.CLOB,
0089: java.sql.Blob.class, // Types.BLOB,
0090: };
0091: } else {
0092: B3_GET_OBJECT = new Class[] { java.lang.Integer.class, // Types.TINYINT,
0093: java.lang.Integer.class, // Types.SMALLINT,
0094: java.lang.Integer.class, // Types.INTEGER,
0095: java.lang.Long.class, // Types.BIGINT,
0096: java.lang.Float.class, // Types.REAL,
0097: java.lang.Double.class, // Types.FLOAT,
0098: java.lang.Double.class, // Types.DOUBLE,
0099: java.lang.String.class, // Types.DECIMAL,
0100: java.lang.String.class, // Types.NUMERIC,
0101: java.lang.Boolean.class, // Types.BIT,
0102: java.lang.Boolean.class, // Types.BOOLEAN
0103: java.lang.String.class, // Types.CHAR,
0104: java.lang.String.class, // Types.VARCHAR,
0105: java.lang.String.class, // Types.LONGVARCHAR,
0106: byte[].class, // Types.NULL, //Types.BINARY,
0107: byte[].class, // Types.VARBINARY,
0108: byte[].class, // Types.LONGVARBINARY,
0109: java.sql.Date.class, // Types.DATE,
0110: java.sql.Time.class, // Types.TIME,
0111: java.sql.Timestamp.class, // Types.TIMESTAMP,
0112: java.sql.Clob.class, // Types.CLOB,
0113: java.sql.Blob.class, // Types.BLOB,
0114: };
0115: }
0116: }
0117:
0118: private static final boolean _ = false;
0119: private static final boolean X = true;
0120:
0121: /**
0122: JDBC 3.0 spec Table B6 - Use of ResultSet getter Methods to Retrieve JDBC Data Types
0123: */
0124: public static final boolean[][] B6 = {
0125:
0126: // Types. T S I B R F D D N B B C V L B V L D T T C B
0127: // I M N I E L O E U I O H A O I A O A I I L L
0128: // N A T G A O U C M T O A R N N R N T M M O O
0129: // Y L E I L A B I E L R C G A B G E E E B B
0130: // I L G N T L M R E H V R I V S
0131: // N I E T E A I A A A Y N A T
0132: // T N R L C N R R A R A
0133: // T C R B M
0134: // H B I P
0135: // A I N
0136: // R N
0137:
0138: /* 0 getByte*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0139: _, _, _, _, _, _, _, _ },
0140: /* 1 getShort*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0141: _, _, _, _, _, _, _, _ },
0142: /* 2 getInt*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0143: _, _, _, _, _, _, _, _ },
0144: /* 3 getLong*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0145: _, _, _, _, _, _, _, _ },
0146: /* 4 getFloat*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0147: _, _, _, _, _, _, _, _ },
0148: /* 5 getDouble*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0149: X, _, _, _, _, _, _, _, _ },
0150: /* 6 getBigDecimal*/{ X, X, X, X, X, X, X, X, X, X, X, X,
0151: X, X, _, _, _, _, _, _, _, _ },
0152: /* 7 getBoolean*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0153: X, _, _, _, _, _, _, _, _ },
0154: /* 8 getString*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0155: X, X, X, X, X, X, X, _, _ },
0156: /* 9 getBytes*/{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0157: X, X, X, _, _, _, _, _ },
0158: /*10 getDate*/{ _, _, _, _, _, _, _, _, _, _, _, X, X, X,
0159: _, _, _, X, _, X, _, _ },
0160: /*11 getTime*/{ _, _, _, _, _, _, _, _, _, _, _, X, X, X,
0161: _, _, _, _, X, X, _, _ },
0162: /*12 getTimestamp*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0163: X, X, _, _, _, X, X, X, _, _ },
0164: /*13 getAsciiStream*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0165: X, X, X, X, X, _, _, _, _, _ },
0166: /*14 getBinaryStream*/{ _, _, _, _, _, _, _, _, _, _, _,
0167: _, _, _, X, X, X, _, _, _, _, _ },
0168: /*15 getCharStream*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0169: X, X, X, X, X, _, _, _, _, _ },
0170: /*16 getClob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0171: _, _, _, _, _, _, X, _ },
0172: /*17 getBlob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0173: _, _, _, _, _, _, _, X },
0174:
0175: /*18 getUnicodeStream */{ _, _, _, _, _, _, _, _, _, _, _,
0176: _, _, _, _, _, _, _, _, _, _, _ }, };
0177:
0178: /**
0179: JDBC 3.0 Section 13.2.2.1 specifies that table B-2 is used to specify type mappings
0180: from the Java types (e.g. int as setInt) to the JDBC SQL Type (Types.INT).
0181:
0182: This table does not include stream methods and does not include conversions
0183: specified elsewhere in the text, Namely
0184:
0185: Section 16.3.2
0186: setBinaryStream may be used to set a BLOB
0187: setAsciiStream and setCharacterStream may be used to set a CLOB
0188:
0189: Thus this B2_MOD table is laid out like the B6 table and makes
0190: the assumptions that
0191:
0192: - Any Java numeric type can be used to set any SQL numeric type
0193: - Any Java numeric type can be used to set any SQL CHAR type
0194: - Numeric and date/time java types can be converted to SQL Char values.
0195:
0196:
0197: */
0198:
0199: // Types. T S I B R F D D N B B C V L B V L D T T C B
0200: // I M N I E L O E U I O H A O I A O A I I L L
0201: // N A T G A O U C M T O A R N N R N T M M O O
0202: // Y L E I L A B I E L R C G A B G E E E B B
0203: // I L G N T L M R E H V R I V S
0204: // N I E T E A I A A A Y N A T
0205: // T N R L C N R R A R A
0206: // T C R B M
0207: // H B I P
0208: // A I N
0209: // R N
0210: public static boolean[][] B2_MOD = {
0211: /* 0 setByte*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0212: _, _, _, _, _, _, _, _ },
0213: /* 1 setShort*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0214: _, _, _, _, _, _, _, _ },
0215: /* 2 setInt*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0216: _, _, _, _, _, _, _, _ },
0217: /* 3 setLong*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0218: _, _, _, _, _, _, _, _ },
0219: /* 4 setFloat*/{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0220: _, _, _, _, _, _, _, _ },
0221: /* 5 setDouble*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0222: X, _, _, _, _, _, _, _, _ },
0223: /* 6 setBigDecimal*/{ X, X, X, X, X, X, X, X, X, X, X, X,
0224: X, X, _, _, _, _, _, _, _, _ },
0225: /* 7 setBoolean*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0226: X, _, _, _, _, _, _, _, _ },
0227: /* 8 setString*/{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0228: X, _, _, _, X, X, X, _, _ },
0229: /* 9 setBytes*/{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0230: X, X, X, _, _, _, _, _ },
0231: /*10 setDate*/{ _, _, _, _, _, _, _, _, _, _, _, X, X, X,
0232: _, _, _, X, _, X, _, _ },
0233: /*11 setTime*/{ _, _, _, _, _, _, _, _, _, _, _, X, X, X,
0234: _, _, _, _, X, X, _, _ },
0235: /*12 setTimestamp*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0236: X, X, _, _, _, X, X, X, _, _ },
0237: /*13 setAsciiStream*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0238: X, X, _, _, _, _, _, _, X, _ },
0239: /*14 setBinaryStream*/{ _, _, _, _, _, _, _, _, _, _, _,
0240: _, _, _, X, X, X, _, _, _, _, X },
0241: /*15 setCharStream*/{ _, _, _, _, _, _, _, _, _, _, _, X,
0242: X, X, _, _, _, _, _, _, X, _ },
0243: /*16 setClob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0244: _, _, _, _, _, _, X, _ },
0245: /*17 setBlob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0246: _, _, _, _, _, _, _, X },
0247:
0248: /*18 setUnicodeStream */{ _, _, _, _, _, _, _, _, _, _, _,
0249: _, _, _, _, _, _, _, _, _, _, _ }, };
0250:
0251: /** Table B5 conversion of Objects using setObject*/
0252:
0253: // Types. T S I B R F D D N B B C V L B V L D T T C B
0254: // I M N I E L O E U I O H A O I A O A I I L L
0255: // N A T G A O U C M T O A R N N R N T M M O O
0256: // Y L E I L A B I E L R C G A B G E E E B B
0257: // I L G N T L M R E H V R I V S
0258: // N I E T E A I A A A Y N A T
0259: // T N R L C N R R A R A
0260: // T C R B M
0261: // H B I P
0262: // A I N
0263: // R N
0264: public static boolean[][] B5 = {
0265: /* 0 String */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0266: X, X, X, X, X, X, _, _ },
0267: /* 1 BigDecimal */{ X, X, X, X, X, X, X, X, X, X, X, X, X,
0268: X, _, _, _, _, _, _, _, _ },
0269: /* 2 Boolean */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0270: _, _, _, _, _, _, _, _ },
0271: /* 3 Integer */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0272: _, _, _, _, _, _, _, _ },
0273: /* 4 Long */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X, _,
0274: _, _, _, _, _, _, _ },
0275: /* 5 Float */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0276: _, _, _, _, _, _, _, _ },
0277: /* 6 Double */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0278: _, _, _, _, _, _, _, _ },
0279: /* 7 byte[] */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0280: X, X, X, _, _, _, _, _ },
0281: /* 8 Date */{ _, _, _, _, _, _, _, _, _, _, _, X, X, X, _,
0282: _, _, X, _, X, _, _ },
0283: /* 9 Time */{ _, _, _, _, _, _, _, _, _, _, _, X, X, X, _,
0284: _, _, _, X, _, _, _ },
0285: /*10 Timestamp */{ _, _, _, _, _, _, _, _, _, _, _, X, X,
0286: X, _, _, _, X, X, X, _, _ },
0287: /*11 Blob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0288: _, _, _, _, _, _, _, X },
0289: /*12 Clob */{ _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
0290: _, _, _, _, _, X, _ },
0291:
0292: // Byte and Short were added to this table in JDBC 4.0. (See DERBY-1500.)
0293:
0294: /*13 Byte */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X, _,
0295: _, _, _, _, _, _, _ },
0296: /*14 Short */{ X, X, X, X, X, X, X, X, X, X, X, X, X, X,
0297: _, _, _, _, _, _, _, _ }, };
0298:
0299: private static boolean isDB2jNet;
0300:
0301: public static void main(String[] args) throws Exception {
0302: isDB2jNet = TestUtil.isNetFramework();
0303: System.out.println("Test parameterMapping starting");
0304: System.out
0305: .println("STILL TO RESOLVE -- Cloudscape getBoolean() allow conversion on strings to match JCC");
0306: System.out
0307: .println("STILL TO RESOLVE -- Cloudscape getXXX() disable on LOBs.");
0308: try {
0309: // use the ij utility to read the property file and
0310: // make the initial connection.
0311: ij.getPropertyArg(args);
0312: Connection conn = ij.startJBMS();
0313:
0314: conn.setAutoCommit(false);
0315:
0316: //create simple a table with BLOB and CLOB thta
0317: // can be used to for setBlob/setClob testing.
0318: Statement scb = conn.createStatement();
0319:
0320: try {
0321: scb.execute("DROP TABLE PM.LOB_GET");
0322: } catch (SQLException seq) {
0323: }
0324: scb
0325: .execute("CREATE TABLE PM.LOB_GET(ID INT, B BLOB, C CLOB)");
0326: PreparedStatement pscb = conn
0327: .prepareStatement("INSERT INTO PM.LOB_GET VALUES (?, ?, ?)");
0328: pscb.setInt(1, 0);
0329: pscb.setNull(2, Types.BLOB);
0330: pscb.setNull(3, Types.CLOB);
0331: pscb.executeUpdate();
0332:
0333: pscb.setInt(1, 1);
0334: {
0335: byte[] data = new byte[6];
0336: data[0] = (byte) 0x32;
0337: data[1] = (byte) 0x43;
0338: data[2] = (byte) 0x72;
0339: data[3] = (byte) 0x43;
0340: data[4] = (byte) 0x00;
0341: data[5] = (byte) 0x37;
0342:
0343: pscb.setBinaryStream(2,
0344: new java.io.ByteArrayInputStream(data), 6);
0345: }
0346: pscb.setCharacterStream(3, new java.io.StringReader("72"),
0347: 2);
0348: pscb.executeUpdate();
0349: scb.close();
0350: pscb.close();
0351: conn.commit();
0352:
0353: for (int type = 0; type < SQLTypes.length; type++) {
0354:
0355: String sqlType = SQLTypes[type];
0356:
0357: System.out.println("\n\ngetXXX on : "
0358: + (sqlType == null ? Integer
0359: .toString(jdbcTypes[type]) : sqlType));
0360: if (sqlType == null || jdbcTypes[type] == Types.NULL) {
0361: System.out.println(" skipping");
0362: continue;
0363: }
0364:
0365: Statement s = conn.createStatement();
0366:
0367: try {
0368: s.execute("DROP TABLE PM.TYPE_AS");
0369: } catch (SQLException seq) {
0370: }
0371: s.execute("CREATE TABLE PM.TYPE_AS(VAL "
0372: + SQLTypes[type] + ")");
0373:
0374: PreparedStatement psi = conn
0375: .prepareStatement("INSERT INTO PM.TYPE_AS(VAL) VALUES(?)");
0376: psi.setNull(1, jdbcTypes[type]);
0377: psi.executeUpdate();
0378:
0379: PreparedStatement psq = conn
0380: .prepareStatement("SELECT VAL FROM PM.TYPE_AS");
0381: ResultSet rs = psq.executeQuery();
0382: ResultSetMetaData rsmd = rs.getMetaData();
0383: if (rsmd.getColumnType(1) != jdbcTypes[type]) {
0384: System.out.println("FAIL - mismatch column type "
0385: + rsmd.getColumnType(1) + " expected "
0386: + jdbcTypes[type]);
0387: }
0388: rs.close();
0389:
0390: // For this data type
0391: // Test inserting a NULL value and then performing all the getXXX() calls on it.
0392:
0393: System.out.println(" NULL VALUE");
0394: getXXX(psq, type, true);
0395:
0396: s.execute("DELETE FROM PM.TYPE_AS");
0397:
0398: // For this data type
0399: // Test inserting a valid value and then performing all the getXXX() calls on it.
0400: if (setValidValue(psi, 1, jdbcTypes[type])) {
0401: psi.executeUpdate();
0402: System.out.println(" VALID VALUE");
0403: getXXX(psq, type, false);
0404: }
0405:
0406: // NOW THE SET METHODS
0407: System.out.println("setNull() with all JDBC Types on "
0408: + SQLTypes[type]);
0409: for (int st = 0; st <= jdbcTypes.length + 1; st++) {
0410:
0411: if (st >= jdbcTypes.length
0412: || jdbcTypes[st] != Types.NULL) {
0413: // explictily test Types.NULL.
0414: int sqlTypeNull;
0415: if (st == jdbcTypes.length + 1)
0416: sqlTypeNull = 235350345; // bad value
0417: else if (st == jdbcTypes.length)
0418: sqlTypeNull = Types.NULL;
0419: else
0420: sqlTypeNull = jdbcTypes[st];
0421:
0422: s.execute("DELETE FROM PM.TYPE_AS");
0423:
0424: SQLException sqleResult = null;
0425: try {
0426: System.out
0427: .print(" setNull("
0428: + TestUtil
0429: .sqlNameFromJdbc(sqlTypeNull)
0430: + ") ");
0431: psi.setNull(1, sqlTypeNull);
0432: psi.executeUpdate();
0433:
0434: getValidValue(psq, jdbcTypes[type]); // yes type, not st
0435:
0436: System.out.println("");
0437:
0438: } catch (SQLException sqle) {
0439: sqleResult = sqle;
0440: if ("22005".equals(sqle.getSQLState()))
0441: System.out.println("IC");
0442: else
0443: dumpSQLExceptions(sqle);
0444:
0445: }
0446:
0447: /**
0448: * Adding this piece of code to test the support for batching of statements.
0449: * Some datatypes had problems when batching was turned on which was
0450: * not there when batching was not on, this will test that behaviour
0451: * for all such datatypes
0452: */
0453: s.execute("DELETE FROM PM.TYPE_AS");
0454: try {
0455: System.out
0456: .print(" setNull with batching support("
0457: + TestUtil
0458: .sqlNameFromJdbc(sqlTypeNull)
0459: + ") ");
0460: psi.setNull(1, sqlTypeNull);
0461: psi.addBatch();
0462: psi.executeBatch();
0463:
0464: getValidValue(psq, jdbcTypes[type]); // yes type, not st
0465:
0466: System.out.println("");
0467:
0468: } catch (SQLException sqle) {
0469: sqleResult = sqle;
0470: if ("22005".equals(sqle.getSQLState()))
0471: System.out.println("IC");
0472: else
0473: dumpSQLExceptions(sqle);
0474: }
0475: }
0476: }
0477:
0478: System.out.println("setXXX() with all JDBC Types on "
0479: + SQLTypes[type]);
0480: System.out
0481: .println("For setXXX() methods that pass an object, a null and valid values are checked");
0482: setXXX(s, psi, psq, type);
0483:
0484: psi.close();
0485: psq.close();
0486: s.execute("DROP TABLE PM.TYPE_AS");
0487: conn.commit();
0488:
0489: if (isDB2jNet)
0490: continue;
0491:
0492: // NOW PROCEDURE PARAMETERS
0493: try {
0494: s.execute("DROP PROCEDURE PMP.TYPE_AS");
0495: } catch (SQLException seq) {
0496: }
0497: String procSQL;
0498: if (HAVE_BIG_DECIMAL) {
0499: procSQL = "CREATE PROCEDURE PMP.TYPE_AS("
0500: + "IN P1 "
0501: + SQLTypes[type]
0502: + ", INOUT P2 "
0503: + SQLTypes[type]
0504: + ", OUT P3 "
0505: + SQLTypes[type]
0506: + ") LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL "
0507: + " EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.ProcedureTest.pmap'";
0508: } else {
0509: procSQL = "CREATE PROCEDURE PMP.TYPE_AS("
0510: + "IN P1 "
0511: + SQLTypes[type]
0512: + ", INOUT P2 "
0513: + SQLTypes[type]
0514: + ", OUT P3 "
0515: + SQLTypes[type]
0516: + ") LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL "
0517: + " EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.SimpleProcedureTest.pmap'";
0518: }
0519:
0520: try {
0521: if (!HAVE_BIG_DECIMAL
0522: && SQLTypes[type].equals("DECIMAL(10,5)"))
0523: continue;
0524: System.out.println(procSQL);
0525: s.execute(procSQL);
0526: } catch (SQLException sqle) {
0527: System.out.println(sqle.getSQLState() + ":"
0528: + sqle.getMessage());
0529: continue;
0530: }
0531:
0532: // For each JDBC type try to register the out parameters with that type.
0533: for (int opt = 0; opt < jdbcTypes.length; opt++) {
0534: int jopt = jdbcTypes[opt];
0535: if (jopt == Types.NULL)
0536: continue;
0537:
0538: CallableStatement csp = conn
0539: .prepareCall("CALL PMP.TYPE_AS(?, ?, ?)");
0540:
0541: boolean bothRegistered = true;
0542: System.out
0543: .print("INOUT "
0544: + sqlType
0545: + " registerOutParameter("
0546: + TestUtil
0547: .getNameFromJdbcType(jopt)
0548: + ") ");
0549: try {
0550: csp.registerOutParameter(2, jopt);
0551: System.out.println("-- OK");
0552: } catch (SQLException sqle) {
0553: System.out.println("-- " + sqle.getSQLState());
0554: bothRegistered = false;
0555: }
0556: System.out
0557: .print("OUT "
0558: + sqlType
0559: + " registerOutParameter("
0560: + TestUtil
0561: .getNameFromJdbcType(jopt)
0562: + ") ");
0563: try {
0564: csp.registerOutParameter(3, jopt);
0565: System.out.println("-- OK");
0566: } catch (SQLException sqle) {
0567: System.out.println("-- " + sqle.getSQLState());
0568: bothRegistered = false;
0569: }
0570:
0571: if (bothRegistered) {
0572:
0573: try {
0574:
0575: // set the IN value with an accepted value according to its type
0576: // set the INOUT value with an accepted value according to its registered type
0577: if (setValidValue(csp, 1, jdbcTypes[type])
0578: && setValidValue(csp, 2, jopt)) {
0579:
0580: csp.execute();
0581:
0582: // now get the INOUT, OUT parameters according to their registered type.
0583: System.out.print("P2=");
0584: getOutValue(csp, 2, jopt);
0585: System.out.println("");
0586: System.out.print("P3=");
0587: getOutValue(csp, 3, jopt);
0588: System.out.println("");
0589: }
0590:
0591: } catch (SQLException sqle) {
0592: dumpSQLExceptions(sqle);
0593: }
0594: }
0595:
0596: csp.close();
0597:
0598: }
0599:
0600: s.execute("DROP PROCEDURE PMP.TYPE_AS");
0601: s.close();
0602: conn.commit();
0603: }
0604: } catch (SQLException sqle) {
0605: unexpectedException(sqle);
0606: } catch (Throwable t) {
0607: t.printStackTrace(System.out);
0608: }
0609: }
0610:
0611: private static void getXXX(PreparedStatement ps, int type,
0612: boolean isNull) throws SQLException, java.io.IOException {
0613:
0614: {
0615: System.out.print(" getByte=");
0616: ResultSet rs = ps.executeQuery();
0617: rs.next();
0618: boolean worked;
0619: SQLException sqleResult = null;
0620: ;
0621: try {
0622: System.out.print(rs.getByte(1));
0623: System.out.print(" was null " + rs.wasNull());
0624: worked = true;
0625:
0626: } catch (SQLException sqle) {
0627: sqleResult = sqle;
0628: worked = false;
0629: }
0630: rs.close();
0631: judge_getXXX(worked, sqleResult, 0, type);
0632: }
0633:
0634: {
0635: System.out.print(" getShort=");
0636: ResultSet rs = ps.executeQuery();
0637: rs.next();
0638: boolean worked;
0639: SQLException sqleResult = null;
0640: ;
0641: try {
0642: System.out.print(rs.getShort(1));
0643: System.out.print(" was null " + rs.wasNull());
0644: worked = true;
0645:
0646: } catch (SQLException sqle) {
0647: sqleResult = sqle;
0648: worked = false;
0649: }
0650: rs.close();
0651: judge_getXXX(worked, sqleResult, 1, type);
0652: }
0653:
0654: {
0655: System.out.print(" getInt=");
0656: ResultSet rs = ps.executeQuery();
0657: rs.next();
0658: boolean worked;
0659: SQLException sqleResult = null;
0660: ;
0661: try {
0662: System.out.print(rs.getInt(1));
0663: System.out.print(" was null " + rs.wasNull());
0664: worked = true;
0665:
0666: } catch (SQLException sqle) {
0667: sqleResult = sqle;
0668: worked = false;
0669: }
0670: rs.close();
0671: judge_getXXX(worked, sqleResult, 2, type);
0672: }
0673:
0674: {
0675: System.out.print(" getLong=");
0676: ResultSet rs = ps.executeQuery();
0677: rs.next();
0678: boolean worked;
0679: SQLException sqleResult = null;
0680: ;
0681: try {
0682: System.out.print(rs.getLong(1));
0683: System.out.print(" was null " + rs.wasNull());
0684: worked = true;
0685:
0686: } catch (SQLException sqle) {
0687: sqleResult = sqle;
0688: worked = false;
0689: }
0690: rs.close();
0691: judge_getXXX(worked, sqleResult, 3, type);
0692: }
0693:
0694: {
0695: System.out.print(" getFloat=");
0696: ResultSet rs = ps.executeQuery();
0697: rs.next();
0698: boolean worked;
0699: SQLException sqleResult = null;
0700: ;
0701: try {
0702: System.out.print(rs.getFloat(1));
0703: System.out.print(" was null " + rs.wasNull());
0704: worked = true;
0705:
0706: } catch (SQLException sqle) {
0707: sqleResult = sqle;
0708: worked = false;
0709: }
0710: rs.close();
0711: judge_getXXX(worked, sqleResult, 4, type);
0712: }
0713:
0714: {
0715: System.out.print(" getDouble=");
0716: ResultSet rs = ps.executeQuery();
0717: rs.next();
0718: boolean worked;
0719: SQLException sqleResult = null;
0720: ;
0721: try {
0722: System.out.print(rs.getDouble(1));
0723: System.out.print(" was null " + rs.wasNull());
0724: worked = true;
0725:
0726: } catch (SQLException sqle) {
0727: sqleResult = sqle;
0728: worked = false;
0729: }
0730: rs.close();
0731: judge_getXXX(worked, sqleResult, 5, type);
0732: }
0733:
0734: if (HAVE_BIG_DECIMAL) {
0735: System.out.print(" getBigDecimal=");
0736: ResultSet rs = ps.executeQuery();
0737: rs.next();
0738: boolean worked;
0739: SQLException sqleResult = null;
0740: ;
0741: try {
0742: System.out.print(rs.getBigDecimal(1));
0743: System.out.print(" was null " + rs.wasNull());
0744: worked = true;
0745:
0746: } catch (SQLException sqle) {
0747: sqleResult = sqle;
0748: worked = false;
0749: }
0750: rs.close();
0751: judge_getXXX(worked, sqleResult, 6, type);
0752: }
0753:
0754: {
0755: System.out.print(" getBoolean=");
0756: ResultSet rs = ps.executeQuery();
0757: rs.next();
0758: boolean worked;
0759: SQLException sqleResult = null;
0760: ;
0761: try {
0762: System.out.print(rs.getBoolean(1));
0763: System.out.print(" was null " + rs.wasNull());
0764: worked = true;
0765:
0766: } catch (SQLException sqle) {
0767: sqleResult = sqle;
0768: worked = false;
0769: }
0770: rs.close();
0771: judge_getXXX(worked, sqleResult, 7, type);
0772: }
0773:
0774: {
0775: System.out.print(" getString=");
0776: ResultSet rs = ps.executeQuery();
0777: rs.next();
0778: boolean worked;
0779: SQLException sqleResult = null;
0780: ;
0781: try {
0782: System.out.print(rs.getString(1));
0783: System.out.print(" was null " + rs.wasNull());
0784: worked = true;
0785:
0786: } catch (SQLException sqle) {
0787: sqleResult = sqle;
0788: worked = false;
0789: }
0790: rs.close();
0791: judge_getXXX(worked, sqleResult, 8, type);
0792: }
0793:
0794: {
0795: System.out.print(" getBytes=");
0796: ResultSet rs = ps.executeQuery();
0797: rs.next();
0798: boolean worked;
0799: SQLException sqleResult = null;
0800: ;
0801: try {
0802: byte[] data = rs.getBytes(1);
0803: System.out.print(data == null ? null : parameterMapping
0804: .showFirstTwo(data));
0805: System.out.print(" was null " + rs.wasNull());
0806: worked = true;
0807:
0808: } catch (SQLException sqle) {
0809: sqleResult = sqle;
0810: worked = false;
0811: }
0812: rs.close();
0813: judge_getXXX(worked, sqleResult, 9, type);
0814: }
0815:
0816: {
0817: System.out.print(" getDate=");
0818: boolean worked;
0819: SQLException sqleResult = null;
0820: ;
0821: ResultSet rs = null;
0822: try {
0823: rs = ps.executeQuery();
0824: rs.next();
0825: System.out.print(rs.getDate(1));
0826: System.out.print(" was null " + rs.wasNull());
0827: worked = true;
0828:
0829: } catch (SQLException sqle) {
0830: sqleResult = sqle;
0831: // 22007 invalid date time conversion
0832: worked = "22007".equals(sqle.getSQLState());
0833: if (worked)
0834: System.out.print(sqle.getSQLState());
0835: } catch (Throwable t) {
0836: System.out.print(t.toString());
0837: worked = false;
0838: }
0839: if (rs != null)
0840: rs.close();
0841: judge_getXXX(worked, sqleResult, 10, type);
0842: }
0843:
0844: {
0845: boolean worked;
0846: SQLException sqleResult = null;
0847: ;
0848: ResultSet rs = null;
0849: try {
0850: System.out.print(" getTime=");
0851: rs = ps.executeQuery();
0852: rs.next();
0853: System.out.print(rs.getTime(1));
0854: System.out.print(" was null " + rs.wasNull());
0855: worked = true;
0856:
0857: } catch (SQLException sqle) {
0858: sqleResult = sqle;
0859: // 22007 invalid date time conversion
0860: worked = "22007".equals(sqle.getSQLState());
0861: if (worked)
0862: System.out.print(sqle.getSQLState());
0863: } catch (Throwable t) {
0864: System.out.print(t.toString());
0865: worked = false;
0866: }
0867: if (rs != null)
0868: rs.close();
0869: judge_getXXX(worked, sqleResult, 11, type);
0870: }
0871:
0872: {
0873: boolean worked;
0874: SQLException sqleResult = null;
0875: ;
0876: ResultSet rs = null;
0877: try {
0878: System.out.print(" getTimestamp=");
0879: rs = ps.executeQuery();
0880: rs.next();
0881: System.out.print(rs.getTimestamp(1));
0882: System.out.print(" was null " + rs.wasNull());
0883: worked = true;
0884:
0885: } catch (SQLException sqle) {
0886: sqleResult = sqle;
0887: // 22007 invalid date time conversion
0888: worked = "22007".equals(sqle.getSQLState());
0889: if (worked)
0890: System.out.print(sqle.getSQLState());
0891: } catch (Throwable t) {
0892: System.out.print(t.toString());
0893: worked = false;
0894: }
0895: if (rs != null)
0896: rs.close();
0897: judge_getXXX(worked, sqleResult, 12, type);
0898: }
0899:
0900: {
0901: System.out.print(" getAsciiStream=");
0902: ResultSet rs = ps.executeQuery();
0903: rs.next();
0904: boolean worked;
0905: SQLException sqleResult = null;
0906: ;
0907: try {
0908: InputStream is = rs.getAsciiStream(1);
0909: // if the value is NULL speific checks are performed below.
0910: if (!isNull || B6[13][type]) {
0911: System.out.print(is == null ? "null"
0912: : parameterMapping.showFirstTwo(is));
0913: System.out.print(" was null " + rs.wasNull());
0914: }
0915: worked = true;
0916:
0917: } catch (SQLException sqle) {
0918: sqleResult = sqle;
0919: worked = false;
0920: }
0921:
0922: // getAsciiStream on a NULL value for an invalid conversion
0923: // is handled differently in JCC to Cloudscape. On a non-NULL
0924: // value an exception is correctly raised by both JCC and CS.
0925: // here we check this specific case to reduce canon differences
0926: // between CNS and CS.
0927:
0928: boolean judge = B6[13][type]
0929: || specificCheck(rs, worked, sqleResult, isNull);
0930: rs.close();
0931: if (judge)
0932: judge_getXXX(worked, sqleResult, 13, type);
0933: }
0934:
0935: {
0936: System.out.print(" getBinaryStream=");
0937: ResultSet rs = ps.executeQuery();
0938: rs.next();
0939: boolean worked;
0940: SQLException sqleResult = null;
0941: ;
0942: try {
0943: InputStream is = rs.getBinaryStream(1);
0944: if (!isNull || B6[14][type]) {
0945: System.out.print(is == null ? "null"
0946: : parameterMapping.showFirstTwo(is));
0947: System.out.print(" was null " + rs.wasNull());
0948: }
0949: worked = true;
0950:
0951: } catch (SQLException sqle) {
0952: sqleResult = sqle;
0953: worked = false;
0954: }
0955: boolean judge = B6[14][type]
0956: || specificCheck(rs, worked, sqleResult, isNull);
0957: rs.close();
0958: if (judge)
0959: judge_getXXX(worked, sqleResult, 14, type);
0960: }
0961:
0962: {
0963: System.out.print(" getCharacterStream=");
0964: ResultSet rs = ps.executeQuery();
0965: rs.next();
0966: boolean worked;
0967: SQLException sqleResult = null;
0968: ;
0969: try {
0970: Reader r = rs.getCharacterStream(1);
0971: if (!isNull || B6[15][type]) {
0972: System.out.print(r == null ? "null"
0973: : parameterMapping.showFirstTwo(r));
0974: System.out.print(" was null " + rs.wasNull());
0975: }
0976: worked = true;
0977:
0978: } catch (SQLException sqle) {
0979: sqleResult = sqle;
0980: worked = false;
0981: }
0982: boolean judge = B6[15][type]
0983: || specificCheck(rs, worked, sqleResult, isNull);
0984: rs.close();
0985: if (judge)
0986: judge_getXXX(worked, sqleResult, 15, type);
0987: }
0988:
0989: {
0990: System.out.print(" getClob=");
0991: ResultSet rs = ps.executeQuery();
0992: rs.next();
0993: boolean worked;
0994: SQLException sqleResult = null;
0995: ;
0996: try {
0997: Clob clob = rs.getClob(1);
0998: if (!isNull || B6[16][type]) {
0999: System.out.print(clob == null ? "null" : clob
1000: .getSubString(1, 10));
1001: System.out.print(" was null " + rs.wasNull());
1002: }
1003: worked = true;
1004:
1005: } catch (SQLException sqle) {
1006: sqleResult = sqle;
1007: worked = false;
1008: }
1009: boolean judge = B6[16][type]
1010: || specificCheck(rs, worked, sqleResult, isNull);
1011: rs.close();
1012: if (judge)
1013: judge_getXXX(worked, sqleResult, 16, type);
1014: }
1015:
1016: {
1017: System.out.print(" getBlob=");
1018: ResultSet rs = ps.executeQuery();
1019: rs.next();
1020: boolean worked;
1021: SQLException sqleResult = null;
1022: ;
1023: try {
1024: Blob blob = rs.getBlob(1);
1025: if (!isNull || B6[17][type]) {
1026: System.out.print(blob == null ? "null"
1027: : parameterMapping.showFirstTwo(blob
1028: .getBinaryStream()));
1029: System.out.print(" was null " + rs.wasNull());
1030: }
1031: worked = true;
1032:
1033: } catch (SQLException sqle) {
1034: sqleResult = sqle;
1035: worked = false;
1036: }
1037: boolean judge = B6[17][type]
1038: || specificCheck(rs, worked, sqleResult, isNull);
1039: rs.close();
1040: if (judge)
1041: judge_getXXX(worked, sqleResult, 17, type);
1042: }
1043:
1044: {
1045: System.out.print(" getUnicodeStream=");
1046: ResultSet rs = ps.executeQuery();
1047: rs.next();
1048: boolean worked;
1049: SQLException sqleResult = null;
1050: ;
1051: try {
1052: InputStream is = rs.getUnicodeStream(1);
1053: System.out.print(is == null ? "null" : "data");
1054: System.out.print(" was null " + rs.wasNull());
1055: worked = true;
1056: } catch (NoSuchMethodError e) {
1057: worked = true;
1058: System.out
1059: .println("ResultSet.getUnicodeStream not present - correct for JSR169");
1060: } catch (SQLException sqle) {
1061: sqleResult = sqle;
1062: worked = false;
1063: }
1064: rs.close();
1065: if (TestUtil.HAVE_DRIVER_CLASS)
1066: judge_getXXX(worked, sqleResult, 18, type);
1067: }
1068:
1069: // Check to see getObject returns the correct type
1070: {
1071: System.out.print(" getObject=");
1072: ResultSet rs = ps.executeQuery();
1073: rs.next();
1074: SQLException sqleResult = null;
1075: ;
1076: try {
1077:
1078: String msg;
1079: if (!SQLTypes[type].equals("DECIMAL(10,5)")
1080: || HAVE_BIG_DECIMAL) {
1081: Object o = rs.getObject(1);
1082:
1083: Class cgo = B3_GET_OBJECT[type];
1084:
1085: String cname;
1086: if (cgo.equals(byte[].class))
1087: cname = "byte[]";
1088: else
1089: cname = cgo.getName();
1090:
1091: if (o == null) {
1092: msg = "null";
1093: } else if (cgo.isInstance(o)) {
1094: msg = "CORRECT :" + cgo.getName();
1095: } else {
1096: msg = "FAIL NOT :" + cgo.getName() + " is "
1097: + o.getClass().getName();
1098: }
1099: } else {
1100: msg = "ResultSet.getObject not called for DECIMAL type for JSR169";
1101: }
1102:
1103: System.out.print(msg);
1104: System.out.println(" was null " + rs.wasNull());
1105:
1106: } catch (SQLException sqle) {
1107: sqleResult = sqle;
1108: }
1109: rs.close();
1110: }
1111:
1112: }
1113:
1114: private static boolean specificCheck(ResultSet rs, boolean worked,
1115: SQLException sqleResult, boolean isNull)
1116: throws SQLException {
1117: boolean judge = true;
1118: if (worked && isNull && rs.wasNull()) {
1119: // JCC returns NULL
1120: if (isDB2jNet)
1121: judge = false;
1122: } else if (!worked && isNull) {
1123: if (!isDB2jNet && "22005".equals(sqleResult.getSQLState()))
1124: judge = false;
1125: }
1126: if (!judge)
1127: System.out.println("SPECIFIC CHECK OK");
1128:
1129: return judge;
1130: }
1131:
1132: private static void judge_getXXX(boolean worked,
1133: SQLException sqleResult, int whichCall, int type) {
1134: String msg;
1135: if (worked && B6[whichCall][type])
1136: msg = " JDBC MATCH(OK)";
1137: else if (worked)
1138: msg = " CLOUD EXT (OK)";
1139: else if (B6[whichCall][type]) {
1140: if (sqleResult != null)
1141: showException(sqleResult);
1142: msg = " JDBC FAIL " + SQLTypes[type];
1143: } else {
1144:
1145: String sqlState = sqleResult.getSQLState();
1146: if ("22005".equals(sqlState))
1147: System.out.print("IC"); // embedded invalid conversion error
1148: else if (sqlState == null) {
1149: // embedded invalid conversion error
1150: if (sqleResult
1151: .getMessage()
1152: .indexOf(
1153: "Wrong result column type for requested conversion") != -1)
1154: System.out.print("IC");
1155: else if (sqleResult != null)
1156: showException(sqleResult);
1157: } else if (sqleResult != null)
1158: showException(sqleResult);
1159:
1160: msg = " JDBC MATCH (INVALID)";
1161: }
1162:
1163: System.out.println(msg);
1164: }
1165:
1166: private static void judge_setXXX(boolean worked,
1167: SQLException sqleResult, int whichCall, int type) {
1168: String msg;
1169: if (worked && B2_MOD[whichCall][type])
1170: msg = " JDBC MATCH(OK)";
1171: else if (worked)
1172: msg = " CLOUD EXT (OK)";
1173: else if (B2_MOD[whichCall][type]) {
1174: if (sqleResult != null)
1175: showException(sqleResult);
1176: msg = " JDBC FAIL " + SQLTypes[type];
1177: } else {
1178: msg = checkForInvalidConversion(sqleResult);
1179: if (msg == null)
1180: return;
1181: }
1182:
1183: System.out.println(msg);
1184: }
1185:
1186: private static void judge_setObject(boolean worked,
1187: SQLException sqleResult, int b5o, int type) {
1188: String msg;
1189: if (worked && B5[b5o][type])
1190: msg = " JDBC MATCH(OK)";
1191: else if (worked)
1192: msg = " CLOUD EXT (OK)";
1193: else if (B5[b5o][type]) {
1194: if (sqleResult != null)
1195: showException(sqleResult);
1196: msg = " JDBC FAIL " + SQLTypes[type];
1197: } else {
1198: msg = checkForInvalidConversion(sqleResult);
1199: if (msg == null)
1200: return;
1201: }
1202:
1203: System.out.println(msg);
1204: }
1205:
1206: /**
1207: * Look for an "Invalid Conversion" exception and format it for display.
1208: *
1209: * Look for an "Invalid Conversion" exception. If one is found,
1210: * print "IC". If one is not found, dump the actual exception to
1211: * the output instead.
1212: *
1213: * Note that the actual invalid conversion exception may be wrapped
1214: * inside a BatchUpdateException, so we may need to hunt through
1215: * the exception chain to find it.
1216: */
1217: private static String checkForInvalidConversion(SQLException sqle) {
1218: if (sqle == null)
1219: return null;
1220:
1221: boolean unknownException = true;
1222: SQLException e = sqle;
1223: while (e != null && unknownException == true) {
1224: // XCL12 is temp
1225: if ("22005".equals(e.getSQLState())
1226: || "XCL12".equals(e.getSQLState())
1227: || e.getMessage().indexOf("Illegal Conv") != -1) {
1228: unknownException = false;
1229: System.out.print("IC");
1230: break;
1231: }
1232: e = e.getNextException();
1233: }
1234: if (unknownException)
1235: showException(sqle);
1236:
1237: return " JDBC MATCH (INVALID)";
1238: }
1239:
1240: private static void setXXX(Statement s, PreparedStatement psi,
1241: PreparedStatement psq, int type) throws SQLException,
1242: java.io.IOException {
1243:
1244: {
1245: s.execute("DELETE FROM PM.TYPE_AS");
1246:
1247: SQLException sqleResult = null;
1248: boolean worked;
1249: try {
1250: System.out.print(" setByte() ");
1251: psi.setByte(1, (byte) 98);
1252: psi.executeUpdate();
1253:
1254: getValidValue(psq, jdbcTypes[type]);
1255:
1256: worked = true;
1257:
1258: } catch (SQLException sqle) {
1259: sqleResult = sqle;
1260: worked = false;
1261: }
1262: judge_setXXX(worked, sqleResult, 0, type);
1263: }
1264: // and as a batch
1265: {
1266: s.execute("DELETE FROM PM.TYPE_AS");
1267:
1268: SQLException sqleResult = null;
1269: boolean worked;
1270: try {
1271: System.out.print(" setByte() as batch ");
1272: psi.setByte(1, (byte) 98);
1273: psi.addBatch();
1274: psi.executeBatch();
1275:
1276: getValidValue(psq, jdbcTypes[type]);
1277:
1278: worked = true;
1279:
1280: } catch (SQLException sqle) {
1281: sqleResult = sqle;
1282: worked = false;
1283: }
1284: judge_setXXX(worked, sqleResult, 0, type);
1285: }
1286: {
1287: s.execute("DELETE FROM PM.TYPE_AS");
1288:
1289: SQLException sqleResult = null;
1290: boolean worked;
1291: try {
1292: System.out.print(" setShort() ");
1293: psi.setShort(1, (short) 98);
1294: psi.executeUpdate();
1295:
1296: getValidValue(psq, jdbcTypes[type]);
1297:
1298: worked = true;
1299:
1300: } catch (SQLException sqle) {
1301: sqleResult = sqle;
1302: worked = false;
1303: }
1304: judge_setXXX(worked, sqleResult, 1, type);
1305: }
1306: // and as a batch
1307: {
1308: s.execute("DELETE FROM PM.TYPE_AS");
1309:
1310: SQLException sqleResult = null;
1311: boolean worked;
1312: try {
1313: System.out.print(" setShort() as batch ");
1314: psi.setShort(1, (short) 98);
1315: psi.addBatch();
1316: psi.executeBatch();
1317:
1318: getValidValue(psq, jdbcTypes[type]);
1319:
1320: worked = true;
1321:
1322: } catch (SQLException sqle) {
1323: sqleResult = sqle;
1324: worked = false;
1325: }
1326: judge_setXXX(worked, sqleResult, 1, type);
1327: }
1328: {
1329: s.execute("DELETE FROM PM.TYPE_AS");
1330:
1331: SQLException sqleResult = null;
1332: boolean worked;
1333: try {
1334: System.out.print(" setInt() ");
1335: psi.setInt(1, 98);
1336: psi.executeUpdate();
1337:
1338: getValidValue(psq, jdbcTypes[type]);
1339:
1340: worked = true;
1341:
1342: } catch (SQLException sqle) {
1343: sqleResult = sqle;
1344: worked = false;
1345: }
1346: judge_setXXX(worked, sqleResult, 2, type);
1347: }
1348: // and as a batch
1349: {
1350: s.execute("DELETE FROM PM.TYPE_AS");
1351:
1352: SQLException sqleResult = null;
1353: boolean worked;
1354: try {
1355: System.out.print(" setInt() as batch ");
1356: psi.setInt(1, 98);
1357: psi.addBatch();
1358: psi.executeBatch();
1359:
1360: getValidValue(psq, jdbcTypes[type]);
1361:
1362: worked = true;
1363:
1364: } catch (SQLException sqle) {
1365: sqleResult = sqle;
1366: worked = false;
1367: }
1368: judge_setXXX(worked, sqleResult, 2, type);
1369: }
1370: {
1371: s.execute("DELETE FROM PM.TYPE_AS");
1372:
1373: SQLException sqleResult = null;
1374: boolean worked;
1375: try {
1376: System.out.print(" setLong() ");
1377: psi.setLong(1, 98L);
1378: psi.executeUpdate();
1379:
1380: getValidValue(psq, jdbcTypes[type]);
1381:
1382: worked = true;
1383:
1384: } catch (SQLException sqle) {
1385: sqleResult = sqle;
1386: worked = false;
1387: }
1388: judge_setXXX(worked, sqleResult, 3, type);
1389: }
1390: // as a batch
1391: {
1392: s.execute("DELETE FROM PM.TYPE_AS");
1393:
1394: SQLException sqleResult = null;
1395: boolean worked;
1396: try {
1397: System.out.print(" setLong() as batch ");
1398: psi.setLong(1, 98L);
1399: psi.addBatch();
1400: psi.executeBatch();
1401:
1402: getValidValue(psq, jdbcTypes[type]);
1403:
1404: worked = true;
1405:
1406: } catch (SQLException sqle) {
1407: sqleResult = sqle;
1408: worked = false;
1409: }
1410: judge_setXXX(worked, sqleResult, 3, type);
1411: }
1412:
1413: {
1414: s.execute("DELETE FROM PM.TYPE_AS");
1415:
1416: SQLException sqleResult = null;
1417: boolean worked;
1418: try {
1419: System.out.print(" setFloat() ");
1420: psi.setFloat(1, 98.4f);
1421: psi.executeUpdate();
1422:
1423: getValidValue(psq, jdbcTypes[type]);
1424:
1425: worked = true;
1426:
1427: } catch (SQLException sqle) {
1428: sqleResult = sqle;
1429: worked = false;
1430: }
1431: judge_setXXX(worked, sqleResult, 4, type);
1432: }
1433:
1434: // and as a batch
1435: {
1436: s.execute("DELETE FROM PM.TYPE_AS");
1437:
1438: SQLException sqleResult = null;
1439: boolean worked;
1440: try {
1441: System.out.print(" setFloat() as batch ");
1442: psi.setFloat(1, 98.4f);
1443: psi.addBatch();
1444: psi.executeBatch();
1445:
1446: getValidValue(psq, jdbcTypes[type]);
1447:
1448: worked = true;
1449:
1450: } catch (SQLException sqle) {
1451: sqleResult = sqle;
1452: worked = false;
1453: }
1454: judge_setXXX(worked, sqleResult, 4, type);
1455: }
1456:
1457: {
1458: s.execute("DELETE FROM PM.TYPE_AS");
1459:
1460: SQLException sqleResult = null;
1461: boolean worked;
1462: try {
1463: System.out.print(" setDouble() ");
1464: psi.setDouble(1, 98.5);
1465: psi.executeUpdate();
1466:
1467: getValidValue(psq, jdbcTypes[type]);
1468:
1469: worked = true;
1470:
1471: } catch (SQLException sqle) {
1472: sqleResult = sqle;
1473: worked = false;
1474: }
1475: judge_setXXX(worked, sqleResult, 5, type);
1476: }
1477:
1478: // as a batch
1479: {
1480: s.execute("DELETE FROM PM.TYPE_AS");
1481:
1482: SQLException sqleResult = null;
1483: boolean worked;
1484: try {
1485: System.out.print(" setDouble() as batch ");
1486: psi.setDouble(1, 98.5);
1487: psi.addBatch();
1488: psi.executeBatch();
1489:
1490: getValidValue(psq, jdbcTypes[type]);
1491:
1492: worked = true;
1493:
1494: } catch (SQLException sqle) {
1495: sqleResult = sqle;
1496: worked = false;
1497: }
1498: judge_setXXX(worked, sqleResult, 5, type);
1499: }
1500:
1501: if (HAVE_BIG_DECIMAL) {
1502: {
1503: s.execute("DELETE FROM PM.TYPE_AS");
1504:
1505: SQLException sqleResult = null;
1506: boolean worked;
1507: try {
1508: System.out.print(" setBigDecimal() ");
1509: psi.setBigDecimal(1, new BigDecimal(99.0));
1510: psi.executeUpdate();
1511:
1512: getValidValue(psq, jdbcTypes[type]);
1513:
1514: worked = true;
1515:
1516: } catch (SQLException sqle) {
1517: sqleResult = sqle;
1518: worked = false;
1519: }
1520: judge_setXXX(worked, sqleResult, 6, type);
1521: }
1522: // as a batch
1523: {
1524: s.execute("DELETE FROM PM.TYPE_AS");
1525:
1526: SQLException sqleResult = null;
1527: boolean worked;
1528: try {
1529: System.out.print(" setBigDecimal() as batch ");
1530: psi.setBigDecimal(1, new BigDecimal(99.0));
1531: psi.addBatch();
1532: psi.executeBatch();
1533:
1534: getValidValue(psq, jdbcTypes[type]);
1535:
1536: worked = true;
1537:
1538: } catch (SQLException sqle) {
1539: sqleResult = sqle;
1540: worked = false;
1541: }
1542: judge_setXXX(worked, sqleResult, 6, type);
1543: }
1544: // null BigDecimal
1545: {
1546: s.execute("DELETE FROM PM.TYPE_AS");
1547:
1548: SQLException sqleResult = null;
1549: boolean worked;
1550: try {
1551: System.out.print(" setBigDecimal(null) ");
1552: psi.setBigDecimal(1, null);
1553: psi.executeUpdate();
1554:
1555: getValidValue(psq, jdbcTypes[type]);
1556:
1557: worked = true;
1558:
1559: } catch (SQLException sqle) {
1560: sqleResult = sqle;
1561: worked = false;
1562: }
1563: judge_setXXX(worked, sqleResult, 6, type);
1564: }
1565:
1566: // null BigDecimal
1567: {
1568: s.execute("DELETE FROM PM.TYPE_AS");
1569:
1570: SQLException sqleResult = null;
1571: boolean worked;
1572: try {
1573: System.out.print(" setBigDecimal(null) as batch ");
1574: psi.setBigDecimal(1, null);
1575: psi.addBatch();
1576: psi.executeBatch();
1577:
1578: getValidValue(psq, jdbcTypes[type]);
1579:
1580: worked = true;
1581:
1582: } catch (SQLException sqle) {
1583: sqleResult = sqle;
1584: worked = false;
1585: }
1586: judge_setXXX(worked, sqleResult, 6, type);
1587: }
1588: }
1589:
1590: {
1591: s.execute("DELETE FROM PM.TYPE_AS");
1592:
1593: SQLException sqleResult = null;
1594: boolean worked;
1595: try {
1596: System.out.print(" setBoolean() ");
1597: psi.setBoolean(1, true);
1598: psi.executeUpdate();
1599:
1600: getValidValue(psq, jdbcTypes[type]);
1601:
1602: worked = true;
1603:
1604: } catch (SQLException sqle) {
1605: sqleResult = sqle;
1606: worked = false;
1607: }
1608: judge_setXXX(worked, sqleResult, 7, type);
1609: }
1610: {
1611: s.execute("DELETE FROM PM.TYPE_AS");
1612:
1613: SQLException sqleResult = null;
1614: boolean worked;
1615: try {
1616: System.out.print(" setBoolean() as batch ");
1617: psi.setBoolean(1, true);
1618: psi.addBatch();
1619: psi.executeBatch();
1620:
1621: getValidValue(psq, jdbcTypes[type]);
1622:
1623: worked = true;
1624:
1625: } catch (SQLException sqle) {
1626: sqleResult = sqle;
1627: worked = false;
1628: }
1629: judge_setXXX(worked, sqleResult, 7, type);
1630: }
1631: {
1632: s.execute("DELETE FROM PM.TYPE_AS");
1633:
1634: SQLException sqleResult = null;
1635: boolean worked;
1636: try {
1637: System.out.print(" setString() ");
1638: psi.setString(1, "97");
1639: psi.executeUpdate();
1640:
1641: getValidValue(psq, jdbcTypes[type]);
1642:
1643: worked = true;
1644:
1645: } catch (SQLException sqle) {
1646: sqleResult = sqle;
1647: worked = false;
1648: } catch (Throwable t) {
1649: // JCC has some bugs
1650: System.out.println(t.getMessage());
1651: worked = false;
1652: sqleResult = null;
1653:
1654: }
1655: judge_setXXX(worked, sqleResult, 8, type);
1656: }
1657: // as batch
1658: {
1659: s.execute("DELETE FROM PM.TYPE_AS");
1660:
1661: SQLException sqleResult = null;
1662: boolean worked;
1663: try {
1664: System.out.print(" setString() as batch ");
1665: psi.setString(1, "97");
1666: psi.addBatch();
1667: psi.executeBatch();
1668:
1669: getValidValue(psq, jdbcTypes[type]);
1670:
1671: worked = true;
1672:
1673: } catch (SQLException sqle) {
1674: sqleResult = sqle;
1675: worked = false;
1676: } catch (Throwable t) {
1677: // JCC has some bugs
1678: System.out.println(t.getMessage());
1679: worked = false;
1680: sqleResult = null;
1681:
1682: }
1683: judge_setXXX(worked, sqleResult, 8, type);
1684: }
1685:
1686: // null String
1687: {
1688: s.execute("DELETE FROM PM.TYPE_AS");
1689:
1690: SQLException sqleResult = null;
1691: boolean worked;
1692: try {
1693: System.out.print(" setString(null) ");
1694: psi.setString(1, null);
1695: psi.executeUpdate();
1696:
1697: getValidValue(psq, jdbcTypes[type]);
1698:
1699: worked = true;
1700:
1701: } catch (SQLException sqle) {
1702: sqleResult = sqle;
1703: worked = false;
1704: } catch (Throwable t) {
1705: // JCC has some bugs
1706: System.out.println(t.getMessage());
1707: worked = false;
1708: sqleResult = null;
1709:
1710: }
1711: judge_setXXX(worked, sqleResult, 8, type);
1712: }
1713: // null String as batch
1714: {
1715: s.execute("DELETE FROM PM.TYPE_AS");
1716:
1717: SQLException sqleResult = null;
1718: boolean worked;
1719: try {
1720: System.out.print(" setString(null) as batch ");
1721: psi.setString(1, null);
1722: psi.addBatch();
1723: psi.executeBatch();
1724:
1725: getValidValue(psq, jdbcTypes[type]);
1726:
1727: worked = true;
1728:
1729: } catch (SQLException sqle) {
1730: sqleResult = sqle;
1731: worked = false;
1732: } catch (Throwable t) {
1733: // JCC has some bugs
1734: System.out.println(t.getMessage());
1735: worked = false;
1736: sqleResult = null;
1737:
1738: }
1739: judge_setXXX(worked, sqleResult, 8, type);
1740: }
1741: {
1742: s.execute("DELETE FROM PM.TYPE_AS");
1743:
1744: // Set Invalid String for nonString types (DERBY-149)
1745: testSetStringInvalidValue(type, psi);
1746: }
1747: {
1748: s.execute("DELETE FROM PM.TYPE_AS");
1749:
1750: SQLException sqleResult = null;
1751: boolean worked;
1752: try {
1753: System.out.print(" setBytes() ");
1754: byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd,
1755: (byte) 0xc3, (byte) 0x73 };
1756: psi.setBytes(1, data);
1757: psi.executeUpdate();
1758:
1759: getValidValue(psq, jdbcTypes[type]);
1760:
1761: worked = true;
1762:
1763: } catch (SQLException sqle) {
1764: sqleResult = sqle;
1765: worked = false;
1766: }
1767: judge_setXXX(worked, sqleResult, 9, type);
1768: }
1769: {
1770: s.execute("DELETE FROM PM.TYPE_AS");
1771:
1772: SQLException sqleResult = null;
1773: boolean worked;
1774: try {
1775: System.out.print(" setBytes() as batch");
1776: byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd,
1777: (byte) 0xc3, (byte) 0x73 };
1778: psi.setBytes(1, data);
1779: psi.addBatch();
1780: psi.executeBatch();
1781:
1782: getValidValue(psq, jdbcTypes[type]);
1783:
1784: worked = true;
1785:
1786: } catch (SQLException sqle) {
1787: sqleResult = sqle;
1788: worked = false;
1789: }
1790: judge_setXXX(worked, sqleResult, 9, type);
1791: }
1792: // null byte[]
1793: {
1794: s.execute("DELETE FROM PM.TYPE_AS");
1795:
1796: SQLException sqleResult = null;
1797: boolean worked;
1798: try {
1799: System.out.print(" setBytes(null) ");
1800: psi.setBytes(1, null);
1801: psi.executeUpdate();
1802:
1803: getValidValue(psq, jdbcTypes[type]);
1804:
1805: worked = true;
1806:
1807: } catch (SQLException sqle) {
1808: sqleResult = sqle;
1809: worked = false;
1810: }
1811: judge_setXXX(worked, sqleResult, 9, type);
1812: }
1813:
1814: {
1815: s.execute("DELETE FROM PM.TYPE_AS");
1816:
1817: SQLException sqleResult = null;
1818: boolean worked;
1819: try {
1820: System.out.print(" setBytes(null) as batch");
1821: psi.setBytes(1, null);
1822: psi.addBatch();
1823: psi.executeBatch();
1824:
1825: getValidValue(psq, jdbcTypes[type]);
1826:
1827: worked = true;
1828:
1829: } catch (SQLException sqle) {
1830: sqleResult = sqle;
1831: worked = false;
1832: }
1833: judge_setXXX(worked, sqleResult, 9, type);
1834: }
1835: {
1836: s.execute("DELETE FROM PM.TYPE_AS");
1837:
1838: SQLException sqleResult = null;
1839: boolean worked;
1840: try {
1841: System.out.print(" setDate() ");
1842: psi.setDate(1, java.sql.Date.valueOf("2004-02-14"));
1843: psi.executeUpdate();
1844:
1845: getValidValue(psq, jdbcTypes[type]);
1846:
1847: worked = true;
1848:
1849: } catch (SQLException sqle) {
1850: sqleResult = sqle;
1851: worked = false;
1852: }
1853: judge_setXXX(worked, sqleResult, 10, type);
1854: }
1855: {
1856: s.execute("DELETE FROM PM.TYPE_AS");
1857:
1858: SQLException sqleResult = null;
1859: boolean worked;
1860: try {
1861: System.out.print(" setDate() as batch ");
1862: psi.setDate(1, java.sql.Date.valueOf("2004-02-14"));
1863: psi.addBatch();
1864: psi.executeBatch();
1865:
1866: getValidValue(psq, jdbcTypes[type]);
1867:
1868: worked = true;
1869:
1870: } catch (SQLException sqle) {
1871: sqleResult = sqle;
1872: worked = false;
1873: }
1874: judge_setXXX(worked, sqleResult, 10, type);
1875: }
1876: // null Date
1877: {
1878: s.execute("DELETE FROM PM.TYPE_AS");
1879:
1880: SQLException sqleResult = null;
1881: boolean worked;
1882: try {
1883: System.out.print(" setDate(null) ");
1884: psi.setDate(1, null);
1885: psi.executeUpdate();
1886:
1887: getValidValue(psq, jdbcTypes[type]);
1888:
1889: worked = true;
1890:
1891: } catch (SQLException sqle) {
1892: sqleResult = sqle;
1893: worked = false;
1894: }
1895: judge_setXXX(worked, sqleResult, 10, type);
1896: }
1897:
1898: // null Date
1899: {
1900: s.execute("DELETE FROM PM.TYPE_AS");
1901:
1902: SQLException sqleResult = null;
1903: boolean worked;
1904: try {
1905: System.out.print(" setDate(null) as batch ");
1906: psi.setDate(1, null);
1907: psi.addBatch();
1908: psi.executeBatch();
1909:
1910: getValidValue(psq, jdbcTypes[type]);
1911:
1912: worked = true;
1913:
1914: } catch (SQLException sqle) {
1915: sqleResult = sqle;
1916: worked = false;
1917: }
1918: judge_setXXX(worked, sqleResult, 10, type);
1919: }
1920:
1921: {
1922: s.execute("DELETE FROM PM.TYPE_AS");
1923:
1924: SQLException sqleResult = null;
1925: boolean worked;
1926: try {
1927: System.out.print(" setTime() ");
1928: psi.setTime(1, java.sql.Time.valueOf("13:26:42"));
1929: psi.executeUpdate();
1930:
1931: getValidValue(psq, jdbcTypes[type]);
1932:
1933: worked = true;
1934:
1935: } catch (SQLException sqle) {
1936: sqleResult = sqle;
1937: worked = false;
1938: }
1939: judge_setXXX(worked, sqleResult, 11, type);
1940: }
1941: {
1942: s.execute("DELETE FROM PM.TYPE_AS");
1943:
1944: SQLException sqleResult = null;
1945: boolean worked;
1946: try {
1947: System.out.print(" setTime() as batch ");
1948: psi.setTime(1, java.sql.Time.valueOf("13:26:42"));
1949: psi.addBatch();
1950: psi.executeBatch();
1951:
1952: getValidValue(psq, jdbcTypes[type]);
1953:
1954: worked = true;
1955:
1956: } catch (SQLException sqle) {
1957: sqleResult = sqle;
1958: worked = false;
1959: }
1960: judge_setXXX(worked, sqleResult, 11, type);
1961: }
1962:
1963: {
1964: s.execute("DELETE FROM PM.TYPE_AS");
1965:
1966: SQLException sqleResult = null;
1967: boolean worked;
1968: try {
1969: System.out.print(" setTime(null) ");
1970: psi.setTime(1, null);
1971: psi.executeUpdate();
1972:
1973: getValidValue(psq, jdbcTypes[type]);
1974:
1975: worked = true;
1976:
1977: } catch (SQLException sqle) {
1978: sqleResult = sqle;
1979: worked = false;
1980: }
1981: judge_setXXX(worked, sqleResult, 11, type);
1982: }
1983: {
1984: s.execute("DELETE FROM PM.TYPE_AS");
1985:
1986: SQLException sqleResult = null;
1987: boolean worked;
1988: try {
1989: System.out.print(" setTime(null) as batch ");
1990: psi.setTime(1, null);
1991: psi.addBatch();
1992: psi.executeBatch();
1993:
1994: getValidValue(psq, jdbcTypes[type]);
1995:
1996: worked = true;
1997:
1998: } catch (SQLException sqle) {
1999: sqleResult = sqle;
2000: worked = false;
2001: }
2002: judge_setXXX(worked, sqleResult, 11, type);
2003: }
2004: {
2005: s.execute("DELETE FROM PM.TYPE_AS");
2006:
2007: SQLException sqleResult = null;
2008: boolean worked;
2009: try {
2010: System.out.print(" setTimestamp() ");
2011: psi.setTimestamp(1, java.sql.Timestamp
2012: .valueOf("2004-02-23 17:14:24.097625551"));
2013: psi.executeUpdate();
2014:
2015: getValidValue(psq, jdbcTypes[type]);
2016:
2017: worked = true;
2018:
2019: } catch (SQLException sqle) {
2020: sqleResult = sqle;
2021: worked = false;
2022: }
2023: judge_setXXX(worked, sqleResult, 12, type);
2024: }
2025: // as batch
2026: {
2027: s.execute("DELETE FROM PM.TYPE_AS");
2028:
2029: SQLException sqleResult = null;
2030: boolean worked;
2031: try {
2032: System.out.print(" setTimestamp() as batch ");
2033: psi.setTimestamp(1, java.sql.Timestamp
2034: .valueOf("2004-02-23 17:14:24.097625551"));
2035: psi.addBatch();
2036: psi.executeBatch();
2037:
2038: getValidValue(psq, jdbcTypes[type]);
2039:
2040: worked = true;
2041:
2042: } catch (SQLException sqle) {
2043: sqleResult = sqle;
2044: worked = false;
2045: }
2046: judge_setXXX(worked, sqleResult, 12, type);
2047: }
2048:
2049: {
2050: s.execute("DELETE FROM PM.TYPE_AS");
2051:
2052: SQLException sqleResult = null;
2053: boolean worked;
2054: try {
2055: System.out.print(" setTimestamp(null) ");
2056: psi.setTimestamp(1, null);
2057: psi.executeUpdate();
2058:
2059: getValidValue(psq, jdbcTypes[type]);
2060:
2061: worked = true;
2062:
2063: } catch (SQLException sqle) {
2064: sqleResult = sqle;
2065: worked = false;
2066: }
2067: judge_setXXX(worked, sqleResult, 12, type);
2068: }
2069: // as batch
2070: {
2071: s.execute("DELETE FROM PM.TYPE_AS");
2072:
2073: SQLException sqleResult = null;
2074: boolean worked;
2075: try {
2076: System.out.print(" setTimestamp(null) as batch ");
2077: psi.setTimestamp(1, null);
2078: psi.addBatch();
2079: psi.executeBatch();
2080:
2081: getValidValue(psq, jdbcTypes[type]);
2082:
2083: worked = true;
2084:
2085: } catch (SQLException sqle) {
2086: sqleResult = sqle;
2087: worked = false;
2088: }
2089: judge_setXXX(worked, sqleResult, 12, type);
2090: }
2091:
2092: {
2093: s.execute("DELETE FROM PM.TYPE_AS");
2094:
2095: SQLException sqleResult = null;
2096: boolean worked;
2097: try {
2098: System.out.print(" setAsciiStream() ");
2099: byte[] data = new byte[6];
2100: data[0] = (byte) 0x65;
2101: data[1] = (byte) 0x67;
2102: data[2] = (byte) 0x30;
2103: data[3] = (byte) 0x31;
2104: data[4] = (byte) 0x32;
2105: data[5] = (byte) 0x64;
2106:
2107: psi.setAsciiStream(1, new java.io.ByteArrayInputStream(
2108: data), 6);
2109: psi.executeUpdate();
2110: getValidValue(psq, jdbcTypes[type]);
2111:
2112: worked = true;
2113:
2114: } catch (SQLException sqle) {
2115: sqleResult = sqle;
2116: worked = false;
2117: }
2118: judge_setXXX(worked, sqleResult, 13, type);
2119: }
2120: {
2121: s.execute("DELETE FROM PM.TYPE_AS");
2122:
2123: SQLException sqleResult = null;
2124: boolean worked;
2125: try {
2126: System.out.print(" setAsciiStream() as batch ");
2127: byte[] data = new byte[6];
2128: data[0] = (byte) 0x65;
2129: data[1] = (byte) 0x67;
2130: data[2] = (byte) 0x30;
2131: data[3] = (byte) 0x31;
2132: data[4] = (byte) 0x32;
2133: data[5] = (byte) 0x64;
2134:
2135: psi.setAsciiStream(1, new java.io.ByteArrayInputStream(
2136: data), 6);
2137: psi.addBatch();
2138: psi.executeBatch();
2139: getValidValue(psq, jdbcTypes[type]);
2140:
2141: worked = true;
2142:
2143: } catch (SQLException sqle) {
2144: sqleResult = sqle;
2145: worked = false;
2146: }
2147: judge_setXXX(worked, sqleResult, 13, type);
2148: }
2149:
2150: {
2151: s.execute("DELETE FROM PM.TYPE_AS");
2152:
2153: SQLException sqleResult = null;
2154: boolean worked;
2155: try {
2156: System.out.print(" setAsciiStream(null) ");
2157: psi.setAsciiStream(1, null, 0);
2158: psi.executeUpdate();
2159: getValidValue(psq, jdbcTypes[type]);
2160:
2161: worked = true;
2162:
2163: } catch (SQLException sqle) {
2164: sqleResult = sqle;
2165: worked = false;
2166: }
2167: judge_setXXX(worked, sqleResult, 13, type);
2168: }
2169: {
2170: s.execute("DELETE FROM PM.TYPE_AS");
2171:
2172: SQLException sqleResult = null;
2173: boolean worked;
2174: try {
2175: System.out.print(" setAsciiStream(null) as batch ");
2176: psi.setAsciiStream(1, null, 0);
2177: psi.addBatch();
2178: psi.executeBatch();
2179: getValidValue(psq, jdbcTypes[type]);
2180:
2181: worked = true;
2182:
2183: } catch (SQLException sqle) {
2184: sqleResult = sqle;
2185: worked = false;
2186: }
2187: judge_setXXX(worked, sqleResult, 13, type);
2188: }
2189: {
2190: s.execute("DELETE FROM PM.TYPE_AS");
2191:
2192: SQLException sqleResult = null;
2193: boolean worked;
2194: try {
2195: System.out.print(" setBinaryStream() ");
2196: byte[] data = new byte[6];
2197: data[0] = (byte) 0x82;
2198: data[1] = (byte) 0x43;
2199: data[2] = (byte) 0xca;
2200: data[3] = (byte) 0xfe;
2201: data[4] = (byte) 0x00;
2202: data[5] = (byte) 0x32;
2203:
2204: psi.setBinaryStream(1,
2205: new java.io.ByteArrayInputStream(data), 6);
2206: psi.executeUpdate();
2207: getValidValue(psq, jdbcTypes[type]);
2208:
2209: worked = true;
2210:
2211: } catch (SQLException sqle) {
2212: sqleResult = sqle;
2213: worked = false;
2214: }
2215: judge_setXXX(worked, sqleResult, 14, type);
2216: }
2217: {
2218: s.execute("DELETE FROM PM.TYPE_AS");
2219:
2220: SQLException sqleResult = null;
2221: boolean worked;
2222: try {
2223: System.out.print(" setBinaryStream() as batch ");
2224: byte[] data = new byte[6];
2225: data[0] = (byte) 0x82;
2226: data[1] = (byte) 0x43;
2227: data[2] = (byte) 0xca;
2228: data[3] = (byte) 0xfe;
2229: data[4] = (byte) 0x00;
2230: data[5] = (byte) 0x32;
2231:
2232: psi.setBinaryStream(1,
2233: new java.io.ByteArrayInputStream(data), 6);
2234: psi.addBatch();
2235: psi.executeBatch();
2236: getValidValue(psq, jdbcTypes[type]);
2237:
2238: worked = true;
2239:
2240: } catch (SQLException sqle) {
2241: sqleResult = sqle;
2242: worked = false;
2243: }
2244: judge_setXXX(worked, sqleResult, 14, type);
2245: }
2246:
2247: {
2248: s.execute("DELETE FROM PM.TYPE_AS");
2249:
2250: SQLException sqleResult = null;
2251: boolean worked;
2252: try {
2253: System.out.print(" setBinaryStream(null) ");
2254: psi.setBinaryStream(1, null, 0);
2255: psi.executeUpdate();
2256: getValidValue(psq, jdbcTypes[type]);
2257:
2258: worked = true;
2259:
2260: } catch (SQLException sqle) {
2261: sqleResult = sqle;
2262: worked = false;
2263: }
2264: judge_setXXX(worked, sqleResult, 14, type);
2265: }
2266: {
2267: s.execute("DELETE FROM PM.TYPE_AS");
2268:
2269: SQLException sqleResult = null;
2270: boolean worked;
2271: try {
2272: System.out.print(" setBinaryStream(null) as batch ");
2273: psi.setBinaryStream(1, null, 0);
2274: psi.addBatch();
2275: psi.executeBatch();
2276: getValidValue(psq, jdbcTypes[type]);
2277:
2278: worked = true;
2279:
2280: } catch (SQLException sqle) {
2281: sqleResult = sqle;
2282: worked = false;
2283: }
2284: judge_setXXX(worked, sqleResult, 14, type);
2285: }
2286:
2287: {
2288: s.execute("DELETE FROM PM.TYPE_AS");
2289:
2290: SQLException sqleResult = null;
2291: boolean worked;
2292: try {
2293: System.out.print(" setCharacterStream() ");
2294: psi.setCharacterStream(1,
2295: new java.io.StringReader("89"), 2);
2296: psi.executeUpdate();
2297: getValidValue(psq, jdbcTypes[type]);
2298:
2299: worked = true;
2300:
2301: } catch (SQLException sqle) {
2302: sqleResult = sqle;
2303: worked = false;
2304: }
2305: judge_setXXX(worked, sqleResult, 15, type);
2306: }
2307: {
2308: s.execute("DELETE FROM PM.TYPE_AS");
2309:
2310: SQLException sqleResult = null;
2311: boolean worked;
2312: try {
2313: System.out.print(" setCharacterStream() as batch ");
2314: psi.setCharacterStream(1,
2315: new java.io.StringReader("89"), 2);
2316: psi.addBatch();
2317: psi.executeBatch();
2318: getValidValue(psq, jdbcTypes[type]);
2319:
2320: worked = true;
2321:
2322: } catch (SQLException sqle) {
2323: sqleResult = sqle;
2324: worked = false;
2325: }
2326: judge_setXXX(worked, sqleResult, 15, type);
2327: }
2328:
2329: {
2330: s.execute("DELETE FROM PM.TYPE_AS");
2331:
2332: SQLException sqleResult = null;
2333: boolean worked;
2334: try {
2335: System.out.print(" setCharacterStream(null) ");
2336: psi.setCharacterStream(1, null, 0);
2337: psi.executeUpdate();
2338: getValidValue(psq, jdbcTypes[type]);
2339:
2340: worked = true;
2341:
2342: } catch (SQLException sqle) {
2343: sqleResult = sqle;
2344: worked = false;
2345: }
2346: judge_setXXX(worked, sqleResult, 15, type);
2347: }
2348: {
2349: s.execute("DELETE FROM PM.TYPE_AS");
2350:
2351: SQLException sqleResult = null;
2352: boolean worked;
2353: try {
2354: System.out
2355: .print(" setCharacterStream(null) as batch ");
2356: psi.setCharacterStream(1, null, 0);
2357: psi.addBatch();
2358: psi.executeBatch();
2359: getValidValue(psq, jdbcTypes[type]);
2360:
2361: worked = true;
2362:
2363: } catch (SQLException sqle) {
2364: sqleResult = sqle;
2365: worked = false;
2366: }
2367: judge_setXXX(worked, sqleResult, 15, type);
2368: }
2369:
2370: {
2371: s.execute("DELETE FROM PM.TYPE_AS");
2372:
2373: SQLException sqleResult = null;
2374: boolean worked;
2375: try {
2376: System.out.print(" setClob() ");
2377:
2378: ResultSet rsc = s
2379: .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
2380: rsc.next();
2381: Clob tester = rsc.getClob(1);
2382: rsc.close();
2383:
2384: psi.setClob(1, tester);
2385: psi.executeUpdate();
2386: getValidValue(psq, jdbcTypes[type]);
2387:
2388: worked = true;
2389:
2390: } catch (SQLException sqle) {
2391: sqleResult = sqle;
2392: worked = false;
2393: }
2394: judge_setXXX(worked, sqleResult, 16, type);
2395: }
2396: {
2397: s.execute("DELETE FROM PM.TYPE_AS");
2398:
2399: SQLException sqleResult = null;
2400: boolean worked;
2401: try {
2402: System.out.print(" setClob() as batch ");
2403:
2404: ResultSet rsc = s
2405: .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
2406: rsc.next();
2407: Clob tester = rsc.getClob(1);
2408: rsc.close();
2409:
2410: psi.setClob(1, tester);
2411: psi.addBatch();
2412: psi.executeBatch();
2413: getValidValue(psq, jdbcTypes[type]);
2414:
2415: worked = true;
2416:
2417: } catch (SQLException sqle) {
2418: sqleResult = sqle;
2419: worked = false;
2420: }
2421: judge_setXXX(worked, sqleResult, 16, type);
2422: }
2423:
2424: {
2425: s.execute("DELETE FROM PM.TYPE_AS");
2426:
2427: SQLException sqleResult = null;
2428: boolean worked;
2429: try {
2430: System.out.print(" setClob(null) ");
2431:
2432: psi.setClob(1, null);
2433: psi.executeUpdate();
2434: getValidValue(psq, jdbcTypes[type]);
2435:
2436: worked = true;
2437:
2438: } catch (SQLException sqle) {
2439: sqleResult = sqle;
2440: worked = false;
2441: }
2442: judge_setXXX(worked, sqleResult, 16, type);
2443: }
2444: {
2445: s.execute("DELETE FROM PM.TYPE_AS");
2446:
2447: SQLException sqleResult = null;
2448: boolean worked;
2449: try {
2450: System.out.print(" setClob(null) as batch ");
2451:
2452: psi.setClob(1, null);
2453: psi.addBatch();
2454: psi.executeBatch();
2455: getValidValue(psq, jdbcTypes[type]);
2456:
2457: worked = true;
2458:
2459: } catch (SQLException sqle) {
2460: sqleResult = sqle;
2461: worked = false;
2462: }
2463: judge_setXXX(worked, sqleResult, 16, type);
2464: }
2465: {
2466: s.execute("DELETE FROM PM.TYPE_AS");
2467: SQLException sqleResult = null;
2468: boolean worked;
2469: try {
2470: System.out.print(" setBlob() ");
2471:
2472: ResultSet rsc = s
2473: .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
2474: rsc.next();
2475: Blob tester = rsc.getBlob(1);
2476: rsc.close();
2477:
2478: psi.setBlob(1, tester);
2479: psi.executeUpdate();
2480: getValidValue(psq, jdbcTypes[type]);
2481:
2482: worked = true;
2483:
2484: } catch (SQLException sqle) {
2485: sqleResult = sqle;
2486: worked = false;
2487: }
2488: judge_setXXX(worked, sqleResult, 17, type);
2489: }
2490: {
2491: s.execute("DELETE FROM PM.TYPE_AS");
2492: SQLException sqleResult = null;
2493: boolean worked;
2494: try {
2495: System.out.print(" setBlob() as batch ");
2496:
2497: ResultSet rsc = s
2498: .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
2499: rsc.next();
2500: Blob tester = rsc.getBlob(1);
2501: rsc.close();
2502:
2503: psi.setBlob(1, tester);
2504: psi.addBatch();
2505: psi.executeBatch();
2506: getValidValue(psq, jdbcTypes[type]);
2507:
2508: worked = true;
2509:
2510: } catch (SQLException sqle) {
2511: sqleResult = sqle;
2512: worked = false;
2513: }
2514: judge_setXXX(worked, sqleResult, 17, type);
2515: }
2516: {
2517: s.execute("DELETE FROM PM.TYPE_AS");
2518: SQLException sqleResult = null;
2519: boolean worked;
2520: try {
2521: System.out.print(" setBlob(null) ");
2522:
2523: psi.setBlob(1, null);
2524: psi.executeUpdate();
2525: getValidValue(psq, jdbcTypes[type]);
2526:
2527: worked = true;
2528:
2529: } catch (SQLException sqle) {
2530: sqleResult = sqle;
2531: worked = false;
2532: }
2533: judge_setXXX(worked, sqleResult, 17, type);
2534: }
2535: {
2536: s.execute("DELETE FROM PM.TYPE_AS");
2537: SQLException sqleResult = null;
2538: boolean worked;
2539: try {
2540: System.out.print(" setBlob(null) as batch ");
2541:
2542: psi.setBlob(1, null);
2543: psi.addBatch();
2544: psi.executeBatch();
2545: getValidValue(psq, jdbcTypes[type]);
2546:
2547: worked = true;
2548:
2549: } catch (SQLException sqle) {
2550: sqleResult = sqle;
2551: worked = false;
2552: }
2553: judge_setXXX(worked, sqleResult, 17, type);
2554: }
2555: {
2556: s.execute("DELETE FROM PM.TYPE_AS");
2557:
2558: SQLException sqleResult = null;
2559: boolean worked;
2560: try {
2561: System.out.print(" setUnicodeStream() ");
2562: byte[] data = new byte[6];
2563: data[0] = (byte) 0x82;
2564: data[1] = (byte) 0x43;
2565: data[2] = (byte) 0xca;
2566: data[3] = (byte) 0xfe;
2567: data[4] = (byte) 0x00;
2568: data[5] = (byte) 0x32;
2569:
2570: try {
2571: psi.setUnicodeStream(1,
2572: new java.io.ByteArrayInputStream(data), 6);
2573: } catch (NoSuchMethodError e) {
2574: System.out
2575: .println("ResultSet.setUnicodeStream not present - correct for JSR169");
2576: }
2577:
2578: if (TestUtil.HAVE_DRIVER_CLASS) {
2579: psi.executeUpdate();
2580: getValidValue(psq, jdbcTypes[type]);
2581: }
2582: worked = true;
2583:
2584: } catch (SQLException sqle) {
2585: sqleResult = sqle;
2586: worked = false;
2587: }
2588: if (TestUtil.HAVE_DRIVER_CLASS)
2589: judge_setXXX(worked, sqleResult, 14, type);
2590: }
2591: {
2592: s.execute("DELETE FROM PM.TYPE_AS");
2593:
2594: SQLException sqleResult = null;
2595: boolean worked;
2596: try {
2597: System.out.print(" setUnicodeStream(null) ");
2598: try {
2599: psi.setUnicodeStream(1, null, 0);
2600: } catch (NoSuchMethodError e) {
2601: System.out
2602: .println("ResultSet.setUnicodeStream not present - correct for JSR169");
2603: }
2604:
2605: if (TestUtil.HAVE_DRIVER_CLASS) {
2606: psi.executeUpdate();
2607: getValidValue(psq, jdbcTypes[type]);
2608: }
2609: worked = true;
2610:
2611: } catch (SQLException sqle) {
2612: sqleResult = sqle;
2613: worked = false;
2614: }
2615: if (TestUtil.HAVE_DRIVER_CLASS)
2616: judge_setXXX(worked, sqleResult, 14, type);
2617: }
2618:
2619: // setObject(null)
2620: {
2621: s.execute("DELETE FROM PM.TYPE_AS");
2622:
2623: SQLException sqleResult = null;
2624: boolean worked;
2625: try {
2626: // should never work!
2627: System.out.print(" setObject(null) ");
2628: psi.setObject(1, null);
2629: psi.executeUpdate();
2630: getValidValue(psq, jdbcTypes[type]);
2631:
2632: worked = true;
2633:
2634: } catch (SQLException sqle) {
2635: sqleResult = sqle;
2636: worked = false;
2637: }
2638: System.out.println(worked ? " FAIL " : (" OK " + sqleResult
2639: .getMessage()));
2640: }
2641: {
2642: s.execute("DELETE FROM PM.TYPE_AS");
2643:
2644: SQLException sqleResult = null;
2645: boolean worked;
2646: try {
2647: // should never work!
2648: System.out.print(" setObject(null) as batch ");
2649: psi.setObject(1, null);
2650: psi.addBatch();
2651: psi.executeBatch();
2652: getValidValue(psq, jdbcTypes[type]);
2653:
2654: worked = true;
2655:
2656: } catch (SQLException sqle) {
2657: sqleResult = sqle;
2658: worked = false;
2659: }
2660: System.out.println(worked ? " FAIL " : (" OK " + sqleResult
2661: .getMessage()));
2662: }
2663:
2664: setXXX_setObject(s, psi, psq, type, "46", "java.lang.String", 0);
2665: if (HAVE_BIG_DECIMAL)
2666: setXXX_setObject(s, psi, psq, type,
2667: BigDecimal.valueOf(72L), "java.math.BigDecimal", 1);
2668: setXXX_setObject(s, psi, psq, type, Boolean.TRUE,
2669: "java.lang.Boolean", 2);
2670:
2671: // DERBY-1500: setObject() should work for Byte and Short too.
2672: setXXX_setObject(s, psi, psq, type, new Byte((byte) 2),
2673: "java.lang.Byte", 13);
2674: setXXX_setObject(s, psi, psq, type, new Short((short) 11),
2675: "java.lang.Short", 14);
2676:
2677: setXXX_setObject(s, psi, psq, type, new Integer(74),
2678: "java.lang.Integer", 3);
2679: setXXX_setObject(s, psi, psq, type, new Long(79),
2680: "java.lang.Long", 4);
2681: setXXX_setObject(s, psi, psq, type, new Float(76.3f),
2682: "java.lang.Float", 5);
2683: setXXX_setObject(s, psi, psq, type, new Double(12.33d),
2684: "java.lang.Double", 6);
2685:
2686: {
2687: byte[] data = { 0x32, 0x39 };
2688: setXXX_setObject(s, psi, psq, type, data, "byte[]", 7);
2689: }
2690:
2691: setXXX_setObject(s, psi, psq, type, java.sql.Date
2692: .valueOf("2004-02-14"), "java.sql.Date", 8);
2693: setXXX_setObject(s, psi, psq, type, java.sql.Time
2694: .valueOf("13:26:42"), "java.sql.Time", 9);
2695: setXXX_setObject(s, psi, psq, type, java.sql.Timestamp
2696: .valueOf("2004-02-23 17:14:24.097625551"),
2697: "java.sql.Timestamp", 10);
2698: s.getConnection().commit();
2699:
2700: if (!isDB2jNet) {
2701: {
2702: ResultSet rsc = s
2703: .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
2704: rsc.next();
2705: Blob tester = rsc.getBlob(1);
2706: rsc.close();
2707: setXXX_setObject(s, psi, psq, type, tester,
2708: "java.sql.Blob", 11);
2709: }
2710:
2711: {
2712: ResultSet rsc = s
2713: .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
2714: rsc.next();
2715: Clob tester = rsc.getClob(1);
2716: rsc.close();
2717: setXXX_setObject(s, psi, psq, type, tester,
2718: "java.sql.Clob", 12);
2719: }
2720: }
2721: }
2722:
2723: private static void setXXX_setObject(Statement s,
2724: PreparedStatement psi, PreparedStatement psq, int type,
2725: Object value, String className, int b5o)
2726: throws SQLException, java.io.IOException {
2727: {
2728: s.execute("DELETE FROM PM.TYPE_AS");
2729:
2730: SQLException sqleResult = null;
2731: boolean worked;
2732: try {
2733: System.out.print(" setObject(" + className + ") ");
2734: psi.setObject(1, value);
2735: psi.executeUpdate();
2736: getValidValue(psq, jdbcTypes[type]);
2737:
2738: worked = true;
2739:
2740: } catch (SQLException sqle) {
2741: sqleResult = sqle;
2742: worked = false;
2743: } catch (Throwable t) {
2744: System.out.println("FAIL " + t.getMessage());
2745: return;
2746: }
2747: judge_setObject(worked, sqleResult, b5o, type);
2748: }
2749: {
2750: s.execute("DELETE FROM PM.TYPE_AS");
2751:
2752: SQLException sqleResult = null;
2753: boolean worked;
2754: try {
2755: System.out.print(" setObject(" + className
2756: + ") as batch ");
2757: psi.setObject(1, value);
2758: psi.addBatch();
2759: psi.executeBatch();
2760: getValidValue(psq, jdbcTypes[type]);
2761:
2762: worked = true;
2763:
2764: } catch (SQLException sqle) {
2765: sqleResult = sqle;
2766: worked = false;
2767: } catch (Throwable t) {
2768: System.out.println("FAIL " + t.getMessage());
2769: return;
2770: }
2771: judge_setObject(worked, sqleResult, b5o, type);
2772: }
2773: }
2774:
2775: private static void unexpectedException(SQLException sqle) {
2776:
2777: System.out.print("FAIL unexpected exception - ");
2778: showException(sqle);
2779: sqle.printStackTrace(System.out);
2780: }
2781:
2782: private static void showException(SQLException sqle) {
2783: do {
2784: String state = sqle.getSQLState();
2785: if (state == null)
2786: state = "?????";
2787:
2788: String msg = sqle.getMessage();
2789: if (msg == null)
2790: msg = "?? no message ??";
2791:
2792: System.out.print(" (" + state + "):" + msg);
2793: sqle = sqle.getNextException();
2794: } while (sqle != null);
2795: }
2796:
2797: private static boolean setValidValue(PreparedStatement ps,
2798: int param, int jdbcType) throws SQLException {
2799:
2800: switch (jdbcType) {
2801: case Types.BIT:
2802: ps.setBoolean(param, true);
2803: return true;
2804: case Types.TINYINT:
2805: ps.setByte(param, (byte) 32);
2806: return true;
2807: case Types.SMALLINT:
2808: ps.setShort(param, (short) 32);
2809: return true;
2810: case Types.INTEGER:
2811: ps.setInt(param, 32);
2812: return true;
2813: case Types.BIGINT:
2814: ps.setLong(param, 32L);
2815: return true;
2816: case Types.REAL:
2817: ps.setFloat(param, 32.0f);
2818: return true;
2819: case Types.FLOAT:
2820: case Types.DOUBLE:
2821: ps.setDouble(param, 32.0);
2822: return true;
2823: case Types.DECIMAL:
2824: BigDecimalHandler.setBigDecimalString(ps, param, "32.0");
2825: return true;
2826: case Types.CHAR:
2827: case Types.VARCHAR:
2828: case Types.LONGVARCHAR:
2829: ps.setString(param, "32");
2830: return true;
2831: case Types.BINARY:
2832: case Types.VARBINARY: {
2833: byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd,
2834: (byte) 0xc3, (byte) 0x73 };
2835: ps.setBytes(param, data);
2836: return true;
2837: }
2838: //Types.LONGVARBINARY:
2839: case Types.DATE:
2840: ps.setDate(param, java.sql.Date.valueOf("2004-02-14"));
2841: return true;
2842: case Types.TIME:
2843: ps.setTime(param, java.sql.Time.valueOf("13:26:42"));
2844: return true;
2845: case Types.TIMESTAMP:
2846: ps.setTimestamp(param, java.sql.Timestamp
2847: .valueOf("2004-02-23 17:14:24.097625551"));
2848: return true;
2849: case Types.CLOB:
2850: // JDBC 3.0 spec section 16.3.2 explictly states setCharacterStream is OK for setting a CLOB
2851: ps.setCharacterStream(param,
2852: new java.io.StringReader("67"), 2);
2853: return true;
2854: case Types.BLOB:
2855: // JDBC 3.0 spec section 16.3.2 explictly states setBinaryStream is OK for setting a BLOB
2856: {
2857: byte[] data = new byte[6];
2858: data[0] = (byte) 0x82;
2859: data[1] = (byte) 0x43;
2860: data[2] = (byte) 0xca;
2861: data[3] = (byte) 0xfe;
2862: data[4] = (byte) 0x00;
2863: data[5] = (byte) 0x32;
2864:
2865: ps.setBinaryStream(param, new java.io.ByteArrayInputStream(
2866: data), 6);
2867: return true;
2868: }
2869: default:
2870: return false;
2871: }
2872: }
2873:
2874: private static boolean getValidValue(PreparedStatement ps,
2875: int jdbcType) throws SQLException, IOException {
2876:
2877: ResultSet rs = ps.executeQuery();
2878: rs.next();
2879:
2880: switch (jdbcType) {
2881: case Types.SMALLINT:
2882: System.out.print("getShort=" + rs.getShort(1)
2883: + " was null " + rs.wasNull());
2884: return true;
2885: case Types.INTEGER:
2886: System.out.print("getInt=" + rs.getInt(1) + " was null "
2887: + rs.wasNull());
2888: return true;
2889: case Types.BIGINT:
2890: System.out.print("getLong=" + rs.getLong(1) + " was null "
2891: + rs.wasNull());
2892: return true;
2893: case Types.REAL:
2894: System.out.print("getFloat=" + rs.getFloat(1)
2895: + " was null " + rs.wasNull());
2896: return true;
2897: case Types.FLOAT:
2898: case Types.DOUBLE:
2899: System.out.print("getDouble=" + rs.getDouble(1)
2900: + " was null " + rs.wasNull());
2901: return true;
2902: case Types.DECIMAL:
2903: System.out.print("getBigDecimal="
2904: + BigDecimalHandler.getBigDecimalString(rs, 1)
2905: + " was null " + rs.wasNull());
2906: return true;
2907: case Types.CHAR:
2908: case Types.VARCHAR:
2909: case Types.LONGVARCHAR: {
2910: String s = rs.getString(1);
2911: if (s != null) {
2912: // With IBM's DB2 universal driver.
2913: // Setting a java.sql.Clob value works with
2914: // a character column but sets the value to
2915: // be the object's toString. This is probably a bug with JCC.
2916: if (s.startsWith("com.ibm.db2.jcc.")
2917: || s.startsWith("org.apache.derby.client"))
2918: s = "<OBJECT.toString()>";
2919:
2920: boolean hasNonAscii = false;
2921: // check for any characters in the control range
2922: for (int si = 0; si < s.length(); si++) {
2923: char c = s.charAt(si);
2924: if (c < (char) 0x20 || c >= (char) 0x7f) {
2925: hasNonAscii = true;
2926: break;
2927: }
2928: }
2929:
2930: if (hasNonAscii) {
2931: StringBuffer sb = new StringBuffer();
2932:
2933: sb.append("EncodedString: >");
2934: for (int si = 0; si < s.length(); si++) {
2935: sb.append(' ');
2936: sb.append((int) s.charAt(si));
2937: }
2938: sb.append(" <");
2939: s = sb.toString();
2940:
2941: }
2942: }
2943: System.out.print("getString=" + s + " was null "
2944: + rs.wasNull());
2945: return true;
2946: }
2947: case Types.BINARY:
2948: case Types.VARBINARY: {
2949: byte[] data = rs.getBytes(1);
2950: System.out.print("getBytes="
2951: + (data == null ? "null" : parameterMapping
2952: .showFirstTwo(data)));
2953: System.out.print(" was null " + rs.wasNull());
2954: return true;
2955: }
2956: case Types.LONGVARBINARY: {
2957: InputStream is = rs.getBinaryStream(1);
2958: System.out.print("getBinaryStream="
2959: + (is == null ? "null" : parameterMapping
2960: .showFirstTwo(is)));
2961: System.out.print(" was null " + rs.wasNull());
2962: return true;
2963: }
2964:
2965: case Types.DATE:
2966: System.out.print("getDate=" + rs.getDate(1) + " was null "
2967: + rs.wasNull());
2968: return true;
2969: case Types.TIME:
2970: System.out.print("getTime=" + rs.getTime(1) + " was null "
2971: + rs.wasNull());
2972: return true;
2973: case Types.TIMESTAMP:
2974: System.out.print("getTimestamp=" + rs.getTimestamp(1)
2975: + " was null " + rs.wasNull());
2976: return true;
2977: case Types.CLOB: {
2978: Clob clob = rs.getClob(1);
2979: System.out.print("getClob="
2980: + (clob == null ? "null" : parameterMapping
2981: .showFirstTwo(clob.getCharacterStream())));
2982: System.out.print(" was null " + rs.wasNull());
2983: return true;
2984: }
2985: case Types.BLOB: {
2986: Blob blob = rs.getBlob(1);
2987: System.out.print("getBlob="
2988: + (blob == null ? "null" : parameterMapping
2989: .showFirstTwo(blob.getBinaryStream())));
2990: System.out.print(" was null " + rs.wasNull());
2991: return true;
2992: }
2993: default:
2994: System.out.println("FAIL JDBC TYPE IN getValidValue "
2995: + TestUtil.sqlNameFromJdbc(jdbcType));
2996: return false;
2997: }
2998: }
2999:
3000: private static boolean getOutValue(CallableStatement cs, int param,
3001: int jdbcType) throws SQLException, IOException {
3002:
3003: switch (jdbcType) {
3004: case Types.BIT:
3005: System.out.print("cs.getBoolean=" + cs.getBoolean(param)
3006: + " was null " + cs.wasNull());
3007: return true;
3008: case Types.TINYINT:
3009: System.out.print("cs.getByte=" + cs.getByte(param)
3010: + " was null " + cs.wasNull());
3011: return true;
3012:
3013: case Types.SMALLINT:
3014: System.out.print("cs.getShort=" + cs.getShort(param)
3015: + " was null " + cs.wasNull());
3016: return true;
3017: case Types.INTEGER:
3018: System.out.print("cs.getInt=" + cs.getInt(param)
3019: + " was null " + cs.wasNull());
3020: return true;
3021: case Types.BIGINT:
3022: System.out.print("cs.getLong=" + cs.getLong(param)
3023: + " was null " + cs.wasNull());
3024: return true;
3025: case Types.REAL:
3026: System.out.print("cs.getFloat=" + cs.getFloat(param)
3027: + " was null " + cs.wasNull());
3028: return true;
3029: case Types.FLOAT:
3030: case Types.DOUBLE:
3031: System.out.print("cs.getDouble=" + cs.getDouble(param)
3032: + " was null " + cs.wasNull());
3033: return true;
3034: case Types.DECIMAL:
3035: System.out.print("cs.getBigDecimal="
3036: + BigDecimalHandler.getBigDecimalString(cs, param,
3037: jdbcType) + " was null " + cs.wasNull());
3038: return true;
3039: case Types.CHAR:
3040: case Types.VARCHAR:
3041: case Types.LONGVARCHAR:
3042: System.out.print("cs.getString=" + cs.getString(param)
3043: + " was null " + cs.wasNull());
3044: return true;
3045: case Types.BINARY:
3046: case Types.VARBINARY:
3047: case Types.LONGVARBINARY: {
3048: byte[] data = cs.getBytes(param);
3049: System.out.print("cs.getBytes="
3050: + (data == null ? "null" : parameterMapping
3051: .showFirstTwo(data)));
3052: System.out.print(" was null " + cs.wasNull());
3053: return true;
3054: }
3055:
3056: case Types.DATE:
3057: System.out.print("cs.getDate=" + cs.getDate(param)
3058: + " was null " + cs.wasNull());
3059: return true;
3060: case Types.TIME:
3061: System.out.print("cs.getTime=" + cs.getTime(param)
3062: + " was null " + cs.wasNull());
3063: return true;
3064: case Types.TIMESTAMP:
3065: System.out.print("cs.getTimestamp=" + cs.getTime(param)
3066: + " was null " + cs.wasNull());
3067: return true;
3068: case Types.CLOB: {
3069: Clob clob = cs.getClob(param);
3070: System.out.print("cs.getClob="
3071: + (clob == null ? "null" : parameterMapping
3072: .showFirstTwo(clob.getCharacterStream())));
3073: System.out.print(" was null " + cs.wasNull());
3074: return true;
3075: }
3076: case Types.BLOB: {
3077: Blob blob = cs.getBlob(param);
3078: System.out.print("cs.getBlob="
3079: + (blob == null ? "null" : parameterMapping
3080: .showFirstTwo(blob.getBinaryStream())));
3081: System.out.print(" was null " + cs.wasNull());
3082: return true;
3083: }
3084: default:
3085: System.out.println("FAIL JDBC TYPE IN getOutValue "
3086: + TestUtil.sqlNameFromJdbc(jdbcType));
3087: return false;
3088: }
3089: }
3090:
3091: static void dumpSQLExceptions(SQLException se) {
3092:
3093: while (se != null) {
3094: System.out.println("SQLSTATE(" + se.getSQLState() + "): "
3095: + se.toString());
3096: se = se.getNextException();
3097: }
3098: }
3099:
3100: /**
3101: * Test for DERBY-149 fix
3102: * Check that setString to an invalid value throws an exception
3103: * rather than causing a hang
3104: *
3105: * @param type type for SQLTypes array
3106: * @param psi - insert prepared statement.
3107: *
3108: */
3109: private static void testSetStringInvalidValue(int type,
3110: PreparedStatement psi) {
3111: // Do not perform this test for string types.
3112: // Only test for types wich will fail with setString("InvalidValue");
3113: switch (jdbcTypes[type]) {
3114: case Types.CHAR:
3115: case Types.VARCHAR:
3116: case Types.LONGVARCHAR:
3117: case Types.CLOB:
3118: return;
3119: }
3120:
3121: String sqlType = SQLTypes[type];
3122: try {
3123: System.out.print(" setString(\"Invalid Value\") ");
3124: psi.setString(1, "Invalid Value");
3125: psi.executeUpdate();
3126: // Should have gotten exception. Test fails
3127: String error = "FAIL - setString(1,\"Invalld Value\") for type "
3128: + sqlType
3129: + " did not throw an exception as expected";
3130: } catch (SQLException sqle) {
3131:
3132: if ("22018".equals(sqle.getSQLState())
3133: || "XCL12".equals(sqle.getSQLState())
3134: || "22007".equals(sqle.getSQLState())
3135: || (sqle.getMessage().indexOf(
3136: "Invalid data conversion") != -1)
3137: || (sqle.getMessage().indexOf("Illegal Conversion") != -1))
3138: System.out.println(" IC (Expected)");
3139: else
3140: dumpSQLExceptions(sqle);
3141: } catch (Exception e) {
3142: // JCC may throw Illegal argument exception for
3143: // String conversion error for date/time/timestamp
3144: if (TestUtil.isJCCFramework()
3145: && e instanceof IllegalArgumentException)
3146: System.out.println(e.getMessage());
3147: else
3148: System.out.println("FAIL: Unexpected Exception "
3149: + e.getMessage());
3150: }
3151: }
3152:
3153: private static String showFirstTwo(java.io.Reader in)
3154: throws java.io.IOException {
3155:
3156: int b1 = in.read();
3157: int b2 = in.read();
3158: in.close();
3159:
3160: return "0x" + Integer.toHexString(b1) + "," + "0x"
3161: + Integer.toHexString(b2);
3162: }
3163:
3164: private static String showFirstTwo(java.io.InputStream in)
3165: throws java.io.IOException {
3166:
3167: int b1 = in.read();
3168: int b2 = in.read();
3169: in.close();
3170:
3171: return "0x" + Integer.toHexString(b1) + "," + "0x"
3172: + Integer.toHexString(b2);
3173: }
3174:
3175: private static String showFirstTwo(byte[] data) {
3176:
3177: int b1 = data[0];
3178: int b2 = data[1];
3179:
3180: return "0x" + Integer.toHexString(((int) b1) & 0xff) + ","
3181: + "0x" + Integer.toHexString(((int) b2) & 0xff);
3182: }
3183: }
|