Package install :: Package MoSTBioDat :: Package DataBase :: Package ForgetSQL2 :: Module forgetsql2 :: Class Database
[hide private]
[frames] | no frames]

Class Database

source code

object --+
         |
        Database
Known Subclasses:

Base class for objects that uses the database.

Provides class methods for executing and querying SQL against the database.

Note that the _db *class attribute* must have been set to a DBConnect instance before any of these methods can be used. Normally this is done by subclassing:

   class MyDatabase(Database):
       _db = DBConnect(db_module, connect_info)
Instance Methods [hide private]

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

Class Methods [hide private]
 
_execute(cls, sql, parameters={})
Execute SQL and return cursor
source code
 
_iter_cursor(cls, cursor)
Provide iterator of cursor results.
source code
 
_query(cls, sql, parameters={})
Execute SQL and yield dictionaries.
source code
 
_query_one(cls, sql, parameters={})
Execute SQL as with _query(), but return first row.
source code
Class Variables [hide private]
  _db = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_iter_cursor(cls, cursor)
Class Method

source code 

Provide iterator of cursor results.

If the cursor does provide an iterator, provide that. Otherwise, return a generator that yield rows by using repeted calls to fetchmany().

_query(cls, sql, parameters={})
Class Method

source code 

Execute SQL and yield dictionaries.

The optional parameters argument can be used for variable expansions as explained in PEP 249 .execute().

_query_one(cls, sql, parameters={})
Class Method

source code 

Execute SQL as with _query(), but return first row.

Return None if no rows were returned. If more than one row is returned, a warning is logged, and only the first row is returned.