/** Check that the "get" conversion table looks like Table B-5 in JDBC 4.1 specification */
 @Test
 public void testTableB6() {
   SqlType[] columns = {
     SqlType.TINYINT, SqlType.SMALLINT, SqlType.INTEGER, SqlType.BIGINT,
     SqlType.REAL, SqlType.FLOAT, SqlType.DOUBLE, SqlType.DECIMAL,
     SqlType.NUMERIC, SqlType.BIT, SqlType.BOOLEAN, SqlType.CHAR,
     SqlType.VARCHAR, SqlType.LONGVARCHAR, SqlType.BINARY, SqlType.VARBINARY,
     SqlType.LONGVARBINARY, SqlType.DATE, SqlType.TIME, SqlType.TIMESTAMP,
     SqlType.CLOB, SqlType.BLOB, SqlType.ARRAY, SqlType.REF,
     SqlType.DATALINK, SqlType.STRUCT, SqlType.JAVA_OBJECT, SqlType.ROWID,
     SqlType.NCHAR, SqlType.NVARCHAR, SqlType.LONGNVARCHAR, SqlType.NCLOB,
     SqlType.SQLXML
   };
   final PrintStream out =
       CalcitePrepareImpl.DEBUG ? System.out : new PrintStream(new ByteArrayOutputStream());
   for (SqlType.Method row : SqlType.Method.values()) {
     out.print(pad(row.methodName));
     for (SqlType column : columns) {
       out.print(SqlType.canGet(row, column) ? "x " : ". ");
     }
     out.println();
   }
 }
 /** Check that the "set" conversion table looks like Table B-5 in JDBC 4.1 specification */
 @Test
 public void testTableB5() {
   SqlType[] columns = {
     SqlType.TINYINT,
     SqlType.SMALLINT,
     SqlType.INTEGER,
     SqlType.BIGINT,
     SqlType.REAL,
     SqlType.FLOAT,
     SqlType.DOUBLE,
     SqlType.DECIMAL,
     SqlType.NUMERIC,
     SqlType.BIT,
     SqlType.BOOLEAN,
     SqlType.CHAR,
     SqlType.VARCHAR,
     SqlType.LONGVARCHAR,
     SqlType.BINARY,
     SqlType.VARBINARY,
     SqlType.LONGVARBINARY,
     SqlType.DATE,
     SqlType.TIME,
     SqlType.TIMESTAMP,
     SqlType.ARRAY,
     SqlType.BLOB,
     SqlType.CLOB,
     SqlType.STRUCT,
     SqlType.REF,
     SqlType.DATALINK,
     SqlType.JAVA_OBJECT,
     SqlType.ROWID,
     SqlType.NCHAR,
     SqlType.NVARCHAR,
     SqlType.LONGNVARCHAR,
     SqlType.NCLOB,
     SqlType.SQLXML
   };
   Class[] rows = {
     String.class,
     BigDecimal.class,
     Boolean.class,
     Byte.class,
     Short.class,
     Integer.class,
     Long.class,
     Float.class,
     Double.class,
     byte[].class,
     BigInteger.class,
     java.sql.Date.class,
     Time.class,
     Timestamp.class,
     Array.class,
     Blob.class,
     Clob.class,
     Struct.class,
     Ref.class,
     URL.class,
     Class.class,
     RowId.class,
     NClob.class,
     SQLXML.class,
     Calendar.class,
     java.util.Date.class
   };
   for (Class row : rows) {
     final String s = row == Date.class ? row.getName() : row.getSimpleName();
     out.print(pad(s));
     for (SqlType column : columns) {
       out.print(SqlType.canSet(row, column) ? "x " : ". ");
     }
     out.println();
   }
 }
 /** For each (source, destination) type, make sure that we can convert bind variables. */
 @Test
 public void testParameterConvert() throws Exception {
   final StringBuilder sql = new StringBuilder("select 1");
   final Map<SqlType, Integer> map = Maps.newHashMap();
   for (Map.Entry<Class, SqlType> entry : SqlType.getSetConversions()) {
     final SqlType sqlType = entry.getValue();
     switch (sqlType) {
       case BIT:
       case LONGVARCHAR:
       case LONGVARBINARY:
       case NCHAR:
       case NVARCHAR:
       case LONGNVARCHAR:
       case BLOB:
       case CLOB:
       case NCLOB:
       case ARRAY:
       case REF:
       case STRUCT:
       case DATALINK:
       case ROWID:
       case JAVA_OBJECT:
       case SQLXML:
         continue;
     }
     if (!map.containsKey(sqlType)) {
       sql.append(", cast(? as ").append(sqlType).append(")");
       map.put(sqlType, map.size() + 1);
     }
   }
   sql.append(" from (values 1)");
   final PreparedStatement statement = localConnection.prepareStatement(sql.toString());
   for (Map.Entry<SqlType, Integer> entry : map.entrySet()) {
     statement.setNull(entry.getValue(), entry.getKey().id);
   }
   for (Map.Entry<Class, SqlType> entry : SqlType.getSetConversions()) {
     final SqlType sqlType = entry.getValue();
     if (!map.containsKey(sqlType)) {
       continue;
     }
     int param = map.get(sqlType);
     Class clazz = entry.getKey();
     for (Object sampleValue : values(sqlType.boxedClass())) {
       switch (sqlType) {
         case DATE:
         case TIME:
         case TIMESTAMP:
           continue; // FIXME
       }
       if (clazz == Calendar.class) {
         continue; // FIXME
       }
       final Object o;
       try {
         o = convert(sampleValue, clazz);
       } catch (IllegalArgumentException | ParseException e) {
         continue;
       }
       out.println(
           "check "
               + o
               + " (originally "
               + sampleValue.getClass()
               + ", now "
               + o.getClass()
               + ") converted to "
               + sqlType);
       if (o instanceof Double && o.equals(Double.POSITIVE_INFINITY)
           || o instanceof Float && o.equals(Float.POSITIVE_INFINITY)) {
         continue;
       }
       statement.setObject(param, o, sqlType.id);
       final ResultSet resultSet = statement.executeQuery();
       assertThat(resultSet.next(), is(true));
       out.println(resultSet.getString(param + 1));
     }
   }
   statement.close();
 }