Package grizzled :: Package db :: Module base :: Class Cursor
[hide private]
[frames] | no frames]

Class Cursor

source code

object --+
         |
        Cursor
Known Subclasses:

Class for DB cursors returned by the DB.cursor() method. This class conforms to the Python DB cursor interface, including the following attributes.
Instance Methods [hide private]
 
__init__(self, cursor, driver)
Create a new Cursor object, wrapping the underlying real DB API cursor.
source code
 
__get_description(self) source code
 
__get_rowcount(self) source code
 
close(self)
Close the cursor.
source code
 
execute(self, statement, parameters=None)
Execute a SQL statement string with the given parameters.
source code
 
executemany(self, statement, *parameters)
Execute a SQL statement once for each item in the given parameters.
source code
 
executeMany(self, statement, *parameters)
Execute a SQL statement once for each item in the given parameters.
source code
tuple
fetchone(self)
Returns the next result set row from the last query, as a sequence of tuples.
source code
list of tuples
fetchall(self)
Returns all remaining result rows from the last query, as a sequence of tuples.
source code
list of tuples
fetchAll(self)
Returns all remaining result rows from the last query, as a sequence of tuples.
source code
list of tuples
fetchmany(self, n)
Returns up to n remaining result rows from the last query, as a sequence of tuples.
source code
list of tuples
fetchMany(self, n)
Returns up to n remaining result rows from the last query, as a sequence of tuples.
source code
named tuple
get_rdbms_metadata(self)
Return data about the RDBMS: the product name, the version, etc.
source code
list
get_table_metadata(self, table)
Get the metadata for a table.
source code
list of tuples
get_index_metadata(self, table)
Get the metadata for the indexes for a table.
source code
list
get_tables(self)
Get the list of tables in the database to which this cursor is connected.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
tuple description
A read-only attribute that is a sequence of 7-item tuples, one per column, from the last query executed.
int rowcount
A read-only attribute that specifies the number of rows fetched in the last query, or -1 if unknown.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, cursor, driver)
(Constructor)

source code 
Create a new Cursor object, wrapping the underlying real DB API cursor.
Parameters:
  • cursor - the real DB API cursor object
  • driver - the driver that is creating this object
Overrides: object.__init__

close(self)

source code 
Close the cursor.
Raises:
  • Warning - Non-fatal warning
  • Error - Error; unable to close

execute(self, statement, parameters=None)

source code 
Execute a SQL statement string with the given parameters. 'parameters' is a sequence when the parameter style is 'format', 'numeric' or 'qmark', and a dictionary when the style is 'pyformat' or 'named'. See DB.paramstyle().
Parameters:
  • statement (str) - the SQL statement to execute
  • parameters (list) - parameters to use, if the statement is parameterized
Raises:

executemany(self, statement, *parameters)

source code 
Execute a SQL statement once for each item in the given parameters.
Parameters:
  • statement (str) - the SQL statement to execute
  • parameters (sequence) - a sequence of sequences when the parameter style is 'format', 'numeric' or 'qmark', and a sequence of dictionaries when the style is 'pyformat' or 'named'.
Raises:

executeMany(self, statement, *parameters)

source code 
Execute a SQL statement once for each item in the given parameters.
Parameters:
  • statement (str) - the SQL statement to execute
  • parameters (sequence) - a sequence of sequences when the parameter style is 'format', 'numeric' or 'qmark', and a sequence of dictionaries when the style is 'pyformat' or 'named'.
Raises:

fetchone(self)

source code 
Returns the next result set row from the last query, as a sequence of tuples. Raises an exception if the last statement was not a query.
Returns: tuple
Next result set row
Raises:

fetchall(self)

source code 
Returns all remaining result rows from the last query, as a sequence of tuples. Raises an exception if the last statement was not a query.
Returns: list of tuples
List of rows, each represented as a tuple
Raises:

fetchAll(self)

source code 
Returns all remaining result rows from the last query, as a sequence of tuples. Raises an exception if the last statement was not a query.
Returns: list of tuples
List of rows, each represented as a tuple
Raises:

fetchmany(self, n)

source code 
Returns up to n remaining result rows from the last query, as a sequence of tuples. Raises an exception if the last statement was not a query.
Parameters:
  • n (int) - maximum number of result rows to get
Returns: list of tuples
List of rows, each represented as a tuple
Raises:

fetchMany(self, n)

source code 
Returns up to n remaining result rows from the last query, as a sequence of tuples. Raises an exception if the last statement was not a query.
Parameters:
  • n (int) - maximum number of result rows to get
Returns: list of tuples
List of rows, each represented as a tuple
Raises:

get_rdbms_metadata(self)

source code 

Return data about the RDBMS: the product name, the version, etc. The result is a named tuple, with the following fields:

vendor
The product vendor, if applicable, or None if not known
product
The name of the database product, or None if not known
version
The database product version, or None if not known

The fields may be accessed by position or name. This method just calls through to the equivalent method in the underlying DBDriver implementation.

Returns: named tuple
the vendor information

get_table_metadata(self, table)

source code 

Get the metadata for a table. Returns a list of tuples, one for each column. Each tuple consists of the following:

(column_name, type_string, max_char_size, precision, scale, nullable)

The tuple elements have the following meanings.

column_name
the name of the column
type_string
the column type, as a string
max_char_size
the maximum size for a character field, or None
precision
the precision, for a numeric field; or None
scale
the scale, for a numeric field; or None
nullable
True if the column is nullable, False if it is not

The tuples are named tuples, so the fields may be referenced by the names above or by position.

The data may come from the DB API's cursor.description field, or it may be richer, coming from a direct SELECT against database-specific tables.

Returns: list
list of tuples, as described above
Raises:

get_index_metadata(self, table)

source code 

Get the metadata for the indexes for a table. Returns a list of tuples, one for each index. Each tuple consists of the following:

(index_name, [index_columns], description)

The tuple elements have the following meanings.

index_name
the index name
index_columns
a list of column names
description
index description, or None

The tuples are named tuples, so the fields may be referenced by the names above or by position.

Returns: list of tuples
the list of tuples, or None if not supported in the underlying database
Raises:

get_tables(self)

source code 
Get the list of tables in the database to which this cursor is connected.
Returns: list
List of table names. The list will be empty if the database contains no tables.
Raises:
  • NotImplementedError - Capability not supported by database driver
  • Warning - Non-fatal warning
  • Error - Error

Instance Variable Details [hide private]

description

A read-only attribute that is a sequence of 7-item tuples, one per column, from the last query executed. The tuple values are: (name, typecode, displaysize, internalsize, precision, scale)
Get Method:
__get_description(self)

rowcount

A read-only attribute that specifies the number of rows fetched in the last query, or -1 if unknown. Note: It's best not to rely on the row count, because some database drivers (such as SQLite) don't report valid row counts.
Get Method:
__get_rowcount(self)