Package winappdbg :: Module sql :: Class BaseDAO
[hide private]
[frames] | no frames]

Class BaseDAO

source code


Data Access Object base class.

Nested Classes [hide private]
class _new_session
Custom configured Session class used to create the _session instance variable.
Instance Methods [hide private]
 
__init__(self, url, creator=None)
Connect to the database using the given connection URL.
source code
 
_transactional(self, method, *argv, **argd)
Begins a transaction and calls the given DAO method.
source code

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

Class Variables [hide private]
bool _echo = False
Set to True to print all SQL queries to standard output.
Instance Variables [hide private]
str _dialect
SQL dialect currently being used.
str _driver
Name of the database driver currently being used.
sqlalchemy.orm.Session _session
Database session object.
sqlalchemy.url.URL _url
Database connection URL.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, url, creator=None)
(Constructor)

source code 

Connect to the database using the given connection URL.

The current implementation uses SQLAlchemy and so it will support whatever database said module supports.

Parameters:
  • url (str) - URL that specifies the database to connect to.

    Some examples:

    • Opening an SQLite file: dao = CrashDAO("sqlite:///C:\some\path\database.sqlite")
    • Connecting to a locally installed SQL Express database: dao = CrashDAO("mssql://.\SQLEXPRESS/Crashes?trusted_connection=yes")
    • Connecting to a MySQL database running locally, using the oursql library, authenticating as the "winappdbg" user with no password: dao = CrashDAO("mysql+oursql://winappdbg@localhost/Crashes")
    • Connecting to a Postgres database running locally, authenticating with user and password: dao = CrashDAO("postgresql://winappdbg:winappdbg@localhost/Crashes")

    For more information see the SQLAlchemy documentation online: http://docs.sqlalchemy.org/en/latest/core/engines.html

    Note that in all dialects except for SQLite the database must already exist. The tables schema, however, is created automatically when connecting for the first time.

    To create the database in MSSQL, you can use the SQLCMD command:

       sqlcmd -Q "CREATE DATABASE Crashes"
    

    In MySQL you can use something like the following:

       mysql -u root -e "CREATE DATABASE Crashes;"
    

    And in Postgres:

       createdb Crashes -h localhost -U winappdbg -p winappdbg -O winappdbg
    

    Some small changes to the schema may be tolerated (for example, increasing the maximum length of string columns, or adding new columns with default values). Of course, it's best to test it first before making changes in a live database. This all depends very much on the SQLAlchemy version you're using, but it's best to use the latest version always.

  • creator (callable) - (Optional) Callback function that creates the SQL database connection.

    Normally it's not necessary to use this argument. However in some odd cases you may need to customize the database connection.

Overrides: object.__init__

_transactional(self, method, *argv, **argd)

source code 

Begins a transaction and calls the given DAO method.

If the method executes successfully the transaction is commited.

If the method fails, the transaction is rolled back.

Parameters:
  • method (callable) - Bound method of this class or one of its subclasses. The first argument will always be self.
Returns:
The return value of the method call.
Raises:
  • Exception - Any exception raised by the method.

Instance Variable Details [hide private]

_driver

Name of the database driver currently being used. To get the actual Python module use _url.get_driver() instead.
Type:
str