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

Class DBConnect

source code

object --+
         |
        DBConnect

Database connection.

In addition to connecting to the database and providing cursors, this class will guess information such as the database type (mysql, postgresql, sqlite) and parameter style.

Instance Methods [hide private]
 
__init__(self, module, connect_info, log=None)
Construct and initialize database connection.
source code
 
_set_connection(self, connection)
Set the database connection.
source code
 
_get_connection(self) source code
 
connect(self, log=None)
Connect to the database.
source code
 
prepare_db_types(self)
Prepare type casting in database results.
source code
 
guess_db_info(self)
Guess database type and parameter style.
source code
 
cursor(self)
Fetch a cursor.
source code
 
close(self)
Close the connection.
source code

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

Properties [hide private]
  connection

Inherited from object: __class__

Method Details [hide private]

__init__(self, module, connect_info, log=None)
(Constructor)

source code 
Construct and initialize database connection.

Parameters:
    module          
        a DB API 2.0 compilent database module object
    connect_info    
        connect info for module.connect()
        * If the parameter is a string it will be passed directly
          to module.connect(connect_info).
        * If a tuple or a list, it will be passed as positional
          arguments as module.connect(*connect_info)
        * If a dictionary, it will be passed as keyword arguments as
          module.connect(**connect_info).

Overrides: object.__init__

_set_connection(self, connection)

source code 

Set the database connection. The connection is as returned by self.module.connect().

If the current database module is not threadsafe on connection level, each thread will require a separate connection. This property ensures this feature.

connect(self, log=None)

source code 

Connect to the database.

The connection object as returned by self.module.connect() is stored in self.connection. In addition, guess_db_info() is called after connecting.

prepare_db_types(self)

source code 

Prepare type casting in database results.

Currently this makes sure that booleans are returned as real True/False objects.

guess_db_info(self)

source code 

Guess database type and parameter style.

self.type is determined to "mysql", "postgresql" or "sqlite"

self.param is "?" or "%s" and denotes how query parameters to be expanded by cursor.execute(sql, params) is to be expressed in the sql.

cursor(self)

source code 

Fetch a cursor. Reconnect if needed.

close(self)

source code 

Close the connection. Any pending transactions will be rolled back.


Property Details [hide private]

connection

Get Method:
_get_connection(self)
Set Method:
_set_connection(self, connection) - Set the database connection.