Package org.apache.derby.iapi.types

Examples of org.apache.derby.iapi.types.StringDataValue


               throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
                                     getParameterSQLType(parameterIndex));

        try {
            ReaderToUTF8Stream utfIn;
            final StringDataValue dvd = (StringDataValue)
                    getParms().getParameter(parameterIndex -1);
            dvd.setStreamHeaderFormat(usePreTenFiveHdrFormat());
            // Need column width to figure out if truncation is needed
            DataTypeDescriptor dtd[] = preparedStatement
                    .getParameterTypes();
            int colWidth = dtd[parameterIndex - 1].getMaximumWidth();
            // Holds either UNKNOWN_LOGICAL_LENGTH or the exact logical length.
            int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;

            if (!lengthLess) {
                // We cast the length from long to int. This wouldn't be
                // appropriate if the limit of 2G-1 is decided to be increased
                // at a later stage.
                usableLength = (int)length;
                int truncationLength = 0;

                // Currently long varchar does not allow for truncation of
                // trailing blanks.
                // For char and varchar types, current mechanism of
                // materializing when using streams seems fine given their max
                // limits.
                // This change is fix for DERBY-352: Insert of clobs using
                // streams should not materialize the entire stream into memory
                // In case of clobs, the truncation of trailing blanks is
                // factored in when reading from the stream without
                // materializing the entire stream, and so the special casing
                // for clob below.
                if (jdbcTypeId == Types.CLOB)
                {

                    // It is possible that the length of the stream passed in
                    // is greater than the column width, in which case the data
                    // from the stream needs to be truncated.
                    // usableLength is the length of the data from stream that
                    // can be inserted which is min(colWidth,length) provided
                    // length - colWidth has trailing blanks only
                    if (usableLength > colWidth) {
                        truncationLength = usableLength - colWidth;
                        usableLength = colWidth;
                    }
                }
                // Create a stream with truncation.
                utfIn = new ReaderToUTF8Stream(reader, usableLength,
                        truncationLength, getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            } else {
                // Create a stream without exactness checks,
                // but with a maximum limit.
                utfIn = new ReaderToUTF8Stream(reader, colWidth,
                        getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            }

            // JDBC is one-based, DBMS is zero-based.
            // Note that for lengthless stream, usableLength will be
            // the maximum length for the column.
View Full Code Here


        int maxLen)
    throws StandardException
  {
    int startInt;
    int lengthInt;
    StringDataValue stringResult;

    if (result == null)
    {
      result = getNewVarchar();
    }

    stringResult = (StringDataValue) result;

    /* The result is null if the receiver (this) is null or if the length is negative.
     * We will return null, which is the only sensible thing to do.
     * (If the user did not specify a length then length is not a user null.)
     */
    if (this.isNull() || start.isNull() || (length != null && length.isNull()))
    {
      stringResult.setToNull();
      return stringResult;
    }

    startInt = start.getInt();

    // If length is not specified, make it till end of the string
    if (length != null)
    {
      lengthInt = length.getInt();
    }
    else lengthInt = maxLen - startInt + 1;

    /* DB2 Compatibility: Added these checks to match DB2. We currently enforce these
     * limits in both modes. We could do these checks in DB2 mode only, if needed, so
     * leaving earlier code for out of range in for now, though will not be exercised
     */
    if ((startInt <= 0 || lengthInt < 0 || startInt > maxLen ||
        lengthInt > maxLen - startInt + 1))
      throw StandardException.newException(SQLState.LANG_SUBSTR_START_OR_LEN_OUT_OF_RANGE);
     
    // Return null if length is non-positive
    if (lengthInt < 0)
    {
      stringResult.setToNull();
      return stringResult;
    }

    /* If startInt < 0 then we count from the right of the string */
    if (startInt < 0)
    {
      // Return '' if window is to left of string.
      if (startInt + getLength() < 0 &&
        (startInt + getLength() + lengthInt <= 0))
      {
        stringResult.setValue("");
        return stringResult;
      }

      // Convert startInt to positive to get substring from right
      startInt += getLength();

      while (startInt < 0)
      {
        startInt++;
        lengthInt--;
      }
    }
    else if (startInt > 0)
    {
      /* java substring() is 0 based */
      startInt--;
    }

    /* Oracle docs don't say what happens if the window is to the
     * left of the string.  Return "" if the window
     * is to the left or right.
     */
    if (lengthInt == 0 ||
      lengthInt <= 0 - startInt ||
      startInt > getLength())
    {
      stringResult.setValue("");
      return stringResult;
    }

    if (lengthInt >= getLength() - startInt)
    {
      stringResult.setValue(getString().substring(startInt));
    }
    else
    {
      stringResult.setValue(getString().substring(startInt, startInt + lengthInt));
    }

    return stringResult;
  }
View Full Code Here

        int maxLen)
    throws StandardException
  {
    int startInt;
    int lengthInt;
    StringDataValue stringResult;

    if (result == null)
    {
      result = getNewVarchar();
    }

    stringResult = (StringDataValue) result;

    /* The result is null if the receiver (this) is null or if the length is negative.
     * We will return null, which is the only sensible thing to do.
     * (If the user did not specify a length then length is not a user null.)
     */
    if (this.isNull() || start.isNull() || (length != null && length.isNull()))
    {
      stringResult.setToNull();
      return stringResult;
    }

    startInt = start.getInt();

    // If length is not specified, make it till end of the string
    if (length != null)
    {
      lengthInt = length.getInt();
    }
    else lengthInt = maxLen - startInt + 1;

    /* DB2 Compatibility: Added these checks to match DB2. We currently enforce these
     * limits in both modes. We could do these checks in DB2 mode only, if needed, so
     * leaving earlier code for out of range in for now, though will not be exercised
     */
    if ((startInt <= 0 || lengthInt < 0 || startInt > maxLen ||
        lengthInt > maxLen - startInt + 1))
      throw StandardException.newException(SQLState.LANG_SUBSTR_START_OR_LEN_OUT_OF_RANGE);
     
    // Return null if length is non-positive
    if (lengthInt < 0)
    {
      stringResult.setToNull();
      return stringResult;
    }

    /* If startInt < 0 then we count from the right of the string */
    if (startInt < 0)
    {
      // Return '' if window is to left of string.
      if (startInt + getLength() < 0 &&
        (startInt + getLength() + lengthInt <= 0))
      {
        stringResult.setValue("");
        return stringResult;
      }

      // Convert startInt to positive to get substring from right
      startInt += getLength();

      while (startInt < 0)
      {
        startInt++;
        lengthInt--;
      }
    }
    else if (startInt > 0)
    {
      /* java substring() is 0 based */
      startInt--;
    }

    /* Oracle docs don't say what happens if the window is to the
     * left of the string.  Return "" if the window
     * is to the left or right.
     */
    if (lengthInt == 0 ||
      lengthInt <= 0 - startInt ||
      startInt > getLength())
    {
      stringResult.setValue("");
      return stringResult;
    }

    if (lengthInt >= getLength() - startInt)
    {
      stringResult.setValue(getString().substring(startInt));
    }
    else
    {
      stringResult.setValue(getString().substring(startInt, startInt + lengthInt));
    }

    return stringResult;
  }
View Full Code Here

                int maxLen)
        throws StandardException
    {
        int startInt;
        int lengthInt;
        StringDataValue stringResult;

        if (result == null)
        {
            result = getNewVarchar();
        }

        stringResult = (StringDataValue) result;

        /* The result is null if the receiver (this) is null or if the length
         * is negative.
         * We will return null, which is the only sensible thing to do.
         * (If user did not specify a length then length is not a user null.)
         */
        if (this.isNull() || start.isNull() ||
                (length != null && length.isNull()))
        {
            stringResult.setToNull();
            return stringResult;
        }

        startInt = start.getInt();

        // If length is not specified, make it till end of the string
        if (length != null)
        {
            lengthInt = length.getInt();
        }
        else lengthInt = maxLen - startInt + 1;

        /* DB2 Compatibility: Added these checks to match DB2. We currently
         * enforce these limits in both modes. We could do these checks in DB2
         * mode only, if needed, so leaving earlier code for out of range in
         * for now, though will not be exercised
         */
        if ((startInt <= 0 || lengthInt < 0 || startInt > maxLen ||
                lengthInt > maxLen - startInt + 1))
        {
            throw StandardException.newException(
                    SQLState.LANG_SUBSTR_START_OR_LEN_OUT_OF_RANGE);
        }
           
        // Return null if length is non-positive
        if (lengthInt < 0)
        {
            stringResult.setToNull();
            return stringResult;
        }

        /* If startInt < 0 then we count from the right of the string */
        if (startInt < 0)
        {
            // Return '' if window is to left of string.
            if (startInt + getLength() < 0 &&
                (startInt + getLength() + lengthInt <= 0))
            {
                stringResult.setValue("");
                return stringResult;
            }

            // Convert startInt to positive to get substring from right
            startInt += getLength();

            while (startInt < 0)
            {
                startInt++;
                lengthInt--;
            }
        }
        else if (startInt > 0)
        {
            /* java substring() is 0 based */
            startInt--;
        }

        /* Oracle docs don't say what happens if the window is to the
         * left of the string.  Return "" if the window
         * is to the left or right.
         */
        if (lengthInt == 0 ||
            lengthInt <= 0 - startInt ||
            startInt > getLength())
        {
            stringResult.setValue("");
            return stringResult;
        }

        if (lengthInt >= getLength() - startInt)
        {
            stringResult.setValue(getString().substring(startInt));
        }
        else
        {
            stringResult.setValue(
                getString().substring(startInt, startInt + lengthInt));
        }

        return stringResult;
    }
View Full Code Here

        int maxLen)
    throws StandardException
  {
    int startInt;
    int lengthInt;
    StringDataValue stringResult;

    if (result == null)
    {
      result = getNewVarchar();
    }

    stringResult = (StringDataValue) result;

    /* The result is null if the receiver (this) is null or if the length is negative.
     * We will return null, which is the only sensible thing to do.
     * (If the user did not specify a length then length is not a user null.)
     */
    if (this.isNull() || start.isNull() || (length != null && length.isNull()))
    {
      stringResult.setToNull();
      return stringResult;
    }

    startInt = start.getInt();

    // If length is not specified, make it till end of the string
    if (length != null)
    {
      lengthInt = length.getInt();
    }
    else lengthInt = maxLen - startInt + 1;

    /* DB2 Compatibility: Added these checks to match DB2. We currently enforce these
     * limits in both modes. We could do these checks in DB2 mode only, if needed, so
     * leaving earlier code for out of range in for now, though will not be exercised
     */
    if ((startInt <= 0 || lengthInt < 0 || startInt > maxLen ||
        lengthInt > maxLen - startInt + 1))
      throw StandardException.newException(SQLState.LANG_SUBSTR_START_OR_LEN_OUT_OF_RANGE);
     
    // Return null if length is non-positive
    if (lengthInt < 0)
    {
      stringResult.setToNull();
      return stringResult;
    }

    /* If startInt < 0 then we count from the right of the string */
    if (startInt < 0)
    {
      // Return '' if window is to left of string.
      if (startInt + getLength() < 0 &&
        (startInt + getLength() + lengthInt <= 0))
      {
        stringResult.setValue("");
        return stringResult;
      }

      // Convert startInt to positive to get substring from right
      startInt += getLength();

      while (startInt < 0)
      {
        startInt++;
        lengthInt--;
      }
    }
    else if (startInt > 0)
    {
      /* java substring() is 0 based */
      startInt--;
    }

    /* Oracle docs don't say what happens if the window is to the
     * left of the string.  Return "" if the window
     * is to the left or right.
     */
    if (lengthInt == 0 ||
      lengthInt <= 0 - startInt ||
      startInt > getLength())
    {
      stringResult.setValue("");
      return stringResult;
    }

    if (lengthInt >= getLength() - startInt)
    {
      stringResult.setValue(getString().substring(startInt));
    }
    else
    {
      stringResult.setValue(getString().substring(startInt, startInt + lengthInt));
    }

    return stringResult;
  }
View Full Code Here

        Statement stmt = createStatement();
        ResultSet rs = stmt.executeQuery(
                "select * from Utf8ReaderTest where id = 101");
        rs.next();
        final int size = rs.getInt(2);
        StringDataValue dvd = (StringDataValue)
                                            ((EmbedResultSet)rs).getColumn(3);
        StoreStreamClob ssClob = new StoreStreamClob(
                dvd.getStreamWithDescriptor(), (EmbedResultSet)rs);
        Reader reader = ssClob.getInternalReader(1);
        assertEquals('a', reader.read());
        // Get internal readers and do stuff.
        checkInternalStream(1, ssClob); // Get first character.
        checkInternalStream(26, ssClob); // Skip forwards inside buffer.
View Full Code Here

        setAutoCommit(false);
        Statement stmt = createStatement();
        ResultSet rs = stmt.executeQuery(
                "select * from Utf8ReaderTest where id = 100");
        rs.next();
        StringDataValue dvd = (StringDataValue)
                                            ((EmbedResultSet)rs).getColumn(3);
        StoreStreamClob ssClob = new StoreStreamClob(
                dvd.getStreamWithDescriptor(), (EmbedResultSet)rs);
        Reader reader = ssClob.getInternalReader(1);
        assertEquals('a', reader.read());
        int bufSize = 26000;
        char[] buf = new char[bufSize];
        int count = 0;
View Full Code Here

        Statement stmt = createStatement();
        ResultSet rs = stmt.executeQuery(
                // See insertTestData
                "select * from Utf8ReaderTest where id = 1");
        rs.next();
        StringDataValue dvd = (StringDataValue)
                                            ((EmbedResultSet)rs).getColumn(3);
        StoreStreamClob ssClob = new StoreStreamClob(
                dvd.getStreamWithDescriptor(), (EmbedResultSet)rs);
        Reader reader = ssClob.getInternalReader(1);
        assertEquals('B', reader.read());
        reader = ssClob.getInternalReader(24);
        assertEquals('\'', reader.read());
        reader = ssClob.getInternalReader(42);
View Full Code Here

               throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
                                     getParameterSQLType(parameterIndex));

        try {
            ReaderToUTF8Stream utfIn;
            final StringDataValue dvd = (StringDataValue)
                    getParms().getParameter(parameterIndex -1);
            dvd.setStreamHeaderFormat(usePreTenFiveHdrFormat());
            // Need column width to figure out if truncation is needed
            DataTypeDescriptor dtd[] = preparedStatement
                    .getParameterTypes();
            int colWidth = dtd[parameterIndex - 1].getMaximumWidth();
            // Holds either UNKNOWN_LOGICAL_LENGTH or the exact logical length.
            int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;

            if (!lengthLess) {
                // We cast the length from long to int. This wouldn't be
                // appropriate if the limit of 2G-1 is decided to be increased
                // at a later stage.
                usableLength = (int)length;
                int truncationLength = 0;

                // Currently long varchar does not allow for truncation of
                // trailing blanks.
                // For char and varchar types, current mechanism of
                // materializing when using streams seems fine given their max
                // limits.
                // This change is fix for DERBY-352: Insert of clobs using
                // streams should not materialize the entire stream into memory
                // In case of clobs, the truncation of trailing blanks is
                // factored in when reading from the stream without
                // materializing the entire stream, and so the special casing
                // for clob below.
                if (jdbcTypeId == Types.CLOB)
                {

                    // It is possible that the length of the stream passed in
                    // is greater than the column width, in which case the data
                    // from the stream needs to be truncated.
                    // usableLength is the length of the data from stream that
                    // can be inserted which is min(colWidth,length) provided
                    // length - colWidth has trailing blanks only
                    if (usableLength > colWidth) {
                        truncationLength = usableLength - colWidth;
                        usableLength = colWidth;
                    }
                }
                // Create a stream with truncation.
                utfIn = new ReaderToUTF8Stream(reader, usableLength,
                        truncationLength, getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            } else {
                // Create a stream without exactness checks,
                // but with a maximum limit.
                utfIn = new ReaderToUTF8Stream(reader, colWidth,
                        getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            }

            // JDBC is one-based, DBMS is zero-based.
            // Note that for lengthless stream, usableLength will be
            // the maximum length for the column.
View Full Code Here

            case Types.CLOB:
                boolean pushStack = false;
                Object syncObject = getConnectionSynchronization();
                synchronized (syncObject) {
                try {
                    StringDataValue param = (StringDataValue)
                        getParms().getParameterForGet(parameterIndex -1);
                    if (param.isNull()) {
                        break;
                    }
                    pushStack = true;
                    setupContextStack();

                    if (param.hasStream()) {
                        CharacterStreamDescriptor csd =
                            param.getStreamWithDescriptor();
                        reader = new UTF8Reader(csd, this, syncObject);
                    } else {
                        reader = new StringReader(param.getString());
                    }
                } catch (Throwable t) {
                    throw EmbedResultSet.noStateChangeException(t);
                } finally {
                    if (pushStack) {
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.types.StringDataValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.