FileDocCategorySizeDatePackage
MsqlStatement.javaAPI DocExample4892Tue Jan 01 00:00:00 GMT 1980COM.imaginary.sql.msql

MsqlStatement

public class MsqlStatement extends Object implements Statement
The MsqlStatement class implements the JDBC Statement interface. This class represents any SQL statement.
Last modified %D%
version
%A%
author
George Reese (borg@imaginary.com)

Fields Summary
private MsqlConnection
connection
private MsqlResultSet
current
private MsqlInputStream
input
private int
max_field_size
private int
max_rows
private MsqlOutputStream
output
private ResultSet
result
private int
row_or_column_count
private int
timeout
private SQLWarning
warnings
Constructors Summary
MsqlStatement(MsqlConnection c, MsqlInputStream in, MsqlOutputStream out)

    
         
      
	connection = c;
	input = in;
	output = out;
    
Methods Summary
public voidcancel()

	
    
public voidclearWarnings()

	warnings = null;
    
public voidclose()

	if( current != null ) {
	    try {
		current.close();
	    }
	    catch( SQLException e ) {
		current = null;
		throw e;
	    }
	    current = null;
	}
    
private voidcloseAllResults()

	if( result != null ) {
	    try {
		result.close();
	    }
	    catch( SQLException e ) {
		e.printStackTrace();
	    }
	    result = null;
	}
	if( current != null ) {
	    try {
		current.close();
	    }
	    catch( SQLException e ) {
		e.printStackTrace();
	    }
	    current = null;
	}
    
public booleanexecute(java.lang.String sql)

	ResultSet r = null;

	closeAllResults();
	if( !sendSQL(sql) ) {
	    return false;
	}
	else {
	    current = new MsqlResultSet(this, input, row_or_column_count);
	    result = current;
	    return true;
	}
    
public synchronized java.sql.ResultSetexecuteQuery(java.lang.String sql)

	closeAllResults();
	if( sendSQL(sql) ) {
	    current = new MsqlResultSet(this, input, row_or_column_count);
	}
	else {
	    throw new SQLException("Non-query sent to executeQuery().");
	}
	return current;
    
public intexecuteUpdate(java.lang.String sql)

	closeAllResults();
	if( !sendSQL(sql) ) {
	    return row_or_column_count;
	}
	else {
	    throw new SQLException("Query sent to executeUpdate().");
	}
    
MsqlConnectiongetConnection()

	return connection;
    
public intgetMaxFieldSize()

	return max_field_size;
    
public intgetMaxRows()

	return max_rows;
    
public intgetMoreCounts()

	return -1;
    
public booleangetMoreResults()

	return (result != null);
    
public intgetQueryTimeout()

	return timeout;
    
public java.sql.ResultSetgetResultSet()

	ResultSet r;
	
	r = result; 
	result = null;
	return r;
    
public intgetUpdateCount()

	int x = row_or_column_count;

	if( result != null ) {
	    x = -1;
	}
	row_or_column_count = -1;
	return x;
    
public final java.sql.SQLWarninggetWarnings()

	return warnings;
    
private booleansendSQL(java.lang.String sql)

	String tmp;
	int i;

	try {
	    output.writeAsciiString("3 " + sql);
	    tmp = input.readAsciiString();
	}
	catch( IOException e ) {
	    try {
		connection.close();
		close();
	    }
	    catch( SQLException ee ) {
	    }
	    throw new MsqlException(e);
	}
	i = tmp.indexOf(':");
	if( i == -1 ) {
	    throw new SQLException("Incorrect mSQL response.");
	}
	row_or_column_count = Integer.parseInt(tmp.substring(0, i));
	if( row_or_column_count == -1 ) {
	    throw new SQLException(tmp.substring(2));
	}
	i = tmp.indexOf(':", 2);
	if( i == -1 ) {
	    return false;
	}
	else {
	    try {
		row_or_column_count = Integer.parseInt(tmp.substring(2, i));
	    }
	    catch( NumberFormatException e ) {
		row_or_column_count = 0;
		return false;
	    }
	    return true;
	}
    
public voidsetCursorName(java.lang.String unused)

	throw new SQLException("mSQL does not support cursors.");
    
public voidsetEscapeProcessing(boolean enable)

	throw new SQLException("mSQL does not support escape processing.");
    
public voidsetMaxFieldSize(int max)

	max_field_size = max;
    
public voidsetMaxRows(int max)

	max_rows = max;
    
public voidsetQueryTimeout(int x)

	timeout = x;