com.ziclix.python.sql
Class PyCursor

java.lang.Object
  |
  +--org.python.core.PyObject
        |
        +--com.ziclix.python.sql.PyCursor
All Implemented Interfaces:
org.python.core.InitModule, java.io.Serializable
Direct Known Subclasses:
PyExtendedCursor

public class PyCursor
extends org.python.core.PyObject
implements org.python.core.InitModule

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

Version:
$Revision: 1.11 $
Author:
brian zimmer, last revised by $Author: bzimmer $
See Also:
Serialized Form

Field Summary
static org.python.core.PyClass __class__
           
protected static org.python.core.PyList __members__
           
protected static org.python.core.PyList __methods__
           
protected  int arraysize
           
protected  java.util.Hashtable cache
           
protected  java.sql.Connection connection
           
protected  int counter
           
protected  DataHandler datahandler
           
protected  org.python.core.PyObject description
           
protected  org.python.core.PyObject results
           
protected  int rowcount
           
 
Constructor Summary
PyCursor()
          InitModule requires there be an empty constructor, but I really want the Statement to be passed in the constructor.
 
Method Summary
 void __del__()
          Delete the cursor.
 org.python.core.PyObject __findattr__(java.lang.String name)
          Gets the value of the attribute name.
 void __setattr__(java.lang.String name, org.python.core.PyObject value)
          Sets the attribute name to value.
protected  java.sql.CallableStatement callableStatement(java.lang.String sqlString)
          Call a stored procedure.
 void callproc(java.lang.String procName, org.python.core.PyObject params)
          This method is optional since not all databases provide stored procedures.
protected  void clear()
          Reset the cursor.
 void close()
          Close the cursor now (rather than whenever __del__ is called).
protected  void create(java.sql.ResultSet rs)
          Create the results after a successful execution.
protected  org.python.core.PyList createDescription(java.sql.ResultSetMetaData meta)
          (name, type_code, display_size, internal_size, precision, scale, null_ok)
protected  org.python.core.PyList createResults(java.sql.ResultSet set)
          Creates the results of a query.
 void execute(java.lang.String sqlString, org.python.core.PyObject params, org.python.core.PyObject bindings)
          Prepare and execute a database operation (query or command).
 void executemany(java.lang.String sqlString, org.python.core.PyObject params, org.python.core.PyObject bindings)
          Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
 org.python.core.PyObject fetchall()
          Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g.
 org.python.core.PyObject fetchmany(int size)
          Fetch the next set of rows of a query result, returning a sequence of sequences (e.g.
 org.python.core.PyObject fetchone()
          Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
protected  org.python.core.PyClass getPyClass()
          $METHOD_DESCRIPTION$
 void initModule(org.python.core.PyObject dict)
          Initializes the object's namespace.
 org.python.core.PyObject nextset()
          Returns the next set, else None if no more sets exist.
protected  java.sql.PreparedStatement prepareStatement(java.lang.String sqlString)
          Prepare a statement ready for executing.
protected  java.sql.Statement statement()
          Create a Statement.
 java.lang.String toString()
          String representation of the object.
 
Methods inherited from class org.python.core.PyObject
__abs__, __add__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __contains__, __delattr__, __delattr__, __delitem__, __delitem__, __delslice__, __delslice__, __dir__, __div__, __divmod__, __findattr__, __finditem__, __finditem__, __finditem__, __float__, __getattr__, __getattr__, __getitem__, __getitem__, __getslice__, __getslice__, __hash__, __hex__, __int__, __invert__, __len__, __long__, __lshift__, __mod__, __mul__, __neg__, __nonzero__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __repr__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rxor__, __setattr__, __setitem__, __setitem__, __setitem__, __setslice__, __setslice__, __str__, __sub__, __tojava__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _dodel, _doget, _doget, _doset, _eq, _ge, _gt, _in, _is, _isnot, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _xor, addKeys, equals, hashCode, invoke, invoke, invoke, invoke, invoke, isCallable, isMappingType, isNumberType, isSequenceType, safeRepr
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

connection

protected java.sql.Connection connection

results

protected org.python.core.PyObject results

counter

protected int counter

rowcount

protected int rowcount

description

protected org.python.core.PyObject description

arraysize

protected int arraysize

cache

protected java.util.Hashtable cache

datahandler

protected DataHandler datahandler

__class__

public static org.python.core.PyClass __class__

__methods__

protected static org.python.core.PyList __methods__

__members__

protected static org.python.core.PyList __members__
Constructor Detail

PyCursor

public PyCursor()
InitModule requires there be an empty constructor, but I really want the Statement to be passed in the constructor. What to do?
Method Detail

getPyClass

protected org.python.core.PyClass getPyClass()
$METHOD_DESCRIPTION$
Overrides:
getPyClass in class org.python.core.PyObject
Returns:
 

toString

public java.lang.String toString()
String representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

__setattr__

public void __setattr__(java.lang.String name,
                        org.python.core.PyObject value)
Sets the attribute name to value.
Overrides:
__setattr__ in class org.python.core.PyObject
Parameters:
name -  
value -  

__findattr__

public org.python.core.PyObject __findattr__(java.lang.String name)
Gets the value of the attribute name.
Overrides:
__findattr__ in class org.python.core.PyObject
Parameters:
name -  
Returns:
 

initModule

public void initModule(org.python.core.PyObject dict)
Initializes the object's namespace.
Specified by:
initModule in interface org.python.core.InitModule
Parameters:
dict -  

__del__

public void __del__()
Delete the cursor.

close

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.

statement

protected java.sql.Statement statement()
                                throws java.sql.SQLException
Create a Statement.
Returns:
 

callableStatement

protected java.sql.CallableStatement callableStatement(java.lang.String sqlString)
                                                throws java.sql.SQLException
Call a stored procedure.
Parameters:
sqlString -  
Returns:
 
Throws:
java.sql.SQLException -  

prepareStatement

protected java.sql.PreparedStatement prepareStatement(java.lang.String sqlString)
                                               throws java.sql.SQLException
Prepare a statement ready for executing.
Parameters:
sqlString -  
Returns:
 
Throws:
java.sql.SQLException -  

callproc

public void callproc(java.lang.String procName,
                     org.python.core.PyObject params)
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.

executemany

public void executemany(java.lang.String sqlString,
                        org.python.core.PyObject params,
                        org.python.core.PyObject bindings)
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.

execute

public void execute(java.lang.String sqlString,
                    org.python.core.PyObject params,
                    org.python.core.PyObject bindings)
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:
sqlString - sql string
params - params for a prepared statement
bindings - dictionary of (param index : SQLType binding)

fetchone

public org.python.core.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 org.python.core.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 org.python.core.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 org.python.core.PyObject nextset()
Returns the next set, else None if no more sets exist.
Returns:
 

create

protected void create(java.sql.ResultSet rs)
Create the results after a successful execution.
Parameters:
rs - A ResultSet.

createDescription

protected org.python.core.PyList createDescription(java.sql.ResultSetMetaData meta)
                                            throws java.sql.SQLException
(name, type_code, display_size, internal_size, precision, scale, null_ok)

createResults

protected org.python.core.PyList createResults(java.sql.ResultSet set)
                                        throws java.sql.SQLException
Creates the results of a query. Iterates through the list and builds the tuple.
Parameters:
set -  
Returns:
a list of tuples of the results
Throws:
java.lang.Exception -  

clear

protected void clear()
Reset the cursor.


Copyright (c) 2000 brian zimmer. All Rights Reserved.