Package org.apache.derby.client.am

Examples of org.apache.derby.client.am.SqlException


        bytesRead = in.read(clearedBytes, pos, leftToRead);
        totalBytesRead += bytesRead;
      } catch (java.io.IOException e) {
        padScalarStreamForError(leftToRead, bytesToRead);
        // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
        netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_,
                                   new ClientMessageId(SQLState.NET_IOEXCEPTION_ON_READ),
                                   new Integer(parameterIndex), e.getMessage(), e));
        return;
      }
      if (bytesRead == -1) {
        //padScalarStreamForError(leftToRead, bytesToRead);
        // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
        /*throw new SqlException(netAgent_.logWriter_,
          "End of Stream prematurely reached while reading InputStream, parameter #" +
          parameterIndex +
          ".  Remaining data has been padded with 0x0.");*/
        //is it OK to do a chain break Exception here. It's not good to
        //pad it with 0 and encrypt and send it to the server because it takes too much time
        //can't just throw a SQLException either because some of the data PRPSQLSTT etc have already
        //been sent to the server, and server is waiting for EXTDTA, server hangs for this.
        netAgent_.accumulateChainBreakingReadExceptionAndThrow(
                                     new DisconnectException(netAgent_,
                                                 new ClientMessageId(SQLState.NET_PREMATURE_EOS_DISCONNECT),
                                                 new Integer(parameterIndex)));
        return;

        /*netAgent_.accumulateReadException(
          new SqlException(netAgent_.logWriter_,
          "End of Stream prematurely reached while reading InputStream, parameter #" +
          parameterIndex +
          ".  Remaining data has been padded with 0x0."));
          return;*/
      } else {
        pos += bytesRead;
        //offset_ += bytesRead;  //comment this out for data stream encryption.
        leftToRead -= bytesRead;
      }

    } while (leftToRead > 0);

    // check to make sure that the specified length wasn't too small
    try {
      if (in.read() != -1) {
        // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
        netAgent_.accumulateReadException(new SqlException(
                                   netAgent_.logWriter_,
                                   new ClientMessageId(SQLState.NET_INPUTSTREAM_LENGTH_TOO_SMALL),
                                   new Integer(parameterIndex)));
      }
    } catch (java.io.IOException e) {
      netAgent_.accumulateReadException(new SqlException(
                                 netAgent_.logWriter_,
                                 new ClientMessageId(
                                           SQLState.NET_IOEXCEPTION_ON_STREAMLEN_VERIFICATION),
                                 new Integer(parameterIndex),
                                 e.getMessage(),
View Full Code Here


          bytesRead = in.read(bytes_, offset_, bytesToRead);
          totalBytesRead += bytesRead;
        } catch (java.io.IOException e) {
          padScalarStreamForError(leftToRead, bytesToRead);
          // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
          netAgent_.accumulateReadException(new SqlException(
                                     netAgent_.logWriter_,
                                     new ClientMessageId(SQLState.NET_IOEXCEPTION_ON_READ),
                                     new Integer(parameterIndex),
                                     e.getMessage(),
                                     e));

          return;
        }
        if (bytesRead == -1) {
          padScalarStreamForError(leftToRead, bytesToRead);
          // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
          netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_,
                                     new ClientMessageId(SQLState.NET_PREMATURE_EOS),
                                     new Integer(parameterIndex)));
          return;
        } else {
          bytesToRead -= bytesRead;
          offset_ += bytesRead;
          leftToRead -= bytesRead;
        }
      } while (bytesToRead > 0);

      bytesToRead = flushScalarStreamSegment(leftToRead, bytesToRead);
    } while (leftToRead > 0);

    // check to make sure that the specified length wasn't too small
    try {
      if (in.read() != -1) {
        // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable.
        netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_,
                                   new ClientMessageId(SQLState.NET_INPUTSTREAM_LENGTH_TOO_SMALL),
                                   new Integer(parameterIndex)));
      }
    } catch (java.io.IOException e) {
      netAgent_.accumulateReadException(new SqlException(
                                 netAgent_.logWriter_,
                                 new ClientMessageId(
                                           SQLState.NET_IOEXCEPTION_ON_STREAMLEN_VERIFICATION),
                                 new Integer(parameterIndex),
                                 e.getMessage(),
View Full Code Here

        {
            ensureLength(offset_ + 10);
            org.apache.derby.client.am.DateTime.dateToDateBytes(bytes_, offset_, date);
            offset_ += 10;
        } catch (java.io.UnsupportedEncodingException e) {
            throw new SqlException(netAgent_.logWriter_,
                    new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
                    "java.sql.Date", "DATE", e);
        }
    }
View Full Code Here

        try{
            ensureLength(offset_ + 8);
            org.apache.derby.client.am.DateTime.timeToTimeBytes(bytes_, offset_, time);
            offset_ += 8;
        } catch(UnsupportedEncodingException e) {
            throw new SqlException(netAgent_.logWriter_,
                    new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
                    "java.sql.Time", "TIME", e);
      }
    }
View Full Code Here

        try{
            ensureLength(offset_ + 26);
            org.apache.derby.client.am.DateTime.timestampToTimestampBytes(bytes_, offset_, timestamp);
            offset_ += 26;
        }catch(UnsupportedEncodingException e) {
            throw new SqlException(netAgent_.logWriter_, 
                    new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
                    "java.sql.Timestamp", "TIMESTAMP", e);
        }
    }
