Top Description Fields Constructors Methods
com.ziclix.python.sql

public Class PyCursor

Additional top-level class in compilation unit: CursorFunc.

extends PyObject
implements ClassDictInit, WarningListener, ContextManager, Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc, org.python.core.ContextManager, com.ziclix.python.sql.WarningListener, org.python.core.ClassDictInit
Known Direct Subclasses
com.ziclix.python.sql.PyExtendedCursor
Imports
java.sql.DatabaseMetaData, .SQLException, .SQLWarning, .Statement, java.util.List, org.python.core.ClassDictInit, .Py, .PyBuiltinMethodSet, .PyDictionary, .PyException, .PyList, .PyObject, .PyString, .PyTuple, .PyUnicode, .Traverseproc, .Visitproc, .ContextManager, .ThreadState, com.ziclix.python.sql.util.PyArgParser

These objects represent a database cursor, which is used to manage the context of a fetch operation.
Author
brian zimmer

Field Summary

Modifier and TypeField and Description
protected static PyList
__members__

Field __members__

protected static PyList
__methods__

Field __methods__

protected int
arraysize

Field arraysize

private boolean
closed

Field closed

protected PyConnection
connection

Field connection

protected DataHandler
datahandler

Field datahandler

private static final DataHandler
protected boolean
dynamicFetch

Field dynamicFetch

protected Fetch
fetch

Field fetch

protected PyObject
lastrowid

Field warnings

protected PyObject
rsConcur

Field rsConcur

protected PyObject
rsType

Field rsType

protected int
softspace

Field softspace

protected PyStatement
statement

Field statement

protected PyObject
updatecount

Field updatecount

protected PyObject
warnings

Field warnings

Inherited from org.python.core.PyObject:
attributesgcMonitorGlobalobjtypeTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
PyCursor(PyConnection connection)

Create the cursor with a static fetch.

pack-priv
PyCursor(PyConnection connection, boolean dynamicFetch)

Create the cursor, optionally choosing the type of fetch (static or dynamic).

pack-priv
PyCursor(PyConnection connection, boolean dynamicFetch, PyObject rsType, PyObject rsConcur)

Create the cursor, optionally choosing the type of fetch (static or dynamic).

Method Summary

Modifier and TypeMethod and Description
public void
__del__()

Delete the cursor.

public PyObject
public PyObject
public boolean
public boolean
__exit__(PyObject type, PyObject value, PyObject traceback)

public PyObject

Returns:

the attribute for the given name
__findattr_ex__
(String name)

Overrides org.python.core.PyObject.__findattr_ex__.

Gets the value of the attribute name.

public PyObject

Returns:

PyObject
__iter__
()

Overrides org.python.core.PyObject.__iter__.

Returns an iteratable object.

public PyObject

Returns:

PyObject
__iternext__
()

Overrides org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for.

public void
__setattr__(String name, PyObject value)

Overrides org.python.core.PyObject.__setattr__.

Sets the attribute name to value.

public void
callproc(PyObject name, final PyObject params, PyObject bindings, PyObject maxRows)

This method is optional since not all databases provide stored procedures.

public static void
classDictInit(PyObject dict)

Initializes the object's namespace.

protected void
clear()

Resets the cursor state.

public void
close()

Close the cursor now (rather than whenever __del__ is called).

private void
ensureOpen()

Throw a ProgrammingError if the cursor has been closed.

public void
execute(final PyObject
sql string or prepared statement
sql
,
PyObject
params for a prepared statement
params
,
PyObject
dictionary of (param index : SQLType binding)
bindings
,
PyObject
integer value of max rows
maxRows
)

Prepare and execute a database operation (query or command).

protected void
execute(PyObject params, PyObject bindings)

Execute the current sql statement.

public void
executemany(PyObject sql, PyObject params, PyObject bindings, PyObject maxRows)

Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.

public PyObject

Returns:

a sequence of sequences from the result set, or an empty sequence when no more data is available
fetchall
()

Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples).

public PyObject

Returns:

a sequence of sequences from the result set, or an empty sequence when no more data is available
fetchmany
(int size)

Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples).

public PyObject

Returns:

a single sequence from the result set, or None when no more data is available
fetchone
()

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

public DataHandler

Returns:

DataHandler
getDataHandler
()

Return the currently bound DataHandler.

protected DatabaseMetaData

Returns:

DatabaseMetaData
getMetaData
()

Return ths DatabaseMetaData for the current connection.

public static boolean

Returns:

boolean
hasParams
(PyObject params)

Method hasParams

public static boolean

Returns:

true for any PyList, PyTuple or java.util.List
isSeq
(PyObject object)

Method isSeq

public static boolean

Returns:

true is a sequence of sequences
isSeqSeq
(PyObject object)

Method isSeqSeq

public PyObject

Returns:

PyObject
next
()

Returns the next row from the currently executing SQL statement using the same semantics as .fetchone().

public PyObject

Returns:

true if more sets exist, else None
nextset
()

Move the result pointer to the next set if available.

public PyStatement

Returns:

A prepared statement usable with .executeXXX()
prepare
(PyObject
The sql string to be prepared.
sql
)

Prepare a sql statement for later execution.

private PyStatement

Returns:

PyStatement
prepareStatement
(PyObject
the sql to execute or a prepared statement
sql
,
PyObject
max number of rows to be returned
maxRows
,
boolean
if true, prepare the statement, otherwise create a normal statement
prepared
)

Prepare a statement ready for executing.

public boolean
public void
scroll(int value, String mode)

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

public String

Returns:

a string representation of the object.
toString
()

Overrides org.python.core.PyObject.toString.

String representation of the object.

public int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

private void
updateAttributes(int
The int value of updatecount
updateCount
)

Update the cursor's lastrowid and updatecount.

public void
warning(WarningEvent event)

Implements com.ziclix.python.sql.WarningListener.warning.

Adds a warning to the tuple and will follow the chain as necessary.

Inherited from org.python.core.PyObject:
__abs____add____and____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____cmp____coerce____coerce_ex____complex____contains____delattr____delattr____delete____delitem____delitem____delslice____delslice____dir____div____divmod____ensure_finalizer____eq____findattr____findattr____finditem____finditem____finditem____float____floordiv____format____ge____get____getattr____getattr____getitem____getitem____getnewargs____getslice____getslice____gt____hash____hex____iadd____iand____idiv____idivmod____ifloordiv____ilshift____imod____imul____index____int____invert____ior____ipow____irshift____isub____itruediv____ixor____le____len____long____lshift____lt____mod____mul____ne____neg____nonzero____not____oct____or____pos____pow____pow____radd____rand____rawdir____rdiv____rdivmod____reduce____reduce_ex____reduce_ex____repr____rfloordiv____rlshift____rmod____rmul____ror____rpow____rrshift____rshift____rsub____rtruediv____rxor____set____setattr____setitem____setitem____setitem____setslice____setslice____str____sub____tojava____truediv____trunc____unicode____xor___add_and_callextra_cmp_div_divmod_doget_doget_doset_eq_floordiv_ge_gt_iadd_iand_idiv_idivmod_ifloordiv_ilshift_imod_imul_in_ior_ipow_irshift_is_isnot_isub_itruediv_ixor_jcall_jcallexc_jthrow_le_lshift_lt_mod_mul_ne_notin_or_pow_rshift_sub_truediv_unsupportedop_xoradaptToCoerceTupleasDoubleasIndexasIndexasIntasIntasIterableasLongasLongasNameasNameasStringasStringasStringOrNullasStringOrNullbit_lengthconjugatedelDictdelTypedispatch__init__equalsfastGetClassfastGetDictfinalizegetDictgetJavaProxygetTypehashCodeimpAttrimplementsDescrDeleteimplementsDescrGetimplementsDescrSetinvokeinvokeinvokeinvokeinvokeinvokeisCallableisDataDescrisIndexisIntegerisMappingTypeisNumberTypeisSequenceTypemergeClassDictmergeDictAttrmergeListAttrnoAttributeErrorobject___subclasshook__readonlyAttributeErrorrunsupportedopMessagesetDictsetTypeunsupportedopMessage

