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

Class DB

source code

object --+
         |
        DB
Known Subclasses:

The object returned by a call to DBDriver.connect(). db wraps the real database object returned by the underlying Python DB API module's connect() method.
Instance Methods [hide private]
 
__init__(self, db, driver)
Create a new DB object.
source code
 
paramstyle(self)
Get the parameter style for the underlying DB API module.
source code
object
Binary(self, string)
Returns an object representing the given string of bytes as a BLOB.
source code
 
Date(self, year, month, day)
Returns an object representing the specified date.
source code
 
DateFromTicks(self, secs)
Returns an object representing the date secs seconds after the epoch.
source code
 
Time(self, hour, minute, second)
Returns an object representing the specified time.
source code
 
TimeFromTicks(self, secs)
Returns an object representing the time 'secs' seconds after the epoch.
source code
 
Timestamp(self, year, month, day, hour, minute, second)
Returns an object representing the specified time.
source code
 
TimestampFromTicks(self, secs)
Returns an object representing the date and time secs seconds after the epoch.
source code
 
cursor(self)
Get a cursor suitable for accessing the database.
source code
 
commit(self)
Commit the current transaction.
source code
 
rollback(self)
Roll the current transaction back.
source code
 
close(self)
Close the database connection.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, db, driver)
(Constructor)

source code 
Create a new DB object.
Parameters:
  • db - the underlying Python DB API database object
  • driver (DBDriver) - the driver (i.e., the subclass of DBDriver) that created the db object
Overrides: object.__init__

paramstyle(self)

source code 

Get the parameter style for the underlying DB API module. The result of this method call corresponds exactly to the underlying DB API module's 'paramstyle' attribute. It will have one of the following values:

format

The parameter marker is '%s', as in string formatting. A query looks like this:

c.execute('SELECT * FROM Foo WHERE Bar=%s', [x])
named

The parameter marker is :name, and parameters are named. A query looks like this:

c.execute('SELECT * FROM Foo WHERE Bar=:x', {'x':x})
numeric

The parameter marker is :n, giving the parameter's number (starting at 1). A query looks like this:

c.execute('SELECT * FROM Foo WHERE Bar=:1', [x])
pyformat

The parameter marker is :name, and parameters are named. A query looks like this:

c.execute('SELECT * FROM Foo WHERE Bar=%(x)s', {'x':x})
qmark

The parameter marker is "?", and parameters are substituted in order. A query looks like this:

c.execute('SELECT * FROM Foo WHERE Bar=?', [x])

Binary(self, string)

source code 

Returns an object representing the given string of bytes as a BLOB.

This method is equivalent to the module-level Binary() method in an underlying DB API-compliant module.

Parameters:
  • string (str) - the string to convert to a BLOB
Returns: object
the corresponding BLOB

Date(self, year, month, day)

source code 

Returns an object representing the specified date.

This method is equivalent to the module-level Date() method in an underlying DB API-compliant module.

Parameters:
  • year - the year
  • month - the month
  • day - the day of the month
Returns:
an object containing the date

DateFromTicks(self, secs)

source code 

Returns an object representing the date secs seconds after the epoch. For example:

import time

d = db.DateFromTicks(time.time())

This method is equivalent to the module-level DateFromTicks() method in an underlying DB API-compliant module.

Parameters:
  • secs (int) - the seconds from the epoch
Returns:
an object containing the date

Time(self, hour, minute, second)

source code 

Returns an object representing the specified time.

This method is equivalent to the module-level Time() method in an underlying DB API-compliant module.

Parameters:
  • hour - the hour of the day
  • minute - the minute within the hour. 0 <= minute <= 59
  • second - the second within the minute. 0 <= second <= 59
Returns:
an object containing the time

TimeFromTicks(self, secs)

source code 

Returns an object representing the time 'secs' seconds after the epoch. For example:

import time

d = db.TimeFromTicks(time.time())

This method is equivalent to the module-level TimeFromTicks() method in an underlying DB API-compliant module.

Parameters:
  • secs (int) - the seconds from the epoch
Returns:
an object containing the time

Timestamp(self, year, month, day, hour, minute, second)

source code 

Returns an object representing the specified time.

This method is equivalent to the module-level Timestamp() method in an underlying DB API-compliant module.

Parameters:
  • year - the year
  • month - the month
  • day - the day of the month
  • hour - the hour of the day
  • minute - the minute within the hour. 0 <= minute <= 59
  • second - the second within the minute. 0 <= second <= 59
Returns:
an object containing the timestamp

TimestampFromTicks(self, secs)

source code 

Returns an object representing the date and time secs seconds after the epoch. For example:

import time

d = db.TimestampFromTicks(time.time())

This method is equivalent to the module-level TimestampFromTicks() method in an underlying DB API-compliant module.

Parameters:
  • secs (int) - the seconds from the epoch
Returns:
an object containing the timestamp

cursor(self)

source code 
Get a cursor suitable for accessing the database. The returned object conforms to the Python DB API cursor interface.
Returns:
the cursor
Raises:

commit(self)

source code 
Commit the current transaction.
Raises:

rollback(self)

source code 
Roll the current transaction back.
Raises:

close(self)

source code 
Close the database connection.
Raises: