public short getShort(String parameterName) throws SQLException {
   checkOpen();
   try {
     return _stmt.getShort(parameterName);
   } catch (SQLException e) {
     handleException(e);
     return 0;
   }
 }
 public Object getResult(CallableStatement cs, int columnIndex)
     throws SQLException {
   short s = cs.getShort(columnIndex);
   if (cs.wasNull()) {
     return null;
   } else {
     return new Short(s);
   }
 }
 public short getShort(int parameterIndex) throws SQLException {
   checkOpen();
   try {
     return _stmt.getShort(parameterIndex);
   } catch (SQLException e) {
     handleException(e);
     return 0;
   }
 }
 public void testGetShort01() throws Throwable {
   try {
     Statement stmt = con.createStatement();
     stmt.execute("create temp table short_tab ( max_val int2, min_val int2, null_val int2 )");
     stmt.execute("insert into short_tab values (32767,-32768,null)");
     boolean ret =
         stmt.execute(
             "create or replace function "
                 + "short_proc( OUT IMAX int2, OUT IMIN int2, OUT INUL int2)  as "
                 + "'begin "
                 + "select max_val into imax from short_tab;"
                 + "select min_val into imin from short_tab;"
                 + "select null_val into inul from short_tab;"
                 + " end;' "
                 + "language plpgsql;");
   } catch (Exception ex) {
     fail(ex.getMessage());
     throw ex;
   }
   try {
     CallableStatement cstmt = con.prepareCall("{ call short_proc(?,?,?) }");
     cstmt.registerOutParameter(1, java.sql.Types.SMALLINT);
     cstmt.registerOutParameter(2, java.sql.Types.SMALLINT);
     cstmt.registerOutParameter(3, java.sql.Types.SMALLINT);
     cstmt.executeUpdate();
     assertTrue(cstmt.getShort(1) == 32767);
     assertTrue(cstmt.getShort(2) == -32768);
     cstmt.getShort(3);
     assertTrue(cstmt.wasNull());
   } catch (Exception ex) {
     fail(ex.getMessage());
   } finally {
     try {
       Statement dstmt = con.createStatement();
       dstmt.execute("drop function short_proc()");
     } catch (Exception ex) {
     }
   }
 }
示例#5
0
  /** The short value */
  @Override
  public short getShort(String name) throws SQLException {
    try {
      return _cstmt.getShort(name);
    } catch (SQLException e) {
      onSqlException(e);

      throw e;
    } catch (RuntimeException e) {
      onRuntimeException(e);

      throw e;
    }
  }
  public void test_wrapperOutputArgs() throws Exception {
    Connection conn = getConnection();
    PreparedStatement ps =
        conn.prepareStatement(
            "create procedure wrapperProc\n"
                + "(\n"
                + "    out bigintCol bigint,\n"
                + "    out booleanCol boolean,\n"
                + "    out doubleCol double,\n"
                + "    out floatCol float,\n"
                + "    out intCol int,\n"
                + "    out realCol real,\n"
                + "    out smallintCol smallint\n"
                + ")\n"
                + "language java\n"
                + "parameter style java\n"
                + "no sql\n"
                + "external name 'org.apache.derbyTesting.functionTests.tests.lang.AnsiSignatures.wrapperProc'\n");
    ps.execute();
    ps.close();

    CallableStatement cs = conn.prepareCall("call wrapperProc(  ?, ?, ?, ?, ?, ?, ? )");
    int param = 1;
    cs.registerOutParameter(param++, Types.BIGINT);
    cs.registerOutParameter(param++, Types.BOOLEAN);
    cs.registerOutParameter(param++, Types.DOUBLE);
    cs.registerOutParameter(param++, Types.FLOAT);
    cs.registerOutParameter(param++, Types.INTEGER);
    cs.registerOutParameter(param++, Types.REAL);
    cs.registerOutParameter(param++, Types.SMALLINT);

    cs.execute();
    param = 1;
    assertEquals(1L, cs.getLong(param++));
    assertEquals(true, cs.getBoolean(param++));
    assertEquals(1.0, cs.getDouble(param++), 0.0);
    assertEquals(1.0, cs.getDouble(param++), 0.0);
    assertEquals(1, cs.getInt(param++));
    assertEquals(1.0F, cs.getFloat(param++), 0.0F);
    assertEquals((short) 1, cs.getShort(param++));
  }
  /** Test of getShort method, of inteface java.sql.CallableStatement. */
  public void testGetShort() throws Exception {
    println("getShort");

    if (!isTestOutParameters()) {
      return;
    }

    CallableStatement stmt;
    short expResult = (short) 1;
    short result = (short) 0;

    try {
      stmt = prepRegAndExec("{?= call cast(1 as smallint)}", 1, Types.INTEGER);

      result = stmt.getShort(1);
    } catch (Exception ex) {
      fail(ex.getMessage());
    }

    assertEquals(expResult, result);
  }
示例#8
0
  @SuppressWarnings("unchecked")
  public static <T> T getFromStatement(ExecuteContext ctx, Class<? extends T> type, int index)
      throws SQLException {
    CallableStatement stmt = (CallableStatement) ctx.statement();

    if (type == Blob.class) {
      return (T) stmt.getBlob(index);
    } else if (type == Boolean.class) {
      return (T) checkWasNull(stmt, Boolean.valueOf(stmt.getBoolean(index)));
    } else if (type == BigInteger.class) {
      BigDecimal result = stmt.getBigDecimal(index);
      return (T) (result == null ? null : result.toBigInteger());
    } else if (type == BigDecimal.class) {
      return (T) stmt.getBigDecimal(index);
    } else if (type == Byte.class) {
      return (T) checkWasNull(stmt, Byte.valueOf(stmt.getByte(index)));
    } else if (type == byte[].class) {
      return (T) stmt.getBytes(index);
    } else if (type == Clob.class) {
      return (T) stmt.getClob(index);
    } else if (type == Date.class) {
      return (T) stmt.getDate(index);
    } else if (type == Double.class) {
      return (T) checkWasNull(stmt, Double.valueOf(stmt.getDouble(index)));
    } else if (type == Float.class) {
      return (T) checkWasNull(stmt, Float.valueOf(stmt.getFloat(index)));
    } else if (type == Integer.class) {
      return (T) checkWasNull(stmt, Integer.valueOf(stmt.getInt(index)));
    } else if (type == Long.class) {
      return (T) checkWasNull(stmt, Long.valueOf(stmt.getLong(index)));
    } else if (type == Short.class) {
      return (T) checkWasNull(stmt, Short.valueOf(stmt.getShort(index)));
    } else if (type == String.class) {
      return (T) stmt.getString(index);
    } else if (type == Time.class) {
      return (T) stmt.getTime(index);
    } else if (type == Timestamp.class) {
      return (T) stmt.getTimestamp(index);
    } else if (type == YearToMonth.class) {
      if (ctx.getDialect() == POSTGRES) {
        Object object = stmt.getObject(index);
        return (T) (object == null ? null : PostgresUtils.toYearToMonth(object));
      } else {
        String string = stmt.getString(index);
        return (T) (string == null ? null : YearToMonth.valueOf(string));
      }
    } else if (type == DayToSecond.class) {
      if (ctx.getDialect() == POSTGRES) {
        Object object = stmt.getObject(index);
        return (T) (object == null ? null : PostgresUtils.toDayToSecond(object));
      } else {
        String string = stmt.getString(index);
        return (T) (string == null ? null : DayToSecond.valueOf(string));
      }
    } else if (type == UByte.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UByte.valueOf(string));
    } else if (type == UShort.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UShort.valueOf(string));
    } else if (type == UInteger.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : UInteger.valueOf(string));
    } else if (type == ULong.class) {
      String string = stmt.getString(index);
      return (T) (string == null ? null : ULong.valueOf(string));
    }

    // The type byte[] is handled earlier. byte[][] can be handled here
    else if (type.isArray()) {
      return (T) convertArray(stmt.getObject(index), (Class<? extends Object[]>) type);
    } else if (ArrayRecord.class.isAssignableFrom(type)) {
      return (T) getArrayRecord(ctx, stmt.getArray(index), (Class<? extends ArrayRecord<?>>) type);
    } else if (EnumType.class.isAssignableFrom(type)) {
      return getEnumType(type, stmt.getString(index));
    } else if (MasterDataType.class.isAssignableFrom(type)) {
      return (T) getMasterDataType(type, stmt.getString(index));
    } else if (UDTRecord.class.isAssignableFrom(type)) {
      switch (ctx.getDialect()) {
        case POSTGRES:
          return (T) pgNewUDTRecord(type, stmt.getObject(index));
      }

      return (T) stmt.getObject(index, DataTypes.udtRecords());
    } else if (Result.class.isAssignableFrom(type)) {
      ResultSet nested = (ResultSet) stmt.getObject(index);
      return (T) getNewFactory(ctx).fetch(nested);
    } else {
      return (T) stmt.getObject(index);
    }
  }
 /** @see java.sql.CallableStatement#getShort(int) */
 public short getShort(int parameterIndex) throws SQLException {
   return original.getShort(parameterIndex);
 }
 /** @see java.sql.CallableStatement#getShort(java.lang.String) */
 public short getShort(String parameterName) throws SQLException {
   return original.getShort(parameterName);
 }
