ResultSet.java
上传用户:tanyanyong
上传日期:2013-06-23
资源大小:1355k
文件大小:140k
- /**
- * The first warning reported by calls on this ResultSet is returned.
- * Subsequent ResultSet warnings will be chained to this
- * java.sql.SQLWarning.
- *
- * <p>
- * The warning chain is automatically cleared each time a new row is read.
- * </p>
- *
- * <p>
- * <B>Note:</B> This warning chain only covers warnings caused by ResultSet
- * methods. Any warnings caused by statement methods (such as reading OUT
- * parameters) will be chained on the Statement object.
- * </p>
- *
- * @return the first java.sql.SQLWarning or null;
- *
- * @exception java.sql.SQLException if a database access error occurs.
- */
- public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
- return warningChain;
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Move to an absolute row number in the result set.
- * </p>
- *
- * <p>
- * If row is positive, moves to an absolute row with respect to the
- * beginning of the result set. The first row is row 1, the second is row
- * 2, etc.
- * </p>
- *
- * <p>
- * If row is negative, moves to an absolute row position with respect to
- * the end of result set. For example, calling absolute(-1) positions the
- * cursor on the last row, absolute(-2) indicates the next-to-last row,
- * etc.
- * </p>
- *
- * <p>
- * An attempt to position the cursor beyond the first/last row in the
- * result set, leaves the cursor before/after the first/last row,
- * respectively.
- * </p>
- *
- * <p>
- * Note: Calling absolute(1) is the same as calling first(). Calling
- * absolute(-1) is the same as calling last().
- * </p>
- *
- * @param row the row number to move to
- *
- * @return true if on the result set, false if off.
- *
- * @exception SQLException if a database-access error occurs, or row is 0,
- * or result set type is TYPE_FORWARD_ONLY.
- */
- public boolean absolute(int row) throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { new Integer(row) };
- Debug.methodCall(this, "absolute", args);
- }
- checkClosed();
- boolean b;
- if (rowData.size() == 0) {
- b = false;
- } else {
- if (row == 0) {
- throw new SQLException("Cannot absolute position to row 0",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- if (row == 1) {
- b = first();
- } else if (row == -1) {
- b = last();
- } else if (row > rowData.size()) {
- afterLast();
- b = false;
- } else {
- if (row < 0) {
- // adjust to reflect after end of result set
- int newRowPosition = rowData.size() + row + 1;
- if (newRowPosition <= 0) {
- beforeFirst();
- b = false;
- } else {
- b = absolute(newRowPosition);
- }
- } else {
- row--; // adjust for index difference
- rowData.setCurrentRow(row);
- thisRow = (byte[][]) rowData.getAt(row);
- b = true;
- }
- }
- }
- if (Driver.TRACE) {
- Debug.returnValue(this, "absolute", new Boolean(b));
- }
- return b;
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves to the end of the result set, just after the last row. Has no
- * effect if the result set contains no rows.
- * </p>
- *
- * @exception SQLException if a database-access error occurs, or result set
- * type is TYPE_FORWARD_ONLY.
- */
- public void afterLast() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "afterLast", args);
- }
- checkClosed();
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- if (rowData.size() != 0) {
- rowData.afterLast();
- thisRow = null;
- }
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves to the front of the result set, just before the first row. Has no
- * effect if the result set contains no rows.
- * </p>
- *
- * @exception SQLException if a database-access error occurs, or result set
- * type is TYPE_FORWARD_ONLY
- */
- public void beforeFirst() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "beforeFirst", args);
- }
- checkClosed();
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- if (rowData.size() == 0) {
- return;
- } else {
- rowData.beforeFirst();
- thisRow = null;
- }
- }
- /**
- * JDBC 2.0 The cancelRowUpdates() method may be called after calling an
- * updateXXX() method(s) and before calling updateRow() to rollback the
- * updates made to a row. If no updates have been made or updateRow() has
- * already been called, then this method has no effect.
- *
- * @exception SQLException if a database-access error occurs, or if called
- * when on the insert row.
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void cancelRowUpdates() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * After this call, getWarnings returns null until a new warning is
- * reported for this ResultSet
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public void clearWarnings() throws java.sql.SQLException {
- warningChain = null;
- }
- /**
- * In some cases, it is desirable to immediately release a ResultSet
- * database and JDBC resources instead of waiting for this to happen when
- * it is automatically closed. The close method provides this immediate
- * release.
- *
- * <p>
- * <B>Note:</B> A ResultSet is automatically closed by the Statement the
- * Statement that generated it when that Statement is closed, re-executed,
- * or is used to retrieve the next result from a sequence of multiple
- * results. A ResultSet is also automatically closed when it is garbage
- * collected.
- * </p>
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public void close() throws java.sql.SQLException {
- realClose(true);
- }
- /**
- * JDBC 2.0 Delete the current row from the result set and the underlying
- * database. Cannot be called when on the insert row.
- *
- * @exception SQLException if a database-access error occurs, or if called
- * when on the insert row.
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void deleteRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * Map a ResultSet column name to a ResultSet column index
- *
- * @param columnName the name of the column
- *
- * @return the column index
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public int findColumn(String columnName) throws java.sql.SQLException {
- Integer index;
- synchronized (this) {
- if (!hasBuiltIndexMapping) {
- buildIndexMapping();
- }
- }
- index = (Integer) columnNameToIndex.get(columnName);
- if (index == null) {
- index = (Integer) fullColumnNameToIndex.get(columnName);
- }
- if (index != null) {
- return index.intValue() + 1;
- } else {
- // Try this inefficient way, now
- String columnNameUC = columnName.toUpperCase();
- for (int i = 0; i < fields.length; i++) {
- if (fields[i].getName().toUpperCase().equals(columnNameUC)) {
- return i + 1;
- } else if (fields[i].getFullName().toUpperCase().equals(columnNameUC)) {
- return i + 1;
- }
- }
- throw new java.sql.SQLException("Column '" + columnName
- + "' not found.", SQLError.SQL_STATE_COLUMN_NOT_FOUND);
- }
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves to the first row in the result set.
- * </p>
- *
- * @return true if on a valid row, false if no rows in the result set.
- *
- * @exception SQLException if a database-access error occurs, or result set
- * type is TYPE_FORWARD_ONLY.
- */
- public boolean first() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "first", args);
- }
- checkClosed();
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (rowData.isEmpty()) {
- return false;
- } else {
- if (doingUpdates) {
- doingUpdates = false;
- }
- rowData.beforeFirst();
- thisRow = rowData.next();
- return true;
- }
- }
- /**
- * JDBC 2.0 Insert the contents of the insert row into the result set and
- * the database. Must be on the insert row when this method is called.
- *
- * @exception SQLException if a database-access error occurs, if called
- * when not on the insert row, or if all non-nullable columns
- * in the insert row have not been given a value
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void insertRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves to the last row in the result set.
- * </p>
- *
- * @return true if on a valid row, false if no rows in the result set.
- *
- * @exception SQLException if a database-access error occurs, or result set
- * type is TYPE_FORWARD_ONLY.
- */
- public boolean last() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "last", args);
- }
- checkClosed();
- if (rowData.size() == 0) {
- return false;
- } else {
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- rowData.beforeLast();
- thisRow = rowData.next();
- return true;
- }
- }
- /**
- * JDBC 2.0 Move the cursor to the remembered cursor position, usually the
- * current row. Has no effect unless the cursor is on the insert row.
- *
- * @exception SQLException if a database-access error occurs, or the result
- * set is not updatable
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void moveToCurrentRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Move to the insert row. The current cursor position is
- * remembered while the cursor is positioned on the insert row. The insert
- * row is a special row associated with an updatable result set. It is
- * essentially a buffer where a new row may be constructed by calling the
- * updateXXX() methods prior to inserting the row into the result set.
- * Only the updateXXX(), getXXX(), and insertRow() methods may be called
- * when the cursor is on the insert row. All of the columns in a result
- * set must be given a value each time this method is called before
- * calling insertRow(). UpdateXXX()must be called before getXXX() on a
- * column.
- *
- * @exception SQLException if a database-access error occurs, or the result
- * set is not updatable
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void moveToInsertRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * A ResultSet is initially positioned before its first row, the first call
- * to next makes the first row the current row; the second call makes the
- * second row the current row, etc.
- *
- * <p>
- * If an input stream from the previous row is open, it is implicitly
- * closed. The ResultSet's warning chain is cleared when a new row is
- * read
- * </p>
- *
- * @return true if the new current is valid; false if there are no more
- * rows
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public boolean next() throws java.sql.SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "next", args);
- }
- checkClosed();
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- boolean b;
- if (!reallyResult()) {
- throw new java.sql.SQLException("ResultSet is from UPDATE. No Data",
- SQLError.SQL_STATE_GENERAL_ERROR);
- }
- if (rowData.size() == 0) {
- b = false;
- } else {
- if (!rowData.hasNext()) {
- // force scroll past end
- rowData.next();
- b = false;
- } else {
- clearWarnings();
- thisRow = rowData.next();
- b = true;
- }
- }
- if (Driver.TRACE) {
- Debug.returnValue(this, "next", new Boolean(b));
- }
- return b;
- }
- /**
- * The prev method is not part of JDBC, but because of the architecture of
- * this driver it is possible to move both forward and backward within the
- * result set.
- *
- * <p>
- * If an input stream from the previous row is open, it is implicitly
- * closed. The ResultSet's warning chain is cleared when a new row is
- * read
- * </p>
- *
- * @return true if the new current is valid; false if there are no more
- * rows
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public boolean prev() throws java.sql.SQLException {
- checkClosed();
- int rowIndex = rowData.getCurrentRowNumber();
- if ((rowIndex - 1) >= 0) {
- rowIndex--;
- rowData.setCurrentRow(rowIndex);
- thisRow = (byte[][]) rowData.getAt(rowIndex);
- return true;
- } else if ((rowIndex - 1) == -1) {
- rowIndex--;
- rowData.setCurrentRow(rowIndex);
- thisRow = null;
- return false;
- } else {
- return false;
- }
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves to the previous row in the result set.
- * </p>
- *
- * <p>
- * Note: previous() is not the same as relative(-1) since it makes sense to
- * call previous() when there is no current row.
- * </p>
- *
- * @return true if on a valid row, false if off the result set.
- *
- * @exception SQLException if a database-access error occurs, or result set
- * type is TYPE_FORWAR_DONLY.
- */
- public boolean previous() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "previous", args);
- }
- if (onInsertRow) {
- onInsertRow = false;
- }
- if (doingUpdates) {
- doingUpdates = false;
- }
- return prev();
- }
- /**
- * JDBC 2.0 Refresh the value of the current row with its current value in
- * the database. Cannot be called when on the insert row. The
- * refreshRow() method provides a way for an application to explicitly
- * tell the JDBC driver to refetch a row(s) from the database. An
- * application may want to call refreshRow() when caching or prefetching
- * is being done by the JDBC driver to fetch the latest value of a row
- * from the database. The JDBC driver may actually refresh multiple rows
- * at once if the fetch size is greater than one. All values are refetched
- * subject to the transaction isolation level and cursor sensitivity. If
- * refreshRow() is called after calling updateXXX(), but before calling
- * updateRow() then the updates made to the row are lost. Calling
- * refreshRow() frequently will likely slow performance.
- *
- * @exception SQLException if a database-access error occurs, or if called
- * when on the insert row.
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void refreshRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Moves a relative number of rows, either positive or negative. Attempting
- * to move beyond the first/last row in the result set positions the
- * cursor before/after the the first/last row. Calling relative(0) is
- * valid, but does not change the cursor position.
- * </p>
- *
- * <p>
- * Note: Calling relative(1) is different than calling next() since is
- * makes sense to call next() when there is no current row, for example,
- * when the cursor is positioned before the first row or after the last
- * row of the result set.
- * </p>
- *
- * @param rows the number of relative rows to move the cursor.
- *
- * @return true if on a row, false otherwise.
- *
- * @throws SQLException if a database-access error occurs, or there is no
- * current row, or result set type is TYPE_FORWARD_ONLY.
- */
- public boolean relative(int rows) throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { new Integer(rows) };
- Debug.methodCall(this, "relative", args);
- }
- checkClosed();
- if (rowData.size() == 0) {
- return false;
- }
- rowData.moveRowRelative(rows);
- thisRow = rowData.getAt(rowData.getCurrentRowNumber());
- boolean b = (!rowData.isAfterLast() && !rowData.isBeforeFirst());
- if (Driver.TRACE) {
- Debug.returnValue(this, "relative", new Boolean(b));
- }
- return b;
- }
- /**
- * JDBC 2.0 Determine if this row has been deleted. A deleted row may
- * leave a visible "hole" in a result set. This method can be used to
- * detect holes in a result set. The value returned depends on whether or
- * not the result set can detect deletions.
- *
- * @return true if deleted and deletes are detected
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotImplemented DOCUMENT ME!
- *
- * @see DatabaseMetaData#deletesAreDetected
- */
- public boolean rowDeleted() throws SQLException {
- throw new NotImplemented();
- }
- /**
- * JDBC 2.0 Determine if the current row has been inserted. The value
- * returned depends on whether or not the result set can detect visible
- * inserts.
- *
- * @return true if inserted and inserts are detected
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotImplemented DOCUMENT ME!
- *
- * @see DatabaseMetaData#insertsAreDetected
- */
- public boolean rowInserted() throws SQLException {
- throw new NotImplemented();
- }
- //---------------------------------------------------------------------
- // Updates
- //---------------------------------------------------------------------
- /**
- * JDBC 2.0 Determine if the current row has been updated. The value
- * returned depends on whether or not the result set can detect updates.
- *
- * @return true if the row has been visibly updated by the owner or
- * another, and updates are detected
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotImplemented DOCUMENT ME!
- *
- * @see DatabaseMetaData#updatesAreDetected
- */
- public boolean rowUpdated() throws SQLException {
- throw new NotImplemented();
- }
- /**
- * @see ResultSet#updateArray(int, Array)
- */
- public void updateArray(int arg0, Array arg1) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * @see ResultSet#updateArray(String, Array)
- */
- public void updateArray(String arg0, Array arg1) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * JDBC 2.0 Update a column with an ascii stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- * @param length the length of the stream
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateAsciiStream(int columnIndex, java.io.InputStream x,
- int length) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with an ascii stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- * @param length of the stream
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateAsciiStream(String columnName, java.io.InputStream x,
- int length) throws SQLException {
- updateAsciiStream(findColumn(columnName), x, length);
- }
- /**
- * JDBC 2.0 Update a column with a BigDecimal value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateBigDecimal(int columnIndex, BigDecimal x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a BigDecimal value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateBigDecimal(String columnName, BigDecimal x)
- throws SQLException {
- updateBigDecimal(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a binary stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- * @param length the length of the stream
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateBinaryStream(int columnIndex, java.io.InputStream x,
- int length) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a binary stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- * @param length of the stream
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateBinaryStream(String columnName, java.io.InputStream x,
- int length) throws SQLException {
- updateBinaryStream(findColumn(columnName), x, length);
- }
- /**
- * @see ResultSet#updateBlob(int, Blob)
- */
- public void updateBlob(int arg0, java.sql.Blob arg1)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * @see ResultSet#updateBlob(String, Blob)
- */
- public void updateBlob(String arg0, java.sql.Blob arg1)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a boolean value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateBoolean(int columnIndex, boolean x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a boolean value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateBoolean(String columnName, boolean x)
- throws SQLException {
- updateBoolean(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a byte value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateByte(int columnIndex, byte x) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a byte value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateByte(String columnName, byte x) throws SQLException {
- updateByte(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a byte array value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateBytes(int columnIndex, byte[] x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a byte array value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateBytes(String columnName, byte[] x)
- throws SQLException {
- updateBytes(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a character stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- * @param length the length of the stream
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateCharacterStream(int columnIndex, java.io.Reader x,
- int length) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a character stream value. The updateXXX()
- * methods are used to update column values in the current row, or the
- * insert row. The updateXXX() methods do not update the underlying
- * database, instead the updateRow() or insertRow() methods are called to
- * update the database.
- *
- * @param columnName the name of the column
- * @param reader the stream to update the column with
- * @param length of the stream
- *
- * @throws SQLException if a database-access error occurs
- */
- public void updateCharacterStream(String columnName, java.io.Reader reader,
- int length) throws SQLException {
- updateCharacterStream(findColumn(columnName), reader, length);
- }
- /**
- * @see ResultSet#updateClob(int, Clob)
- */
- public void updateClob(int arg0, java.sql.Clob arg1) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * @see ResultSet#updateClob(String, Clob)
- */
- public void updateClob(String columnName, java.sql.Clob clob) throws SQLException {
- updateClob(findColumn(columnName), clob);
- }
- /**
- * JDBC 2.0 Update a column with a Date value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateDate(int columnIndex, java.sql.Date x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a Date value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateDate(String columnName, java.sql.Date x)
- throws SQLException {
- updateDate(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a Double value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateDouble(int columnIndex, double x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a double value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateDouble(String columnName, double x)
- throws SQLException {
- updateDouble(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a float value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateFloat(int columnIndex, float x) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a float value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateFloat(String columnName, float x)
- throws SQLException {
- updateFloat(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with an integer value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateInt(int columnIndex, int x) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with an integer value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateInt(String columnName, int x) throws SQLException {
- updateInt(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a long value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateLong(int columnIndex, long x) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a long value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateLong(String columnName, long x) throws SQLException {
- updateLong(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Give a nullable column a null value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateNull(int columnIndex) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a null value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateNull(String columnName) throws SQLException {
- updateNull(findColumn(columnName));
- }
- /**
- * JDBC 2.0 Update a column with an Object value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
- * this is the number of digits after the decimal. For all other
- * types this value will be ignored.
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateObject(int columnIndex, Object x, int scale)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with an Object value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateObject(int columnIndex, Object x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with an Object value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
- * this is the number of digits after the decimal. For all other
- * types this value will be ignored.
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateObject(String columnName, Object x, int scale)
- throws SQLException {
- updateObject(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with an Object value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateObject(String columnName, Object x)
- throws SQLException {
- updateObject(findColumn(columnName), x);
- }
- /**
- * @see ResultSet#updateRef(int, Ref)
- */
- public void updateRef(int arg0, Ref arg1) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * @see ResultSet#updateRef(String, Ref)
- */
- public void updateRef(String arg0, Ref arg1) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * JDBC 2.0 Update the underlying database with the new contents of the
- * current row. Cannot be called when on the insert row.
- *
- * @exception SQLException if a database-access error occurs, or if called
- * when on the insert row
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateRow() throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a short value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateShort(int columnIndex, short x) throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a short value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateShort(String columnName, short x)
- throws SQLException {
- updateShort(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a String value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateString(int columnIndex, String x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a String value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateString(String columnName, String x)
- throws SQLException {
- updateString(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a Time value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateTime(int columnIndex, java.sql.Time x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a Time value. The updateXXX() methods are
- * used to update column values in the current row, or the insert row. The
- * updateXXX() methods do not update the underlying database, instead the
- * updateRow() or insertRow() methods are called to update the database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateTime(String columnName, java.sql.Time x)
- throws SQLException {
- updateTime(findColumn(columnName), x);
- }
- /**
- * JDBC 2.0 Update a column with a Timestamp value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- * @throws NotUpdatable DOCUMENT ME!
- */
- public void updateTimestamp(int columnIndex, java.sql.Timestamp x)
- throws SQLException {
- throw new NotUpdatable();
- }
- /**
- * JDBC 2.0 Update a column with a Timestamp value. The updateXXX() methods
- * are used to update column values in the current row, or the insert row.
- * The updateXXX() methods do not update the underlying database, instead
- * the updateRow() or insertRow() methods are called to update the
- * database.
- *
- * @param columnName the name of the column
- * @param x the new column value
- *
- * @exception SQLException if a database-access error occurs
- */
- public void updateTimestamp(String columnName, java.sql.Timestamp x)
- throws SQLException {
- updateTimestamp(findColumn(columnName), x);
- }
- /**
- * A column may have the value of SQL NULL; wasNull() reports whether the
- * last column read had this special value. Note that you must first call
- * getXXX on a column to try to read its value and then call wasNull() to
- * find if the value was SQL NULL
- *
- * @return true if the last column read was SQL NULL
- *
- * @exception java.sql.SQLException if a database access error occurred
- */
- public boolean wasNull() throws java.sql.SQLException {
- return wasNullFlag;
- }
- ///////////////////////////////////////////
- //
- // These number conversion routines save
- // a ton of "new()s", especially for the heavily
- // used getInt() and getDouble() methods
- //
- ///////////////////////////////////////////
- /**
- * Converts a string representation of a number to a double. Need a faster
- * way to do this.
- *
- * @param colIndex the 1-based index of the column to retrieve a double
- * from.
- *
- * @return the double value represented by the string in buf
- *
- * @throws SQLException if an error occurs
- */
- protected double getDoubleInternal(int colIndex) throws SQLException {
- String s = "";
- try {
- s = getString(colIndex);
- if ((s == null) || (s.length() == 0)) {
- return 0;
- }
- double d = Double.parseDouble(s);
- if (this.useStrictFloatingPoint) {
- // Fix endpoint rounding precision loss in MySQL server
- if (d == 2.147483648E9) {
- // Fix Odd end-point rounding on MySQL
- d = 2.147483647E9;
- } else if (d == 1.0000000036275E-15) {
- // Fix odd end-point rounding on MySQL
- d = 1.0E-15;
- } else if (d == 9.999999869911E14) {
- d = 9.99999999999999E14;
- } else if (d == 1.4012984643248E-45) {
- d = 1.4E-45;
- } else if (d == 1.4013E-45) {
- d = 1.4E-45;
- } else if (d == 3.4028234663853E37) {
- d = 3.4028235E37;
- } else if (d == -2.14748E9) {
- d = -2.147483648E9;
- } else if (d == 3.40282E37) {
- d = 3.4028235E37;
- }
- }
- return d;
- } catch (NumberFormatException e) {
- throw new SQLException("Bad format for number '" + s + "'");
- }
- }
- /**
- * Sets the first character of the query that this result set was created
- * from.
- *
- * @param c the first character of the query...uppercased
- */
- protected void setFirstCharOfQuery(char c) {
- this.firstCharOfQuery = c;
- }
- /**
- * Returns the first character of the query that this result set was
- * created from.
- *
- * @return the first character of the query...uppercased
- */
- protected char getFirstCharOfQuery() {
- return this.firstCharOfQuery;
- }
- /**
- * Sets the concurrency (JDBC2)
- *
- * @param concurrencyFlag CONCUR_UPDATABLE or CONCUR_READONLY
- */
- protected void setResultSetConcurrency(int concurrencyFlag) {
- resultSetConcurrency = concurrencyFlag;
- }
- /**
- * Sets the result set type for (JDBC2)
- *
- * @param typeFlag SCROLL_SENSITIVE or SCROLL_INSENSITIVE (we only support
- * SCROLL_INSENSITIVE)
- */
- protected void setResultSetType(int typeFlag) {
- resultSetType = typeFlag;
- }
- /**
- * Sets server info (if any)
- *
- * @param info the server info message
- */
- protected void setServerInfo(String info) {
- this.serverInfo = info;
- }
- /**
- * Returns the server info (if any), or null if none.
- *
- * @return server info created for this ResultSet
- */
- protected String getServerInfo() {
- return this.serverInfo;
- }
- /**
- * Builds a hash between column names and their indices for fast retrieval.
- */
- protected void buildIndexMapping() {
- int numFields = fields.length;
- columnNameToIndex = new HashMap();
- fullColumnNameToIndex = new HashMap();
- // We do this in reverse order, so that the 'first' column
- // with a given name ends up as the final mapping in the
- // hashtable...
- //
- // Quoting the JDBC Spec:
- //
- // "Column names used as input to getter
- // methods are case insensitive. When a getter method is called with a column
- // name and several columns have the same name, the value of the first
- // matching column will be returned. "
- //
-
- for (int i = numFields-1; i>= 0 ; i--) {
- Integer index = new Integer(i);
- String columnName = fields[i].getName();
- String fullColumnName = fields[i].getFullName();
- if (columnName != null) {
- columnNameToIndex.put(columnName, index);
- columnNameToIndex.put(columnName.toUpperCase(), index);
- columnNameToIndex.put(columnName.toLowerCase(), index);
- }
- if (fullColumnName != null) {
- fullColumnNameToIndex.put(fullColumnName, index);
- fullColumnNameToIndex.put(fullColumnName.toUpperCase(), index);
- fullColumnNameToIndex.put(fullColumnName.toLowerCase(), index);
- }
- }
- // set the flag to prevent rebuilding...
- hasBuiltIndexMapping = true;
- }
- /**
- * Ensures that the result set is not closed
- *
- * @throws SQLException if the result set is closed
- */
- protected void checkClosed() throws SQLException {
- if (isClosed) {
- throw new SQLException("Operation not allowed after ResultSet closed",
- SQLError.SQL_STATE_GENERAL_ERROR);
- }
- }
- /**
- * Ensures that the cursor is positioned on a valid row and that the result
- * set is not closed
- *
- * @throws SQLException if the result set is not in a valid state for
- * traversal
- */
- protected void checkRowPos() throws SQLException {
- checkClosed();
- if (!rowData.isDynamic() && (rowData.size() == 0)) {
- throw new SQLException("Illegal operation on empty result set",
- SQLError.SQL_STATE_GENERAL_ERROR);
- }
- if (rowData.isBeforeFirst()) {
- throw new SQLException("Before start of result set", SQLError.SQL_STATE_GENERAL_ERROR);
- }
- if (rowData.isAfterLast()) {
- throw new SQLException("After end of result set", SQLError.SQL_STATE_GENERAL_ERROR);
- }
- }
- protected void realClose(boolean closeRowData) throws SQLException {
- try {
- if (closeRowData && (this.rowData != null)) {
- rowData.close();
- }
- } finally {
- this.defaultTimeZone = null;
- this.rowData = null;
- this.isClosed = true;
- }
- }
- void setStatement(com.mysql.jdbc.Statement stmt) {
- owningStatement = stmt;
- }
- long getUpdateCount() {
- return updateCount;
- }
- long getUpdateID() {
- return updateId;
- }
- boolean reallyResult() {
- return reallyResult;
- }
- /**
- * Get the value of a column in the current row as a java.sql.Time object
- * in the given timezone
- *
- * @param columnIndex the first column is 1, the second is 2...
- * @param tz the Timezone to use
- *
- * @return the column value; null if SQL NULL
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- private Time getTimeInternal(int columnIndex, TimeZone tz)
- throws java.sql.SQLException {
- int hr = 0;
- int min = 0;
- int sec = 0;
- try {
- String timeAsString = getString(columnIndex);
- if (timeAsString == null) {
- return null;
- } else {
- int length = timeAsString.length();
- if ((length > 0) && (timeAsString.charAt(0) == '0')
- && (timeAsString.equals("0000-00-00")
- || timeAsString.equals("0000-00-00 00:00:00")
- || timeAsString.equals("00000000000000"))) {
- wasNullFlag = true;
- return null;
- }
- Field timeColField = fields[columnIndex - 1];
- if (timeColField.getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP) {
- // It's a timestamp
- switch (length) {
- case 14:
- case 12: {
- hr = Integer.parseInt(timeAsString.substring(length - 6,
- length - 4));
- min = Integer.parseInt(timeAsString.substring(length
- - 4, length - 2));
- sec = Integer.parseInt(timeAsString.substring(length
- - 2, length));
- }
- break;
- case 10: {
- hr = Integer.parseInt(timeAsString.substring(6, 8));
- min = Integer.parseInt(timeAsString.substring(8, 10));
- sec = 0;
- }
- break;
- default:
- throw new SQLException(
- "Timestamp too small to convert to Time value in column "
- + columnIndex + "(" + fields[columnIndex - 1]
- + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- } /* endswitch */
- SQLWarning precisionLost = new SQLWarning(
- "Precision lost converting TIMESTAMP to Time with getTime() on column "
- + columnIndex + "(" + fields[columnIndex - 1]
- + ").");
- if (warningChain == null) {
- warningChain = precisionLost;
- } else {
- warningChain.setNextWarning(precisionLost);
- }
- } else if (timeColField.getMysqlType() == MysqlDefs.FIELD_TYPE_DATETIME) {
- hr = Integer.parseInt(timeAsString.substring(11, 13));
- min = Integer.parseInt(timeAsString.substring(14, 16));
- sec = Integer.parseInt(timeAsString.substring(17, 19));
- SQLWarning precisionLost = new SQLWarning(
- "Precision lost converting DATETIME to Time with getTime() on column "
- + columnIndex + "(" + fields[columnIndex - 1]
- + ").");
- if (warningChain == null) {
- warningChain = precisionLost;
- } else {
- warningChain.setNextWarning(precisionLost);
- }
- } else {
- // convert a String to a Time
- if ((length != 5) && (length != 8)) {
- throw new SQLException("Bad format for Time '"
- + timeAsString + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- hr = Integer.parseInt(timeAsString.substring(0, 2));
- min = Integer.parseInt(timeAsString.substring(3, 5));
- sec = (length == 5) ? 0
- : Integer.parseInt(timeAsString
- .substring(6));
- }
- return TimeUtil.changeTimezone(this.connection,
- fastTimeCreate(null, hr, min, sec),
- connection.getServerTimezone(), tz);
- }
- } catch (Exception ex) {
- throw new java.sql.SQLException(ex.getClass().getName(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- /**
- * Get the value of a column in the current row as a java.sql.Timestamp
- * object in the given timezone
- *
- * @param columnIndex the first column is 1, the second is 2...
- * @param tz the timezone to use
- *
- * @return the column value; null if SQL NULL
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- private Timestamp getTimestampInternal(int columnIndex, TimeZone tz)
- throws java.sql.SQLException {
- String timestampValue = getString(columnIndex);
- try {
- if (timestampValue == null) {
- return null;
- } else {
- int length = timestampValue.length();
- if ((length > 0) && (timestampValue.charAt(0) == '0')
- && (timestampValue.equals("0000-00-00")
- || timestampValue.equals("0000-00-00 00:00:00")
- || timestampValue.equals("00000000000000")
- || timestampValue.equals("0"))) {
- wasNullFlag = true;
- return null;
- } else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) {
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null,
- Integer.parseInt(timestampValue.substring(0, 4))
- - 1900, 0, 1, 0, 0, 0, 0),
- connection.getServerTimezone(), tz);
- } else {
- // Convert from TIMESTAMP or DATE
- switch (length) {
- case 19: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 4));
- int month = Integer.parseInt(timestampValue.substring(
- 5, 7));
- int day = Integer.parseInt(timestampValue.substring(8,
- 10));
- int hour = Integer.parseInt(timestampValue.substring(
- 11, 13));
- int minutes = Integer.parseInt(timestampValue.substring(
- 14, 16));
- int seconds = Integer.parseInt(timestampValue.substring(
- 17, 19));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year - 1900, month - 1,
- day, hour, minutes, seconds, 0),
- connection.getServerTimezone(), tz);
- }
- case 14: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 4));
- int month = Integer.parseInt(timestampValue.substring(
- 4, 6));
- int day = Integer.parseInt(timestampValue.substring(6, 8));
- int hour = Integer.parseInt(timestampValue.substring(
- 8, 10));
- int minutes = Integer.parseInt(timestampValue.substring(
- 10, 12));
- int seconds = Integer.parseInt(timestampValue.substring(
- 12, 14));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year - 1900, month - 1,
- day, hour, minutes, seconds, 0),
- connection.getServerTimezone(), tz);
- }
- case 12: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 2));
- if (year <= 69) {
- year = (year + 100);
- }
- int month = Integer.parseInt(timestampValue.substring(
- 2, 4));
- int day = Integer.parseInt(timestampValue.substring(4, 6));
- int hour = Integer.parseInt(timestampValue.substring(
- 6, 8));
- int minutes = Integer.parseInt(timestampValue.substring(
- 8, 10));
- int seconds = Integer.parseInt(timestampValue.substring(
- 10, 12));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year, month - 1, day,
- hour, minutes, seconds, 0),
- connection.getServerTimezone(), tz);
- }
- case 10: {
- int year;
- int month;
- int day;
- int hour;
- int minutes;
- if ((this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_DATE)
- || (timestampValue.indexOf("-") != -1)) {
- year = Integer.parseInt(timestampValue.substring(
- 0, 4)) - 1900;
- month = Integer.parseInt(timestampValue.substring(
- 5, 7));
- day = Integer.parseInt(timestampValue.substring(8,
- 10));
- hour = 0;
- minutes = 0;
- } else {
- year = Integer.parseInt(timestampValue.substring(
- 0, 2));
- if (year <= 69) {
- year = (year + 100);
- }
- month = Integer.parseInt(timestampValue.substring(
- 2, 4));
- day = Integer.parseInt(timestampValue.substring(4, 6));
- hour = Integer.parseInt(timestampValue.substring(
- 6, 8));
- minutes = Integer.parseInt(timestampValue.substring(
- 8, 10));
- }
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year, month - 1, day,
- hour, minutes, 0, 0),
- connection.getServerTimezone(), tz);
- }
- case 8: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 4));
- int month = Integer.parseInt(timestampValue.substring(
- 4, 6));
- int day = Integer.parseInt(timestampValue.substring(6, 8));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year - 1900, month - 1,
- day, 0, 0, 0, 0),
- connection.getServerTimezone(), tz);
- }
- case 6: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 2));
- if (year <= 69) {
- year = (year + 100);
- }
- int month = Integer.parseInt(timestampValue.substring(
- 2, 4));
- int day = Integer.parseInt(timestampValue.substring(4, 6));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year, month - 1, day, 0,
- 0, 0, 0), connection.getServerTimezone(), tz);
- }
- case 4: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 2));
- if (year <= 69) {
- year = (year + 100);
- }
- int month = Integer.parseInt(timestampValue.substring(
- 2, 4));
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year, month - 1, 1, 0, 0,
- 0, 0), connection.getServerTimezone(), tz);
- }
- case 2: {
- int year = Integer.parseInt(timestampValue.substring(
- 0, 2));
- if (year <= 69) {
- year = (year + 100);
- }
- return TimeUtil.changeTimezone(this.connection,
- fastTimestampCreate(null, year, 0, 1, 0, 0, 0, 0),
- connection.getServerTimezone(), tz);
- }
- default:
- throw new java.sql.SQLException(
- "Bad format for Timestamp '" + timestampValue
- + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- }
- } catch (Exception e) {
- throw new java.sql.SQLException("Cannot convert value '"
- + timestampValue + "' from column " + columnIndex + "("
- + timestampValue + " ) to TIMESTAMP.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- private synchronized Date fastDateCreate(Calendar cal, int year, int month,
- int day) {
- if (cal == null) {
- if (this.fastDateCal == null) {
- this.fastDateCal = new GregorianCalendar();
- this.fastDateCal.setTimeZone(this.defaultTimeZone);
- }
- cal = this.fastDateCal;
- }
- cal.clear();
- cal.set(year + 1900, month, day, 0, 0, 0);
- long dateAsMillis = 0;
- try {
- dateAsMillis = cal.getTimeInMillis();
- } catch (IllegalAccessError iae) {
- // Must be on JDK-1.3.1 or older....
- dateAsMillis = cal.getTime().getTime();
- }
- return new Date(dateAsMillis);
- }
- private synchronized Time fastTimeCreate(Calendar cal, int hour,
- int minute, int second) {
- if (cal == null) {
- if (this.fastDateCal == null) {
- this.fastDateCal = new GregorianCalendar();
- this.fastDateCal.setTimeZone(this.defaultTimeZone);
- }
- cal = this.fastDateCal;
- }
- cal.clear();
- // Set 'date' to epoch of Jan 1, 1970
- cal.set(1970, 0, 1, hour, minute, second);
- long timeAsMillis = 0;
- try {
- timeAsMillis = cal.getTimeInMillis();
- } catch (IllegalAccessError iae) {
- // Must be on JDK-1.3.1 or older....
- timeAsMillis = cal.getTime().getTime();
- }
- return new Time(timeAsMillis);
- }
- private synchronized Timestamp fastTimestampCreate(Calendar cal, int year,
- int month, int day, int hour, int minute, int seconds, int secondsPart) {
- if (cal == null) {
- if (this.fastDateCal == null) {
- this.fastDateCal = new GregorianCalendar();
- this.fastDateCal.setTimeZone(this.defaultTimeZone);
- }
- cal = this.fastDateCal;
- }
- cal.clear();
- cal.set(year + 1900, month, day, hour, minute, seconds);
- long tsAsMillis = 0;
- try {
- tsAsMillis = cal.getTimeInMillis();
- } catch (IllegalAccessError iae) {
- // Must be on JDK-1.3.1 or older....
- tsAsMillis = cal.getTime().getTime();
- }
- Timestamp ts = new Timestamp(tsAsMillis);
- ts.setNanos(secondsPart);
- return ts;
- }
- }