You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: brian z. <bz...@us...> - 2002-05-10 16:11:44
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql/handler In directory usw-pr-cvs1:/tmp/cvs-serv25484/com/ziclix/python/sql/handler Modified Files: SQLServerDataHandler.java Log Message: extensible stored procedures Index: SQLServerDataHandler.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/handler/SQLServerDataHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SQLServerDataHandler.java 29 Dec 2001 07:16:20 -0000 1.1 --- SQLServerDataHandler.java 10 May 2002 16:11:41 -0000 1.2 *************** *** 15,18 **** --- 15,19 ---- import org.python.core.*; import com.ziclix.python.sql.*; + import com.ziclix.python.sql.procedure.*; /** *************** *** 37,40 **** --- 38,45 ---- } + public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException { + return new SQLServerProcedure(cursor, name); + } + /** * Given a ResultSet, column and type, return the appropriate *************** *** 63,87 **** return (set.wasNull() || (obj == null)) ? Py.None : obj; - } - - /** - * Method getProcedureName - * - * @param PyObject catalog - * @param PyObject schema - * @param PyObject name - * - * @return String - * - */ - public String getProcedureName(PyObject catalog, PyObject schema, PyObject name) { - - StringBuffer procName = new StringBuffer(); - - if ((schema != Py.EmptyString) && (schema != Py.None)) { - procName.append(schema.toString()).append("."); - } - - return procName.append(name.toString()).toString(); } } --- 68,71 ---- |
From: brian z. <bz...@us...> - 2002-05-10 16:11:44
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv25484/Lib/test/zxjdbc Modified Files: zxtest.py test.xml sptest.py dbextstest.py Log Message: extensible stored procedures Index: zxtest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/zxtest.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** zxtest.py 9 May 2002 01:03:37 -0000 1.16 --- zxtest.py 10 May 2002 16:11:41 -0000 1.17 *************** *** 764,769 **** c.execute("select * from zxtesting", maxrows=3) ! f = c.fetchall() ! assert len(f) == 3, "expected length [3], got [%d]" % (len(f)) c.execute("select count(*) from zxtesting") --- 764,771 ---- c.execute("select * from zxtesting", maxrows=3) ! self.assertEquals(3, len(c.fetchall())) ! ! c.execute("select * from zxtesting where id > ?", (1,), maxrows=3) ! self.assertEquals(3, len(c.fetchall())) c.execute("select count(*) from zxtesting") *************** *** 772,777 **** c.execute("select * from zxtesting", maxrows=0) ! f = c.fetchall() ! assert len(f) == num, "expected length [%d], got [%d]" % (num, len(f)) finally: --- 774,778 ---- c.execute("select * from zxtesting", maxrows=0) ! self.assertEquals(num, len(c.fetchall())) finally: Index: test.xml =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/test.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test.xml 9 May 2002 01:03:37 -0000 1.8 --- test.xml 10 May 2002 16:11:41 -0000 1.9 *************** *** 210,214 **** <ignore name="testRowid"/> </testcase> - <testcase from="zxtest" import="LOBTestCase"/> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> --- 210,213 ---- Index: sptest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/sptest.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sptest.py 9 May 2002 01:03:37 -0000 1.4 --- sptest.py 10 May 2002 16:11:41 -0000 1.5 *************** *** 191,202 **** c = self.cursor() try: ! c.execute("use ziclix") ! ! self.assertEquals("ziclix", c.connection.__connection__.getCatalog()) ! ! try: ! c.execute("drop table sptest") ! except: ! pass c.execute("create table sptest (a int, b varchar(32))") --- 191,199 ---- c = self.cursor() try: ! for a in (("table", "sptest"), ("procedure", "sp_proctest")): ! try: ! c.execute("drop %s %s" % (a)) ! except: ! pass c.execute("create table sptest (a int, b varchar(32))") *************** *** 205,220 **** c.execute("insert into sptest values (3, 'goodbye')") ! try: ! c.execute("drop procedure sp_proctest") ! except: ! pass ! ! c.execute(""" ! create procedure sp_proctest (@A int) ! as ! select a, b from sptest where a <= @A ! """) ! c.callproc(("ziclix", "jython", "sp_proctest"), (2,)) data = c.fetchall() self.assertEquals(2, len(data)) --- 202,209 ---- c.execute("insert into sptest values (3, 'goodbye')") ! c.execute(""" create procedure sp_proctest (@A int) as select a, b from sptest where a <= @A """) ! self.db.commit() ! c.callproc("sp_proctest", (2,)) data = c.fetchall() self.assertEquals(2, len(data)) *************** *** 227,239 **** c.close() ! def testSalesByCategory(self): ! c = self.cursor() ! try: ! c.execute("use northwind") ! c.callproc(("northwind", "dbo", "SalesByCategory"), ["Seafood", "1998"]) ! data = c.fetchall() ! assert data is not None, "no results from SalesByCategory" ! assert len(data) > 0, "expected numerous results" ! finally: ! c.close() ! --- 216,227 ---- c.close() ! # def testSalesByCategory(self): ! # c = self.cursor() ! # try: ! # c.execute("use northwind") ! # c.callproc(("northwind", "dbo", "SalesByCategory"), ["Seafood", "1998"]) ! # data = c.fetchall() ! # assert data is not None, "no results from SalesByCategory" ! # assert len(data) > 0, "expected numerous results" ! # finally: ! # c.close() Index: dbextstest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/dbextstest.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dbextstest.py 21 Apr 2002 14:22:15 -0000 1.5 --- dbextstest.py 10 May 2002 16:11:41 -0000 1.6 *************** *** 114,119 **** self._insertInto("one", 45) self.db.raw("select * from one where a > ?", [(12,)], maxrows=3) ! assert len(self.db.results) == 3, "failed to query set number of max rows, got [%d], expected [%d]" % (len(self.db.results), 3) def testBulkcopy(self): --- 114,121 ---- self._insertInto("one", 45) + self.db.raw("select * from one", maxrows=3) + self.assertEquals(3, len(self.db.results)) self.db.raw("select * from one where a > ?", [(12,)], maxrows=3) ! self.assertEquals(3, len(self.db.results)) def testBulkcopy(self): |
From: brian z. <bz...@us...> - 2002-05-10 16:11:44
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv25484/com/ziclix/python/sql Modified Files: PyCursor.java PyConnection.java Procedure.java DataHandler.java Log Message: extensible stored procedures Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** PyCursor.java 9 May 2002 21:44:29 -0000 1.26 --- PyCursor.java 10 May 2002 16:11:41 -0000 1.27 *************** *** 461,465 **** } ! final Procedure procedure = new Procedure(this, name); Statement stmt = procedure.prepareCall(this.rsType, this.rsConcur); --- 461,465 ---- } ! final Procedure procedure = datahandler.getProcedure(this, name); Statement stmt = procedure.prepareCall(this.rsType, this.rsConcur); *************** *** 813,817 **** * Method isSeq * - * * @param object * --- 813,816 ---- *************** *** 819,823 **** * */ ! protected boolean isSeq(PyObject object) { if ((object == null) || (object == Py.None)) { --- 818,822 ---- * */ ! public static boolean isSeq(PyObject object) { if ((object == null) || (object == Py.None)) { *************** *** 837,841 **** * Method hasParams * - * * @param params * --- 836,839 ---- *************** *** 843,847 **** * */ ! protected boolean hasParams(PyObject params) { if (Py.None == params) { --- 841,845 ---- * */ ! public static boolean hasParams(PyObject params) { if (Py.None == params) { *************** *** 862,866 **** * Method isSeqSeq * - * * @param object * --- 860,863 ---- *************** *** 868,872 **** * */ ! protected boolean isSeqSeq(PyObject object) { if (isSeq(object) && (object.__len__() > 0)) { --- 865,869 ---- * */ ! public static boolean isSeqSeq(PyObject object) { if (isSeq(object) && (object.__len__() > 0)) { Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PyConnection.java 9 May 2002 01:03:37 -0000 1.10 --- PyConnection.java 10 May 2002 16:11:41 -0000 1.11 *************** *** 118,122 **** * Method classDictInit * - * * @param dict * --- 118,121 ---- Index: Procedure.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Procedure.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Procedure.java 12 Apr 2002 20:32:45 -0000 1.7 --- Procedure.java 10 May 2002 16:11:41 -0000 1.8 *************** *** 82,87 **** if (name instanceof PyString) { ! this.procedureCatalog = Py.EmptyString; ! this.procedureSchema = Py.EmptyString; this.procedureName = name; } else if (this.cursor.isSeq(name)) { --- 82,87 ---- if (name instanceof PyString) { ! this.procedureCatalog = getDefault(); ! this.procedureSchema = getDefault(); this.procedureName = name; } else if (this.cursor.isSeq(name)) { *************** *** 275,279 **** } ! String name = cursor.datahandler.getProcedureName(procedureCatalog, procedureSchema, procedureName); sql.append("call ").append(name).append("("); --- 275,279 ---- } ! String name = this.getProcedureName(); sql.append("call ").append(name).append("("); *************** *** 324,328 **** /** ! * Method fetchColumns * * @throws SQLException --- 324,328 ---- /** ! * Get the columns for the stored procedure. * * @throws SQLException *************** *** 342,345 **** --- 342,372 ---- pec.close(); } + } + + /** + * The value for a missing schema or catalog. This value is used to find + * the column names for the procedure. Not all DBMS use the same default + * value; for instance Oracle uses an empty string and SQLServer a null. + * This implementation returns the empty string. + * + * @return the default value (the empty string) + * @see java.sql.DatabaseMetaData#getProcedureColumns + */ + protected PyObject getDefault() { + return Py.EmptyString; + } + + /** + * Construct a procedure name for the relevant schema and catalog information. + */ + protected String getProcedureName() { + + StringBuffer proc = new StringBuffer(); + + if (this.procedureCatalog.__nonzero__()) { + proc.append(this.procedureCatalog.toString()).append("."); + } + + return proc.append(this.procedureName.toString()).toString(); } } Index: DataHandler.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/DataHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataHandler.java 11 Jan 2002 21:46:01 -0000 1.6 --- DataHandler.java 10 May 2002 16:11:41 -0000 1.7 *************** *** 54,76 **** } ! /** ! * Method getProcedureName ! * ! * @param PyObject catalog ! * @param PyObject schema ! * @param PyObject name ! * ! * @return String ! * ! */ ! public String getProcedureName(PyObject catalog, PyObject schema, PyObject name) { ! ! StringBuffer procName = new StringBuffer(); ! ! if ((catalog != Py.EmptyString) && (catalog != Py.None)) { ! procName.append(catalog.toString()).append("."); ! } ! ! return procName.append(name.toString()).toString(); } --- 54,59 ---- } ! public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException { ! return new Procedure(cursor, name); } |
From: brian z. <bz...@us...> - 2002-05-10 16:08:47
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv24363/com/ziclix/python/sql Modified Files: Fetch.java Log Message: fixed indexing out of output parameters Index: Fetch.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Fetch.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Fetch.java 9 May 2002 21:44:28 -0000 1.10 --- Fetch.java 10 May 2002 16:08:44 -0000 1.11 *************** *** 349,352 **** --- 349,356 ---- switch (colType) { + case DatabaseMetaData.procedureColumnIn : + j++; + break; + case DatabaseMetaData.procedureColumnOut : case DatabaseMetaData.procedureColumnInOut : |
From: brian z. <bz...@us...> - 2002-05-10 16:08:04
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql/procedure In directory usw-pr-cvs1:/tmp/cvs-serv24086/com/ziclix/python/sql/procedure Log Message: Directory /cvsroot/jython/jython/com/ziclix/python/sql/procedure added to the repository |
From: Finn B. <bc...@us...> - 2002-05-10 08:48:12
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv10782 Modified Files: index.ht Log Message: Another article. Index: index.ht =================================================================== RCS file: /cvsroot/jython/htdocs/index.ht,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** index.ht 10 May 2002 07:59:51 -0000 1.30 --- index.ht 10 May 2002 08:48:09 -0000 1.31 *************** *** 43,46 **** --- 43,51 ---- <dl> + <p><dt><b>11-apr-2002</b> + <dd>Noel Rappin has written another + <a href="http://www.onjava.com/pub/a/onjava/2002/03/27/jython.html"> + article</a> with jython tips for python programmers. + <p><dt><b>2-apr-2002</b> <dd>Our second Jython book called |
From: Finn B. <bc...@us...> - 2002-05-10 08:47:18
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv10356 Modified Files: users.ht Log Message: Added TestMaker Index: users.ht =================================================================== RCS file: /cvsroot/jython/htdocs/users.ht,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** users.ht 10 May 2002 07:56:23 -0000 1.8 --- users.ht 10 May 2002 08:47:14 -0000 1.9 *************** *** 37,39 **** --- 37,47 ---- simulations. + <p><dt><b><a href="http://www.pushtotest.com/ptt">TestMaker</a></b> + <dd>A free open-source framework for building intelligent test agents to + check Web Services (HTTP, HTTPS, SOAP, .NET, XML-RPC) for functionality, + scalability and performance. TestMaker embeds Jython as a scripting language + that calls a library of test objects. TestMaker is built on NetBeans so it + offers Jython users a very nice graphical integrated development environment + for general Jython development too. + </dl> |
From: Finn B. <bc...@us...> - 2002-05-10 07:59:54
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv30219 Modified Files: index.ht Log Message: Added more press news. Index: index.ht =================================================================== RCS file: /cvsroot/jython/htdocs/index.ht,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** index.ht 20 Apr 2002 11:01:52 -0000 1.29 --- index.ht 10 May 2002 07:59:51 -0000 1.30 *************** *** 43,46 **** --- 43,58 ---- <dl> + <p><dt><b>2-apr-2002</b> + <dd>Our second Jython book called + <i><a href="http://www.oreilly.com/catalog/jythoness/"> + Jython Essentials</a></i> was written by By Noel Rappin and + Samuele Pedroni and published by <a href="http://www.oreilly.com/"> + O'Reilly</a>. + + <p><dt><b>28-mar-2002</b> + <dd>Noel Rappin has written an + <a href="http://www.onjava.com/pub/a/onjava/2002/03/27/jython.html"> + article</a> on how to script java with Jython. + <p><dt><b>15-jan-2002</b> <dd>The very first Jython book called |
From: Finn B. <bc...@us...> - 2002-05-10 07:56:27
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv29149 Modified Files: users.ht Log Message: Added JSIMMOD Index: users.ht =================================================================== RCS file: /cvsroot/jython/htdocs/users.ht,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** users.ht 23 Jul 2001 16:17:28 -0000 1.7 --- users.ht 10 May 2002 07:56:23 -0000 1.8 *************** *** 30,32 **** --- 30,39 ---- portal server product: Mission Control. + <p><dt><b><a href="http://www.AirportTools.com/jsimmod">JSIMMOD</a></b> + <dd>JSIMMOD is a free simulation tool which is + bringing advanced concepts to the modeling of aviation + issues. Jython provides dynamic elements to the + simulation which are not easily replicated in other + simulations. + </dl> |
From: brian z. <bz...@us...> - 2002-05-09 21:44:32
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv6142/ziclix/python/sql Modified Files: Fetch.java PyCursor.java PyStatement.java Log Message: api cleanup Index: Fetch.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Fetch.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Fetch.java 9 May 2002 01:03:37 -0000 1.9 --- Fetch.java 9 May 2002 21:44:28 -0000 1.10 *************** *** 94,98 **** /** ! * The number of rows in the current result set. */ public int getRowCount() { --- 94,98 ---- /** ! * The number of rows in the current result set. */ public int getRowCount() { Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** PyCursor.java 9 May 2002 01:03:37 -0000 1.25 --- PyCursor.java 9 May 2002 21:44:29 -0000 1.26 *************** *** 391,398 **** if (sql instanceof PyStatement) { stmt = (PyStatement)sql; - - if (stmt.closed) { - throw zxJDBC.makeException(zxJDBC.ProgrammingError, "statement is closed"); - } } else { Statement sqlStatement = null; --- 391,394 ---- *************** *** 482,490 **** } ! this.statement = new PyStatement(stmt, procedure, params); ! // prepare the statement ! this.statement.prepare(this, params, callableBindings); ! this.execute(); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); --- 478,484 ---- } ! this.statement = new PyStatement(stmt, procedure); ! this.execute(params, callableBindings); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); *************** *** 577,591 **** PyObject param = params.__getitem__(i); ! this.statement.prepare(this, param, bindings); ! this.execute(); } } else { ! this.statement.prepare(this, params, bindings); ! this.execute(); } } else { // execute the sql string straight up ! execute(); } } --- 571,583 ---- PyObject param = params.__getitem__(i); ! this.execute(param, bindings); } } else { ! this.execute(params, bindings); } } else { // execute the sql string straight up ! this.execute(Py.None, Py.None); } } *************** *** 609,613 **** * as updating the lastrowid and updatecount occur as well. */ ! protected void execute() { try { --- 601,605 ---- * as updating the lastrowid and updatecount occur as well. */ ! protected void execute(PyObject params, PyObject bindings) { try { *************** *** 617,621 **** // this performs the SQL execution and fetch per the Statement type ! this.statement.execute(this); this.lastrowid = this.datahandler.getRowId(stmt); --- 609,613 ---- // this performs the SQL execution and fetch per the Statement type ! this.statement.execute(this, params, bindings); this.lastrowid = this.datahandler.getRowId(stmt); Index: PyStatement.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyStatement.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyStatement.java 21 Apr 2002 14:22:15 -0000 1.2 --- PyStatement.java 9 May 2002 21:44:29 -0000 1.3 *************** *** 36,52 **** /** Field style */ ! protected int style; /** Field sql */ ! protected Object sql; /** Field closed */ ! boolean closed; ! ! /** Field params */ ! protected PyObject params; /** Field statement */ ! protected Statement statement; /** --- 36,49 ---- /** Field style */ ! private int style; /** Field sql */ ! private Object sql; /** Field closed */ ! private boolean closed; /** Field statement */ ! Statement statement; /** *************** *** 71,82 **** * @param statement * @param procedure - * @param params * */ ! public PyStatement(Statement statement, Procedure procedure, PyObject params) { ! this(statement, procedure, STATEMENT_CALLABLE); - - this.params = params; } --- 68,75 ---- * @param statement * @param procedure * */ ! public PyStatement(Statement statement, Procedure procedure) { this(statement, procedure, STATEMENT_CALLABLE); } *************** *** 195,200 **** dict.__setitem__("classDictInit", null); dict.__setitem__("statement", null); - dict.__setitem__("params", null); dict.__setitem__("execute", null); dict.__setitem__("STATEMENT_STATIC", null); dict.__setitem__("STATEMENT_PREPARED", null); --- 188,193 ---- dict.__setitem__("classDictInit", null); dict.__setitem__("statement", null); dict.__setitem__("execute", null); + dict.__setitem__("prepare", null); dict.__setitem__("STATEMENT_STATIC", null); dict.__setitem__("STATEMENT_PREPARED", null); *************** *** 213,227 **** * Method execute * ! * @param cursor ! * * * @throws SQLException */ ! void execute(PyCursor cursor) throws SQLException { ! if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "statement is closed"); } Fetch fetch = cursor.fetch; --- 206,224 ---- * Method execute * ! * @param PyCursor cursor ! * @param PyObject params ! * @param PyObject bindings * * @throws SQLException + * */ ! public void execute(PyCursor cursor, PyObject params, PyObject bindings) throws SQLException { ! if (this.closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "statement is closed"); } + this.prepare(cursor, params, bindings); + Fetch fetch = cursor.fetch; *************** *** 267,271 **** * */ ! void prepare(PyCursor cursor, PyObject params, PyObject bindings) throws SQLException { if ((params == Py.None) || (this.style == STATEMENT_STATIC)) { --- 264,268 ---- * */ ! private void prepare(PyCursor cursor, PyObject params, PyObject bindings) throws SQLException { if ((params == Py.None) || (this.style == STATEMENT_STATIC)) { |
From: brian z. <bz...@us...> - 2002-05-09 01:03:40
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv20877/com/ziclix/python/sql Modified Files: PyCursor.java PyConnection.java Fetch.java Added Files: WarningEvent.java WarningListener.java Log Message: added public Java API for Fetch; fetch[many|all] return empty list on completion --- NEW FILE: WarningEvent.java --- /* * Jython Database Specification API 2.0 * * $Id: WarningEvent.java,v 1.1 2002/05/09 01:03:37 bzimmer Exp $ * * Copyright (c) 2001 brian zimmer <bz...@zi...> * */ package com.ziclix.python.sql; import java.sql.SQLWarning; import java.util.EventObject; /** * An event signalling the a SQLWarning was encountered * while building results from a ResultSet. */ public class WarningEvent extends EventObject { private SQLWarning warning; public WarningEvent(Object source, SQLWarning warning) { super(source); this.warning = warning; } public SQLWarning getWarning() { return this.warning; } } --- NEW FILE: WarningListener.java --- /* * Jython Database Specification API 2.0 * * $Id: WarningListener.java,v 1.1 2002/05/09 01:03:37 bzimmer Exp $ * * Copyright (c) 2001 brian zimmer <bz...@zi...> * */ package com.ziclix.python.sql; public interface WarningListener { /** * A callback for any SQLWarnings encountered by the source. * * @param event An event instance with the source and warning. */ public void warning(WarningEvent event); } Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** PyCursor.java 21 Apr 2002 14:22:15 -0000 1.24 --- PyCursor.java 9 May 2002 01:03:37 -0000 1.25 *************** *** 25,29 **** * @version $Revision$ */ ! public class PyCursor extends PyObject implements ClassDictInit { /** Field fetch */ --- 25,29 ---- * @version $Revision$ */ ! public class PyCursor extends PyObject implements ClassDictInit, WarningListener { /** Field fetch */ *************** *** 270,274 **** dict.__setitem__("toString", null); dict.__setitem__("getDataHandler", null); ! dict.__setitem__("addWarning", null); dict.__setitem__("fetch", null); dict.__setitem__("statement", null); --- 270,274 ---- dict.__setitem__("toString", null); dict.__setitem__("getDataHandler", null); ! dict.__setitem__("warning", null); dict.__setitem__("fetch", null); dict.__setitem__("statement", null); *************** *** 348,352 **** PyObject row = fetchone(); ! return (row == Py.None) ? null : row; } --- 348,352 ---- PyObject row = fetchone(); ! return row.__nonzero__() ? row : null; } *************** *** 391,394 **** --- 391,398 ---- if (sql instanceof PyStatement) { stmt = (PyStatement)sql; + + if (stmt.closed) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, "statement is closed"); + } } else { Statement sqlStatement = null; *************** *** 621,625 **** this.updatecount = (uc < 0) ? Py.None : Py.newInteger(uc); ! addWarning(stmt.getWarnings()); this.datahandler.postExecute(stmt); } catch (PyException e) { --- 625,629 ---- this.updatecount = (uc < 0) ? Py.None : Py.newInteger(uc); ! warning(new WarningEvent(this, stmt.getWarnings())); this.datahandler.postExecute(stmt); } catch (PyException e) { *************** *** 651,655 **** * did not produce any result set or no call was issued yet. * ! * @return a sequence of sequences from the result set, or None when no more data is available */ public PyObject fetchall() { --- 655,660 ---- * did not produce any result set or no call was issued yet. * ! * @return a sequence of sequences from the result set, or an empty sequence when ! * no more data is available */ public PyObject fetchall() { *************** *** 676,682 **** * from one fetchmany() call to the next. * - * * @param size ! * @return a sequence of sequences from the result set, or None when no more data is available */ public PyObject fetchmany(int size) { --- 681,687 ---- * from one fetchmany() call to the next. * * @param size ! * @return a sequence of sequences from the result set, or an empty sequence when ! * no more data is available */ public PyObject fetchmany(int size) { *************** *** 742,746 **** * @param warning */ ! protected void addWarning(SQLWarning warning) { if (warning == null) { --- 747,753 ---- * @param warning */ ! public void warning(WarningEvent event) { ! ! SQLWarning warning = event.getWarning(); if (warning == null) { *************** *** 765,769 **** if (next != null) { ! addWarning(next); } --- 772,776 ---- if (next != null) { ! warning(new WarningEvent(event.getSource(), next)); } *************** *** 790,794 **** } catch (Exception e) {} finally { ! this.fetch = Fetch.newFetch(this); } --- 797,803 ---- } catch (Exception e) {} finally { ! this.fetch = Fetch.newFetch(this.datahandler, this.dynamicFetch); ! ! this.fetch.addWarningListener(this); } Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PyConnection.java 21 Apr 2002 14:22:15 -0000 1.9 --- PyConnection.java 9 May 2002 01:03:37 -0000 1.10 *************** *** 67,80 **** m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[9]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); m[2] = new PyString("dbversion"); ! m[3] = new PyString("driverversion"); ! m[4] = new PyString("url"); ! m[5] = new PyString("__connection__"); ! m[6] = new PyString("__cursors__"); ! m[7] = new PyString("__statements__"); ! m[8] = new PyString("closed"); __members__ = new PyList(m); } --- 67,81 ---- m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[10]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); m[2] = new PyString("dbversion"); ! m[3] = new PyString("drivername"); ! m[4] = new PyString("driverversion"); ! m[5] = new PyString("url"); ! m[6] = new PyString("__connection__"); ! m[7] = new PyString("__cursors__"); ! m[8] = new PyString("__statements__"); ! m[9] = new PyString("closed"); __members__ = new PyList(m); } *************** *** 187,190 **** --- 188,197 ---- try { return Py.newString(this.connection.getMetaData().getDatabaseProductVersion()); + } catch (SQLException e) { + throw zxJDBC.makeException(zxJDBC.DatabaseError, e); + } + } else if ("drivername".equals(name)) { + try { + return Py.newString(this.connection.getMetaData().getDriverName()); } catch (SQLException e) { throw zxJDBC.makeException(zxJDBC.DatabaseError, e); Index: Fetch.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Fetch.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Fetch.java 12 Apr 2002 04:12:27 -0000 1.8 --- Fetch.java 9 May 2002 01:03:37 -0000 1.9 *************** *** 52,72 **** /** Field cursor */ ! protected PyCursor cursor; /** Field description */ protected PyObject description; /** * Constructor Fetch * ! * @param PyCursor cursor * */ ! protected Fetch(PyCursor cursor) { this.rowcount = -1; this.rownumber = -1; - this.cursor = cursor; this.description = Py.None; } --- 52,76 ---- /** Field cursor */ ! protected DataHandler datahandler; /** Field description */ protected PyObject description; + /** A list of warning listeners. */ + protected List listeners; + /** * Constructor Fetch * ! * @param datahandler * */ ! protected Fetch(DataHandler datahandler) { this.rowcount = -1; this.rownumber = -1; this.description = Py.None; + this.datahandler = datahandler; + this.listeners = new ArrayList(3); } *************** *** 74,92 **** * Method newFetch * ! * @param PyCursor cursor * * @return Fetch * */ ! public static Fetch newFetch(PyCursor cursor) { ! if (cursor.dynamicFetch) { ! return new DynamicFetch(cursor); } else { ! return new StaticFetch(cursor); } } /** * Create the results after a successful execution and manages the result set. * --- 78,104 ---- * Method newFetch * ! * @param datahandler ! * @param dynamic * * @return Fetch * */ ! public static Fetch newFetch(DataHandler datahandler, boolean dynamic) { ! if (dynamic) { ! return new DynamicFetch(datahandler); } else { ! return new StaticFetch(datahandler); } } /** + * The number of rows in the current result set. + */ + public int getRowCount() { + return this.rowcount; + } + + /** * Create the results after a successful execution and manages the result set. * *************** *** 131,139 **** PyObject sequence = fetchmany(1); ! if (sequence != Py.None) { ! sequence = sequence.__getitem__(0); } - - return sequence; } --- 143,151 ---- PyObject sequence = fetchmany(1); ! if (sequence.__len__() == 1) { ! return sequence.__getitem__(0); ! } else { ! return Py.None; } } *************** *** 207,211 **** * Cleanup any resources. */ ! public abstract void close() throws SQLException; /** --- 219,225 ---- * Cleanup any resources. */ ! public void close() throws SQLException { ! this.listeners.clear(); ! } /** *************** *** 337,341 **** case DatabaseMetaData.procedureColumnOut : case DatabaseMetaData.procedureColumnInOut : ! obj = cursor.getDataHandler().getPyObject(callableStatement, i + 1, dataType); params.__setitem__(j++, obj); --- 351,355 ---- case DatabaseMetaData.procedureColumnOut : case DatabaseMetaData.procedureColumnInOut : ! obj = datahandler.getPyObject(callableStatement, i + 1, dataType); params.__setitem__(j++, obj); *************** *** 343,347 **** case DatabaseMetaData.procedureColumnReturn : ! obj = cursor.getDataHandler().getPyObject(callableStatement, i + 1, dataType); // Oracle sends ResultSets as a return value --- 357,361 ---- case DatabaseMetaData.procedureColumnReturn : ! obj = datahandler.getPyObject(callableStatement, i + 1, dataType); // Oracle sends ResultSets as a return value *************** *** 358,362 **** if (results.__len__() == 0) { ! return Py.None; } --- 372,376 ---- if (results.__len__() == 0) { ! return results; } *************** *** 378,386 **** protected PyList createResults(ResultSet set, Set skipCols, PyObject metaData) throws SQLException { - PyObject tuple = Py.None; PyList res = new PyList(); while (set.next()) { ! tuple = createResult(set, skipCols, metaData); res.append(tuple); --- 392,399 ---- protected PyList createResults(ResultSet set, Set skipCols, PyObject metaData) throws SQLException { PyList res = new PyList(); while (set.next()) { ! PyObject tuple = createResult(set, skipCols, metaData); res.append(tuple); *************** *** 409,417 **** int type = ((PyInteger)metaData.__getitem__(i).__getitem__(1)).getValue(); ! row[i] = this.cursor.getDataHandler().getPyObject(set, i + 1, type); } } ! this.cursor.addWarning(set.getWarnings()); PyTuple tuple = new PyTuple(row); --- 422,434 ---- int type = ((PyInteger)metaData.__getitem__(i).__getitem__(1)).getValue(); ! row[i] = datahandler.getPyObject(set, i + 1, type); } } ! SQLWarning warning = set.getWarnings(); ! ! if (warning != null) { ! fireWarning(warning); ! } PyTuple tuple = new PyTuple(row); *************** *** 419,422 **** --- 436,458 ---- return tuple; } + + protected void fireWarning(SQLWarning warning) { + + WarningEvent event = new WarningEvent(this, warning); + + for (int i = listeners.size() - 1; i >= 0; i--) { + try { + ((WarningListener)listeners.get(i)).warning(event); + } catch (Throwable t) {} + } + } + + public void addWarningListener(WarningListener listener) { + this.listeners.add(listener); + } + + public boolean removeWarningListener(WarningListener listener) { + return this.listeners.remove(listener); + } } *************** *** 440,446 **** * is added and the result set is immediately closed. */ ! public StaticFetch(PyCursor cursor) { ! super(cursor); this.results = new LinkedList(); --- 476,482 ---- * is added and the result set is immediately closed. */ ! public StaticFetch(DataHandler datahandler) { ! super(datahandler); this.results = new LinkedList(); *************** *** 510,514 **** PyObject result = this.createResults(callableStatement, procedure, params); ! if ((result != Py.None) && (result.__len__() > 0)) { this.results.add(result); this.descriptions.add(this.createDescription(procedure)); --- 546,550 ---- PyObject result = this.createResults(callableStatement, procedure, params); ! if (result.__len__() > 0) { this.results.add(result); this.descriptions.add(this.createDescription(procedure)); *************** *** 538,542 **** * did not produce any result set or no call was issued yet. * ! * @return a sequence of sequences from the result set, or None when no more data is available */ public PyObject fetchall() { --- 574,579 ---- * did not produce any result set or no call was issued yet. * ! * @return a sequence of sequences from the result set, or an empty sequence when ! * no more data is available */ public PyObject fetchall() { *************** *** 563,578 **** * from one fetchmany() call to the next. * ! * @return a sequence of sequences from the result set, or None when no more data is available */ public PyObject fetchmany(int size) { ! PyObject res = Py.None, current = Py.None; ! if ((results != null) && (results.size() > 0)) { ! current = (PyObject)results.get(0); ! } else { ! return current; } if (size <= 0) { size = this.rowcount; --- 600,616 ---- * from one fetchmany() call to the next. * ! * @return a sequence of sequences from the result set, or an empty sequence when ! * no more data is available */ public PyObject fetchmany(int size) { ! PyObject res = new PyList(); ! if ((results == null) || (results.size() == 0)) { ! return res; } + PyObject current = (PyObject)results.get(0); + if (size <= 0) { size = this.rowcount; *************** *** 640,643 **** --- 678,683 ---- public void close() throws SQLException { + super.close(); + this.rownumber = -1; *************** *** 664,669 **** * Construct a dynamic fetch. */ ! public DynamicFetch(PyCursor cursor) { ! super(cursor); } --- 704,709 ---- * Construct a dynamic fetch. */ ! public DynamicFetch(DataHandler datahandler) { ! super(datahandler); } *************** *** 748,757 **** private PyObject fetch(int size, boolean all) { if (this.resultSet == null) { ! return Py.None; } - PyList res = new PyList(); - try { all = (size < 0) ? true : all; --- 788,797 ---- private PyObject fetch(int size, boolean all) { + PyList res = new PyList(); + if (this.resultSet == null) { ! return res; } try { all = (size < 0) ? true : all; *************** *** 772,776 **** } ! return (res.__len__() == 0) ? Py.None : res; } --- 812,816 ---- } ! return res; } *************** *** 821,824 **** --- 861,865 ---- } else { String msg = "dynamic result set of type [" + type + "] does not support scrolling"; + throw zxJDBC.makeException(zxJDBC.NotSupportedError, msg); } *************** *** 832,835 **** --- 873,878 ---- */ public void close() throws SQLException { + + super.close(); if (this.resultSet == null) { |
From: brian z. <bz...@us...> - 2002-05-09 01:03:40
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv20877/Lib/test/zxjdbc Modified Files: zxtest.py test.xml sptest.py runner.py Log Message: added public Java API for Fetch; fetch[many|all] return empty list on completion Index: zxtest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/zxtest.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** zxtest.py 19 Apr 2002 19:47:45 -0000 1.15 --- zxtest.py 9 May 2002 01:03:37 -0000 1.16 *************** *** 298,304 **** def _test_scrolling(self, dynamic=0): ! if self.vendor.name == "oracle": c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, rsconcur=zxJDBC.CONCUR_READ_ONLY ) --- 298,304 ---- def _test_scrolling(self, dynamic=0): ! if self.vendor.scroll: c = self.cursor(dynamic, ! rstype=getattr(zxJDBC, self.vendor.scroll), rsconcur=zxJDBC.CONCUR_READ_ONLY ) *************** *** 340,346 **** def _test_rownumber(self, dynamic=0): ! if self.vendor.name == "oracle": c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, rsconcur=zxJDBC.CONCUR_READ_ONLY ) --- 340,346 ---- def _test_rownumber(self, dynamic=0): ! if self.vendor.scroll: c = self.cursor(dynamic, ! rstype=getattr(zxJDBC, self.vendor.scroll), rsconcur=zxJDBC.CONCUR_READ_ONLY ) *************** *** 379,385 **** def _test_rowcount(self, dynamic=0): ! if self.vendor.name == "oracle": c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, rsconcur=zxJDBC.CONCUR_READ_ONLY ) --- 379,385 ---- def _test_rowcount(self, dynamic=0): ! if self.vendor.scroll: c = self.cursor(dynamic, ! rstype=getattr(zxJDBC, self.vendor.scroll), rsconcur=zxJDBC.CONCUR_READ_ONLY ) *************** *** 811,817 **** c = self.cursor(dynamic) try: ! # make sure None is result from an empty result set c.execute("select * from zxtesting where 1<0") ! self.assertEquals(None, c.fetchall()) # test some arraysize features c.execute("select * from zxtesting") --- 811,823 ---- c = self.cursor(dynamic) try: ! # make sure None if the result is an empty result set c.execute("select * from zxtesting where 1<0") ! self.assertEquals(None, c.fetchone()) ! # make sure an empty sequence if the result is an empty result set ! c.execute("select * from zxtesting where 1<0") ! self.assertEquals([], c.fetchmany()) ! # make sure an empty sequence if the result is an empty result set ! c.execute("select * from zxtesting where 1<0") ! self.assertEquals([], c.fetchall()) # test some arraysize features c.execute("select * from zxtesting") *************** *** 842,846 **** try: f = c.fetchall() ! assert f is None, "expecting no results since no execute*() has been called" finally: c.close() --- 848,852 ---- try: f = c.fetchall() ! assert not f, "expecting no results since no execute*() has been called" finally: c.close() *************** *** 908,912 **** c.close() ! class LOBTest(zxJDBCTestCase): def _test_blob(self, obj=0): --- 914,957 ---- c.close() ! def _test_fetchapi(self, dynamic=0): ! """Test the public Java API for Fetch""" ! from com.ziclix.python.sql import Fetch, WarningListener ! cur = self.cursor() ! try: ! c = self.db.__connection__ ! stmt = c.prepareStatement("select * from zxtesting where id < ?") ! stmt.setInt(1, 5) ! rs = stmt.executeQuery() ! fetch = Fetch.newFetch(cur.datahandler, dynamic) ! class WL(WarningListener): ! def warning(self, event): ! raise event.getWarning() ! wl = WL() ! fetch.addWarningListener(wl) ! # the RS is closed by Fetch ! fetch.add(rs) ! ! if not dynamic: ! self.assertEquals(4, fetch.getRowCount()) ! assert fetch.fetchone() ! assert fetch.fetchmany(2) ! assert fetch.fetchall() ! assert not fetch.fetchall() ! self.assertEquals(4, fetch.getRowCount()) ! assert fetch.removeWarningListener(wl) ! fetch.close() ! stmt.close() ! finally: ! cur.close() ! ! def testStaticFetchAPI(self): ! """Test static Java Fetch API""" ! self._test_fetchapi(0) ! ! def testDynamicFetchAPI(self): ! """Test dynamic Java Fetch API""" ! self._test_fetchapi(1) ! ! class LOBTestCase(zxJDBCTestCase): def _test_blob(self, obj=0): Index: test.xml =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/test.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test.xml 21 Apr 2002 14:22:15 -0000 1.7 --- test.xml 9 May 2002 01:03:37 -0000 1.8 *************** *** 24,27 **** --- 24,28 ---- </testcase> <testcase from="zxtest" import="BCPTestCase"/> + <!--<testcase from="zxtest" import="LOBTestCase"/>--> <testcase from="dbextstest" import="dbextsTestCase"/> </test> *************** *** 83,86 **** --- 84,88 ---- </testcase> <testcase from="zxtest" import="BCPTestCase"/> + <!--<testcase from="zxtest" import="LOBTestCase"/>--> <testcase from="dbextstest" import="dbextsTestCase"/> </test> *************** *** 97,100 **** --- 99,103 ---- <ignore name="testBestRow"/> </testcase> + <!--<testcase from="zxtest" import="LOBTestCase"/>--> <testcase from="zxtest" import="BCPTestCase"/> </test> *************** *** 135,139 **** </vendor> <vendor name="oracle" ! datahandler="com.ziclix.python.sql.handler.OracleDataHandler"> <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> --- 138,143 ---- </vendor> <vendor name="oracle" ! datahandler="com.ziclix.python.sql.handler.OracleDataHandler" ! scroll="TYPE_SCROLL_INSENSITIVE"> <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> *************** *** 146,149 **** --- 150,154 ---- <ignore name="testRowid"/> </testcase> + <!--<testcase from="zxtest" import="LOBTestCase"/>--> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> *************** *** 162,165 **** --- 167,171 ---- </testcase> <testcase from="zxtest" import="BCPTestCase"/> + <testcase from="zxtest" import="LOBTestCase"/> <testcase from="sptest" import="OracleSPTest"/> </test> *************** *** 190,241 **** </table> </vendor> ! <vendor name="microsoft" ! datahandler="com.ziclix.python.sql.handler.SQLServerDataHandler"> ! <!-- ! <test name="freetds" os="java"> ! <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:freetds:sqlserver://localhost:1433/ziclix"/> ! <argument name="usr" value="jython"/> ! <argument name="pwd" value="jython"/> ! <argument name="driver" value="com.internetcds.jdbc.tds.Driver"/> ! </factory> ! <testcase from="zxtest" import="zxAPITestCase"> ! <ignore name="testRowid"/> ! </testcase> ! <testcase from="dbextstest" import="dbextsTestCase"> ! <ignore name="testBulkcopy"/> ! <ignore name="testBulkcopyWithDynamicColumns"/> ! </testcase> ! </test> ! --> ! <test name="opta driver" os="java"> ! <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:inetdae7:localhost:1433?database=ziclix"/> ! <argument name="usr" value="jython"/> ! <argument name="pwd" value="jython"/> ! <argument name="driver" value="com.inet.tds.TdsDriver"/> ! </factory> ! <testcase from="zxtest" import="zxAPITestCase"> ! <ignore name="testRowid"/> ! </testcase> ! <testcase from="dbextstest" import="dbextsTestCase"> ! <ignore name="testBulkcopy"/> ! <ignore name="testBulkcopyWithDynamicColumns"/> ! </testcase> ! <!-- ! <testcase from="sptest" import="SQLServerSPTest"/> ! --> ! </test> <!-- ! <test name="microsoft driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:microsoft:sqlserver://localhost:1433"/> <argument name="usr" value="jython"/> <argument name="pwd" value="jython"/> ! <argument name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/> </factory> <testcase from="zxtest" import="zxAPITestCase"> <ignore name="testRowid"/> </testcase> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> --- 196,214 ---- </table> </vendor> ! <vendor name="netdirect" ! datahandler="com.ziclix.python.sql.handler.SQLServerDataHandler" ! scroll="TYPE_SCROLL_INSENSITIVE"> <!-- ! <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:JSQLConnect://127.0.0.1:1433/ziclix"/> <argument name="usr" value="jython"/> <argument name="pwd" value="jython"/> ! <argument name="driver" value="com.jnetdirect.jsql.JSQLDriver"/> </factory> <testcase from="zxtest" import="zxAPITestCase"> <ignore name="testRowid"/> </testcase> + <testcase from="zxtest" import="LOBTestCase"/> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> *************** *** 359,362 **** --- 332,336 ---- </testcase> <testcase from="zxtest" import="BCPTestCase"/> + <!--<testcase from="zxtest" import="LOBTestCase"/>--> <testcase from="dbextstest" import="dbextsTestCase"> <ignore name="testQueryWithMaxRows"/> Index: sptest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/sptest.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sptest.py 29 Dec 2001 07:16:55 -0000 1.3 --- sptest.py 9 May 2002 01:03:37 -0000 1.4 *************** *** 49,54 **** errors = c.fetchall() try: ! assert errors is None, "found errors" except AssertionError, e: for a in errors: print a --- 49,55 ---- errors = c.fetchall() try: ! assert not errors, "found errors" except AssertionError, e: + print "printing errors:" for a in errors: print a *************** *** 103,107 **** params = ["testProcin"] c.callproc("procin", params) ! self.assertEquals(None, c.fetchall()) c.execute("select * from sptest") self.assertEquals(1, len(c.fetchall())) --- 104,108 ---- params = ["testProcin"] c.callproc("procin", params) ! self.assertEquals([], c.fetchall()) c.execute("select * from sptest") self.assertEquals(1, len(c.fetchall())) Index: runner.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/runner.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** runner.py 19 Apr 2002 19:01:06 -0000 1.3 --- runner.py 9 May 2002 01:03:37 -0000 1.4 *************** *** 49,52 **** --- 49,53 ---- def __init__(self, name, datahandler=None): self.name = name + self.scroll = None self.datahandler = datahandler self.tests = [] *************** *** 94,97 **** --- 95,100 ---- else: v = Vendor(attrs['name']) + if attrs.has_key('scroll'): + v.scroll = attrs['scroll'] self.vendors.append(v) |
From: brian z. <bz...@us...> - 2002-04-21 14:22:18
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv7571/Lib/test/zxjdbc Modified Files: dbextstest.py test.xml Log Message: prepared statements can live outside the cursor Index: dbextstest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/dbextstest.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dbextstest.py 19 Apr 2002 19:47:45 -0000 1.4 --- dbextstest.py 21 Apr 2002 14:22:15 -0000 1.5 *************** *** 255,256 **** --- 255,264 ---- self.fail("failed autocommit query with u=[%d], v=[%d]" % (u, v)) + def testPrepare(self): + """testing the handling of a prepared statement""" + self._insertInto("one", 10) + p = self.db.prepare("select * from one") + self.db.isql(p) + self.db.isql(p) + p.close() + assert p.closed Index: test.xml =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/test.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test.xml 12 Apr 2002 04:12:27 -0000 1.6 --- test.xml 21 Apr 2002 14:22:15 -0000 1.7 *************** *** 79,83 **** <argument name="driver" value="org.gjt.mm.mysql.Driver"/> </factory> ! <testcase from="zxtest" import="zxAPITestCase"/> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> --- 79,85 ---- <argument name="driver" value="org.gjt.mm.mysql.Driver"/> </factory> ! <testcase from="zxtest" import="zxAPITestCase"> ! <ignore name="testBestRow"/> ! </testcase> <testcase from="zxtest" import="BCPTestCase"/> <testcase from="dbextstest" import="dbextsTestCase"/> *************** *** 85,89 **** <test name="datasource" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> ! <argument name="datasource" value="org.gjt.mm.mysql.MysqlDataSource"/> <keyword name="serverName" value="192.168.1.102"/> <keyword name="databaseName" value="ziclix"/> --- 87,91 ---- <test name="datasource" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> ! <argument name="datasource" value="org.gjt.mm.mysql.jdbc2.optional.MysqlDataSource"/> <keyword name="serverName" value="192.168.1.102"/> <keyword name="databaseName" value="ziclix"/> *************** *** 92,96 **** <keyword name="port" value="3306" type="int"/> </factory> ! <testcase from="zxtest" import="zxAPITestCase"/> <testcase from="zxtest" import="BCPTestCase"/> </test> --- 94,100 ---- <keyword name="port" value="3306" type="int"/> </factory> ! <testcase from="zxtest" import="zxAPITestCase"> ! <ignore name="testBestRow"/> ! </testcase> <testcase from="zxtest" import="BCPTestCase"/> </test> |
From: brian z. <bz...@us...> - 2002-04-21 14:22:18
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv7571/com/ziclix/python/sql Modified Files: PyStatement.java PyCursor.java PyConnection.java Log Message: prepared statements can live outside the cursor Index: PyStatement.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyStatement.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyStatement.java 19 Apr 2002 19:01:05 -0000 1.1 --- PyStatement.java 21 Apr 2002 14:22:15 -0000 1.2 *************** *** 258,261 **** --- 258,327 ---- /** + * Method prepare + * + * @param PyCursor cursor + * @param PyObject params + * @param PyObject bindings + * + * @throws SQLException + * + */ + void prepare(PyCursor cursor, PyObject params, PyObject bindings) throws SQLException { + + if ((params == Py.None) || (this.style == STATEMENT_STATIC)) { + return; + } + + // [3, 4] or (3, 4) + final DataHandler datahandler = cursor.datahandler; + int columns = 0, column = 0, index = params.__len__(); + final PreparedStatement preparedStatement = (PreparedStatement)statement; + final Procedure procedure = (this.style == STATEMENT_CALLABLE) ? (Procedure)this.sql : null; + + if (this.style != STATEMENT_CALLABLE) { + columns = params.__len__(); + + // clear the statement so all new bindings take affect only if not a callproc + // this is because Procedure already registered the OUT parameters and we + // don't want to lose those + preparedStatement.clearParameters(); + } else { + columns = (procedure.columns == Py.None) ? 0 : procedure.columns.__len__(); + } + + // count backwards through all the columns + while (columns-- > 0) { + column = columns + 1; + + if ((procedure != null) && (!procedure.isInput(column))) { + continue; + } + + // working from right to left + PyObject param = params.__getitem__(--index); + + if (bindings != Py.None) { + PyObject binding = bindings.__finditem__(Py.newInteger(index)); + + if (binding != null) { + try { + int bindingValue = binding.__int__().getValue(); + + datahandler.setJDBCObject(preparedStatement, column, param, bindingValue); + } catch (PyException e) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, zxJDBC.getString("bindingValue")); + } + + continue; + } + } + + datahandler.setJDBCObject(preparedStatement, column, param); + } + + return; + } + + /** * Method close * Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** PyCursor.java 19 Apr 2002 19:47:45 -0000 1.23 --- PyCursor.java 21 Apr 2002 14:22:15 -0000 1.24 *************** *** 66,72 **** protected PyStatement statement; - /** A set of statements which this cursor prepared and distributed. */ - protected Set preparedStatements; - // they are stateless instances, so we only need to instantiate it once private static DataHandler DATAHANDLER = null; --- 66,69 ---- *************** *** 107,111 **** this.datahandler = DATAHANDLER; this.dynamicFetch = dynamicFetch; - this.preparedStatements = new HashSet(3); // constructs the appropriate Fetch among other things --- 104,107 ---- *************** *** 281,285 **** dict.__setitem__("rsConcur", null); dict.__setitem__("rsType", null); - dict.__setitem__("preparedStatements", null); } --- 277,280 ---- *************** *** 303,315 **** try { this.clear(); ! ! for (Iterator i = this.preparedStatements.iterator(); i.hasNext(); ) { ! try { ! ((PyStatement)i.next()).close(); ! } catch (Throwable t) {} ! } ! ! this.preparedStatements.clear(); ! this.connection.unregister(this); } finally { this.closed = true; --- 298,302 ---- try { this.clear(); ! this.connection.remove(this); } finally { this.closed = true; *************** *** 494,499 **** // prepare the statement ! prepare(params, callableBindings, procedure); ! this.statement.execute(this); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); --- 481,486 ---- // prepare the statement ! this.statement.prepare(this, params, callableBindings); ! this.execute(); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); *************** *** 567,571 **** boolean hasParams = hasParams(params); ! PyStatement stmt = prepareStatement(sql, maxRows, hasParams); if (stmt == null) { --- 554,558 ---- boolean hasParams = hasParams(params); ! PyStatement stmt = this.prepareStatement(sql, maxRows, hasParams); if (stmt == null) { *************** *** 576,599 **** try { ! 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); ! prepare(param, bindings, null); ! execute(); } } else { ! prepare(params, bindings, null); execute(); } - } else { - - // execute the sql string straight up - execute(); } } catch (PyException e) { --- 563,588 ---- try { ! synchronized (this.statement) { ! 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); ! this.statement.prepare(this, param, bindings); ! this.execute(); ! } ! } else { ! this.statement.prepare(this, params, bindings); ! this.execute(); } } else { ! ! // execute the sql string straight up execute(); } } } catch (PyException e) { *************** *** 642,709 **** /** - * Properly prepare the parameters of a prepared statement. - * - * @param params - * @param bindings - * @param procedure - * - * @throws SQLException - * - */ - protected void prepare(PyObject params, final PyObject bindings, final Procedure procedure) throws SQLException { - - if (params == Py.None) { - return; - } - - // [3, 4] or (3, 4) - final PreparedStatement preparedStatement = (PreparedStatement)this.statement.statement; - int columns = 0, column = 0, index = params.__len__(); - - if (procedure == null) { - columns = params.__len__(); - - // clear the statement so all new bindings take affect only if not a callproc - // this is because Procedure already registered the OUT parameters and we - // don't want to lose those - preparedStatement.clearParameters(); - } else { - columns = (procedure.columns == Py.None) ? 0 : procedure.columns.__len__(); - } - - // count backwards through all the columns - while (columns-- > 0) { - column = columns + 1; - - if ((procedure != null) && (!procedure.isInput(column))) { - continue; - } - - // working from right to left - PyObject param = params.__getitem__(--index); - - if (bindings != Py.None) { - PyObject binding = bindings.__finditem__(Py.newInteger(index)); - - if (binding != null) { - try { - int bindingValue = binding.__int__().getValue(); - - this.datahandler.setJDBCObject(preparedStatement, column, param, bindingValue); - } catch (PyException e) { - throw zxJDBC.makeException(zxJDBC.ProgrammingError, zxJDBC.getString("bindingValue")); - } - - continue; - } - } - - this.datahandler.setJDBCObject(preparedStatement, column, param); - } - - return; - } - - /** * Fetch the next row of a query result set, returning a single sequence, * or None when no more data is available. --- 631,634 ---- *************** *** 780,784 **** // add to the set of statements which are leaving our control ! this.preparedStatements.add(s); return s; --- 705,709 ---- // add to the set of statements which are leaving our control ! this.connection.add(s); return s; *************** *** 875,879 **** // it underneath someone; we can check this by looking in the set try { ! if (this.dynamicFetch && (!this.preparedStatements.contains(this.statement))) { this.statement.close(); } --- 800,804 ---- // it underneath someone; we can check this by looking in the set try { ! if (this.dynamicFetch && (!this.connection.contains(this.statement))) { this.statement.close(); } Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyConnection.java 19 Apr 2002 19:01:06 -0000 1.8 --- PyConnection.java 21 Apr 2002 14:22:15 -0000 1.9 *************** *** 34,38 **** /** Field cursors */ ! protected List cursors; /** Field __class__ */ --- 34,41 ---- /** Field cursors */ ! private Set cursors; ! ! /** Field statements */ ! private Set statements; /** Field __class__ */ *************** *** 64,68 **** m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[8]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); --- 67,71 ---- m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[9]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); *************** *** 72,76 **** m[5] = new PyString("__connection__"); m[6] = new PyString("__cursors__"); ! m[7] = new PyString("closed"); __members__ = new PyList(m); } --- 75,80 ---- m[5] = new PyString("__connection__"); m[6] = new PyString("__cursors__"); ! m[7] = new PyString("__statements__"); ! m[8] = new PyString("closed"); __members__ = new PyList(m); } *************** *** 86,91 **** this.closed = false; this.connection = connection; ! this.cursors = new LinkedList(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); --- 90,96 ---- this.closed = false; + this.cursors = new HashSet(); this.connection = connection; ! this.statements = new HashSet(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); *************** *** 200,204 **** return Py.java2py(this.connection); } else if ("__cursors__".equals(name)) { ! return Py.java2py(Collections.unmodifiableList(this.cursors)); } else if ("__methods__".equals(name)) { return __methods__; --- 205,211 ---- return Py.java2py(this.connection); } else if ("__cursors__".equals(name)) { ! return Py.java2py(Collections.unmodifiableSet(this.cursors)); ! } else if ("__statements__".equals(name)) { ! return Py.java2py(Collections.unmodifiableSet(this.statements)); } else if ("__methods__".equals(name)) { return __methods__; *************** *** 226,234 **** } synchronized (this.cursors) { // close the cursors ! for (int i = this.cursors.size() - 1; i >= 0; i--) { ! ((PyCursor)this.cursors.get(i)).close(); } --- 233,246 ---- } + // mark ourselves closed now so that any callbacks we + // get from closing down cursors and statements to not + // try and modify our internal sets + this.closed = true; + synchronized (this.cursors) { // close the cursors ! for (Iterator i = this.cursors.iterator(); i.hasNext(); ) { ! ((PyCursor)i.next()).close(); } *************** *** 236,245 **** } try { this.connection.close(); } catch (SQLException e) { throw zxJDBC.makeException(e); - } finally { - this.closed = true; } } --- 248,265 ---- } + synchronized (this.statements) { + + // close the cursors + for (Iterator i = this.statements.iterator(); i.hasNext(); ) { + ((PyStatement)i.next()).close(); + } + + this.statements.clear(); + } + try { this.connection.close(); } catch (SQLException e) { throw zxJDBC.makeException(e); } } *************** *** 370,374 **** PyCursor cursor = new PyExtendedCursor(this, dynamicFetch, rsType, rsConcur); ! cursors.add(cursor); return cursor; --- 390,394 ---- PyCursor cursor = new PyExtendedCursor(this, dynamicFetch, rsType, rsConcur); ! this.cursors.add(cursor); return cursor; *************** *** 376,387 **** /** ! * Unregister an open PyCursor. ! * * * @param cursor * */ ! void unregister(PyCursor cursor) { this.cursors.remove(cursor); } } --- 396,443 ---- /** ! * Remove an open PyCursor. * * @param cursor * */ ! void remove(PyCursor cursor) { ! ! if (closed) { ! return; ! } ! this.cursors.remove(cursor); + } + + /** + * Method register + * + * @param PyStatement statement + * + */ + void add(PyStatement statement) { + + if (closed) { + return; + } + + this.statements.add(statement); + } + + /** + * Method contains + * + * @param PyStatement statement + * + * @return boolean + * + */ + boolean contains(PyStatement statement) { + + if (closed) { + return false; + } + + return this.statements.contains(statement); } } |
From: brian z. <bz...@us...> - 2002-04-21 14:22:18
|
Update of /cvsroot/jython/jython/Lib In directory usw-pr-cvs1:/tmp/cvs-serv7571/Lib Modified Files: dbexts.py Log Message: prepared statements can live outside the cursor Index: dbexts.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/dbexts.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dbexts.py 19 Apr 2002 19:01:06 -0000 1.6 --- dbexts.py 21 Apr 2002 14:22:15 -0000 1.7 *************** *** 261,265 **** return c ! def commit(self, cursor=None): """ commit the cursor and create the result set """ if cursor and cursor.description: --- 261,265 ---- return c ! def commit(self, cursor=None, close=1): """ commit the cursor and create the result set """ if cursor and cursor.description: *************** *** 276,281 **** if hasattr(cursor, "updatecount"): self.updatecount = cursor.updatecount ! if not self.autocommit or cursor is None: self.db.commit() ! if cursor: cursor.close() def rollback(self): --- 276,283 ---- if hasattr(cursor, "updatecount"): self.updatecount = cursor.updatecount ! if not self.autocommit or cursor is None: ! if not self.db.autocommit: ! self.db.commit() ! if cursor and close: cursor.close() def rollback(self): *************** *** 312,316 **** cur.execute(sql, maxrows=maxrows) finally: ! self.commit(cur) def isql(self, sql, params=None, bindings=None, maxrows=None): --- 314,318 ---- cur.execute(sql, maxrows=maxrows) finally: ! self.commit(cur, close=isinstance(sql, StringType)) def isql(self, sql, params=None, bindings=None, maxrows=None): |
From: Samuele P. <ped...@us...> - 2002-04-20 11:01:55
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv18508 Modified Files: index.ht Log Message: fixed broken link to project announcement on jpython list. Index: index.ht =================================================================== RCS file: /cvsroot/jython/htdocs/index.ht,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** index.ht 16 Jan 2002 17:39:38 -0000 1.28 --- index.ht 20 Apr 2002 11:01:52 -0000 1.29 *************** *** 35,39 **** <p><dt><b>Jython project announced</b> <dd>The Jython project have been created on sourceforge. Read the ! <a href="http://www.python.org/pipermail/jpython-interest/2000-October/006417.html"> announcement</a> (19-oct-2000). </dl> --- 35,39 ---- <p><dt><b>Jython project announced</b> <dd>The Jython project have been created on sourceforge. Read the ! <a href="http://www.python.org/pipermail/jpython-interest/2000-October/003998.html"> announcement</a> (19-oct-2000). </dl> |
From: brian z. <bz...@us...> - 2002-04-19 19:47:49
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv11379/com/ziclix/python/sql Modified Files: PyCursor.java zxJDBC.java Log Message: cleanup dynamic statements Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PyCursor.java 19 Apr 2002 19:01:06 -0000 1.22 --- PyCursor.java 19 Apr 2002 19:47:45 -0000 1.23 *************** *** 66,69 **** --- 66,72 ---- protected PyStatement statement; + /** A set of statements which this cursor prepared and distributed. */ + protected Set preparedStatements; + // they are stateless instances, so we only need to instantiate it once private static DataHandler DATAHANDLER = null; *************** *** 104,107 **** --- 107,111 ---- this.datahandler = DATAHANDLER; this.dynamicFetch = dynamicFetch; + this.preparedStatements = new HashSet(3); // constructs the appropriate Fetch among other things *************** *** 277,280 **** --- 281,285 ---- dict.__setitem__("rsConcur", null); dict.__setitem__("rsType", null); + dict.__setitem__("preparedStatements", null); } *************** *** 296,303 **** public void close() { ! this.clear(); ! this.connection.unregister(this); ! this.closed = true; } --- 301,318 ---- public void close() { ! try { ! this.clear(); ! for (Iterator i = this.preparedStatements.iterator(); i.hasNext(); ) { ! try { ! ((PyStatement)i.next()).close(); ! } catch (Throwable t) {} ! } ! ! this.preparedStatements.clear(); ! this.connection.unregister(this); ! } finally { ! this.closed = true; ! } } *************** *** 378,382 **** * @return PyStatement */ ! protected PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared) { PyStatement stmt = null; --- 393,397 ---- * @return PyStatement */ ! private PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared) { PyStatement stmt = null; *************** *** 754,757 **** --- 769,789 ---- /** + * Prepare a sql statement for later execution. + * + * @param sql The sql string to be prepared. + * + * @return A prepared statement usable with .executeXXX() + */ + public PyStatement prepare(PyObject sql) { + + PyStatement s = this.prepareStatement(sql, Py.None, true); + + // add to the set of statements which are leaving our control + this.preparedStatements.add(s); + + return s; + } + + /** * Scroll the cursor in the result set to a new position according * to mode. *************** *** 825,829 **** } - this.statement = null; this.warnings = Py.None; this.lastrowid = Py.None; --- 857,860 ---- *************** *** 836,839 **** --- 867,885 ---- this.fetch = Fetch.newFetch(this); } + + if (this.statement != null) { + + // we can't close a dynamic fetch statement until everything has been + // consumed so the only time we can clean up is now + // but if this is a previously prepared statement we don't want to close + // it underneath someone; we can check this by looking in the set + try { + if (this.dynamicFetch && (!this.preparedStatements.contains(this.statement))) { + this.statement.close(); + } + } finally { + this.statement = null; + } + } } *************** *** 1034,1038 **** case 12 : ! return cursor.prepareStatement(arg, Py.None, true); default : --- 1080,1084 ---- case 12 : ! return cursor.prepare(arg); default : Index: zxJDBC.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/zxJDBC.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** zxJDBC.java 12 Apr 2002 04:12:27 -0000 1.8 --- zxJDBC.java 19 Apr 2002 19:47:45 -0000 1.9 *************** *** 125,129 **** * Add the types from java.sql.Types * ! * @param PyObject dict * * @throws PyException --- 125,130 ---- * Add the types from java.sql.Types * ! * ! * @param dict * * @throws PyException *************** *** 169,173 **** * Add all the possible connectors * ! * @param PyObject dict * * @throws PyException --- 170,175 ---- * Add all the possible connectors * ! * ! * @param dict * * @throws PyException *************** *** 204,207 **** --- 206,211 ---- /** * Create the exception classes and get their descriptions from the resource bundle. + * + * @param dict */ protected static void _buildExceptions(PyObject dict) { *************** *** 222,227 **** * Method _empty__init__ * ! * @param PyObject[] arg ! * @param String[] kws * * @return PyObject --- 226,232 ---- * Method _empty__init__ * ! * ! * @param arg ! * @param kws * * @return PyObject *************** *** 243,246 **** --- 248,255 ---- * separator. If no indexed key is found, it defaults to checking the bundle by the * key value alone. + * + * @param key + * + * @return String */ public static String getString(String key) { *************** *** 265,269 **** if ((lines == null) || (lines.size() == 0)) { ! resource = resourceBundle.getString(key); } else { String sep = System.getProperty("line.separator"); --- 274,282 ---- if ((lines == null) || (lines.size() == 0)) { ! try { ! resource = resourceBundle.getString(key); ! } catch (MissingResourceException e) { ! return key; ! } } else { String sep = System.getProperty("line.separator"); *************** *** 285,288 **** --- 298,306 ---- * Return a formatted string. The key is used to get the format and the values * are passed, along with the format, to a MessageFormat who formats it appropriately. + * + * @param key + * @param values + * + * @return String */ public static String getString(String key, Object[] values) { *************** *** 295,298 **** --- 313,320 ---- /** * Return a newly instantiated PyException of the type Error. + * + * @param msg + * + * @return PyException */ public static PyException makeException(String msg) { *************** *** 302,305 **** --- 324,332 ---- /** * Return a newly instantiated PyException of the given type. + * + * @param type + * @param msg + * + * @return PyException */ public static PyException makeException(PyObject type, String msg) { *************** *** 309,312 **** --- 336,343 ---- /** * Return a newly instantiated PyException of the type Error. + * + * @param throwable + * + * @return PyException */ public static PyException makeException(Throwable throwable) { *************** *** 316,319 **** --- 347,355 ---- /** * Return a newly instantiated PyException of the given type. + * + * @param type + * @param t + * + * @return PyException */ public static PyException makeException(PyObject type, Throwable t) { *************** *** 363,366 **** --- 399,408 ---- /** * This function constructs an object holding a date value. + * + * @param year + * @param month + * @param day + * + * @return PyObject */ protected static PyObject Date(int year, int month, int day) { *************** *** 377,380 **** --- 419,428 ---- /** * This function constructs an object holding a time value. + * + * @param hour + * @param minute + * @param second + * + * @return PyObject */ protected static PyObject Time(int hour, int minute, int second) { *************** *** 391,394 **** --- 439,451 ---- /** * This function constructs an object holding a time stamp value. + * + * @param year + * @param month + * @param day + * @param hour + * @param minute + * @param second + * + * @return PyObject */ protected static PyObject Timestamp(int year, int month, int day, int hour, int minute, int second) { *************** *** 418,421 **** --- 475,480 ---- * * @param ticks number of seconds since the epoch + * + * @return PyObject */ protected static PyObject DateFromTicks(long ticks) { *************** *** 443,446 **** --- 502,507 ---- * * @param ticks number of seconds since the epoch + * + * @return PyObject */ protected static PyObject TimeFromTicks(long ticks) { *************** *** 459,462 **** --- 520,525 ---- * * @param ticks number of seconds since the epoch + * + * @return PyObject */ protected static PyObject TimestampFromTicks(long ticks) { *************** *** 467,473 **** * Method buildClass * ! * @param String classname ! * @param PyObject superclass ! * @param String classCodeName * * @return PyObject --- 530,537 ---- * Method buildClass * ! * ! * @param classname ! * @param superclass ! * @param classCodeName * * @return PyObject *************** *** 498,507 **** * Constructor zxJDBCFunc * ! * @param String name ! * @param int index ! * @param int minargs ! * @param int maxargs ! * @param boolean func ! * @param String doc * */ --- 562,572 ---- * Constructor zxJDBCFunc * ! * ! * @param name ! * @param index ! * @param minargs ! * @param maxargs ! * @param func ! * @param doc * */ *************** *** 513,517 **** * Method __call__ * ! * @param PyObject arg * * @return PyObject --- 578,583 ---- * Method __call__ * ! * ! * @param arg * * @return PyObject *************** *** 541,547 **** * Method __call__ * ! * @param PyObject arga ! * @param PyObject argb ! * @param PyObject argc * * @return PyObject --- 607,614 ---- * Method __call__ * ! * ! * @param arga ! * @param argb ! * @param argc * * @return PyObject *************** *** 574,578 **** * Method fancyCall * ! * @param PyObject[] args * * @return PyObject --- 641,646 ---- * Method fancyCall * ! * ! * @param args * * @return PyObject |
From: brian z. <bz...@us...> - 2002-04-19 19:47:49
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv11379/Lib/test/zxjdbc Modified Files: dbextstest.py zxtest.py Log Message: cleanup dynamic statements Index: dbextstest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/dbextstest.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dbextstest.py 10 Jan 2002 03:42:32 -0000 1.3 --- dbextstest.py 19 Apr 2002 19:47:45 -0000 1.4 *************** *** 253,255 **** self.db.isql("select * from one") except Exception, e: ! fail("failed autocommit query with u=[%d], v=[%d]" % (u, v)) --- 253,256 ---- self.db.isql("select * from one") except Exception, e: ! self.fail("failed autocommit query with u=[%d], v=[%d]" % (u, v)) ! Index: zxtest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/zxtest.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** zxtest.py 19 Apr 2002 19:01:06 -0000 1.14 --- zxtest.py 19 Apr 2002 19:47:45 -0000 1.15 *************** *** 115,123 **** p = c.prepare("select * from zxtesting where id = ?") for i in range(1, 8): ! try: ! c.execute(p, (i,)) ! except: ! print i ! raise data = c.fetchall() self.assertEquals(1, len(data)) --- 115,119 ---- p = c.prepare("select * from zxtesting where id = ?") for i in range(1, 8): ! c.execute(p, (i,)) data = c.fetchall() self.assertEquals(1, len(data)) *************** *** 497,501 **** assert data == f[0][0], "failed to retrieve the same text as inserted" except Exception, e: - print e raise e finally: --- 493,496 ---- |
From: brian z. <bz...@us...> - 2002-04-19 19:08:07
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv25122/com/ziclix/python/sql Modified Files: PyCursor.java PyConnection.java Added Files: PyStatement.java Log Message: added .prepare() to cursor --- NEW FILE: PyStatement.java --- /* * Jython Database Specification API 2.0 * * $Id: PyStatement.java,v 1.1 2002/04/19 19:01:05 bzimmer Exp $ * * Copyright (c) 2001 brian zimmer <bz...@zi...> * */ package com.ziclix.python.sql; import java.sql.Statement; import java.sql.SQLException; import java.sql.PreparedStatement; import java.sql.CallableStatement; import org.python.core.*; /** * Class PyStatement * * @author brian zimmer * @date 2002-04-19 08:58:22.11 * @date last modified on $Date: 2002/04/19 19:01:05 $ * @version $Revision: 1.1 $ */ public class PyStatement extends PyObject { /** Field STATEMENT_STATIC */ public static final int STATEMENT_STATIC = 2; /** Field STATEMENT_PREPARED */ public static final int STATEMENT_PREPARED = 4; /** Field STATEMENT_CALLABLE */ public static final int STATEMENT_CALLABLE = 8; /** Field style */ protected int style; /** Field sql */ protected Object sql; /** Field closed */ boolean closed; /** Field params */ protected PyObject params; /** Field statement */ protected Statement statement; /** * Constructor PyStatement * * @param statement * @param sql * @param style * */ public PyStatement(Statement statement, Object sql, int style) { this.sql = sql; this.style = style; this.closed = false; this.statement = statement; } /** * Constructor PyStatement * * @param statement * @param procedure * @param params * */ public PyStatement(Statement statement, Procedure procedure, PyObject params) { this(statement, procedure, STATEMENT_CALLABLE); this.params = params; } /** Field __class__ */ public static PyClass __class__; /** * Method getPyClass * * @return PyClass * */ protected PyClass getPyClass() { return __class__; } /** Field __methods__ */ protected static PyList __methods__; /** Field __members__ */ protected static PyList __members__; static { PyObject[] m = new PyObject[1]; m[0] = new PyString("close"); __methods__ = new PyList(m); m = new PyObject[3]; m[0] = new PyString("style"); m[1] = new PyString("closed"); m[2] = new PyString("__statement__"); __members__ = new PyList(m); } /** * Method __str__ * * @return PyString * */ public PyString __str__() { if (sql instanceof String) { return Py.newString((String)sql); } else if (sql instanceof Procedure) { try { return Py.newString(((Procedure)sql).toSql()); } catch (SQLException e) { throw zxJDBC.makeException(e); } } return super.__str__(); } /** * Method __repr__ * * @return PyString * */ public PyString __repr__() { // care is taken not to display a rounded second value StringBuffer buf = new StringBuffer("<PyStatement object for ["); buf.append(__str__().toString()); buf.append("] at ").append(Py.id(this)).append(">"); return Py.newString(buf.toString()); } /** * Method toString * * @return String * */ public String toString() { return __repr__().toString(); } /** * Gets the value of the attribute name. * * @param name * @return the attribute for the given name */ public PyObject __findattr__(String name) { if ("style".equals(name)) { return Py.newInteger(style); } else if ("closed".equals(name)) { return Py.newBoolean(closed); } else if ("__statement__".equals(name)) { return Py.java2py(statement); } else if ("__methods__".equals(name)) { return __methods__; } else if ("__members__".equals(name)) { return __members__; } return super.__findattr__(name); } /** * Initializes the object's namespace. * * @param dict */ static public void classDictInit(PyObject dict) { dict.__setitem__("__version__", Py.newString("$Revision: 1.1 $").__getslice__(Py.newInteger(11), Py.newInteger(-2), null)); // hide from python dict.__setitem__("classDictInit", null); dict.__setitem__("statement", null); dict.__setitem__("params", null); dict.__setitem__("execute", null); dict.__setitem__("STATEMENT_STATIC", null); dict.__setitem__("STATEMENT_PREPARED", null); dict.__setitem__("STATEMENT_CALLABLE", null); } /** * Delete the statement. * */ public void __del__() { close(); } /** * Method execute * * @param cursor * * * @throws SQLException */ void execute(PyCursor cursor) throws SQLException { if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "statement is closed"); } Fetch fetch = cursor.fetch; switch (this.style) { case STATEMENT_STATIC : if (this.statement.execute((String)this.sql)) { fetch.add(this.statement.getResultSet()); } break; case STATEMENT_PREPARED : final PreparedStatement preparedStatement = (PreparedStatement)this.statement; if (preparedStatement.execute()) { fetch.add(preparedStatement.getResultSet()); } break; case STATEMENT_CALLABLE : final CallableStatement callableStatement = (CallableStatement)this.statement; if (callableStatement.execute()) { fetch.add(callableStatement.getResultSet()); } fetch.add(callableStatement, (Procedure)sql, params); break; default : throw zxJDBC.makeException(zxJDBC.ProgrammingError, zxJDBC.getString("invalidStyle")); } } /** * Method close * */ public void close() { try { this.statement.close(); } catch (SQLException e) { throw zxJDBC.makeException(e); } finally { this.closed = true; } } } Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** PyCursor.java 12 Apr 2002 20:32:45 -0000 1.21 --- PyCursor.java 19 Apr 2002 19:01:06 -0000 1.22 *************** *** 63,68 **** protected DataHandler datahandler; ! /** Field sqlStatement */ ! protected Statement sqlStatement; // they are stateless instances, so we only need to instantiate it once --- 63,68 ---- protected DataHandler datahandler; ! /** Field statement */ ! protected PyStatement statement; // they are stateless instances, so we only need to instantiate it once *************** *** 80,83 **** --- 80,85 ---- /** * Create the cursor with a static fetch. + * + * @param connection */ PyCursor(PyConnection connection) { *************** *** 88,91 **** --- 90,96 ---- * Create the cursor, optionally choosing the type of fetch (static or dynamic). * If dynamicFetch is true, then use a dynamic fetch. + * + * @param connection + * @param dynamicFetch */ PyCursor(PyConnection connection, boolean dynamicFetch) { *************** *** 108,111 **** --- 113,121 ---- * If dynamicFetch is true, then use a dynamic fetch. * rsType and rsConcur are used to create the Statement if both are non-None + * + * @param connection + * @param dynamicFetch + * @param rsType + * @param rsConcur */ PyCursor(PyConnection connection, boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { *************** *** 149,153 **** m[8] = new PyString("write"); __methods__ = new PyList(m); ! m = new PyObject[9]; m[0] = new PyString("arraysize"); m[1] = new PyString("rowcount"); --- 159,163 ---- m[8] = new PyString("write"); __methods__ = new PyList(m); ! m = new PyObject[10]; m[0] = new PyString("arraysize"); m[1] = new PyString("rowcount"); *************** *** 159,162 **** --- 169,173 ---- m[7] = new PyString("updatecount"); m[8] = new PyString("softspace"); + m[9] = new PyString("closed"); __members__ = new PyList(m); } *************** *** 226,229 **** --- 237,242 ---- } else if ("connection".equals(name)) { return this.connection; + } else if ("closed".equals(name)) { + return Py.newBoolean(closed); } *************** *** 251,254 **** --- 264,268 ---- dict.__setitem__("scroll", new CursorFunc("scroll", 10, 1, 2, "scroll the cursor in the result set to a new position according to mode")); dict.__setitem__("write", new CursorFunc("write", 11, 1, "execute the sql written to this file-like object")); + dict.__setitem__("prepare", new CursorFunc("prepare", 12, 1, "prepare the sql statement for later execution")); // hide from python *************** *** 258,263 **** dict.__setitem__("addWarning", null); dict.__setitem__("fetch", null); ! dict.__setitem__("closed", null); ! dict.__setitem__("sqlStatement", null); dict.__setitem__("dynamicFetch", null); dict.__setitem__("getPyClass", null); --- 272,276 ---- dict.__setitem__("addWarning", null); dict.__setitem__("fetch", null); ! dict.__setitem__("statement", null); dict.__setitem__("dynamicFetch", null); dict.__setitem__("getPyClass", null); *************** *** 267,286 **** /** - * 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. * --- 280,283 ---- *************** *** 342,345 **** --- 339,344 ---- * * @since Jython 2.2 + * + * @return PyObject */ public PyObject __iternext__() { *************** *** 355,358 **** --- 354,358 ---- * @return DatabaseMetaData * + * @throws SQLException */ protected DatabaseMetaData getMetaData() throws SQLException { *************** *** 362,365 **** --- 362,367 ---- /** * Return the currently bound DataHandler. + * + * @return DataHandler */ public DataHandler getDataHandler() { *************** *** 370,402 **** * 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 ! * @throws SQLException */ ! 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); } } ! if (maxRows != Py.None) { ! this.sqlStatement.setMaxRows(maxRows.__int__().getValue()); ! } } --- 372,434 ---- * Prepare a statement ready for executing. * ! * @param sql the sql to execute or a prepared statement * @param maxRows max number of rows to be returned * @param prepared if true, prepare the statement, otherwise create a normal statement ! * ! * @return PyStatement */ ! protected PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared) { ! PyStatement stmt = null; ! if (sql == Py.None) { ! return null; ! } ! ! try { ! if (sql instanceof PyStatement) { ! stmt = (PyStatement)sql; } else { ! Statement sqlStatement = null; ! String sqlString = sql.__str__().toString(); ! ! if (sqlString.trim().length() == 0) { ! return null; ! } ! ! boolean normal = ((this.rsType == Py.None) && (this.rsConcur == Py.None)); ! ! if (normal) { ! if (prepared) { ! sqlStatement = this.connection.connection.prepareStatement(sqlString); ! } else { ! sqlStatement = this.connection.connection.createStatement(); ! } ! } else { ! int t = this.rsType.__int__().getValue(); ! int c = this.rsConcur.__int__().getValue(); ! ! if (prepared) { ! sqlStatement = this.connection.connection.prepareStatement(sqlString, t, c); ! } else { ! sqlStatement = this.connection.connection.createStatement(t, c); ! } ! } ! ! int style = prepared ? PyStatement.STATEMENT_PREPARED : PyStatement.STATEMENT_STATIC; ! ! stmt = new PyStatement(sqlStatement, sqlString, style); } ! if (maxRows != Py.None) { ! stmt.statement.setMaxRows(maxRows.__int__().getValue()); } + } catch (PyException e) { + throw e; + } catch (Exception e) { + throw zxJDBC.makeException(e); } ! return stmt; } *************** *** 411,418 **** * The procedure may also provide a result set as output. This must then be made available * through the standard fetchXXX() methods. */ public void callproc(PyObject name, final PyObject params, PyObject bindings, PyObject maxRows) { ! clear(); try { --- 443,455 ---- * The procedure may also provide a result set as output. This must then be made available * through the standard fetchXXX() methods. + * + * @param name + * @param params + * @param bindings + * @param maxRows */ public void callproc(PyObject name, final PyObject params, PyObject bindings, PyObject maxRows) { ! this.clear(); try { *************** *** 423,435 **** final Procedure procedure = new Procedure(this, name); ! PyDictionary callableBindings = new PyDictionary(); ! ! this.sqlStatement = procedure.prepareCall(this.rsType, this.rsConcur); if (maxRows != Py.None) { ! this.sqlStatement.setMaxRows(maxRows.__int__().getValue()); } // get the bindings per the stored proc spec procedure.normalizeInput(params, callableBindings); --- 460,472 ---- final Procedure procedure = new Procedure(this, name); ! Statement stmt = procedure.prepareCall(this.rsType, this.rsConcur); if (maxRows != Py.None) { ! stmt.setMaxRows(maxRows.__int__().getValue()); } // get the bindings per the stored proc spec + PyDictionary callableBindings = new PyDictionary(); + procedure.normalizeInput(params, callableBindings); *************** *** 439,459 **** } // prepare the statement prepare(params, callableBindings, procedure); ! ! // call the procedure ! execute(new ExecuteSQL() { ! ! public void executeSQL() throws SQLException { ! ! final CallableStatement callableStatement = (CallableStatement)sqlStatement; ! ! if (callableStatement.execute()) { ! fetch.add(callableStatement.getResultSet()); ! } ! ! fetch.add(callableStatement, procedure, params); ! } ! }); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); --- 476,484 ---- } + this.statement = new PyStatement(stmt, procedure, params); + // prepare the statement prepare(params, callableBindings, procedure); ! this.statement.execute(this); } else { throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); *************** *** 463,466 **** --- 488,497 ---- } catch (Exception e) { throw zxJDBC.makeException(e); + } finally { + if (this.statement != null) { + + // close what we opened + this.statement.close(); + } } } *************** *** 476,479 **** --- 507,515 ---- * * Return values are not defined. + * + * @param sql + * @param params + * @param bindings + * @param maxRows */ public void executemany(PyObject sql, PyObject params, PyObject bindings, PyObject maxRows) { *************** *** 506,510 **** * Return values are not defined. * ! * @param sql sql string * @param params params for a prepared statement * @param bindings dictionary of (param index : SQLType binding) --- 542,546 ---- * Return values are not defined. * ! * @param sql sql string or prepared statement * @param params params for a prepared statement * @param bindings dictionary of (param index : SQLType binding) *************** *** 513,543 **** public void execute(final PyObject sql, PyObject params, PyObject bindings, PyObject maxRows) { ! if (sql == Py.None) { ! return; ! } ! final String sqlString = sql.__str__().toString(); ! if (sqlString.trim().length() == 0) { return; } ! clear(); ! ! boolean hasParams = hasParams(params); try { - prepareStatement(sqlString, maxRows, hasParams); - if (hasParams) { - ExecuteSQL esql = new ExecuteSQL() { - - public void executeSQL() throws SQLException { - - if (((PreparedStatement)sqlStatement).execute()) { - fetch.add(sqlStatement.getResultSet()); - } - } - }; // if we have a sequence of sequences, let's run through them and finish --- 549,565 ---- public void execute(final PyObject sql, PyObject params, PyObject bindings, PyObject maxRows) { ! this.clear(); ! boolean hasParams = hasParams(params); ! PyStatement stmt = prepareStatement(sql, maxRows, hasParams); ! if (stmt == null) { return; } ! this.statement = stmt; try { if (hasParams) { // if we have a sequence of sequences, let's run through them and finish *************** *** 549,570 **** prepare(param, bindings, null); ! execute(esql); } } else { prepare(params, bindings, null); ! execute(esql); } } else { // execute the sql string straight up ! execute(new ExecuteSQL() { ! ! public void executeSQL() throws SQLException { ! ! if (sqlStatement.execute(sqlString)) { ! fetch.add(sqlStatement.getResultSet()); ! } ! } ! }); } } catch (PyException e) { --- 571,584 ---- prepare(param, bindings, null); ! execute(); } } else { prepare(params, bindings, null); ! execute(); } } else { // execute the sql string straight up ! execute(); } } catch (PyException e) { *************** *** 572,575 **** --- 586,597 ---- } catch (Exception e) { throw zxJDBC.makeException(e); + } finally { + if (this.statement != null) { + + // only close static, single-use statements + if (!(sql instanceof PyStatement) && (!this.dynamicFetch)) { + this.statement.close(); + } + } } } *************** *** 578,602 **** * Execute the current sql statement. Some generic functionality such * as updating the lastrowid and updatecount occur as well. - * - * @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.lastrowid = this.datahandler.getRowId(this.sqlStatement); ! int uc = this.sqlStatement.getUpdateCount(); ! this.updatecount = (uc < 0) ? Py.None : Py.newInteger(uc); ! addWarning(this.sqlStatement.getWarnings()); ! this.datahandler.postExecute(this.sqlStatement); } --- 600,627 ---- * Execute the current sql statement. Some generic functionality such * as updating the lastrowid and updatecount occur as well. */ ! protected void execute() { ! try { ! Statement stmt = this.statement.statement; ! this.datahandler.preExecute(stmt); ! // this performs the SQL execution and fetch per the Statement type ! this.statement.execute(this); ! this.lastrowid = this.datahandler.getRowId(stmt); ! int uc = stmt.getUpdateCount(); ! this.updatecount = (uc < 0) ? Py.None : Py.newInteger(uc); ! ! addWarning(stmt.getWarnings()); ! this.datahandler.postExecute(stmt); ! } catch (PyException e) { ! throw e; ! } catch (Exception e) { ! throw zxJDBC.makeException(e); ! } } *************** *** 604,610 **** * Properly prepare the parameters of a prepared statement. * ! * @param PyObject params a non-None seq of sequences or entities ! * @param PyObject bindings an optional dictionary of index:DBApiType mappings ! * @param Procedure procedure * * @throws SQLException --- 629,635 ---- * Properly prepare the parameters of a prepared statement. * ! * @param params ! * @param bindings ! * @param procedure * * @throws SQLException *************** *** 618,622 **** // [3, 4] or (3, 4) ! final PreparedStatement preparedStatement = (PreparedStatement)this.sqlStatement; int columns = 0, column = 0, index = params.__len__(); --- 643,647 ---- // [3, 4] or (3, 4) ! final PreparedStatement preparedStatement = (PreparedStatement)this.statement.statement; int columns = 0, column = 0, index = params.__len__(); *************** *** 711,714 **** --- 736,741 ---- * from one fetchmany() call to the next. * + * + * @param size * @return a sequence of sequences from the result set, or None when no more data is available */ *************** *** 744,749 **** * database (e.g. backward scrolling). * ! * @param int value ! * @param String mode * */ --- 771,777 ---- * database (e.g. backward scrolling). * ! * ! * @param value ! * @param mode * */ *************** *** 754,757 **** --- 782,787 ---- /** * Adds a warning to the tuple and will follow the chain as necessary. + * + * @param warning */ protected void addWarning(SQLWarning warning) { *************** *** 792,798 **** if (closed) { ! throw zxJDBC.makeException(zxJDBC.InternalError, "cursor is closed"); } this.warnings = Py.None; this.lastrowid = Py.None; --- 822,829 ---- if (closed) { ! throw zxJDBC.makeException(zxJDBC.ProgrammingError, "cursor is closed"); } + this.statement = null; this.warnings = Py.None; this.lastrowid = Py.None; *************** *** 805,815 **** this.fetch = Fetch.newFetch(this); } - - try { - this.sqlStatement.close(); - } catch (Exception e) {} - finally { - this.sqlStatement = null; - } } --- 836,839 ---- *************** *** 817,821 **** * Method isSeq * ! * @param PyObject object * * @return true for any PyList, PyTuple or java.util.List --- 841,846 ---- * Method isSeq * ! * ! * @param object * * @return true for any PyList, PyTuple or java.util.List *************** *** 840,844 **** * Method hasParams * ! * @param PyObject params * * @return boolean --- 865,870 ---- * Method hasParams * ! * ! * @param params * * @return boolean *************** *** 864,868 **** * Method isSeqSeq * ! * @param PyObject object * * @return true is a sequence of sequences --- 890,895 ---- * Method isSeqSeq * ! * ! * @param object * * @return true is a sequence of sequences *************** *** 899,906 **** * Constructor CursorFunc * ! * @param String name ! * @param int index ! * @param int argcount ! * @param String doc * */ --- 926,934 ---- * Constructor CursorFunc * ! * ! * @param name ! * @param index ! * @param argcount ! * @param doc * */ *************** *** 912,920 **** * Constructor CursorFunc * ! * @param String name ! * @param int index ! * @param int minargs ! * @param int maxargs ! * @param String doc * */ --- 940,949 ---- * Constructor CursorFunc * ! * ! * @param name ! * @param index ! * @param minargs ! * @param maxargs ! * @param doc * */ *************** *** 960,964 **** * Method __call__ * ! * @param PyObject arg * * @return PyObject --- 989,994 ---- * Method __call__ * ! * ! * @param arg * * @return PyObject *************** *** 1003,1006 **** --- 1033,1039 ---- return Py.None; + case 12 : + return cursor.prepareStatement(arg, Py.None, true); + default : throw argCountError(1); *************** *** 1011,1016 **** * Method __call__ * ! * @param PyObject arga ! * @param PyObject argb * * @return PyObject --- 1044,1050 ---- * Method __call__ * ! * ! * @param arga ! * @param argb * * @return PyObject *************** *** 1054,1060 **** * Method __call__ * ! * @param PyObject arga ! * @param PyObject argb ! * @param PyObject argc * * @return PyObject --- 1088,1095 ---- * Method __call__ * ! * ! * @param arga ! * @param argb ! * @param argc * * @return PyObject *************** *** 1090,1095 **** * Method __call__ * ! * @param PyObject[] args ! * @param String[] keywords * * @return PyObject --- 1125,1131 ---- * Method __call__ * ! * ! * @param args ! * @param keywords * * @return PyObject Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PyConnection.java 12 Apr 2002 04:12:27 -0000 1.7 --- PyConnection.java 19 Apr 2002 19:01:06 -0000 1.8 *************** *** 24,27 **** --- 24,30 ---- public class PyConnection extends PyObject implements ClassDictInit { + /** Field closed */ + protected boolean closed; + /** Field connection */ protected Connection connection; *************** *** 61,65 **** m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[7]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); --- 64,68 ---- m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[8]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); *************** *** 69,72 **** --- 72,76 ---- m[5] = new PyString("__connection__"); m[6] = new PyString("__cursors__"); + m[7] = new PyString("closed"); __members__ = new PyList(m); } *************** *** 74,80 **** --- 78,89 ---- /** * Create a PyConnection with the open connection. + * + * @param connection + * + * @throws SQLException */ public PyConnection(Connection connection) throws SQLException { + this.closed = false; this.connection = connection; this.cursors = new LinkedList(); *************** *** 103,107 **** * Method classDictInit * ! * @param PyObject dict * */ --- 112,117 ---- * Method classDictInit * ! * ! * @param dict * */ *************** *** 195,198 **** --- 205,210 ---- } else if ("__members__".equals(name)) { return __members__; + } else if ("closed".equals(name)) { + return Py.newBoolean(closed); } *************** *** 210,213 **** --- 222,229 ---- public void close() { + if (closed) { + return; + } + synchronized (this.cursors) { *************** *** 224,227 **** --- 240,245 ---- } catch (SQLException e) { throw zxJDBC.makeException(e); + } finally { + this.closed = true; } } *************** *** 238,241 **** --- 256,263 ---- public void commit() { + if (closed) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); + } + if (!this.supportsTransactions) { return; *************** *** 261,264 **** --- 283,290 ---- public void rollback() { + if (closed) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); + } + if (!this.supportsTransactions) { return; *************** *** 278,282 **** * that the driver would have sent. * ! * @param PyObject a SQL statement that may contain one or more '?' parameter placeholders * * @return the native form of this statement --- 304,309 ---- * that the driver would have sent. * ! * ! * @param nativeSQL * * @return the native form of this statement *************** *** 285,288 **** --- 312,319 ---- public PyObject nativesql(PyObject nativeSQL) { + if (closed) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); + } + if (nativeSQL == Py.None) { return Py.None; *************** *** 333,336 **** --- 364,371 ---- public PyCursor cursor(boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { + if (closed) { + throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); + } + PyCursor cursor = new PyExtendedCursor(this, dynamicFetch, rsType, rsConcur); *************** *** 343,347 **** * Unregister an open PyCursor. * ! * @param PyCursor cursor * */ --- 378,383 ---- * Unregister an open PyCursor. * ! * ! * @param cursor * */ *************** *** 365,373 **** * Constructor ConnectionFunc * ! * @param String name ! * @param int index ! * @param int minargs ! * @param int maxargs ! * @param String doc * */ --- 401,410 ---- * Constructor ConnectionFunc * ! * ! * @param name ! * @param index ! * @param minargs ! * @param maxargs ! * @param doc * */ *************** *** 414,418 **** * Method __call__ * ! * @param PyObject arg * * @return PyObject --- 451,456 ---- * Method __call__ * ! * ! * @param arg * * @return PyObject *************** *** 439,444 **** * Method __call__ * ! * @param PyObject arg1 ! * @param PyObject arg2 * * @return PyObject --- 477,483 ---- * Method __call__ * ! * ! * @param arg1 ! * @param arg2 * * @return PyObject *************** *** 461,467 **** * Method __call__ * ! * @param PyObject arg1 ! * @param PyObject arg2 ! * @param PyObject arg3 * * @return PyObject --- 500,507 ---- * Method __call__ * ! * ! * @param arg1 ! * @param arg2 ! * @param arg3 * * @return PyObject *************** *** 485,490 **** * Method __call__ * ! * @param PyObject[] args ! * @param String[] keywords * * @return PyObject --- 525,531 ---- * Method __call__ * ! * ! * @param args ! * @param keywords * * @return PyObject |
From: brian z. <bz...@us...> - 2002-04-19 19:08:07
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv25122/Lib/test/zxjdbc Modified Files: zxtest.py runner.py Log Message: added .prepare() to cursor Index: zxtest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/zxtest.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** zxtest.py 12 Apr 2002 04:12:27 -0000 1.13 --- zxtest.py 19 Apr 2002 19:01:06 -0000 1.14 *************** *** 110,113 **** --- 110,140 ---- c.close() + def _test_preparedstatement(self, dynamic): + c = self.cursor(dynamic) + try: + p = c.prepare("select * from zxtesting where id = ?") + for i in range(1, 8): + try: + c.execute(p, (i,)) + except: + print i + raise + data = c.fetchall() + self.assertEquals(1, len(data)) + assert not p.closed + p.close() + assert p.closed + self.assertRaises(zxJDBC.ProgrammingError, c.execute, p, (1,)) + finally: + c.close() + + def testStaticPrepare(self): + """testing the prepare() functionality for static cursors""" + self._test_preparedstatement(0) + + def testDynamicPrepare(self): + """testing the prepare() functionality for dynamic cursors""" + self._test_preparedstatement(1) + def _test_cursorkeywords(self, *args, **kws): c = self.cursor(*args, **kws) *************** *** 183,187 **** finally: c.close() ! self.assertRaises(zxJDBC.InternalError, c.execute, ("select * from zxtesting",)) def testClosingConnectionWithOpenCursors(self): --- 210,214 ---- finally: c.close() ! self.assertRaises(zxJDBC.ProgrammingError, c.execute, ("select * from zxtesting",)) def testClosingConnectionWithOpenCursors(self): *************** *** 193,199 **** # open a new connection so the tearDown can run self.db = self.connect() ! self.assertRaises(zxJDBC.InternalError, c.execute, ("select * from zxtesting",)) ! self.assertRaises(zxJDBC.InternalError, d.execute, ("select * from zxtesting",)) ! self.assertRaises(zxJDBC.InternalError, e.execute, ("select * from zxtesting",)) def testNativeSQL(self): --- 220,226 ---- # open a new connection so the tearDown can run self.db = self.connect() ! self.assertRaises(zxJDBC.ProgrammingError, c.execute, ("select * from zxtesting",)) ! self.assertRaises(zxJDBC.ProgrammingError, d.execute, ("select * from zxtesting",)) ! self.assertRaises(zxJDBC.ProgrammingError, e.execute, ("select * from zxtesting",)) def testNativeSQL(self): Index: runner.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/runner.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** runner.py 12 Apr 2002 04:10:47 -0000 1.2 --- runner.py 19 Apr 2002 19:01:06 -0000 1.3 *************** *** 185,189 **** opts, args = getopt.getopt(sys.argv[1:], "t:", []) except getopt.error, msg: ! print "%s -s [search] -r [replace] <pattern>" sys.exit(0) --- 185,189 ---- opts, args = getopt.getopt(sys.argv[1:], "t:", []) except getopt.error, msg: ! print "%s -t [testmask] <vendor>[,<vendor>]" sys.exit(0) *************** *** 199,200 **** --- 199,201 ---- fp.close() test(configParser.vendors, args[1:], mask=mask) + sys.exit(0) |
From: brian z. <bz...@us...> - 2002-04-19 19:08:07
|
Update of /cvsroot/jython/jython/Lib In directory usw-pr-cvs1:/tmp/cvs-serv25122/Lib Modified Files: dbexts.py Log Message: added .prepare() to cursor Index: dbexts.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/dbexts.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dbexts.py 7 Jan 2002 04:59:50 -0000 1.5 --- dbexts.py 19 Apr 2002 19:01:06 -0000 1.6 *************** *** 47,50 **** --- 47,51 ---- import os, re + from types import StringType __author__ = "brian zimmer (bz...@zi...)" *************** *** 282,285 **** --- 283,294 ---- self.db.rollback() + def prepare(self, sql): + """ prepare the sql statement """ + cur = self.begin() + try: + return cur.prepare(sql) + finally: + self.commit(cur) + def display(self): """ using the formatter, display the results """ *************** *** 315,321 **** headers = [] results = [] ! if comments: sql = comments(sql) ! statements = filter(lambda x: len(x) > 0, ! map(lambda statement: statement.strip(), sql.split(delim))) for a in statements: self.__execute__(a, params, bindings, maxrows=maxrows) --- 324,333 ---- headers = [] results = [] ! if type(sql) == type(StringType): ! if comments: sql = comments(sql) ! statements = filter(lambda x: len(x) > 0, ! map(lambda statement: statement.strip(), sql.split(delim))) ! else: ! statements = [sql] for a in statements: self.__execute__(a, params, bindings, maxrows=maxrows) |
From: brian z. <bz...@us...> - 2002-04-12 20:44:55
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv18054/com/ziclix/python/sql Modified Files: Procedure.java PyCursor.java Log Message: added rstype and rsconcur for prepared statements Index: Procedure.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/Procedure.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Procedure.java 10 Jan 2002 03:42:07 -0000 1.6 --- Procedure.java 12 Apr 2002 20:32:45 -0000 1.7 *************** *** 111,117 **** --- 111,133 ---- */ public CallableStatement prepareCall() throws SQLException { + return prepareCall(Py.None, Py.None); + } + + /** + * Prepares the statement and registers the OUT/INOUT parameters (if any). + * + * @param rsType the value of to be created ResultSet type + * @param rsConcur the value of the to be created ResultSet concurrency + * + * @return CallableStatement + * + * @throws SQLException + * + */ + public CallableStatement prepareCall(PyObject rsType, PyObject rsConcur) throws SQLException { // prepare the statement CallableStatement statement = null; + boolean normal = ((rsType == Py.None) && (rsConcur == Py.None)); try { *************** *** 120,124 **** String sqlString = toSql(); ! statement = cursor.connection.connection.prepareCall(sqlString); // prepare the OUT parameters --- 136,147 ---- String sqlString = toSql(); ! if (normal) { ! statement = cursor.connection.connection.prepareCall(sqlString); ! } else { ! int t = rsType.__int__().getValue(); ! int c = rsConcur.__int__().getValue(); ! ! statement = cursor.connection.connection.prepareCall(sqlString, t, c); ! } // prepare the OUT parameters Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** PyCursor.java 12 Apr 2002 04:12:27 -0000 1.20 --- PyCursor.java 12 Apr 2002 20:32:45 -0000 1.21 *************** *** 425,429 **** PyDictionary callableBindings = new PyDictionary(); ! this.sqlStatement = procedure.prepareCall(); if (maxRows != Py.None) { --- 425,429 ---- PyDictionary callableBindings = new PyDictionary(); ! this.sqlStatement = procedure.prepareCall(this.rsType, this.rsConcur); if (maxRows != Py.None) { |
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); |
From: brian z. <bz...@us...> - 2002-04-12 04:12:29
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv31769/Lib/test/zxjdbc Modified Files: test.xml zxtest.py Log Message: added result set type and concurrency Index: test.xml =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/test.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test.xml 29 Dec 2001 07:16:55 -0000 1.5 --- test.xml 12 Apr 2002 04:12:27 -0000 1.6 *************** *** 14,18 **** <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:postgresql://localhost:5432/ziclix"/> <argument name="usr" value="jython"/> <argument name="pwd" value=""/> --- 14,18 ---- <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:postgresql://192.168.1.102:5432/ziclix"/> <argument name="usr" value="jython"/> <argument name="pwd" value=""/> *************** *** 30,34 **** <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> <argument name="datasource" value="org.postgresql.PostgresqlDataSource"/> ! <keyword name="serverName" value="localhost"/> <keyword name="databaseName" value="ziclix"/> <keyword name="user" value="jython"/> --- 30,34 ---- <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> <argument name="datasource" value="org.postgresql.PostgresqlDataSource"/> ! <keyword name="serverName" value="192.168.1.102"/> <keyword name="databaseName" value="ziclix"/> <keyword name="user" value="jython"/> *************** *** 74,80 **** <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:mysql://localhost/ziclix"/> ! <argument name="usr" value=""/> ! <argument name="pwd" value=""/> <argument name="driver" value="org.gjt.mm.mysql.Driver"/> </factory> --- 74,80 ---- <test name="driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> ! <argument name="url" value="jdbc:mysql://192.168.1.102/ziclix"/> ! <argument name="usr" value="jython"/> ! <argument name="pwd" value="jython"/> <argument name="driver" value="org.gjt.mm.mysql.Driver"/> </factory> *************** *** 86,93 **** <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> <argument name="datasource" value="org.gjt.mm.mysql.MysqlDataSource"/> ! <keyword name="serverName" value="localhost"/> <keyword name="databaseName" value="ziclix"/> ! <keyword name="user" value=""/> ! <keyword name="password" value=""/> <keyword name="port" value="3306" type="int"/> </factory> --- 86,93 ---- <factory class="com.ziclix.python.sql.zxJDBC" method="connectx"> <argument name="datasource" value="org.gjt.mm.mysql.MysqlDataSource"/> ! <keyword name="serverName" value="192.168.1.102"/> <keyword name="databaseName" value="ziclix"/> ! <keyword name="user" value="jython"/> ! <keyword name="password" value="jython"/> <keyword name="port" value="3306" type="int"/> </factory> *************** *** 188,191 **** --- 188,208 ---- <vendor name="microsoft" datahandler="com.ziclix.python.sql.handler.SQLServerDataHandler"> + <!-- + <test name="freetds" os="java"> + <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> + <argument name="url" value="jdbc:freetds:sqlserver://localhost:1433/ziclix"/> + <argument name="usr" value="jython"/> + <argument name="pwd" value="jython"/> + <argument name="driver" value="com.internetcds.jdbc.tds.Driver"/> + </factory> + <testcase from="zxtest" import="zxAPITestCase"> + <ignore name="testRowid"/> + </testcase> + <testcase from="dbextstest" import="dbextsTestCase"> + <ignore name="testBulkcopy"/> + <ignore name="testBulkcopyWithDynamicColumns"/> + </testcase> + </test> + --> <test name="opta driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> *************** *** 195,199 **** <argument name="driver" value="com.inet.tds.TdsDriver"/> </factory> - <!-- <testcase from="zxtest" import="zxAPITestCase"> <ignore name="testRowid"/> --- 212,215 ---- *************** *** 203,209 **** <ignore name="testBulkcopyWithDynamicColumns"/> </testcase> ! --> <testcase from="sptest" import="SQLServerSPTest"/> </test> <test name="microsoft driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> --- 219,227 ---- <ignore name="testBulkcopyWithDynamicColumns"/> </testcase> ! <!-- <testcase from="sptest" import="SQLServerSPTest"/> + --> </test> + <!-- <test name="microsoft driver" os="java"> <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> *************** *** 213,217 **** <argument name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/> </factory> - <!-- <testcase from="zxtest" import="zxAPITestCase"> <ignore name="testRowid"/> --- 231,234 ---- *************** *** 220,225 **** <testcase from="dbextstest" import="dbextsTestCase"/> <testcase from="sptest" import="SQLServerSPTest"/> - --> </test> <table ref="texttable" name="c_texttable"> create table c_texttable (a int not null, primary key(a), b text not null) --- 237,242 ---- <testcase from="dbextstest" import="dbextsTestCase"/> <testcase from="sptest" import="SQLServerSPTest"/> </test> + --> <table ref="texttable" name="c_texttable"> create table c_texttable (a int not null, primary key(a), b text not null) *************** *** 283,285 **** --- 300,386 ---- </vendor> --> + <vendor name="interbase"> + <test name="driver" os="java"> + <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> + <argument name="url" value="jdbc:interbase://rook/usr/local/interbase/data/ziclix.gdb"/> + <argument name="usr" value="jython"/> + <argument name="pwd" value="jython"/> + <argument name="driver" value="interbase.interclient.Driver"/> + </factory> + <testcase from="zxtest" import="zxAPITestCase"> + <ignore name="testRowid"/> + </testcase> + <testcase from="zxtest" import="BCPTestCase"/> + <testcase from="dbextstest" import="dbextsTestCase"/> + </test> + <table ref="texttable" name="c_texttable"> + create table c_texttable (a int not null, primary key(a), b blob not null) + </table> + <table ref="floattable" name="c_floattable"> + create table c_floattable (a int, b numeric(5,2)) + </table> + <table ref="datetable" name="c_datetable"> + create table c_datetable (a int, b timestamp) + </table> + <table ref="timetable" name="c_timetable"> + create table c_timetable (a int, b timestamp) + </table> + <table ref="timestamptable" name="c_timestamptable"> + create table c_timestamptable (a int, b timestamp) + </table> + <table ref="blobtable" name="b_blobtable"> + create table b_blobtable (a int, b blob) + </table> + <table ref="pktable" name="b_pktable"> + create table b_pktable (a int not null, b int, primary key(a)) + </table> + <table ref="autoincrementtable" name="aitable"> + create table aitable (a serial not null, b int, primary key(a)) + </table> + </vendor> + <vendor name="sapdb"> + <test name="driver" os="java"> + <factory class="com.ziclix.python.sql.zxJDBC" method="connect"> + <argument name="url" value="jdbc:sapdb://localhost/TST"/> + <argument name="usr" value="TEST"/> + <argument name="pwd" value="TEST"/> + <argument name="driver" value="com.sap.dbtech.jdbc.DriverSapDB"/> + </factory> + <testcase from="zxtest" import="zxAPITestCase"> + <ignore name="testRowid"/> + <!-- Returns any empty ResultSet every time. --> + <ignore name="testIndexInfo"/> + <ignore name="testMaxrows"/> + <ignore name="testOrderOfArgsMaxRowsOnly"/> + </testcase> + <testcase from="zxtest" import="BCPTestCase"/> + <testcase from="dbextstest" import="dbextsTestCase"> + <ignore name="testQueryWithMaxRows"/> + </testcase> + </test> + <table ref="texttable" name="c_texttable"> + create table c_texttable (a int, b long varchar not null) + </table> + <table ref="floattable" name="c_floattable"> + create table c_floattable (a int, b decimal(5,2)) + </table> + <table ref="datetable" name="c_datetable"> + create table c_datetable (a int, b date) + </table> + <table ref="timetable" name="c_timetable"> + create table c_timetable (a int, b time) + </table> + <table ref="timestamptable" name="c_timestamptable"> + create table c_timestamptable (a int, b timestamp) + </table> + <table ref="blobtable" name="b_blobtable"> + create table b_blobtable (a int, b blob) + </table> + <table ref="pktable" name="b_pktable"> + create table b_pktable (a int not null, b int, primary key(a)) + </table> + <table ref="clobtable" name="b_clobtable"> + create table b_clobtable (a int, b clob) + </table> + </vendor> </tests> Index: zxtest.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/zxtest.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** zxtest.py 29 Mar 2002 04:01:03 -0000 1.12 --- zxtest.py 12 Apr 2002 04:12:27 -0000 1.13 *************** *** 28,33 **** return apply(connect, args, self.factory.keywords) ! def cursor(self, dynamic=0): ! c = self.db.cursor(dynamic) if hasattr(self, "datahandler"): c.datahandler = self.datahandler(c.datahandler) --- 28,33 ---- return apply(connect, args, self.factory.keywords) ! def cursor(self, *args, **kws): ! c = apply(self.db.cursor, args, kws) if hasattr(self, "datahandler"): c.datahandler = self.datahandler(c.datahandler) *************** *** 110,113 **** --- 110,136 ---- c.close() + def _test_cursorkeywords(self, *args, **kws): + c = self.cursor(*args, **kws) + try: + c.execute("select * from zxtesting") + data = c.fetchmany(1) + assert len(data) == 1, "expecting one row" + finally: + c.close() + + def testCursorKeywords(self): + """testing the creation of a cursor with keywords""" + self._test_cursorkeywords(dynamic=1) + self._test_cursorkeywords(dynamic=1, + rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, + rsconcur=zxJDBC.CONCUR_READ_ONLY + ) + self._test_cursorkeywords(1, + rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, + rsconcur=zxJDBC.CONCUR_READ_ONLY + ) + self._test_cursorkeywords(1,zxJDBC.TYPE_SCROLL_INSENSITIVE,zxJDBC.CONCUR_READ_ONLY) + self.assertRaises(TypeError, self.cursor, 1, zxJDBC.TYPE_SCROLL_INSENSITIVE) + def testFileLikeCursor(self): """testing the cursor as a file-like object""" *************** *** 252,256 **** def _test_scrolling(self, dynamic=0): ! c = self.cursor(dynamic) try: # set everything up --- 275,286 ---- def _test_scrolling(self, dynamic=0): ! if self.vendor.name == "oracle": ! c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, ! rsconcur=zxJDBC.CONCUR_READ_ONLY ! ) ! else: ! c = self.cursor(dynamic) ! try: # set everything up *************** *** 287,291 **** def _test_rownumber(self, dynamic=0): ! c = self.cursor(dynamic) try: if not dynamic: --- 317,328 ---- def _test_rownumber(self, dynamic=0): ! if self.vendor.name == "oracle": ! c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, ! rsconcur=zxJDBC.CONCUR_READ_ONLY ! ) ! else: ! c = self.cursor(dynamic) ! try: if not dynamic: *************** *** 319,323 **** def _test_rowcount(self, dynamic=0): ! c = self.cursor(dynamic) try: c.execute("select * from zxtesting") --- 356,367 ---- def _test_rowcount(self, dynamic=0): ! if self.vendor.name == "oracle": ! c = self.cursor(dynamic, ! rstype=zxJDBC.TYPE_SCROLL_INSENSITIVE, ! rsconcur=zxJDBC.CONCUR_READ_ONLY ! ) ! else: ! c = self.cursor(dynamic) ! try: c.execute("select * from zxtesting") *************** *** 654,666 **** self._test_time(self.table("timestamptable"), zxJDBC.Timestamp, values, zxJDBC.TIMESTAMP, _cmp_) ! def testOrderOfArgs(self): ! """testing execute with different argument orderings""" c = self.cursor() try: ! # maxrows only c.execute("select * from zxtesting", maxrows=3) f = c.fetchall() assert len(f) == 3, "expected length [3], got [%d]" % (len(f)) # bindings and params flipped --- 698,719 ---- self._test_time(self.table("timestamptable"), zxJDBC.Timestamp, values, zxJDBC.TIMESTAMP, _cmp_) ! def testOrderOfArgsMaxRowsOnly(self): ! """testing execute with max rows only""" c = self.cursor() try: ! # maxrows only (SAPDB doesn't support maxrows as of version 7.2.0) c.execute("select * from zxtesting", maxrows=3) f = c.fetchall() assert len(f) == 3, "expected length [3], got [%d]" % (len(f)) + + finally: + c.close() + self.db.commit() + + def testOrderOfArgs(self): + """testing execute with different argument orderings""" + c = self.cursor() + try: # bindings and params flipped |
From: brian z. <bz...@us...> - 2002-04-12 04:10:50
|
Update of /cvsroot/jython/jython/Lib/test/zxjdbc In directory usw-pr-cvs1:/tmp/cvs-serv31457/Lib/test/zxjdbc Modified Files: runner.py Log Message: added option to run a single test Index: runner.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/test/zxjdbc/runner.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** runner.py 14 Dec 2001 04:20:03 -0000 1.1 --- runner.py 12 Apr 2002 04:10:47 -0000 1.2 *************** *** 15,19 **** """ ! import unittest, sys, os import xmllib, __builtin__, re --- 15,19 ---- """ ! import unittest, os import xmllib, __builtin__, re *************** *** 157,167 **** return self.vendor.tables.has_key(name) ! def make_suite(vendor, testcase, factory): clz = __imp__(testcase.frm, testcase.impt) caseNames = filter(lambda x, i=testcase.ignore: x not in i, unittest.getTestCaseNames(clz, "test")) tests = [clz(caseName, vendor, factory) for caseName in caseNames] return unittest.TestSuite(tests) ! def test(vendors, include=None): for vendor in vendors: if not include or vendor.name in include: --- 157,169 ---- return self.vendor.tables.has_key(name) ! def make_suite(vendor, testcase, factory, mask=None): clz = __imp__(testcase.frm, testcase.impt) caseNames = filter(lambda x, i=testcase.ignore: x not in i, unittest.getTestCaseNames(clz, "test")) + if mask is not None: + caseNames = filter(lambda x, mask=mask: x == mask, caseNames) tests = [clz(caseName, vendor, factory) for caseName in caseNames] return unittest.TestSuite(tests) ! def test(vendors, include=None, mask=None): for vendor in vendors: if not include or vendor.name in include: *************** *** 171,175 **** if not test.os or test.os == os.name: for testcase in test.tests: ! suite = make_suite(vendor, testcase, test.factory) unittest.TextTestRunner().run(suite) else: --- 173,177 ---- if not test.os or test.os == os.name: for testcase in test.tests: ! suite = make_suite(vendor, testcase, test.factory, mask) unittest.TextTestRunner().run(suite) else: *************** *** 178,184 **** if __name__ == '__main__': configParser = ConfigParser() ! fp = open(sys.argv[1], "r") configParser.feed(fp.read()) fp.close() ! test(configParser.vendors, sys.argv[2:]) --- 180,200 ---- if __name__ == '__main__': + import sys, getopt + + try: + opts, args = getopt.getopt(sys.argv[1:], "t:", []) + except getopt.error, msg: + print "%s -s [search] -r [replace] <pattern>" + sys.exit(0) + + mask = None + for a in opts: + opt, arg = a + if opt == '-t': + mask = arg + configParser = ConfigParser() ! fp = open(args[0], "r") configParser.feed(fp.read()) fp.close() ! test(configParser.vendors, args[1:], mask=mask) |