示例#11
0
  private static void callGetMethod(
      CallableStatement cs, int arg, int type, int paramType, StringBuilder strbuf)
      throws Throwable {
    switch (type) {
      case Types.BIT:
      case Types.BOOLEAN:
        strbuf.append("getBoolean(" + arg + ") = ");
        strbuf.append(cs.getBoolean(arg));
        break;

      case Types.TINYINT:
        strbuf.append("getByte(" + arg + ") = ");
        strbuf.append(Byte.toString(cs.getByte(arg)));
        break;

      case Types.SMALLINT:
        strbuf.append("getShort(" + arg + ") = ");
        strbuf.append(Short.toString(cs.getShort(arg)));
        break;

      case Types.INTEGER:
        strbuf.append("getInt(" + arg + ") = ");
        strbuf.append(Integer.toString(cs.getInt(arg)));
        break;

      case Types.BIGINT:
        strbuf.append("getLong(" + arg + ") = ");
        strbuf.append(Long.toString(cs.getLong(arg)));
        break;

      case Types.FLOAT:
      case Types.REAL:
        strbuf.append("getFloat(" + arg + ") = ");
        strbuf.append(Float.toString(cs.getFloat(arg)));
        break;

      case Types.DOUBLE:
        strbuf.append("getDouble(" + arg + ") = ");
        strbuf.append(Double.toString(cs.getDouble(arg)));
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        strbuf.append("getBigDecimal(" + arg + ") = ");
        strbuf.append(BigDecimalHandler.getBigDecimalString(cs, arg, paramType));
        break;

      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        strbuf.append("getString(" + arg + ") = ");
        String s = cs.getString(arg);
        if (s.startsWith("[B@")) s = "byte[] reference";
        strbuf.append(s);
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        strbuf.append("getBytes(" + arg + ") = ");
        byteArrayToString(cs.getBytes(arg), strbuf);
        break;

      case Types.DATE:
        strbuf.append("getDate(" + arg + ") = ");
        Date date = cs.getDate(arg);
        strbuf.append(date == null ? "null" : date.toString());
        break;

      case Types.TIME:
        strbuf.append("getTime(" + arg + ") = ");
        Time time = cs.getTime(arg);
        strbuf.append(time == null ? "null" : time.toString());
        break;

      case Types.TIMESTAMP:
        strbuf.append("getTimestamp(" + arg + ") = ");
        Timestamp timestamp = cs.getTimestamp(arg);
        strbuf.append(timestamp == null ? "null" : timestamp.toString());
        break;

      case Types.OTHER:
        strbuf.append("getObject(" + arg + ") = ");
        Object o = cs.getObject(arg);
        if (o == null) {
          strbuf.append("null");
        } else if (o instanceof byte[]) {
          byteArrayToString((byte[]) o, strbuf);
        } else {
          strbuf.append(o.toString());
        }

        break;

      default:
        throw new Throwable("TEST ERROR: unexpected type " + type);
    }
  }
 public short getShort(String parameterName) throws SQLException {
   return passThru.getShort(parameterName);
 }
 public short getShort(int parameterIndex) throws SQLException {
   return passThru.getShort(parameterIndex);
 }