Field Detail

__members__back to summary
protected static PyList __members__

Field __members__

__methods__back to summary
protected static PyList __methods__

Field __methods__

arraysizeback to summary
protected int arraysize

Field arraysize

closedback to summary
private boolean closed

Field closed

connectionback to summary
protected PyConnection connection

Field connection

datahandlerback to summary
protected DataHandler datahandler

Field datahandler

DATAHANDLERback to summary
private static final DataHandler DATAHANDLER
dynamicFetchback to summary
protected boolean dynamicFetch

Field dynamicFetch

fetchback to summary
protected Fetch fetch

Field fetch

lastrowidback to summary
protected PyObject lastrowid

Field warnings

rsConcurback to summary
protected PyObject rsConcur

Field rsConcur

rsTypeback to summary
protected PyObject rsType

Field rsType

softspaceback to summary
protected int softspace

Field softspace

statementback to summary
protected PyStatement statement

Field statement

updatecountback to summary
protected PyObject updatecount

Field updatecount

warningsback to summary
protected PyObject warnings

Field warnings

Constructor Detail

PyCursorback to summary
pack-priv PyCursor(PyConnection connection)

Create the cursor with a static fetch.

PyCursorback to summary
pack-priv PyCursor(PyConnection connection, boolean dynamicFetch)

Create the cursor, optionally choosing the type of fetch (static or dynamic). If dynamicFetch is true, then use a dynamic fetch.

PyCursorback to summary
pack-priv PyCursor(PyConnection connection, boolean dynamicFetch, PyObject rsType, PyObject rsConcur)

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

Method Detail

__del__back to summary
public void __del__()

Delete the cursor.

__enter__back to summary
public PyObject __enter__(ThreadState ts)

Implements org.python.core.ContextManager.__enter__.

__enter__back to summary
public PyObject __enter__()
__exit__back to summary
public boolean __exit__(ThreadState ts, PyException exception)

Implements org.python.core.ContextManager.__exit__.

__exit__back to summary
public boolean __exit__(PyObject type, PyObject value, PyObject traceback)
__findattr_ex__back to summary
public PyObject __findattr_ex__(String name)

Overrides org.python.core.PyObject.__findattr_ex__.

Gets the value of the attribute name.

Returns:PyObject

the attribute for the given name

Annotations
@Override

__iter__back to summary
public PyObject __iter__()

Overrides org.python.core.PyObject.__iter__.

Returns an iteratable object.

Returns:PyObject

PyObject

Annotations
@Override
Since
Jython 2.2, DB API 2.0+

__iternext__back to summary
public PyObject __iternext__()

Overrides org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for. Returns null when the end of the sequence is reached.

Returns:PyObject

PyObject

Annotations
@Override
Since
Jython 2.2

__setattr__back to summary
public void __setattr__(String name, PyObject value)

Overrides org.python.core.PyObject.__setattr__.

Sets the attribute name to value.

Annotations
@Override
callprocback to summary
public void callproc(PyObject name, final PyObject params, PyObject bindings, PyObject maxRows)

This method is optional since not all databases provide stored procedures. Call a stored database procedure with the given name. The sequence of parameters must contain one entry for each argument that the procedure expects. The result of the call is returned as modified copy of the input sequence. Input parameters are left untouched, output and input/output parameters replaced with possibly new values. The procedure may also provide a result set as output. This must then be made available through the standard fetchXXX() methods.

classDictInitback to summary
public static void classDictInit(PyObject dict)

Initializes the object's namespace.

clearback to summary
protected void clear()

Resets the cursor state. This includes flushing the warnings and any previous results.

closeback to summary
public void close()

