private void testParameterMetaData(Connection conn) throws SQLException {
    PreparedStatement prep = conn.prepareStatement("SELECT ?, ?, ? FROM DUAL");
    ParameterMetaData pm = prep.getParameterMetaData();
    assertEquals("java.lang.String", pm.getParameterClassName(1));
    assertEquals("VARCHAR", pm.getParameterTypeName(1));
    assertEquals(3, pm.getParameterCount());
    assertEquals(ParameterMetaData.parameterModeIn, pm.getParameterMode(1));
    assertEquals(Types.VARCHAR, pm.getParameterType(1));
    assertEquals(0, pm.getPrecision(1));
    assertEquals(0, pm.getScale(1));
    assertEquals(ResultSetMetaData.columnNullableUnknown, pm.isNullable(1));
    assertEquals(pm.isSigned(1), true);
    assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(0);
    assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(4);
    prep.close();
    assertThrows(ErrorCode.OBJECT_CLOSED, pm).getPrecision(1);

    Statement stat = conn.createStatement();
    stat.execute("CREATE TABLE TEST3(ID INT, NAME VARCHAR(255), DATA DECIMAL(10,2))");
    PreparedStatement prep1 = conn.prepareStatement("UPDATE TEST3 SET ID=?, NAME=?, DATA=?");
    PreparedStatement prep2 = conn.prepareStatement("INSERT INTO TEST3 VALUES(?, ?, ?)");
    checkParameter(prep1, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
    checkParameter(prep1, 2, "java.lang.String", 12, "VARCHAR", 255, 0);
    checkParameter(prep1, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
    checkParameter(prep2, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
    checkParameter(prep2, 2, "java.lang.String", 12, "VARCHAR", 255, 0);
    checkParameter(prep2, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
    PreparedStatement prep3 =
        conn.prepareStatement("SELECT * FROM TEST3 WHERE ID=? AND NAME LIKE ? AND ?>DATA");
    checkParameter(prep3, 1, "java.lang.Integer", 4, "INTEGER", 10, 0);
    checkParameter(prep3, 2, "java.lang.String", 12, "VARCHAR", 0, 0);
    checkParameter(prep3, 3, "java.math.BigDecimal", 3, "DECIMAL", 10, 2);
    stat.execute("DROP TABLE TEST3");
  }
  @Test
  public void testParameterMetaData() throws Exception {
    assertEquals(parameters.length, paramMetaData.getParameterCount());

    for (int i = 1; i <= parameters.length; i++) {
      assertEquals(ParameterMetaData.parameterNoNulls, paramMetaData.isNullable(i));
      assertTrue(paramMetaData.isSigned(i));
      assertEquals(0, paramMetaData.getPrecision(i));
      assertEquals(0, paramMetaData.getScale(i));
      assertEquals(0, paramMetaData.getParameterType(i));
      assertNull(paramMetaData.getParameterTypeName(i));
      assertNull(paramMetaData.getParameterClassName(i));
      assertEquals(ParameterMetaData.parameterModeIn, paramMetaData.getParameterMode(i));
    }
  }
 private void checkParameter(
     PreparedStatement prep,
     int index,
     String className,
     int type,
     String typeName,
     int precision,
     int scale)
     throws SQLException {
   ParameterMetaData meta = prep.getParameterMetaData();
   assertEquals(className, meta.getParameterClassName(index));
   assertEquals(type, meta.getParameterType(index));
   assertEquals(typeName, meta.getParameterTypeName(index));
   assertEquals(precision, meta.getPrecision(index));
   assertEquals(scale, meta.getScale(index));
 }
Ejemplo n.º 4
0
 public int getScale(int param) throws SQLException {
   return realMetaData.getScale(param);
 }