Update of /cvsroot/jython/jython/com/ziclix/python/sql
In directory usw-pr-cvs1:/tmp/cvs-serv18246/com/ziclix/python/sql
Modified Files:
PyCursor.java
Log Message:
implemented iteration protocol
Index: PyCursor.java
===================================================================
RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** PyCursor.java 2002/01/07 02:59:00 1.13
--- PyCursor.java 2002/01/08 05:39:32 1.14
***************
*** 257,260 ****
--- 257,309 ----
/**
+ * Returns an iteratable object.
+ *
+ * @return PyObject
+ *
+ * @since Jython 2.2, DB API 2.0+
+ */
+ public PyObject __iter__() {
+ return this;
+ }
+
+ /**
+ * Returns the next row from the currently executing SQL statement
+ * using the same semantics as .fetchone(). A StopIteration
+ * exception is raised when the result set is exhausted for Python
+ * versions 2.2 and later.
+ *
+ * @return PyObject
+ *
+ * @since Jython 2.2, DB API 2.0+
+ */
+ public PyObject next() {
+
+ PyObject row = __iternext__();
+
+ if (row == null) {
+ throw Py.StopIteration(null);
+ }
+
+ return row;
+ }
+
+ /**
+ * Return the next element of the sequence that this is an iterator
+ * for. Returns null when the end of the sequence is reached.
+ *
+ * @since Jython 2.2
+ */
+ public PyObject __iternext__() {
+
+ PyObject row = fetchone();
+
+ if (row == Py.None) {
+ row = null;
+ }
+
+ return row;
+ }
+
+ /**
* Return ths DatabaseMetaData for the current connection.
*
|