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

📄 ssresultset.java

📁 java 数据库 功能强大 效率高 SmallSQL Database is a free DBMS library for the Java(tm) platform. It runs on
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* =============================================================
 * SmallSQL : a free Java DBMS library for the Java(tm) platform
 * =============================================================
 *
 * (C) Copyright 2004-2006, by Volker Berlin.
 *
 * Project Info:  http://www.smallsql.de/
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 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 Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * SSResultSet.java
 * ---------------
 * Author: Volker Berlin
 * 
 */
package smallsql.database;

import java.sql.*;
import java.math.*;
import java.io.InputStream;
import java.io.Reader;
import java.util.Map;
import java.util.Calendar;
import java.net.URL;


public class SSResultSet implements ResultSet {

    SSResultSetMetaData metaData = new SSResultSetMetaData();
    private CommandSelect cmd;
    private boolean wasNull;
    SSStatement st;
    private boolean isUpdatable;
    private boolean isInsertRow;
    private ExpressionValue[] values;
    private int fetchDirection;
    private int fetchSize;

    SSResultSet( SSStatement st, CommandSelect cmd ){
        this.st = st;
        metaData.columns = cmd.columnExpressions;
        this.cmd = cmd;
		isUpdatable = st != null && st.rsConcurrency == CONCUR_UPDATABLE && !cmd.isGroupResult();
    }

/*==============================================================================

    Public Interface

==============================================================================*/

    public void close(){
    	st.con.log.println("ResultSet.close");
        cmd = null;
    }
    
    
    public boolean wasNull(){
        return wasNull;
    }
    
    
    public String getString(int columnIndex) throws SQLException {
        try{
            String obj = getValue(columnIndex).getString();
            wasNull = obj == null;
            return obj;
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public boolean getBoolean(int columnIndex) throws SQLException {
        try{
            Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
            return expr.getBoolean();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public byte getByte(int columnIndex) throws SQLException {
        return (byte)getInt( columnIndex );
    }
    public short getShort(int columnIndex) throws SQLException {
        return (short)getInt( columnIndex );
    }
    public int getInt(int columnIndex) throws SQLException {
        try{
            Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
            return expr.getInt();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public long getLong(int columnIndex) throws SQLException {
        try{
            Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
            return expr.getLong();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public float getFloat(int columnIndex) throws SQLException {
        try{
            Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
            return expr.getFloat();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public double getDouble(int columnIndex) throws SQLException {
        try{
            Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
            return expr.getDouble();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
        try{
            MutableNumeric obj = getValue(columnIndex).getNumeric();
            wasNull = obj == null;
            if(wasNull) return null;
            return obj.toBigDecimal(scale);
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public byte[] getBytes(int columnIndex) throws SQLException {
        try{
            byte[] obj = getValue(columnIndex).getBytes();
            wasNull = obj == null;
            return obj;
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public Date getDate(int columnIndex) throws SQLException {
        try{
			Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
			if(wasNull) return null;
			return DateTime.getDate( expr.getLong() );
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    
    
    public Time getTime(int columnIndex) throws SQLException {
        try{
			Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
			if(wasNull) return null;
			return DateTime.getTime( expr.getLong() );
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public Timestamp getTimestamp(int columnIndex) throws SQLException {
        try{
			Expression expr = getValue(columnIndex);
            wasNull = expr.isNull();
			if(wasNull) return null;
			return DateTime.getTimestamp( expr.getLong() );
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    
    
    public InputStream getAsciiStream(int columnIndex) throws SQLException {
        /**@todo: Implement this java.sql.ResultSet.getAsciiStream method*/
        throw Utils.createUnsupportedException("getAsciiStream");
    }
    
    
    public InputStream getUnicodeStream(int columnIndex) throws SQLException {
        /**@todo: Implement this java.sql.ResultSet.getUnicodeStream method*/
        throw Utils.createUnsupportedException("getUnicodeStream");
    }
    
    
    public InputStream getBinaryStream(int columnIndex) throws SQLException {
        /**@todo: Implement this java.sql.ResultSet.getBinaryStream method*/
        throw Utils.createUnsupportedException("getBinaryStream");
    }
    
    
    public String getString(String columnName) throws SQLException {
        return getString( findColumn( columnName ) );
    }
    public boolean getBoolean(String columnName) throws SQLException {
        return getBoolean( findColumn( columnName ) );
    }
    public byte getByte(String columnName) throws SQLException {
        return getByte( findColumn( columnName ) );
    }
    public short getShort(String columnName) throws SQLException {
        return getShort( findColumn( columnName ) );
    }
    public int getInt(String columnName) throws SQLException {
        return getInt( findColumn( columnName ) );
    }
    public long getLong(String columnName) throws SQLException {
        return getLong( findColumn( columnName ) );
    }
    public float getFloat(String columnName) throws SQLException {
        return getFloat( findColumn( columnName ) );
    }
    public double getDouble(String columnName) throws SQLException {
        return getDouble( findColumn( columnName ) );
    }
    public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
        return getBigDecimal( findColumn( columnName ), scale );
    }
    public byte[] getBytes(String columnName) throws SQLException {
        return getBytes( findColumn( columnName ) );
    }
    public Date getDate(String columnName) throws SQLException {
        return getDate( findColumn( columnName ) );
    }
    public Time getTime(String columnName) throws SQLException {
        return getTime( findColumn( columnName ) );
    }
    public Timestamp getTimestamp(String columnName) throws SQLException {
        return getTimestamp( findColumn( columnName ) );
    }
    public InputStream getAsciiStream(String columnName) throws SQLException {
        return getAsciiStream( findColumn( columnName ) );
    }
    public InputStream getUnicodeStream(String columnName) throws SQLException {
        return getUnicodeStream( findColumn( columnName ) );
    }
    public InputStream getBinaryStream(String columnName) throws SQLException {
        return getBinaryStream( findColumn( columnName ) );
    }
    
    
    public SQLWarning getWarnings(){
        return null;
    }
    
    
    public void clearWarnings(){
        //TODO support for Warnings
    }
    
    
    public String getCursorName(){
        return null;
    }
    
    
    public ResultSetMetaData getMetaData(){
        return metaData;
    }
    
    
    public Object getObject(int columnIndex) throws SQLException {
        try{
            Object obj = getValue(columnIndex).getApiObject();
            wasNull = obj == null;
            return obj;
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public Object getObject(String columnName) throws SQLException {
        return getObject( findColumn( columnName ) );
    }
    
    
    public int findColumn(String columnName) throws SQLException {
    	return getCmd().findColumn(columnName) + 1;
    }
    

    public Reader getCharacterStream(int columnIndex) throws SQLException {
        /**@todo: Implement this java.sql.ResultSet.getCharacterStream method*/
        throw Utils.createUnsupportedException("getCharacterStream");
    }
    
    
    public Reader getCharacterStream(String columnName) throws SQLException {
        return getCharacterStream( findColumn( columnName ) );
    }
    
    
    public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
        try{
            MutableNumeric obj = getValue(columnIndex).getNumeric();
            wasNull = obj == null;
            if(wasNull) return null;
            return obj.toBigDecimal();
        }catch(Exception e){
            throw Utils.createSQLException( e );
        }
    }
    public BigDecimal getBigDecimal(String columnName) throws SQLException {
        return getBigDecimal( findColumn( columnName ) );
    }
    public boolean isBeforeFirst() throws SQLException {
		return getCmd().isBeforeFirst();
    }
    
    
    public boolean isAfterLast() throws SQLException {
        try{
            return getCmd().isAfterLast();
        }catch(Exception e){
            throw Utils.createSQLException(e);
        }
    }
    
    
    public boolean isFirst() throws SQLException {
    	return getCmd().isFirst();
    }
    
    
    public boolean isLast() throws SQLException {
    	try{
    		return getCmd().isLast();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
    }
    
    
    public void beforeFirst() throws SQLException {
    	try{
            moveToCurrentRow();
    		getCmd().beforeFirst();
    	}catch(Exception e){
    		throw Utils.createSQLException(e);
    	}
    }
    
    
    public boolean first() throws SQLException {
		try{
			if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only.");
            moveToCurrentRow();
			return getCmd().first();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
    }
    
    
	public boolean previous() throws SQLException {
		try{
            moveToCurrentRow();
			return getCmd().previous();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
	}
    
    
	public boolean next() throws SQLException {
		try{
            moveToCurrentRow();
            return getCmd().next();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
	}
	
	
    public boolean last() throws SQLException {
		try{
            moveToCurrentRow();
            return getCmd().last();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
    }
    
    
	public void afterLast() throws SQLException {
		try{
			if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only.");
            moveToCurrentRow();
            getCmd().afterLast();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
	}
    
    
    public boolean absolute(int row) throws SQLException {
		try{
            moveToCurrentRow();
			return getCmd().absolute(row);
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
    }
    
    
    public boolean relative(int rows) throws SQLException {
		try{
            moveToCurrentRow();
			return getCmd().relative(rows);
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
    }
    
    
	public int getRow() throws SQLException {
		try{
			return getCmd().getRow();
		}catch(Exception e){
			throw Utils.createSQLException(e);
		}
	}
    
    
    public void setFetchDirection(int direction){
        fetchDirection = direction;
    }
    

⌨️ 快捷键说明

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