1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 |
# 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 |