/**
  * Returns the parameter precision. The value 0 is returned if the precision is not known.
  *
  * @param param the column index (1,2,...)
  * @return the precision
  */
 public int getPrecision(int param) throws SQLException {
   try {
     debugCodeCall("getPrecision", param);
     ParameterInterface p = getParameter(param);
     return MathUtils.convertLongToInt(p.getPrecision());
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
 /**
  * Returns the parameter scale. The value 0 is returned if the scale is not known.
  *
  * @param param the column index (1,2,...)
  * @return the scale
  */
 public int getScale(int param) throws SQLException {
   try {
     debugCodeCall("getScale", param);
     ParameterInterface p = getParameter(param);
     return p.getScale();
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
 /**
  * Returns the parameter type. java.sql.Types.VARCHAR is returned if the data type is not known.
  *
  * @param param the column index (1,2,...)
  * @return the data type
  */
 public int getParameterType(int param) throws SQLException {
   try {
     debugCodeCall("getParameterType", param);
     ParameterInterface p = getParameter(param);
     int type = p.getType();
     if (type == Value.UNKNOWN) {
       type = Value.STRING;
     }
     return DataType.getDataType(type).sqlType;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
 /**
  * Returns the Java class name of the parameter. "java.lang.String" is returned if the type is not
  * known.
  *
  * @param param the column index (1,2,...)
  * @return the Java class name
  */
 @Override
 public String getParameterClassName(int param) throws SQLException {
   try {
     debugCodeCall("getParameterClassName", param);
     ParameterInterface p = getParameter(param);
     int type = p.getType();
     if (type == Value.UNKNOWN) {
       type = Value.STRING;
     }
     return DataType.getTypeClassName(type);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
예제 #5
0
  @Override
  public String format(PreparedStatement stmt) {
    try {
      if (stmt instanceof JdbcPreparedStatement) {
        String sql = (String) ReflectUtil.getValue(SQL_FIELD, stmt);

        boolean insert = false;
        if (sql.toUpperCase().startsWith("INSERT INTO")) {
          int pos = sql.indexOf("(");
          sql = sql.substring(0, pos) + "SET " + sql.substring(pos + 1);
          sql = sql.substring(0, sql.indexOf(" VALUES"));
          insert = true;
        }

        CommandInterface command = (CommandInterface) ReflectUtil.getValue(COMMAND_FIELD, stmt);
        ObjectArray<? extends ParameterInterface> parameters = command.getParameters();

        int pos = 0;
        for (int i = 0; i < parameters.size(); i++) {
          ParameterInterface parameter = parameters.get(i);
          Value value = parameter.getParamValue();

          if (insert) {
            String string = "=" + value;

            pos = sql.indexOf(',', pos);
            if (pos == -1) {
              pos = sql.indexOf(')');
              sql = sql.substring(0, pos) + string;
              break;
            }

            sql = sql.substring(0, pos) + string + sql.substring(pos);
            pos += string.length() + 1;
          } else {
            pos = sql.indexOf('?');
            sql = sql.substring(0, pos) + value + sql.substring(pos + 1);
          }
        }

        return sql;
      }
    } catch (Throwable t) {
      // $FALL-THROUGH$
    }

    return super.format(stmt);
  }
 private void registerOutParameter(int parameterIndex) throws SQLException {
   try {
     checkClosed();
     if (outParameters == null) {
       maxOutParameters =
           Math.min(
               getParameterMetaData().getParameterCount(), getCheckedMetaData().getColumnCount());
       outParameters = new BitField();
     }
     checkIndexBounds(parameterIndex);
     ParameterInterface param = command.getParameters().get(--parameterIndex);
     if (!param.isValueSet()) {
       param.setValue(ValueNull.INSTANCE, false);
     }
     outParameters.set(parameterIndex);
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }