Package grizzled :: Package db :: Module dbgadfly :: Class GadflyDriver
[hide private]
[frames] | no frames]

Class GadflyDriver

source code

   object --+    
            |    
base.DBDriver --+
                |
               GadflyDriver

DB Driver for Gadfly, a pure Python RDBMS
Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
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
db
connect(self, host=None, port=None, user='', password='', database='default')
Connect to the underlying database.
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
bool
_is_valid_table(self, cursor, table_name)
Determines whether a table name represents a legal table in the current database, throwing an Error if not.
source code

Inherited from base.DBDriver: do_connect

Inherited from base.DBDriver (private): _ensure_valid_table

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __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]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

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)

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

source code 
Connect to the underlying database. Subclasses should not override this method. Instead, a subclass should override the do_connect() method.
Parameters:
  • host - the host where the database lives
  • port - the TCP port to use when connecting, or None
  • user - the user to use when connecting, or None
  • password - the password to use when connecting, or None
  • database - the name of the database to which to connect
Returns: db
a db object representing the open database
Raises:
Overrides: base.DBDriver.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)

_is_valid_table(self, cursor, table_name)

source code 
Determines whether a table name represents a legal table in the current database, throwing an Error if not.
Parameters:
  • cursor - an open Cursor
  • table_name - the table name
Returns: bool
True if the table is valid, False if not
Overrides: base.DBDriver._is_valid_table
(inherited documentation)