Example #1
0
  public String getString() throws SQLException {
    if (savedObject_ != null) // @loch
    { // @loch
      // get value from RS.updateX(value)
      doConversion(); // @loch
      truncated_ = 0; // @loch
      return value_; // @loch
    } // @loch

    DBLobData data = locator_.retrieveData(0, locator_.getMaxLength());
    String value =
        converter_.byteArrayToString(data.getRawBytes(), data.getOffset(), data.getLength());
    truncated_ = 0; // @pda make consistent with other SQLData Clob classes
    return value;
  }
  // @pda jdbc40
  public String getNString() throws SQLException {
    truncated_ = 0;
    outOfBounds_ = false;

    if (savedObject_ != null) // @loch
    { // @loch
      // get value from RS.updateX(value)
      doConversion(); // @loch
      truncated_ = 0;
      outOfBounds_ = false; // @loch
      return value_; // @loch
    } // @loch

    DBLobData data = locator_.retrieveData(0, locator_.getMaxLength());
    String value =
        converter_.byteArrayToString(data.getRawBytes(), data.getOffset(), data.getLength());
    return value;
  }
  /**
   * Returns part of the contents of the CLOB.
   *
   * @param position The position within the CLOB (1-based).
   * @param length The number of characters to return.
   * @return The contents.
   * @exception SQLException If the position is not valid, if the length is not valid, or an error
   *     occurs.
   */
  public String getSubString(long position, int length) throws SQLException {
    if (locator_ == null) // @free
    JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free

    synchronized (locator_) {
      int offset = (int) position - 1;
      if (offset < 0 || length < 0 || (offset > length())) {
        JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);
      }

      int lengthToUse = (int) length() - offset;
      if (lengthToUse < 0) return "";
      if (lengthToUse > length) lengthToUse = length;

      // @xml4 if xml column, remove xml declaration via ConvTableReader
      if (isXML_) {
        ConvTableReader r = null;
        try {
          r =
              new ConvTableReader(
                  new AS400JDBCInputStream(locator_),
                  converter_.getCcsid(),
                  converter_.bidiStringType_,
                  isXML_); // @xml4
          r.skip(offset); // @xml4 ConvTableReader will already have skipped XML header if column is
          // XML type
          return r.read(lengthToUse); // @xml4
        } catch (Exception e) {
          JDError.throwSQLException(this, JDError.EXC_INTERNAL, e);
          return null;
        } finally {
          try {
            if (r != null) r.close();
          } catch (Exception ee) {
            JDTrace.logException(this, "getSubString r.close() threw exception", ee);
          }
        }
      }

      DBLobData data = locator_.retrieveData(offset, lengthToUse);
      int actualLength = data.getLength();
      return converter_.byteArrayToString(data.getRawBytes(), data.getOffset(), actualLength);
    }
  }
Example #4
0
  public byte[] getBytes() throws SQLException {
    if (savedObject_ != null) // @loch
    { // @loch
      // get value from RS.updateX(value)
      doConversion(); // @loch
      truncated_ = 0;
      outOfBounds_ = false; // @loch
      return value_; // @loch
    } // @loch

    int locatorLength = (int) locator_.getLength();
    if (locatorLength == 0) return new byte[0];
    DBLobData data = locator_.retrieveData(0, locatorLength);
    int actualLength = data.getLength();
    byte[] bytes = new byte[actualLength];
    System.arraycopy(data.getRawBytes(), data.getOffset(), bytes, 0, actualLength);
    truncated_ = 0;
    outOfBounds_ = false;
    return bytes;
  }