From: brian z. <bz...@us...> - 2002-04-12 04:12:30
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv31769/com/ziclix/python/sql Modified Files: Fetch.java PyConnection.java PyCursor.java PyExtendedCursor.java zxJDBC.java Log Message: added result set type and concurrency Index: Fetch.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Fetch.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Fetch.java 14 Jan 2002 04:28:41 -0000 1.7 --- Fetch.java 12 Apr 2002 04:12:27 -0000 1.8 *************** *** 794,798 **** int type = this.resultSet.getType(); ! if ((type == ResultSet.TYPE_SCROLL_SENSITIVE) || (type == ResultSet.TYPE_SCROLL_INSENSITIVE)) { if ("relative".equals(mode)) { if (value < 0) { --- 794,798 ---- int type = this.resultSet.getType(); ! if ((type != ResultSet.TYPE_FORWARD_ONLY) || (value > 0)) { if ("relative".equals(mode)) { if (value < 0) { *************** *** 820,824 **** this.rownumber = this.resultSet.getRow(); } else { ! throw zxJDBC.makeException(zxJDBC.NotSupportedError, "dynamic result set does not support scrolling"); } } catch (SQLException e) { --- 820,825 ---- this.rownumber = this.resultSet.getRow(); } else { ! String msg = "dynamic result set of type [" + type + "] does not support scrolling"; ! throw zxJDBC.makeException(zxJDBC.NotSupportedError, msg); } } catch (SQLException e) { Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyConnection.java 26 Mar 2002 02:46:36 -0000 1.6 --- PyConnection.java 12 Apr 2002 04:12:27 -0000 1.7 *************** *** 13,16 **** --- 13,17 ---- import java.util.*; import org.python.core.*; + import com.ziclix.python.sql.util.PyArgParser; /** *************** *** 111,115 **** dict.__setitem__("close", new ConnectionFunc("close", 0, 0, 0, zxJDBC.getString("close"))); dict.__setitem__("commit", new ConnectionFunc("commit", 1, 0, 0, zxJDBC.getString("commit"))); ! dict.__setitem__("cursor", new ConnectionFunc("cursor", 2, 0, 1, zxJDBC.getString("cursor"))); dict.__setitem__("rollback", new ConnectionFunc("rollback", 3, 0, 0, zxJDBC.getString("rollback"))); dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); --- 112,116 ---- dict.__setitem__("close", new ConnectionFunc("close", 0, 0, 0, zxJDBC.getString("close"))); dict.__setitem__("commit", new ConnectionFunc("commit", 1, 0, 0, zxJDBC.getString("commit"))); ! dict.__setitem__("cursor", new ConnectionFunc("cursor", 2, 0, 4, zxJDBC.getString("cursor"))); dict.__setitem__("rollback", new ConnectionFunc("rollback", 3, 0, 0, zxJDBC.getString("rollback"))); dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); *************** *** 312,320 **** * * @param dynamicFetch if true, dynamically iterate the result * @return a new cursor using this connection */ public PyCursor cursor(boolean dynamicFetch) { ! PyCursor cursor = new PyExtendedCursor(this, dynamicFetch); cursors.add(cursor); --- 313,337 ---- * * @param dynamicFetch if true, dynamically iterate the result + * * @return a new cursor using this connection */ public PyCursor cursor(boolean dynamicFetch) { + return this.cursor(dynamicFetch, Py.None, Py.None); + } ! /** ! * Return a new Cursor Object using the connection. If the database does not ! * provide a direct cursor concept, the module will have to emulate cursors ! * using other means to the extent needed by this specification. ! * ! * @param dynamicFetch if true, dynamically iterate the result ! * @param rsType the type of the underlying ResultSet ! * @param rsConcur the concurrency of the underlying ResultSet ! * ! * @return a new cursor using this connection ! */ ! public PyCursor cursor(boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { ! ! PyCursor cursor = new PyExtendedCursor(this, dynamicFetch, rsType, rsConcur); cursors.add(cursor); *************** *** 416,419 **** --- 433,514 ---- default : throw argCountError(1); + } + } + + /** + * Method __call__ + * + * @param PyObject arg1 + * @param PyObject arg2 + * + * @return PyObject + * + */ + public PyObject __call__(PyObject arg1, PyObject arg2) { + + PyConnection c = (PyConnection)__self__; + + switch (index) { + + case 2 : + throw Py.TypeError(name + "() takes exactly 0, 1 or 3 arguments (2 given)"); + default : + throw argCountError(2); + } + } + + /** + * Method __call__ + * + * @param PyObject arg1 + * @param PyObject arg2 + * @param PyObject arg3 + * + * @return PyObject + * + */ + public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { + + PyConnection c = (PyConnection)__self__; + + switch (index) { + + case 2 : + return c.cursor(arg1.__nonzero__(), arg2, arg3); + + default : + throw argCountError(3); + } + } + + /** + * Method __call__ + * + * @param PyObject[] args + * @param String[] keywords + * + * @return PyObject + * + */ + public PyObject __call__(PyObject[] args, String[] keywords) { + + PyConnection c = (PyConnection)__self__; + PyArgParser parser = new PyArgParser(args, keywords); + + switch (index) { + + case 2 : + PyObject dynamic = parser.kw("dynamic", Py.None); + PyObject rstype = parser.kw("rstype", Py.None); + PyObject rsconcur = parser.kw("rsconcur", Py.None); + + dynamic = (parser.numArg() >= 1) ? parser.arg(0) : dynamic; + rstype = (parser.numArg() >= 2) ? parser.arg(1) : rstype; + rsconcur = (parser.numArg() >= 3) ? parser.arg(2) : rsconcur; + + return c.cursor(dynamic.__nonzero__(), rstype, rsconcur); + + default : + throw argCountError(args.length); } } Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PyCursor.java 29 Mar 2002 04:01:03 -0000 1.19 --- PyCursor.java 12 Apr 2002 04:12:27 -0000 1.20 *************** *** 39,42 **** --- 39,48 ---- protected int softspace; + /** Field rsType */ + protected PyObject rsType; + + /** Field rsConcur */ + protected PyObject rsConcur; + /** Field warnings */ protected PyObject warnings; *************** *** 88,91 **** --- 94,99 ---- this.softspace = 0; this.closed = false; + this.rsType = Py.None; + this.rsConcur = Py.None; this.connection = connection; this.datahandler = DATAHANDLER; *************** *** 96,99 **** --- 104,120 ---- } + /** + * Create the cursor, optionally choosing the type of fetch (static or dynamic). + * If dynamicFetch is true, then use a dynamic fetch. + * rsType and rsConcur are used to create the Statement if both are non-None + */ + PyCursor(PyConnection connection, boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { + + this(connection, dynamicFetch); + + this.rsType = rsType; + this.rsConcur = rsConcur; + } + /** Field __class__ */ public static PyClass __class__; *************** *** 147,151 **** */ public String toString() { ! return "<PyCursor object instance at " + hashCode() + ">"; } --- 168,172 ---- */ public String toString() { ! return "<PyCursor object instance at " + Py.id(this) + ">"; } *************** *** 241,244 **** --- 262,267 ---- dict.__setitem__("dynamicFetch", null); dict.__setitem__("getPyClass", null); + dict.__setitem__("rsConcur", null); + dict.__setitem__("rsType", null); } *************** *** 347,351 **** * Prepare a statement ready for executing. * ! * @param sqlString * @param maxRows max number of rows to be returned * @param prepared if true, prepare the statement, otherwise create a normal statement --- 370,374 ---- * Prepare a statement ready for executing. * ! * @param sqlString the sql to execute * @param maxRows max number of rows to be returned * @param prepared if true, prepare the statement, otherwise create a normal statement *************** *** 354,361 **** protected void prepareStatement(String sqlString, PyObject maxRows, boolean prepared) throws SQLException { ! if (prepared) { ! this.sqlStatement = this.connection.connection.prepareStatement(sqlString); } else { ! this.sqlStatement = this.connection.connection.createStatement(); } --- 377,397 ---- protected void prepareStatement(String sqlString, PyObject maxRows, boolean prepared) throws SQLException { ! boolean normal = ((this.rsType == Py.None) && (this.rsConcur == Py.None)); ! ! if (normal) { ! if (prepared) { ! this.sqlStatement = this.connection.connection.prepareStatement(sqlString); ! } else { ! this.sqlStatement = this.connection.connection.createStatement(); ! } } else { ! int t = this.rsType.__int__().getValue(); ! int c = this.rsConcur.__int__().getValue(); ! ! if (prepared) { ! this.sqlStatement = this.connection.connection.prepareStatement(sqlString, t, c); ! } else { ! this.sqlStatement = this.connection.connection.createStatement(t, c); ! } } *************** *** 1091,1095 **** default : ! throw argCountError(4); } } --- 1127,1131 ---- default : ! throw argCountError(args.length); } } Index: PyExtendedCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyExtendedCursor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PyExtendedCursor.java 11 Jan 2002 21:46:01 -0000 1.9 --- PyExtendedCursor.java 12 Apr 2002 04:12:27 -0000 1.10 *************** *** 87,90 **** --- 87,103 ---- /** + * Constructor PyExtendedCursor + * + * @param PyConnection connection + * @param boolean dynamicFetch + * @param PyObject rsType + * @param PyObject rsConcur + * + */ + PyExtendedCursor(PyConnection connection, boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { + super(connection, dynamicFetch, rsType, rsConcur); + } + + /** * String representation of the object. * *************** *** 92,96 **** */ public String toString() { ! return "<PyExtendedCursor object instance at " + hashCode() + ">"; } --- 105,109 ---- */ public String toString() { ! return "<PyExtendedCursor object instance at " + Py.id(this) + ">"; } Index: zxJDBC.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/zxJDBC.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** zxJDBC.java 11 Jan 2002 21:46:01 -0000 1.7 --- zxJDBC.java 12 Apr 2002 04:12:27 -0000 1.8 *************** *** 148,151 **** --- 148,162 ---- sqltype.__setitem__(value, name); } + + c = Class.forName("java.sql.ResultSet"); + fields = c.getFields(); + + for (int i = 0; i < fields.length; i++) { + Field f = fields[i]; + PyString name = Py.newString(f.getName()); + PyObject value = Py.newInteger(f.getInt(c)); + + dict.__setitem__(name, value); + } } catch (Throwable t) { throw makeException(t); |