📄 tinysqlstatement.java
字号:
/** * * Statement object for the tinySQL driver * * A lot of this code is based on or directly taken from * George Reese's (borg@imaginary.com) mSQL driver. * * So, it's probably safe to say: * * Portions of this code Copyright (c) 1996 George Reese * * The rest of it: * * Copyright 1996, Brian C. Jepson * (bjepson@ids.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */import java.sql.SQLException;import java.sql.SQLWarning;import java.sql.ResultSet;public class tinySQLStatement implements java.sql.Statement { /** * * A connection object to execute queries and... stuff * */ private tinySQLConnection connection; /** * * A result set returned from this query * */ private tinySQLResultSet result; /** * * The max field size for tinySQL * This can be pretty big, before things start to break. * */ private int max_field_size = 0; /** * * The max rows supported by tinySQL * I can't think of any limits, right now, but I'm sure some * will crop up... * */ private int max_rows = 65536; /** * * The number of seconds the driver will allow for a SQL statement to * execute before giving up. The default is to wait forever (0). * */ private int timeout = 0; /** * * Constructs a new tinySQLStatement object. * @param conn the tinySQLConnection object * */ public tinySQLStatement(tinySQLConnection conn) { connection = conn; } /** * * Execute an SQL statement and return a result set. * @see java.sql.Statement#executeQuery * @exception SQLException raised for any errors * @param sql the SQL statement string * @return the result set from the query * */ public ResultSet executeQuery(String sql) throws SQLException { // tinySQL only supports one result set at a time, so // don't let them get another one, just in case it's // hanging out. // result = null; // create a new tinySQLResultSet with the tsResultSet // returned from connection.executetinySQL() // return new tinySQLResultSet(connection.executetinySQL(sql)); } /** * * Execute an update, insert, delete, create table, etc. This can * be anything that doesn't return rows. * @see java.sql.Statement#executeUpdate * @exception java.sql.SQLException thrown when an error occurs executing * the SQL * @return 0 - tinySQL does not support row count returns, yet */ public int executeUpdate(String sql) throws SQLException { connection.executetinySQL(sql); return 0; } /** * * Executes some SQL and returns true or false, depending on * the success. The result set is stored in result, and can * be retrieved with getResultSet(); * @see java.sql.Statement#execute * @exception SQLException raised for any errors * @param sql the SQL to be executed * @return true if there is a result set available */ public boolean execute(String sql) throws SQLException { // a result set object // tsResultSet r; // execute the query // r = connection.executetinySQL(sql); // check for a null result set. If it wasn't null, // use it to create a tinySQLResultSet, and return whether or // not it is null (not null returns true). // if( r == null ) { result = null; } else { result = new tinySQLResultSet(r); } return (result != null); } /** * * Close any result sets. This is not used by tinySQL. * @see java.sql.Statement#close * */ public void close() throws SQLException { } /** * * Returns the last result set * @see java.sql.Statement#getResultSet * @return null if no result set is available, otherwise a result set * */ public ResultSet getResultSet() throws SQLException { ResultSet r; r = result; // save the existing result set result = null; // null out the existing result set return r; // return the previously extant result set } /** * * Return the row count of the last operation. tinySQL does not support * this, so it returns -1 * @see java.sql.Statement#getUpdateCount * @return -1 */ public int getUpdateCount() throws SQLException { return -1; } /** * * This returns true if there are any pending result sets. This * should only be true after invoking execute() * @see java.sql.Statement#getMoreResults * @return true if rows are to be gotten * */ public boolean getMoreResults() throws SQLException { return (result != null); } /** * * Get the maximum field size to return in a result set. * @see java.sql.Statement#getMaxFieldSize * @return the value of max field size * */ public int getMaxFieldSize() throws SQLException { return max_field_size; } /** * * set the max field size. * @see java.sql.Statement#setMaxFieldSize * @param max the maximum field size * */ public void setMaxFieldSize(int max) throws SQLException { max_field_size = max; } /** * * Get the maximum row count that can be returned by a result set. * @see java.sql.Statement#getMaxRows * @return the maximum rows * */ public int getMaxRows() throws SQLException { return max_rows; } /** * * Get the maximum row count that can be returned by a result set. * @see java.sql.Statement.setMaxRows * @param max the max rows * */ public void setMaxRows(int max) throws SQLException { max_rows = max; } /** * * If escape scanning is on (the default) the driver will do * escape substitution before sending the SQL to the database. * @see java.sql.Statement#setEscapeProcessing * @param enable this does nothing right now * */ public void setEscapeProcessing(boolean enable) throws SQLException { throw new SQLException("The tinySQL Driver doesn't " + "support escape processing."); } /** * * Discover the query timeout. * @see java.sql.Statement#getQueryTimeout * @see setQueryTimeout * @return the timeout value for this statement * */ public int getQueryTimeout() throws SQLException { return timeout; } /** * * Set the query timeout. * @see java.sql.Statement#setQueryTimeout * @see getQueryTimeout * @param x the new query timeout value * */ public void setQueryTimeout(int x) throws SQLException { timeout = x; } /** * * This can be used by another thread to cancel a statement. This * doesn't matter for tinySQL, as far as I can tell. * @see java.sql.Statement#cancel * */ public void cancel() { } /** * * Get the warning chain associated with this Statement * @see java.sql.Statement#getWarnings * @return the chain of warnings * */ public final SQLWarning getWarnings() throws SQLException { return null; } /** * * Clear the warning chain associated with this Statement * @see java.sql.Statement#clearWarnings * */ public void clearWarnings() throws SQLException { } /** * * Sets the cursor name for this connection. Presently unsupported. * */ public void setCursorName(String unused) throws SQLException { throw new SQLException("tinySQL does not support cursors."); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -