⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultset.java

📁 SearchPathServer
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * MM JDBC Drivers for MySQL
 *
 * $Id: ResultSet.java,v 1.8 2002/05/16 20:22:44 mark_matthews Exp $
 *
 * Copyright (C) 1998 Mark Matthews <mmatthew@worldserver.com>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 * 
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330
 * Boston, MA  02111-1307, USA.
 *
 * See the COPYING file located in the top-level-directory of
 * the archive of this library for complete text of license.
 *
 * Some portions:
 *
 * Copyright (c) 1996 Bradley McLean / Jeffrey Medeiros
 * Modifications Copyright (c) 1996/1997 Martin Rode
 * Copyright (c) 1997 Peter T Mount
 */

/**
 * A ResultSet provides access to a table of data generated by executing a
 * Statement.  The table rows are retrieved in sequence.  Within a row its
 * column values can be accessed in any order.
 *
 * <P>A ResultSet maintains a cursor pointing to its current row of data.
 * Initially the cursor is positioned before the first row.  The 'next'
 * method moves the cursor to the next row.
 *
 * <P>The getXXX methods retrieve column values for the current row.  You can
 * retrieve values either using the index number of the column, or by using
 * the name of the column.  In general using the column index will be more
 * efficient.  Columns are numbered from 1.
 *
 * <P>For maximum portability, ResultSet columns within each row should be read
 * in left-to-right order and each column should be read only once.
 *
 *<P> For the getXXX methods, the JDBC driver attempts to convert the
 * underlying data to the specified Java type and returns a suitable Java
 * value.  See the JDBC specification for allowable mappings from SQL types
 * to Java types with the ResultSet getXXX methods.
 *
 * <P>Column names used as input to getXXX methods are case insenstive.  When
 * performing a getXXX using a column name, if several columns have the same
 * name, then the value of the first matching column will be returned.  The
 * column name option is designed to be used when column names are used in the
 * SQL Query.  For columns that are NOT explicitly named in the query, it is
 * best to use column numbers.  If column names were used there is no way for
 * the programmer to guarentee that they actually refer to the intended
 * columns.
 *
 * <P>A ResultSet is automatically closed by 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.
 *
 * <P>The number, types and properties of a ResultSet's columns are provided by
 * the ResultSetMetaData object returned by the getMetaData method.
 *
 * @see ResultSetMetaData
 * @see java.sql.ResultSet
 * @author Mark Matthews <mmatthew@worldserver.com>
 * @version $Id: ResultSet.java,v 1.8 2002/05/16 20:22:44 mark_matthews Exp $
 */

package com.mysql.jdbc.jdbc2;

import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;

import com.mysql.jdbc.Debug;
import com.mysql.jdbc.Driver;


public class ResultSet
	extends com.mysql.jdbc.ResultSet
	implements java.sql.ResultSet {
	private final static String UPDATEABLE_MESSAGE =
		"Result Set not updateable. The "
			+ "query that generated this result set must select only one table, and must "
			+ "select all primary keys from that table. See the JDBC 2.1 API Specification, "
			+ "section 5.6 for more details.";

	/**
	 * SQL for in-place modifcation
	 */

	protected String _UpdateSQL = null;

	protected String _DeleteSQL = null;

	protected String _InsertSQL = null;
	
	protected String _RefreshSQL = null;

	/**
	 * PreparedStatement used to refresh data
	 */
	
	protected com.mysql.jdbc.jdbc2.PreparedStatement _Refresher;
	/**
	 * PreparedStatement used to delete data
	 */

	protected com.mysql.jdbc.jdbc2.PreparedStatement _Updater = null;

	/**
	 * PreparedStatement used to insert data
	 */

	protected com.mysql.jdbc.jdbc2.PreparedStatement _Inserter = null;

	/**
	 * PreparedStatement used to delete data
	 */

	protected com.mysql.jdbc.jdbc2.PreparedStatement _Deleter = null;

	/**
	 * List of primary keys
	 */

	protected Vector _PrimaryKeyIndicies = null;

	/**
	 * Is this result set updateable?
	 */

	protected boolean _updatable = false;

	/**
	 * Are we in the middle of doing updates to the current row?
	 */

	protected boolean _doing_updates = false;
	

	/**
	 * Are we on the insert row?
	 */

	protected boolean _on_insert_row = false;

	/**
	 * The numbers, types and properties of a ResultSet's columns are
	 * provided by the getMetaData method
	 *
	 * @return a description of the ResultSet's columns
	 * @exception java.sql.SQLException if a database access error occurs
	 */

	public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException {
		return new com.mysql.jdbc.jdbc2.ResultSetMetaData(_rows, _fields);
	}

	//--------------------------JDBC 2.0-----------------------------------

	//---------------------------------------------------------------------
	// Getter's and Setter's
	//---------------------------------------------------------------------

	/**
	 * JDBC 2.0
	 *
	 * <p>Get the value of a column in the current row as a java.io.Reader.
	 */

	public  java.io.Reader getCharacterStream(int columnIndex) throws SQLException {
		throw new NotImplemented();
	}

	/**
	 * JDBC 2.0
	 *
	 * <p>Get the value of a column in the current row as a java.io.Reader.
	 */

	public  java.io.Reader getCharacterStream(String columnName)
		throws SQLException {
		throw new NotImplemented();
	}

	/**
	 * JDBC 2.0
	 *
	 * Get the value of a column in the current row as a java.math.BigDecimal 
	 * object.
	 *
	 * @param columnIndex the first column is 1, the second is 2, ...
	 * @return the column value (full precision); if the value is SQL NULL, 
	 * the result is null
	 * @exception SQLException if a database-access error occurs.
	 */

	public  BigDecimal getBigDecimal(int columnIndex) throws SQLException {
		String S = getString(columnIndex);

		BigDecimal Val;

		if (S != null) {
			if (S.length() == 0) {
				Val = new BigDecimal(0);
				return Val;
			}
			try {
				Val = new BigDecimal(S);

				return Val;
			}
			catch (NumberFormatException E) {
				throw new java.sql.SQLException(
					"Bad format for BigDecimal '"
						+ S
						+ "' in column "
						+ columnIndex
						+ "("
						+ _fields[columnIndex
						- 1]
						+ ").",
					"S1009");
			}
		}

		return null; // SQL NULL
	}

	/**
	 * JDBC 2.0
	 *
	 * Get the value of a column in the current row as a java.math.BigDecimal 
	 * object.
	 *
	 */

	public  BigDecimal getBigDecimal(String columnName) throws SQLException {
		String S = getString(columnName);

		BigDecimal Val;

		if (S != null) {
			if (S.length() == 0) {
				Val = new BigDecimal(0);
				return Val;
			}
			try {
				Val = new BigDecimal(S);

				return Val;
			}
			catch (NumberFormatException E) {
				throw new java.sql.SQLException(
					"Bad format for BigDecimal '" + S + "' in column " + columnName + ".",
					"S1009");
			}
		}

		return null; // SQL NULL
	}

	//---------------------------------------------------------------------
	// Traversal/Positioning
	//---------------------------------------------------------------------

	/**
	 * JDBC 1.0, over-ridden to handle row-updates
	 */

	public  boolean next() throws SQLException {
		if (_on_insert_row) {
			_on_insert_row = false;
		}

		if (_doing_updates) {
			_doing_updates = false;
			
		}

		return super.next();
	}

	/**
	 * JDBC 2.0
	 *
	 * <p>Determine if the cursor is before the first row in the result 
	 * set.   
	 *
	 * @return true if before the first row, false otherwise. Returns
	 * false when the result set contains no rows.
	 * @exception SQLException if a database-access error occurs.
	 */

	public  boolean isBeforeFirst() throws SQLException {
		if (Driver.trace) {
			Object[] args = {
			};
			Debug.methodCall(this, "isBeforeFirst", args);
		}
		
		boolean b = false;
		
		if (_rows.size() == 0) {
			b = false;
		}
		else {
			b = (_currentRow == -1);
		}
		
		if (Driver.trace) {
			Debug.returnValue(this, "isBeforeFirst", new Boolean(b));
		}
		
		return b;
	}

	/**
	 * JDBC 2.0
	 *
	 * <p>Determine if the cursor is after the last row in the result 
	 * set.   
	 *
	 * @return true if after the last row, false otherwise.  Returns
	 * false when the result set contains no rows.
	 * @exception SQLException if a database-access error occurs.
	 */

	public  boolean isAfterLast() throws SQLException {
		if (Driver.trace) {
			Object[] args = {
			};
			Debug.methodCall(this, "isAfterLast", args);
		}
		
		boolean b = false;
		
		if (_rows.size() == 0) {
			b =  false;
		}
		else {
			b = (_currentRow >= _rows.size());
		}
		
		if (Driver.trace) {
			Debug.returnValue(this, "isAfterLast", new Boolean(b));
		}
		
		return b;
	}

	/**
	 * JDBC 2.0
	 *
	 * <p>Determine if the cursor is on the first row of the result set.   
	 *
	 * @return true if on the first row, false otherwise.   
	 * @exception SQLException if a database-access error occurs.
	 */

	public  boolean isFirst() throws SQLException {
		if (Driver.trace) {
			Object[] args = {
			};
			Debug.methodCall(this, "isFirst", args);
		}
		
		boolean b = false;
		
		if (_rows.size() == 0) {
			b = false;
		}
		else {
			b = (_currentRow == 0);
		}
		
		if (Driver.trace) {
			Debug.returnValue(this, "isFirst", new Boolean(b));
		}
		
		return b;
	}

	/**
	 * JDBC 2.0
	 *
	 * <p>Determine if the cursor is on the last row of the result set.   
	 * Note: Calling isLast() may be expensive since the JDBC driver
	 * might need to fetch ahead one row in order to determine 
	 * whether the current row is the last row in the result set.
	 *
	 * @return true if on the last row, false otherwise. 
	 * @exception SQLException if a database-access error occurs.
	 */

	public  boolean isLast() throws SQLException {
		if (Driver.trace) {
			Object[] args = {
			};
			Debug.methodCall(this, "isLast", args);
		}
		
		boolean b = false;
		
		if (_rows.size() == 0) {
			b = false;
		}
		else {
			b = (_currentRow == _rows.size() - 1);
		}
		
		if (Driver.trace) {
			Debug.returnValue(this, "relative", new Boolean(b));
		}
		
		return b;
	}

	/**
	 * 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.
	 *
	 * @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);
		}
		if (_on_insert_row) {
			_on_insert_row = false;
		}

		if (_doing_updates) {
			_doing_updates = false;
			
		}

		if (_rows.size() == 0) {
			return;
		}
		else {
			_currentRow = -1;
			_thisRow = null;
		}
	}

	/**
	 * 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.
	 *
	 * @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);
		}
		if (_on_insert_row) {
			_on_insert_row = false;
		}

		if (_doing_updates) {
			_doing_updates = false;
			
		}

		if (_rows.size() != 0) {
			_currentRow = _rows.size();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -