Fetch (Jython API documentation)
Date: 2022-09-10

com.ziclix.python.sql

## Class Fetch

- java.lang.Object
- - com.ziclix.python.sql.Fetch

- All Implemented Interfaces:
    Traverseproc

      public abstract class Fetch
      extends java.lang.Object
      implements Traverseproc

  The responsibility of a Fetch instance is to manage the iteration of a ResultSet. Two different alogorithms are available: static or dynamic.

  Static The static variety iterates the entire set immediately, creating the necessary Jython objects and storing them. It is able to immediately close the ResultSet so a call to close() is essentially a no-op from a database resource perspective (it does clear the results list however). This approach also allows for the correct rowcount to be determined since the entire result set has been iterated.

  Dynamic The dynamic variety iterates the result set only as requested. This holds a bit truer to the intent of the API as the fetch*() methods actually fetch when instructed. This is especially useful for managing exeedingly large results, but is unable to determine the rowcount without having worked through the entire result set. The other disadvantage is the ResultSet remains open throughout the entire iteration. So the tradeoff is in open database resources versus JVM resources since the application can keep constant space if it doesn't require the entire result set be presented as one.

  Author:
    brian zimmer

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `add(java.sql.CallableStatement callableStatement, Procedure procedure, PyObject params)` Method add
    `abstract void` | `add(java.sql.ResultSet resultSet)` Create the results after a successful execution and manages the result set.
    `abstract void` | `add(java.sql.ResultSet resultSet, java.util.Set<java.lang.Integer> skipCols)` Create the results after a successful execution and manages the result set.
    `void` | `addWarningListener(WarningListener listener)`
    `void` | `close()` Cleanup any resources.
    `abstract PyObject` | `fetchall()` Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples).
    `abstract PyObject` | `fetchmany(int size)` Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples).
    `PyObject` | `fetchone()` Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
    `PyObject` | `getDescription()` The description of each column, in order, for the data in the result set.
    `int` | `getRowCount()` The number of rows in the current result set.
    `static Fetch` | `newFetch(DataHandler datahandler, boolean dynamic)` Method newFetch
    `abstract PyObject` | `nextset()` Move the result pointer to the next set if available.
    `boolean` | `refersDirectlyTo(PyObject ob)` Optional operation.
    `boolean` | `removeWarningListener(WarningListener listener)`
    `abstract void` | `scroll(int value, java.lang.String mode)` Scroll the cursor in the result set to a new position according to mode.
    `int` | `traverse(Visitproc visit, java.lang.Object arg)` Traverses all directly contained `PyObject`s.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### newFetch

          public static Fetch newFetch(DataHandler datahandler,
                                       boolean dynamic)

      Method newFetch
      Parameters:
        `datahandler` -
        `dynamic` -
      Returns:
        Fetch

    - #### getRowCount

          public int getRowCount()

      The number of rows in the current result set.

    - #### getDescription

          public PyObject getDescription()

      The description of each column, in order, for the data in the result set.

    - #### add

          public abstract void add(java.sql.ResultSet resultSet)

      Create the results after a successful execution and manages the result set.
      Parameters:
        `resultSet` -

    - #### add

          public abstract void add(java.sql.ResultSet resultSet,
                                   java.util.Set<java.lang.Integer> skipCols)

      Create the results after a successful execution and manages the result set. Optionally takes a set of JDBC-indexed columns to automatically set to None primarily to support getTypeInfo() which sets a column type of a number but doesn't use the value so a driver is free to put anything it wants there.
      Parameters:
        `resultSet` -
        `skipCols` - JDBC-indexed set of columns to be skipped

    - #### add

          public abstract void add(java.sql.CallableStatement callableStatement,
                                   Procedure procedure,
                                   PyObject params)

      Method add
      Parameters:
        `callableStatement` -
        `procedure` -
        `params` -

    - #### fetchone

          public PyObject fetchone()

      Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.

      An Error (or subclass) exception is raised if the previous call to executeXXX() did not produce any result set or no call was issued yet.

      Returns:
        a single sequence from the result set, or None when no more data is available

    - #### fetchall

          public abstract PyObject fetchall()

      Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.

      An Error (or subclass) exception is raised if the previous call to executeXXX() did not produce any result set or no call was issued yet.

      Returns:
        a sequence of sequences from the result set, or None when no more data is available

    - #### fetchmany

          public abstract PyObject fetchmany(int size)

      Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available.

      The number of rows to fetch per call is specified by the parameter. If it is not given, the cursor's arraysize determines the number of rows to be fetched. The method should try to fetch as many rows as indicated by the size parameter. If this is not possible due to the specified number of rows not being available, fewer rows may be returned.

      An Error (or subclass) exception is raised if the previous call to executeXXX() did not produce any result set or no call was issued yet.

      Note there are performance considerations involved with the size parameter. For optimal performance, it is usually best to use the arraysize attribute. If the size parameter is used, then it is best for it to retain the same value from one fetchmany() call to the next.

      Returns:
        a sequence of sequences from the result set, or None when no more data is available

    - #### nextset

          public abstract PyObject nextset()

      Move the result pointer to the next set if available.
      Returns:
        true if more sets exist, else None

    - #### scroll

          public abstract void scroll(int value,
                                      java.lang.String mode)

      Scroll the cursor in the result set to a new position according to mode.

      If mode is 'relative' (default), value is taken as offset to the current position in the result set, if set to 'absolute', value states an absolute target position.

      An IndexError should be raised in case a scroll operation would leave the result set. In this case, the cursor position is left undefined (ideal would be to not move the cursor at all).

      Note: This method should use native scrollable cursors, if available, or revert to an emulation for forward-only scrollable cursors. The method may raise NotSupportedErrors to signal that a specific operation is not supported by the database (e.g. backward scrolling).

      Parameters:
        `value` -
        `mode` -

    - #### close

          public void close()
                     throws java.sql.SQLException

      Cleanup any resources.
      Throws:
        `java.sql.SQLException`

    - #### addWarningListener

          public void addWarningListener(WarningListener listener)

    - #### removeWarningListener

          public boolean removeWarningListener(WarningListener listener)

    - #### traverse

          public int traverse(Visitproc visit,
                              java.lang.Object arg)

      Description copied from interface: `Traverseproc`
      Traverses all directly contained `PyObject`s. Like in CPython, `arg` must be passed unmodified to `visit` as its second parameter. If `Visitproc.visit(PyObject, Object)` returns nonzero, this return value must be returned immediately by traverse. `Visitproc.visit(PyObject, Object)` must not be called with a `null` PyObject-argument.
      Specified by:
        `traverse` in interface `Traverseproc`

    - #### refersDirectlyTo

          public boolean refersDirectlyTo(PyObject ob)
                                   throws java.lang.UnsupportedOperationException

      Description copied from interface: `Traverseproc`
      Optional operation. Should only be implemented if it is more efficient than calling `Traverseproc.traverse(Visitproc, Object)` with a visitproc that just watches out for `ob`. Must return `false` if `ob` is `null`.
      Specified by:
        `refersDirectlyTo` in interface `Traverseproc`
      Throws:
        `java.lang.UnsupportedOperationException`

Jython homepage