Close the cursor now (rather than whenever __del__ is called). The cursor will be unusable from this point forward; an Error (or subclass) exception will be raised if any operation is attempted with the cursor.

ensureOpenback to summary
private void ensureOpen()

Throw a ProgrammingError if the cursor has been closed.

executeback to summary
public void execute(final PyObject sql, PyObject params, PyObject bindings, PyObject maxRows)

Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified in a database-specific notation (see the module's paramstyle attribute for details). A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times). For maximum efficiency when reusing an operation, it is best to use the setinputsizes() method to specify the parameter types and sizes ahead of time. It is legal for a parameter to not match the predefined information; the implementation should compensate, possibly with a loss of efficiency. The parameters may also be specified as list of tuples to e.g. insert multiple rows in a single operation, but this kind of usage is deprecated: executemany() should be used instead. Return values are not defined.

Parameters
sql:PyObject

sql string or prepared statement

params:PyObject

params for a prepared statement

bindings:PyObject

dictionary of (param index : SQLType binding)

maxRows:PyObject

integer value of max rows

executeback to summary
protected void execute(PyObject params, PyObject bindings)

Execute the current sql statement. Some generic functionality such as updating the lastrowid and updatecount occur as well.

executemanyback to summary
public void executemany(PyObject sql, PyObject params, PyObject bindings, PyObject maxRows)

Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. Modules are free to implement this method using multiple calls to the execute() method or by using array operations to have the database process the sequence as a whole in one call. The same comments as for execute() also apply accordingly to this method. Return values are not defined.

fetchallback to summary
public 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:PyObject

a sequence of sequences from the result set, or an empty sequence when no more data is available

fetchmanyback to summary
public 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:PyObject

a sequence of sequences from the result set, or an empty sequence when no more data is available

fetchoneback to summary
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:PyObject

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

getDataHandlerback to summary
public DataHandler getDataHandler()

Return the currently bound DataHandler.

Returns:DataHandler

DataHandler

getMetaDataback to summary
protected DatabaseMetaData getMetaData() throws SQLException

Return ths DatabaseMetaData for the current connection.

Returns:DatabaseMetaData

DatabaseMetaData

hasParamsback to summary
public static boolean hasParams(PyObject params)

Method hasParams

Returns:boolean

boolean

isSeqback to summary
public static boolean isSeq(PyObject object)

Method isSeq

Returns:boolean

true for any PyList, PyTuple or java.util.List

isSeqSeqback to summary
public static boolean isSeqSeq(PyObject object)

Method isSeqSeq

Returns:boolean

true is a sequence of sequences

nextback to summary
public PyObject next()

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.

Returns:PyObject

PyObject

Since
Jython 2.2, DB API 2.0+

nextsetback to summary
public PyObject nextset()

Move the result pointer to the next set if available.

Returns:PyObject

true if more sets exist, else None

prepareback to summary
public PyStatement prepare(PyObject sql)

Prepare a sql statement for later execution.

Parameters
sql:PyObject

The sql string to be prepared.

Returns:PyStatement

A prepared statement usable with .executeXXX()

prepareStatementback to summary
private PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared)

Prepare a statement ready for executing.

Parameters
sql:PyObject

the sql to execute or a prepared statement

maxRows:PyObject

max number of rows to be returned

prepared:boolean

if true, prepare the statement, otherwise create a normal statement

Returns:PyStatement

PyStatement

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob)

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
scrollback to summary
public void scroll(int value, 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).

toStringback to summary
public String toString()

Overrides org.python.core.PyObject.toString.

String representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override

traverseback to summary
public int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. 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.

Annotations
@Override
updateAttributesback to summary
private void updateAttributes(int updateCount) throws SQLException

Update the cursor's lastrowid and updatecount.

Parameters
updateCount:int

The int value of updatecount

warningback to summary
public void warning(WarningEvent event)

Implements com.ziclix.python.sql.WarningListener.warning.

Adds a warning to the tuple and will follow the chain as necessary.