From: brian z. <bz...@us...> - 2001-12-16 05:01:30
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv5797/ziclix/python/sql Modified Files: PyCursor.java Log Message: abstract the sql execution in preparation for callable statements Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyCursor.java 2001/12/10 03:37:40 1.8 --- PyCursor.java 2001/12/16 05:01:27 1.9 *************** *** 216,219 **** --- 216,235 ---- /** + * An interface to allow the abstraction of SQL execution for + * different statements. + */ + private static interface ExecuteSQL { + + /** + * Execute a SQL statement and add the results to Fetch as + * appropriate. + * + * @throws SQLException + * + */ + public void executeSQL() throws SQLException; + } + + /** * Delete the cursor. * *************** *** 364,368 **** * @param maxRows integer value of max rows */ ! public void execute(String sqlString, PyObject params, PyObject bindings, PyObject maxRows) { clear(); --- 380,384 ---- * @param maxRows integer value of max rows */ ! public void execute(final String sqlString, PyObject params, PyObject bindings, PyObject maxRows) { clear(); *************** *** 374,389 **** if (hasParams) { - execute(params, bindings); - } else { - this.datahandler.preExecute(this.sqlStatement); ! if (this.sqlStatement.execute(sqlString)) { ! create(this.sqlStatement.getResultSet()); } ! this.rowid = this.datahandler.getRowId(this.sqlStatement); ! addWarning(this.sqlStatement.getWarnings()); ! this.datahandler.postExecute(this.sqlStatement); } } catch (PyException e) { --- 390,418 ---- if (hasParams) { ! // if we have a sequence of sequences, let's run through them and finish ! if (isSeqSeq(params)) { ! ! // [(3, 4)] or [(3, 4), (5, 6)] ! for (int i = 0, len = params.__len__(); i < len; i++) { ! PyObject param = params.__getitem__(i); ! ! execute(param, bindings); ! } ! } else { ! execute(params, bindings); } + } else { ! // execute the sql string straight up ! execute(new ExecuteSQL() { ! public void executeSQL() throws SQLException { ! ! if (sqlStatement.execute(sqlString)) { ! create(sqlStatement.getResultSet()); ! } ! } ! }); } } catch (PyException e) { *************** *** 395,424 **** /** ! * The workhorse for properly executing a prepared statement. * ! * @param PyObject params a non-None seq of sequences or entities ! * @param PyObject bindings an optional dictionary of index:DBApiType mappings * * @throws SQLException * */ ! protected void execute(PyObject params, PyObject bindings) throws SQLException { ! // if we have a sequence of sequences, let's run through them and finish ! if (isSeqSeq(params)) { ! // [(3, 4)] or [(3, 4), (5, 6)] ! for (int i = 0, len = params.__len__(); i < len; i++) { ! PyObject param = params.__getitem__(i); ! execute(param, bindings); ! } ! // we've recursed through everything, so we're done ! return; ! } // [3, 4] or (3, 4) ! PreparedStatement preparedStatement = (PreparedStatement)this.sqlStatement; // clear the statement so all new bindings take affect --- 424,461 ---- /** ! * Performs the execution * ! * @param ExecuteSQL execute * * @throws SQLException * */ ! protected void execute(ExecuteSQL execute) throws SQLException { ! this.datahandler.preExecute(this.sqlStatement); ! // this performs the SQL execution and fetch per the Statement type ! execute.executeSQL(); ! this.rowid = this.datahandler.getRowId(this.sqlStatement); ! addWarning(this.sqlStatement.getWarnings()); ! this.datahandler.postExecute(this.sqlStatement); ! } ! ! /** ! * The workhorse for properly preparing the parameters and executing a ! * prepared statement. ! * ! * @param PyObject params a non-None seq of sequences or entities ! * @param PyObject bindings an optional dictionary of index:DBApiType mappings ! * ! * @throws SQLException ! * ! */ ! protected void execute(PyObject params, PyObject bindings) throws SQLException { // [3, 4] or (3, 4) ! final PreparedStatement preparedStatement = (PreparedStatement)this.sqlStatement; // clear the statement so all new bindings take affect *************** *** 449,460 **** } ! this.datahandler.preExecute(preparedStatement); ! preparedStatement.execute(); ! create(preparedStatement.getResultSet()); ! this.rowid = this.datahandler.getRowId(preparedStatement); ! addWarning(preparedStatement.getWarnings()); ! this.datahandler.postExecute(preparedStatement); return; --- 486,498 ---- } ! execute(new ExecuteSQL() { ! public void executeSQL() throws SQLException { ! if (preparedStatement.execute()) { ! create(preparedStatement.getResultSet()); ! } ! } ! }); return; *************** *** 523,527 **** /** ! * Create the results after a successful execution and closes the result set. * * @param rs A ResultSet. --- 561,565 ---- /** ! * Create the results after a successful execution and manages the result set. * * @param rs A ResultSet. *************** *** 532,536 **** /** ! * Create the results after a successful execution and closes the result set. * Optionally takes a set of JDBC-indexed columns to automatically set to None * primarily to support getTypeInfo() which sets a column type of a number but --- 570,574 ---- /** ! * Create the results after a successful execution and manages the result set. * Optionally takes a set of JDBC-indexed columns to automatically set to None * primarily to support getTypeInfo() which sets a column type of a number but *************** *** 547,551 **** * Adds a warning to the tuple and will follow the chain as necessary. */ ! void addWarning(SQLWarning warning) { if (warning == null) { --- 585,589 ---- * Adds a warning to the tuple and will follow the chain as necessary. */ ! protected void addWarning(SQLWarning warning) { if (warning == null) { |