root/ORMs/SqlAlchemy/SQLAlchemy-0.5.6/lib/sqlalchemy/databases/rdbhost.py

User picture

Author: dkeeney

Revision: 74 («Previous)

(Jan 02 04:44 2010 UTC) About 2 years ago

comment fix

 
Show/hide line numbers
# rdbhost.py
# This module written by David Keeney
#    derived from postgres.py, by Michael Bayer
#
# This module is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php

"""Support for the Rdbhost.com service using PostgreSQL database.

Put this file in the sqlalchemy/databases directory wherever sqlalchemy is
installed on your system, probably under site-packages.

Before you can access an rdbhost.com database, you must go to the site (using a
web browser), and register for a free account. 

Driver
------

This supports the Rdbhost rdbhdb driver, for the Rdbhost database service.
Rdbhost uses the PostgreSQL engine, so that flavor of SQL is the appropriate
one.

Connecting
----------

URLs are of the form `rdbhost://rolename:authcode@host`

Example:
  rolename = 's0000000002'
  authcode = 'qTPJ2yT8V........................aUqV1Kxdty12Q'
  dsnurl = 'rdbhost://'+rolename+':'+authcode+'@www.rdbhost.com'
  engine = create_engine(dsnurl)

Keyword parameters 'server_side_cursors' and 'postgresql_returning' are
*not* supported.  Server side cursors are used on SELECTs whenever appropriate,
and the RETURNING constructs are prohibited.


"""

import sys
import decimal, random, re, string

# most functionality of this module is just imported from postgres.py
import sqlalchemy.databases.postgres
from sqlalchemy.databases.postgres import (
    PGInteger, PGSmallInteger, PGBigInteger, PGNumeric, PGFloat,
    PGDateTime, PGDate, PGTime, PGInterval,
    PGText, PGString, PGChar,
    PGBinary, PGBoolean, PGInet, PGCidr, PGMacAddr, PGBit, PGUuid,
    PGArray,
    colspecs, ischema_names,
    PGExecutionContext,
    #PGDialect,
    PGCompiler,
    PGSchemaGenerator,
    PGSchemaDropper,
    PGDefaultRunner,
    PGIdentifierPreparer )


class RDBDialect(sqlalchemy.databases.postgres.PGDialect):
    """Subclass PGDialect, to override url interpretation, and install rdbhdb as
      the dbapi.
    """
    name = 'rdbhost'
    #supports_alter = True
    #supports_unicode_statements = False
    #max_identifier_length = 63
    #supports_sane_rowcount = True
    #supports_sane_multi_rowcount = False
    #preexecute_pk_sequences = True
    #supports_pk_autoincrement = False
    #default_paramstyle = 'pyformat'
    #supports_default_values = True
    #supports_empty_insert = False

    def dbapi(cls):
        def rollback(self):
            #sei = sys.exec_info()
            #if (sei[0] is not None):
            #print >> sys.stderr, 'rollback() called (%s)'%sei[0]
            pass
        from rdbhdb import rdbhdb
        setattr(rdbhdb.Connection,'rollback',rollback)
        return rdbhdb
    dbapi = classmethod(dbapi)
    
    def create_connect_args(self, url):
        """Create *args and **kwargs for connect
        
        @returns [role,auth] as args, {host:...} as opts
        """
        # should return role, authcode
        opts = url.translate_connect_args(username='user')
        args = [opts.pop('user',None),opts.pop('password',None)]
        return (args, opts)
    


dialect = RDBDialect
dialect.statement_compiler = PGCompiler
dialect.schemagenerator = PGSchemaGenerator
dialect.schemadropper = PGSchemaDropper
dialect.preparer = PGIdentifierPreparer
dialect.defaultrunner = PGDefaultRunner
dialect.execution_ctx_cls = PGExecutionContext