/** * Returns a <code>Reader</code> object that contains a partial <code>Clob</code> value, starting * with the character specified by pos, which is length characters in length. * * @param pos the offset to the first character of the partial value to be retrieved. The first * character in the Clob is at position 1. * @param length the length in characters of the partial value to be retrieved. * @return <code>Reader</code> through which the partial <code>Clob</code> value can be read. * @throws SQLException if pos is less than 1 or if pos is greater than the number of characters * in the <code>Clob</code> or if pos + length is greater than the number of characters in the * <code>Clob</code> */ public Reader getCharacterStream(long pos, long length) throws SQLException // @sync { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) // @sync { if (pos < 1 || (pos - 1 + length) > locator_.getMaxLength() || length < 0) // @pdc change parm check like getSubString { JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } Reader r = null; try { // @xml3 if xml column, remove xml declaration via ConvTableReader r = new ConvTableReader( new AS400JDBCInputStream(locator_), converter_.getCcsid(), converter_.bidiStringType_, isXML_); // @xml3 r.skip(pos); return r; } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } catch (IOException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } } }
/** * Set the commit mode on the system. * * @param commitMode The commit mode. * @exception SQLException If an error occurs. */ private void setCommitMode(int commitMode) throws SQLException { // If auto-commit is on, then override the commit mode // to "NONE". if (autoCommit_) // @C5D && (!newAutoCommitSupport_)) // @C5C commitMode = COMMIT_MODE_NONE_; // Act only if the server commit mode is something other // then the what was requested. if (commitMode != serverCommitMode_) { JDSQLStatement sqlStatement = new JDSQLStatement("SET TRANSACTION ISOLATION LEVEL " + COMMIT_MODE_[commitMode]); // Send the execute immediate data stream. try { DBSQLRequestDS request = null; // @P0A DBReplyRequestedDS reply = null; // @P0A try { request = DBDSPool.getDBSQLRequestDS( // @P0C DBSQLRequestDS.FUNCTIONID_EXECUTE_IMMEDIATE, id_, DBBaseRequestDS.ORS_BITMAP_RETURN_DATA + DBBaseRequestDS.ORS_BITMAP_SQLCA, 0); boolean extended = false; // @540 if (connection_.getVRM() >= JDUtilities.vrm540) extended = true; // @540 // Bidi-HCG request.setStatementText (sqlStatement.toString (), // connection_.unicodeConverter_, extended); // @C3C @P0C @540C request.setStatementText( sqlStatement.toString(), connection_.packageCCSID_Converter, extended); // Bidi-HCG request.setStatementType(sqlStatement.getNativeType()); // This statement certainly does not need a cursor, but some // versions of the system choke when none is specified. request.setCursorName("MURCH", connection_.converter_); // @P0C reply = connection_.sendAndReceive(request); // @P0C int errorClass = reply.getErrorClass(); int returnCode = reply.getReturnCode(); if (errorClass != 0) JDError.throwSQLException(connection_, id_, errorClass, returnCode); } finally { if (request != null) { request.returnToPool(); request = null; } if (reply != null) { reply.returnToPool(); reply = null; } // Only errorClass Used from reply } } catch (DBDataStreamException e) { JDError.throwSQLException(JDError.EXC_INTERNAL, e); } serverCommitMode_ = commitMode; } }
/** * Writes a String to this CLOB, starting at position <i>position</i> in the CLOB. The CLOB will * be truncated after the last character written. The <i>lengthOfWrite</i> characters written will * start from <i>offset</i> in the string that was provided by the application. * * @param position The position (1-based) in the CLOB where writes should start. * @param string The string that will be written to the CLOB. * @param offset The offset into string to start reading characters (0-based). * @param lengthOfWrite The number of characters to write. * @return The number of characters written. * @exception SQLException If there is an error accessing the CLOB value or if the position * specified is greater than the length of the CLOB. */ public int setString(long position, String string, int offset, int lengthOfWrite) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { int clobOffset = (int) position - 1; if (clobOffset < 0 || clobOffset >= maxLength_ || string == null || offset < 0 || lengthOfWrite < 0 || (offset + lengthOfWrite) > string.length() || (clobOffset + lengthOfWrite) > maxLength_) { throw JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } // We will write as many chars as we can. If our internal char array // would overflow past the 2 GB boundary, we don't throw an error, we just // return the number of chars that were set. int newSize = clobOffset + lengthOfWrite; if (newSize < 0) newSize = 0x7FFFFFFF; // In case the addition resulted in overflow. int numChars = newSize - clobOffset; int realLength = (numChars < lengthOfWrite ? numChars : lengthOfWrite); char[] charsToWrite = new char[realLength]; string.getChars(offset, offset + numChars, charsToWrite, 0); // @K2C // We don't really know if all of these chars can be written until we go to // the system, so we just return the char[] length as the number written. byte[] bytesToWrite = converter_.stringToByteArray(charsToWrite, 0, charsToWrite.length); locator_.writeData((long) clobOffset, bytesToWrite, false); // @k1A return charsToWrite.length; } }
/** * Returns the position at which a pattern is found in the CLOB. This method is not supported. * * @param pattern The pattern. * @param position The position within the CLOB to begin searching (1-based). * @return The position in the CLOB at which the pattern was found, or -1 if the pattern was not * found. * @exception SQLException If the pattern is null, the position is not valid, or an error occurs. */ public long position(String pattern, long position) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { int offset = (int) position - 1; if (pattern == null || offset < 0 || offset >= length()) { throw JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } char[] charPattern = pattern.toCharArray(); int end = (int) length() - charPattern.length; // We use a cache of chars so we don't have to read in the entire // contents of the CLOB. initCache(); for (int i = offset; i <= end; ++i) { int j = 0; int cachedChar = getCachedChar(i + j); while (j < charPattern.length && cachedChar != -1 && charPattern[j] == cachedChar) { ++j; cachedChar = getCachedChar(i + j); } if (j == charPattern.length) return i + 1; } return -1; } }
/** * Writes a String to this CLOB, starting at position <i>position</i>. The CLOB will be truncated * after the last character written. * * @param position The position (1-based) in the CLOB where writes should start. * @param stringToWrite The string that will be written to the CLOB. * @return The number of characters that were written. * @exception SQLException If there is an error accessing the CLOB or if the position specified is * greater than the length of the CLOB. */ public int setString(long position, String stringToWrite) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { int offset = (int) position - 1; if (offset < 0 || offset >= maxLength_ || stringToWrite == null) { throw JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } // We will write as many chars as we can. If our internal char array // would overflow past the 2 GB boundary, we don't throw an error, we just // return the number of chars that were set. char[] charsToWrite = stringToWrite.toCharArray(); int newSize = offset + charsToWrite.length; if (newSize < 0) newSize = 0x7FFFFFFF; // In case the addition resulted in overflow. int numChars = newSize - offset; if (numChars != charsToWrite.length) { char[] temp = charsToWrite; charsToWrite = new char[newSize]; System.arraycopy(temp, 0, charsToWrite, 0, numChars); } // We don't really know if all of these chars can be written until we go to // the system, so we just return the char[] length as the number written. byte[] bytesToWrite = converter_.stringToByteArray(charsToWrite, 0, charsToWrite.length); locator_.writeData((long) offset, bytesToWrite, false); // @K1A return charsToWrite.length; } }
/** * Returns a stream that an application can use to write a stream of Unicode characters to this * CLOB. The stream begins at position <i>position</i>, and the CLOB will be truncated after the * last character of the write. * * @param position The position (1-based) in the CLOB where writes should start. * @return An OutputStream object to which data can be written by an application. * @exception SQLException If there is an error accessing the CLOB or if the position specified is * greater than the length of the CLOB. */ public Writer setCharacterStream(long position) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free if (position <= 0 || position > maxLength_) { JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } return new AS400JDBCWriter(this, position); }
/** * Returns a stream that an application can use to write Ascii characters to this CLOB. The stream * begins at position <i>position</i>, and the CLOB will be truncated after the last character of * the write. * * @param position The position (1-based) in the CLOB where writes should start. * @return An OutputStream object to which data can be written by an application. * @exception SQLException If there is an error accessing the CLOB or if the position specified is * greater than the length of the CLOB. */ public OutputStream setAsciiStream(long position) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free if (position <= 0 || position > maxLength_) { JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } try { return new AS400JDBCClobLocatorOutputStream(this, position, ConvTable.getTable(819, null)); } catch (UnsupportedEncodingException e) { // Should never happen. JDError.throwSQLException(JDError.EXC_INTERNAL, e); return null; } }
/** * Returns the length of the current contents of the CLOB in characters. * * @return The length of the CLOB in characters. * @exception SQLException If an error occurs. */ public long length() throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { return locator_.getLength(); } }
public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter) // @P0C throws SQLException { try { typeConverter_.toBytes(value_, rawBytes, offset); } catch (ExtendedIllegalArgumentException e) { JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, e); } }
public InputStream getUnicodeStream() throws SQLException { truncated_ = 0; try { return new ReaderInputStream(new StringReader(value_), 13488); } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } }
public InputStream getAsciiStream() throws SQLException { truncated_ = 0; try { return new ByteArrayInputStream(ConvTable.getTable(819, null).stringToByteArray(value_)); } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } }
/** * Returns the entire CLOB as a character stream. * * @return The stream. * @exception SQLException If an error occurs. */ public Reader getCharacterStream() throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { try { // @xml3 if xml column, remove xml declaration via ConvTableReader return new ConvTableReader( new AS400JDBCInputStream(locator_), converter_.getCcsid(), converter_.bidiStringType_, isXML_); // @xml3 } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } } }
/** * 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); } }
public byte[] getBytes() throws SQLException { truncated_ = 0; try { return BinaryConverter.stringToBytes(getString()); } catch (NumberFormatException nfe) { // this Clob contains non-hex characters JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, nfe); return null; } }
public float getFloat() throws SQLException { truncated_ = 0; try { return (new Double(value_.trim())).floatValue(); } catch (NumberFormatException e) { JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, e); return -1; } }
public Blob getBlob() throws SQLException { truncated_ = 0; try { return new AS400JDBCBlob(BinaryConverter.stringToBytes(value_), maxLength_); } catch (NumberFormatException nfe) { // this field contains non-hex characters JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, nfe); return null; } }
public short getShort() throws SQLException { truncated_ = 0; try { return (new Double(getString().trim())).shortValue(); } catch (NumberFormatException e) { JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, e); return -1; } }
/** * Sets the cursor hold indicator. * * @param hold The cursor hold value. * @exception SQLException If a database error occurs. */ void setHoldIndicator(String hold) throws SQLException // @C1 { if (hold.equalsIgnoreCase(JDProperties.CURSORHOLD_TRUE)) holdIndicator_ = CURSOR_HOLD_TRUE; else if (hold.equalsIgnoreCase(JDProperties.CURSORHOLD_FALSE)) holdIndicator_ = CURSOR_HOLD_FALSE; else { JDError.throwSQLException(JDError.EXC_ATTRIBUTE_VALUE_INVALID); holdIndicator_ = -1; } }
/** * Returns the handle to this CLOB locator in the database. * * @return The handle to this locator in the databaes. */ int getHandle() throws SQLException // @free called from rs.updateValue(), which in turn will throw exc back to // rs.updateX() caller { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free return locator_.getHandle(); }
public Blob getBlob() throws SQLException { truncated_ = 0; try { byte[] bytes = BinaryConverter.stringToBytes(getString()); return new AS400JDBCBlob(bytes, bytes.length); } catch (NumberFormatException nfe) { // this Clob contains non-hex characters JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, nfe); return null; } }
public byte[] getBytes() throws SQLException { truncated_ = 0; outOfBounds_ = false; try { return BinaryConverter.stringToBytes(value_); } catch (NumberFormatException nfe) { // this field contains non-hex characters JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, nfe); return null; } }
/** * Truncates this CLOB to a length of <i>lengthOfCLOB</i> characters. * * @param lengthOfCLOB The length, in characters, that this CLOB should be after truncation. * @exception SQLException If there is an error accessing the CLOB or if the length specified is * greater than the length of the CLOB. */ public void truncate(long lengthOfCLOB) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { int length = (int) lengthOfCLOB; if (length < 0 || length > maxLength_) { JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } // truncate_ = length; // The host server does not currently provide a way for us // to truncate the temp space used to hold the locator data, // so we just keep track of it ourselves. This should work, // since the temp space on the system should only be valid // within the scope of our transaction/connection. That means // there's no reason to go to the system to update the data, // since no other process can get at it. locator_.writeData(length, new byte[0], 0, 0, true); // @k1A } }
/** * Commit the current transaction. * * @exception SQLException If an error occurs. */ void commit() throws SQLException { try { DBSQLRequestDS request = null; // @P0A DBReplyRequestedDS reply = null; // @P0A try { request = DBDSPool.getDBSQLRequestDS( // @P0C DBSQLRequestDS.FUNCTIONID_COMMIT, id_, DBBaseRequestDS.ORS_BITMAP_RETURN_DATA, 0); // Set cursor hold. // request.setHoldIndicator (1); // @C1 request.setHoldIndicator(getHoldIndicator()); // @C1 reply = connection_.sendAndReceive(request); // @P0C int errorClass = reply.getErrorClass(); if (errorClass != 0) { int returnCode = reply.getReturnCode(); JDError.throwSQLException(connection_, id_, errorClass, returnCode); } } finally { if (request != null) { request.returnToPool(); request = null; } if (reply != null) { reply.returnToPool(); reply = null; } // Only errorClass used from reply } } catch (DBDataStreamException e) { JDError.throwSQLException(JDError.EXC_INTERNAL, e); } resetServer(); activeLocal_ = false; // @C4C }
/** * Returns the entire CLOB as a stream of ASCII characters. * * @return The stream. * @exception SQLException If an error occurs. */ public InputStream getAsciiStream() throws SQLException { // Following Native, throw HY010 after free() has been called. Note: NullPointerException if // synchronized(null-ref) if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { try { // @xml3 if xml column, remove xml declaration via ConvTableReader return new ReaderInputStream( new ConvTableReader( new AS400JDBCInputStream(locator_), converter_.getCcsid(), converter_.bidiStringType_, isXML_), 819); // ISO 8859-1. //@xml3 } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } } }
public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter) throws SQLException { try { int bidiStringType = settings_.getBidiStringType(); // if bidiStringType is not set by user, use ccsid to get value if (bidiStringType == -1) bidiStringType = ccsidConverter.bidiStringType_; BidiConversionProperties bidiConversionProperties = new BidiConversionProperties(bidiStringType); bidiConversionProperties.setBidiImplicitReordering(settings_.getBidiImplicitReordering()); bidiConversionProperties.setBidiNumericOrderingRoundTrip(settings_.getBidiNumericOrdering()); // The length in the first 2 bytes is actually the length in characters. byte[] temp = ccsidConverter.stringToByteArray(value_, bidiConversionProperties); BinaryConverter.unsignedShortToByteArray(temp.length, rawBytes, offset); if (temp.length > maxLength_) { maxLength_ = temp.length; JDError.throwSQLException(this, JDError.EXC_INTERNAL); } System.arraycopy(temp, 0, rawBytes, offset + 2, temp.length); // The buffer we are filling with data is big enough to hold the entire field. // For varchar fields the actual data is often smaller than the field width. // That means whatever is in the buffer from the previous send is sent to the // system. The data stream includes actual data length so the old bytes are not // written to the database, but the junk left over may decrease the affectiveness // of compression. The following code will write hex 0s to the buffer when // actual length is less that field length. Note the 0s are written only if // the field length is pretty big. The data stream code (DBBaseRequestDS) // does not compress anything smaller than 1K. if ((maxLength_ > 256) && (maxLength_ - temp.length > 16)) { int stopHere = offset + 2 + maxLength_; for (int i = offset + 2 + temp.length; i < stopHere; i++) rawBytes[i] = 0x00; } } catch (Exception e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); } }
/** * Returns the position at which a pattern is found in the CLOB. This method is not supported. * * @param pattern The pattern. * @param position The position within the CLOB to begin searching (1-based). * @return The position in the CLOB at which the pattern was found, or -1 if the pattern was not * found. * @exception SQLException If the pattern is null, the position is not valid, or an error occurs. */ public long position(Clob pattern, long position) throws SQLException { if (locator_ == null) // @free JDError.throwSQLException(this, JDError.EXC_FUNCTION_SEQUENCE); // @free synchronized (locator_) { int offset = (int) position - 1; if (pattern == null || offset < 0 || offset >= length()) { throw JDError.throwSQLException(this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); } int patternLength = (int) pattern.length(); int locatorLength = (int) length(); if (patternLength > locatorLength || patternLength < 0) return -1; int end = locatorLength - patternLength; char[] charPattern = pattern .getSubString(1L, patternLength) .toCharArray(); // @CRS - Get all chars for now, improve this later. // We use a cache of chars so we don't have to read in the entire // contents of the CLOB. initCache(); for (int i = offset; i <= end; ++i) { int j = 0; int cachedChar = getCachedChar(i + j); while (j < patternLength && cachedChar != -1 && charPattern[j] == cachedChar) { ++j; cachedChar = getCachedChar(i + j); } if (j == patternLength) return i + 1; } return -1; } }
public void set(Object object, Calendar calendar, int scale) throws SQLException { String value = null; if (object instanceof String) value = (String) object; else if (object instanceof Number) value = object.toString(); else if (object instanceof Boolean) { // @PDC // if "translate boolean" == false, then use "0" and "1" values to match native driver if (settings_.getTranslateBoolean() == true) value = object.toString(); // "true" or "false" else value = ((Boolean) object).booleanValue() == true ? "1" : "0"; } else if (object instanceof Time) value = SQLTime.timeToString((Time) object, settings_, calendar); else if (object instanceof Timestamp) value = SQLTimestamp.timestampToString((Timestamp) object, calendar); else if (object instanceof java.util.Date) value = SQLDate.dateToString((java.util.Date) object, settings_, calendar); else if (object instanceof URL) value = object.toString(); else if (JDUtilities.JDBCLevel_ >= 20 && object instanceof Clob) { Clob clob = (Clob) object; value = clob.getSubString(1, (int) clob.length()); } /* ifdef JDBC40 else if(object instanceof SQLXML) //@PDA jdbc40 { SQLXML xml = (SQLXML)object; value = xml.getString(); } endif */ if (value == null) JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH); value_ = value; originalValue_ = value; // Set to the exact length. int valueLength = value_.length(); int exactLength = getDisplaySize(); if (valueLength < exactLength) { StringBuffer buffer = new StringBuffer(value_); char c = '\u0020'; for (int i = valueLength; i < exactLength; ++i) buffer.append(c); value_ = buffer.toString(); truncated_ = 0; } else if (valueLength > exactLength) { value_ = value_.substring(0, exactLength); truncated_ = valueLength - exactLength; } else truncated_ = 0; }
public InputStream getUnicodeStream() throws SQLException { truncated_ = 0; outOfBounds_ = false; // return new AS400JDBCInputStream(new JDLobLocator(locator_)); // fix this to use a Stream try { return new ByteArrayInputStream( ConvTable.getTable(13488, null) .stringToByteArray(BinaryConverter.bytesToHexString(getBytes()))); } catch (UnsupportedEncodingException e) { JDError.throwSQLException(this, JDError.EXC_INTERNAL, e); return null; } }
public byte getByte() throws SQLException { truncated_ = 0; try { // return(new Double(value_.trim())).byteValue(); //@trunc Double doubleValue = new Double(value_.trim()); // @trunc double d = doubleValue.doubleValue(); // @trunc if (d > Byte.MAX_VALUE || d < Byte.MIN_VALUE) // @trunc truncated_ = 1; // @trunc return doubleValue.byteValue(); // @trunc } catch (NumberFormatException e) { JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH, e); return -1; } }
public void set(Object object, Calendar calendar, int scale) throws SQLException { String value = null; if (object instanceof String) value = (String) object; else if (object instanceof Number) value = object.toString(); else if (object instanceof Boolean) { // if "translate boolean" == false, then use "0" and "1" values to match native driver if (settings_.getTranslateBoolean() == true) value = object.toString(); // "true" or "false" else value = ((Boolean) object).booleanValue() == true ? "1" : "0"; } else if (object instanceof Time) value = SQLTime.timeToString((Time) object, settings_, calendar); else if (object instanceof Timestamp) value = SQLTimestamp.timestampToStringTrimTrailingZeros((Timestamp) object, calendar); else if (object instanceof java.util.Date) value = SQLDate.dateToString((java.util.Date) object, settings_, calendar); else if (JDUtilities.JDBCLevel_ >= 20 && object instanceof Clob) { Clob clob = (Clob) object; value = clob.getSubString(1, (int) clob.length()); } /* ifdef JDBC40 else if(object instanceof SQLXML) { SQLXML xml = (SQLXML)object; value = xml.getString(); } endif */ if (value == null) JDError.throwSQLException(this, JDError.EXC_DATA_TYPE_MISMATCH); value_ = value; // Truncate if necessary. int valueLength = value_.length(); int truncLimit = maxLength_; if (valueLength > truncLimit) { value_ = value_.substring(0, truncLimit); truncated_ = valueLength - truncLimit; } else truncated_ = 0; outOfBounds_ = false; length_ = value_.length(); }