*
* 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.]
*
* ---------------
* SSStatement.java
* ---------------
* Author: Volker Berlin
*
*/
package smallsql.database;
import java.sql.*;
class SSStatement implements Statement {
SSConnection con;
Command cmd;
int rsType;
int rsConcurrency;
private int fetchDirection;
private int fetchSize;
private int queryTimeout;
private int maxRows;
private int maxFieldSize;
SSStatement( SSConnection con ) throws SQLException{
this( con, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY );
}
SSStatement( SSConnection con, int rsType, int rsConcurrency ) throws SQLException{
this.con = con;
this.rsType = rsType;
this.rsConcurrency = rsConcurrency;
con.testClosedConnection();
}
public ResultSet executeQuery(String sql) throws SQLException {
executeImpl(sql);
return cmd.getQueryResult();
}
public int executeUpdate(String sql) throws SQLException {
executeImpl(sql);
return cmd.getUpdateCount();
}
public boolean execute(String sql) throws SQLException {
executeImpl(sql);
return cmd.getResultSet() != null;
}
final private void executeImpl(String sql) throws SQLException {
try{
con.log.println(sql);
SQLParser parser = new SQLParser();
cmd = parser.parse( con, sql );
cmd.execute( con, this);
}catch(Exception e){
throw Utils.createSQLException(e);
}
}
public void close() throws SQLException {
}
public int getMaxFieldSize() throws SQLException {
return maxFieldSize;
}
public void setMaxFieldSize(int max) throws SQLException {
maxFieldSize = max;
}
public int getMaxRows(){
return maxRows;
}
public void setMaxRows(int max){
maxRows = max;
}
public void setEscapeProcessing(boolean enable) throws SQLException {
}
public int getQueryTimeout() throws SQLException {
return queryTimeout;
}
public void setQueryTimeout(int seconds) throws SQLException {
queryTimeout = seconds;
}
public void cancel() throws SQLException {
}
public SQLWarning getWarnings() throws SQLException {
return null;
}
public void clearWarnings() throws SQLException {
}
public void setCursorName(String name) throws SQLException {
throw new java.lang.UnsupportedOperationException("Method setCursorName() not yet implemented.");
}
public ResultSet getResultSet() throws SQLException {
return cmd.getResultSet();
}
public int getUpdateCount() throws SQLException {
return cmd.getUpdateCount();
}
public boolean getMoreResults() throws SQLException {
return getMoreResults(CLOSE_CURRENT_RESULT);
}
public void setFetchDirection(int direction) throws SQLException {
fetchDirection = direction;
}
public int getFetchDirection() throws SQLException {
return fetchDirection;
}
public void setFetchSize(int rows) throws SQLException {
fetchSize = rows;
}
public int getFetchSize() throws SQLException {
return fetchSize;
}
public int getResultSetConcurrency() throws SQLException {
return rsConcurrency;
}
public int getResultSetType() throws SQLException {
return rsType;
}
public void addBatch(String sql) throws SQLException {
throw new java.lang.UnsupportedOperationException("Method addBatch() not yet implemented.");
}
public void clearBatch() throws SQLException {
throw new java.lang.UnsupportedOperationException("Method clearBatch() not yet implemented.");
}
public int[] executeBatch() throws SQLException {
throw new java.lang.UnsupportedOperationException("Method executeBatch() not yet implemented.");
}
public Connection getConnection() throws SQLException {
return con;
}
public boolean getMoreResults(int current) throws SQLException {
switch(current){
case CLOSE_ALL_RESULTS:
case CLOSE_CURRENT_RESULT:
ResultSet rs = cmd.getResultSet();
cmd.rs = null;
if(rs != null) rs.close();
break;
case KEEP_CURRENT_RESULT:
break;
default:
throw Utils.createSQLException("Invalid flag value in method getMoreResults:"+current);
}
return false;
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new java.lang.UnsupportedOperationException("Method getGeneratedKeys() not yet implemented.");
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
return executeUpdate(sql);
}
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
return executeUpdate(sql);
}
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
return executeUpdate(sql);
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
return execute(sql);
}
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
return execute(sql);
}
public boolean execute(String sql, String[] columnNames) throws SQLException {
return execute(sql);
}
public int getResultSetHoldability() throws SQLException {
throw new java.lang.UnsupportedOperationException("Method getResultSetHoldability() not yet implemented.");
}
}