View Full Code Here

    final void writeSingleorMixedCcsidLDString(String s, String encoding) throws SqlException {
        byte[] b;
        try {
            b = s.getBytes(encoding);
        } catch (UnsupportedEncodingException e) {
            throw new SqlException(netAgent_.logWriter_, 
                    new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
                    "String", "byte", e);
        }
        if (b.length > 0x7FFF) {
            throw new SqlException(netAgent_.logWriter_,
                new ClientMessageId(SQLState.LANG_STRING_TOO_LONG),
                "32767");
        }
        ensureLength(offset_ + b.length + 2);
        writeLDBytesX(b.length, b);
View Full Code Here

        case ResultSet.scrollOrientation_relative__:
            return CodePoint.QRYSCRREL;

        default:
            throw new SqlException(netAgent_.logWriter_,
                new ClientMessageId(SQLState.NET_INVALID_SCROLL_ORIENTATION));
        }
    }
View Full Code Here

        checkRequiredObjects(svrcodReceived, rdbnamReceived, pkgnamcsnReceived);

        // move into a method
        netAgent_.setSvrcod(svrcod);
        if (svrcod == CodePoint.SVRCOD_WARNING) {
            netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_,
                new ClientMessageId(SQLState.DRDA_CURSOR_NOT_OPEN)));
        } else {
            agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
                new ClientMessageId(SQLState.DRDA_CONNECTION_TERMINATED),
                    SqlException.getMessageUtil().
View Full Code Here

                        o = retrievePromotedParameterIfExists(i);
                        if (o == null) {
                            try {
                                dataLength = ((java.sql.Clob) inputs[i]).length();
                            } catch (java.sql.SQLException e) {
                                throw new SqlException(netAgent_.logWriter_,
                                    new ClientMessageId(SQLState.NET_ERROR_GETTING_BLOB_LENGTH),
                                    e);
                            }
                        } else {
                            dataLength = ((Clob) o).length();
                        }
                        setFDODTALobLength(protocolTypesAndLengths, i, dataLength);
                        break;
                    case DRDAConstants.DRDA_TYPE_NLOBBYTES:
                        // check for a promoted Clob
                        o = retrievePromotedParameterIfExists(i);
                        if (o == null) {
                            try {
                                dataLength = ((java.sql.Blob) inputs[i]).length();
                            } catch (java.sql.SQLException e) {
                                throw new SqlException(netAgent_.logWriter_,
                                    new ClientMessageId(SQLState.NET_ERROR_GETTING_BLOB_LENGTH),
                                    e);
                            }
                        } else { // use promoted Blob
                            dataLength = ((Blob) o).length();
                        }
                        setFDODTALobLength(protocolTypesAndLengths, i, dataLength);
                        break;
                    case DRDAConstants.DRDA_TYPE_NLOBCMIXED:
                        // check for a promoted Clob
                        o = retrievePromotedParameterIfExists(i);
                        if (o == null) {
                            if (((Clob) inputs[i]).isString()) {
                                dataLength = ((Clob) inputs[i]).getUTF8Length();
                            } else // must be a Unicode stream
                            {
                                dataLength = ((Clob) inputs[i]).length();
                            }
                        } else { // use promoted Clob
                            dataLength = ((Clob) o).length();
                        }
                        setFDODTALobLength(protocolTypesAndLengths, i, dataLength);
                        break;
                    default:
                        throw new SqlException(netAgent_.logWriter_,
                            new ClientMessageId(SQLState.NET_UNRECOGNIZED_JDBC_TYPE),
                               new Integer(protocolTypesAndLengths[i][0]),
                               new Integer(numVars), new Integer(i));
                    }
                }
            }
            updateLengthBytes(); // for fdodta
        }
        catch ( java.sql.SQLException se )
        {
            throw new SqlException(se);
        }
    }
View Full Code Here

                                        (int) b.length(),
                                        b.getBinaryStream(),
                                        writeNullByte,
                                        index + 1);
                            } catch (java.sql.SQLException e) {
                                throw new SqlException(netAgent_.logWriter_,
                                    new ClientMessageId(SQLState.NET_ERROR_GETTING_BLOB_LENGTH),
                                    e);
                            }
                        } else if (((Blob) b).isBinaryStream()) {
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Blob) b).length(),
                                    ((Blob) b).getBinaryStream(),
                                    writeNullByte,
                                    index + 1);
                        } else { // must be a binary string
                            // note: a possible optimization is to use writeScalarLobBytes
                            //       when the input is small
                            //   use this: if (b.length () < DssConstants.MAX_DSS_LEN - 6 - 4)
                            //               writeScalarLobBytes (...)
                            // Yes, this would avoid having to new up a java.io.ByteArrayInputStream
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Blob) b).length(),
                                    ((Blob) b).getBinaryStream(),
                                    writeNullByte,
                                    index + 1);
                        }
                    }
                    // the follow types are possible due to promotion to CLOB
                    else if (
                            parameterType == Types.CLOB
                            || parameterType == Types.CHAR
                            || parameterType == Types.VARCHAR
                            || parameterType == Types.LONGVARCHAR) {
                        Clob o = (Clob) retrievePromotedParameterIfExists(index);
                        java.sql.Clob c = (o == null) ? (java.sql.Clob) inputRow[index] : o;
                        boolean isExternalClob = !(c instanceof org.apache.derby.client.am.Clob);

                        if (isExternalClob) {
                            try {
                                writeScalarStream(chainFlag,
                                        chainedWithSameCorrelator,
                                        CodePoint.EXTDTA,
                                        (int) c.length(),
                                        c.getCharacterStream(),
                                        writeNullByte,
                                        index + 1);
                            } catch (java.sql.SQLException e) {
                                throw new SqlException(netAgent_.logWriter_,
                                    new ClientMessageId(SQLState.NET_ERROR_GETTING_BLOB_LENGTH),
                                    e);
                            }
                        } else if (((Clob) c).isCharacterStream()) {
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Clob) c).length(),
                                    ((Clob) c).getCharacterStream(),
                                    writeNullByte,
                                    index + 1);
                        } else if (((Clob) c).isAsciiStream()) {
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Clob) c).length(),
                                    ((Clob) c).getAsciiStream(),
                                    writeNullByte,
                                    index + 1);
                        } else if (((Clob) c).isUnicodeStream()) {
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Clob) c).length(),
                                    ((Clob) c).getUnicodeStream(),
                                    writeNullByte,
                                    index + 1);
                        } else { // must be a String
                            // note: a possible optimization is to use writeScalarLobBytes
                            //       when the input is small.
                            //   use this: if (c.length () < DssConstants.MAX_DSS_LEN - 6 - 4)
                            //               writeScalarLobBytes (...)
                            writeScalarStream(chainFlag,
                                    chainedWithSameCorrelator,
                                    CodePoint.EXTDTA,
                                    (int) ((Clob) c).getUTF8Length(),
                                    new java.io.ByteArrayInputStream(((Clob) c).getUtf8String()),
                                    writeNullByte,
                                    index + 1);
                        }
                    }
                }
            }
        }
        catch ( java.sql.SQLException se )
        {
            throw new SqlException(se);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.derby.client.am.SqlException

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.