Package grizzled :: Package db :: Module oracle :: Class OracleDriver
[hide private]
[frames] | no frames]

Class OracleDriver

source code

   object --+    
            |    
base.DBDriver --+
                |
               OracleDriver

DB Driver for Oracle, using the cx_Oracle DB API module.
Instance Methods [hide private]
 
get_import(self)
Get a bound import for the underlying DB API module.
source code
str
get_display_name(self)
Get the driver's name, for display.
source code
object
do_connect(self, host='localhost', port=None, user='', password='', database='default')
Connect to the actual underlying database, using the driver.
source code
list
get_tables(self, cursor)
Get the list of tables in the database.
source code
named tuple
get_rdbms_metadata(self, cursor)
Return data about the RDBMS: the product name, the version, etc.
source code
list
get_table_metadata(self, table, cursor)
Get the metadata for a table.
source code
list of tuples
get_index_metadata(self, table, cursor)
Get the metadata for the indexes for a table.
source code

Inherited from base.DBDriver: connect

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

Properties [hide private]

Inherited from base.DBDriver: display_name

Inherited from object: __class__

Method Details [hide private]

get_import(self)

source code 

Get a bound import for the underlying DB API module. All subclasses must provide an implementation of this method. Here's an example, assuming the real underlying Python DB API module is 'foosql':

def get_import(self):
    import foosql
    return foosql
Returns:
a bound module
Overrides: base.DBDriver.get_import
(inherited documentation)

get_display_name(self)

source code 
Get the driver's name, for display. The returned name ought to be a reasonable identifier for the database (e.g., 'SQL Server', 'MySQL'). All subclasses must provide an implementation of this method.
Returns: str
the driver's displayable name
Overrides: base.DBDriver.get_display_name
(inherited documentation)

do_connect(self, host='localhost', port=None, user='', password='', database='default')

source code 

Connect to the actual underlying database, using the driver. Subclasses must provide an implementation of this method. The method must return the result of the real DB API implementation's connect() method. For instance:

def do_connect():
    dbi = self.get_import()
    return dbi.connect(host=host, user=user, passwd=password,
                       database=database)

There is no need to catch exceptions; the DBDriver class's connect() method handles that.

Parameters:
  • host - the host where the database lives
  • port - the TCP port to use when connecting
  • user - the user to use when connecting
  • password - the password to use when connecting
  • database - the name of the database to which to connect
Returns: object
a DB API-compliant object representing the open database
Raises:
Overrides: base.DBDriver.do_connect
(inherited documentation)

get_tables(self, cursor)

source code 
Get the list of tables in the database.
Parameters:
  • cursor - a Cursor object from a recent query
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
Overrides: base.DBDriver.get_tables
(inherited documentation)

get_rdbms_metadata(self, cursor)

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

Parameters:
  • cursor - a Cursor object from a recent query
Returns: named tuple
the vendor information
Overrides: base.DBDriver.get_rdbms_metadata
(inherited documentation)

get_table_metadata(self, table, cursor)

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 default implementation uses the DB API's cursor.description field. Subclasses are free to override this method to produce their own version that uses other means.

Parameters:
  • table - the table name for which metadata is desired
  • cursor - a Cursor object from a recent query
Returns: list
list of tuples, as described above
Raises:
Overrides: base.DBDriver.get_table_metadata
(inherited documentation)

get_index_metadata(self, table, cursor)

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.

The default implementation of this method returns None

Parameters:
  • table - table name
  • cursor - a Cursor object from a recent query
Returns: list of tuples
the list of tuples, or None if not supported in the underlying database
Raises:
Overrides: base.DBDriver.get_index_metadata
(inherited documentation)