summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/__init__.py4
-rw-r--r--lib/sqlalchemy/databases/postgres.py6
-rw-r--r--lib/sqlalchemy/databases/sqlite.py4
-rw-r--r--lib/sqlalchemy/engine.py6
-rw-r--r--lib/sqlalchemy/ext/proxy.py17
-rw-r--r--lib/sqlalchemy/schema.py13
6 files changed, 36 insertions, 14 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index d38a557f9..5efbf6652 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -11,3 +11,7 @@ from schema import *
from exceptions import *
import mapping as mapperlib
from mapping import *
+
+import sqlalchemy.schema
+import sqlalchemy.ext.proxy
+sqlalchemy.schema.default_engine = sqlalchemy.ext.proxy.ProxyEngine()
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 13714ba3e..92407637f 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -199,7 +199,7 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
self.opts['port'] = str(self.opts['port'])
ansisql.ANSISQLEngine.__init__(self, **params)
-
+
def connect_args(self):
return [[], self.opts]
@@ -277,7 +277,9 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
else:
ischema_names = pg1_ischema_names
- ischema.reflecttable(self, table, ischema_names)
+ # give ischema the given table's engine with which to look up
+ # other tables, not 'self', since it could be a ProxyEngine
+ ischema.reflecttable(table.engine, table, ischema_names)
class PGCompiler(ansisql.ANSICompiler):
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index bb46578a3..2e366e432 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -182,7 +182,9 @@ class SQLiteSQLEngine(ansisql.ANSISQLEngine):
break
(tablename, localcol, remotecol) = (row[2], row[3], row[4])
#print "row! " + repr(row)
- remotetable = Table(tablename, self, autoload = True)
+ # look up the table based on the given table's engine, not 'self',
+ # since it could be a ProxyEngine
+ remotetable = Table(tablename, table.engine, autoload = True)
table.c[localcol].append_item(schema.ForeignKey(remotetable.c[remotecol]))
# check for UNIQUE indexes
c = self.execute("PRAGMA index_list(" + table.name + ")", {})
diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py
index 612cec751..757d3517e 100644
--- a/lib/sqlalchemy/engine.py
+++ b/lib/sqlalchemy/engine.py
@@ -172,6 +172,7 @@ class SQLEngine(schema.SchemaEngine):
# get a handle on the connection pool via the connect arguments
# this insures the SQLEngine instance integrates with the pool referenced
# by direct usage of pool.manager(<module>).connect(*args, **params)
+ schema.SchemaEngine.__init__(self)
(cargs, cparams) = self.connect_args()
if pool is None:
params['echo'] = echo_pool
@@ -183,7 +184,6 @@ class SQLEngine(schema.SchemaEngine):
self.echo_uow = echo_uow
self.convert_unicode = convert_unicode
self.context = util.ThreadLocal(raiseerror=False)
- self.tables = {}
self._ischema = None
self._figure_paramstyle()
if logger is None:
@@ -204,6 +204,10 @@ class SQLEngine(schema.SchemaEngine):
def hash_key(self):
return "%s(%s)" % (self.__class__.__name__, repr(self.connect_args()))
+
+ def _get_name(self):
+ return sys.modules[self.__module__].descriptor()['name']
+ name = property(_get_name)
def dispose(self):
"""disposes of the underlying pool manager for this SQLEngine."""
diff --git a/lib/sqlalchemy/ext/proxy.py b/lib/sqlalchemy/ext/proxy.py
index 783ea969e..b8351d38f 100644
--- a/lib/sqlalchemy/ext/proxy.py
+++ b/lib/sqlalchemy/ext/proxy.py
@@ -6,16 +6,14 @@ except ImportError:
from sqlalchemy import sql
from sqlalchemy.engine import create_engine
from sqlalchemy.types import TypeEngine
-
+import sqlalchemy.schema as schema
import thread, weakref
-class BaseProxyEngine(object):
+class BaseProxyEngine(schema.SchemaEngine):
'''
Basis for all proxy engines
'''
- def __init__(self):
- self.tables = {}
-
+
def get_engine(self):
raise NotImplementedError
@@ -24,6 +22,9 @@ class BaseProxyEngine(object):
engine = property(get_engine, set_engine)
+ def reflecttable(self, table):
+ return self.get_engine().reflecttable(table)
+
def hash_key(self):
return "%s(%s)" % (self.__class__.__name__, id(self))
@@ -83,16 +84,20 @@ class ProxyEngine(BaseProxyEngine):
classes for TypeEngine.
"""
- def __init__(self):
+ def __init__(self, **kwargs):
BaseProxyEngine.__init__(self)
# create the local storage for uri->engine map and current engine
self.storage = local()
self.storage.connection = {}
self.storage.engine = None
+ self.kwargs = kwargs
def connect(self, uri, opts=None, **kwargs):
"""Establish connection to a real engine.
"""
+ kw = self.kwargs.copy()
+ kw.update(kwargs)
+ kwargs = kw
key = "%s(%s,%s)" % (uri, repr(opts), repr(kwargs))
try:
map = self.storage.connection
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 6152537dd..6d43d8e9d 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -45,8 +45,10 @@ def _get_table_key(engine, name, schema):
class TableSingleton(type):
"""a metaclass used by the Table object to provide singleton behavior."""
- def __call__(self, name, engine, *args, **kwargs):
+ def __call__(self, name, engine=None, *args, **kwargs):
try:
+ if engine is None:
+ engine = default_engine
name = str(name) # in case of incoming unicode
schema = kwargs.get('schema', None)
autoload = kwargs.pop('autoload', False)
@@ -146,7 +148,6 @@ class Table(sql.TableClause, SchemaItem):
metaclass constructor."""
self._clear()
- print "RELOAD VALUES", args
self._init_items(*args)
def append_item(self, item):
@@ -383,7 +384,7 @@ class ForeignKey(SchemaItem):
if isinstance(self._colspec, str):
return self._colspec
elif self._colspec.table.schema is not None:
- return "%s.%s.%s" % (self._colspec.table.schema, self._colspec.table.name, self._colspec.column.key)
+ return "%s.%s.%s" % (self._colspec.table.schema, self._colspec.table.name, self._colspec.key)
else:
return "%s.%s" % (self._colspec.table.name, self._colspec.key)
@@ -412,7 +413,6 @@ class ForeignKey(SchemaItem):
self._column = table.c[colname]
else:
self._column = self._colspec
-
return self._column
column = property(lambda s: s._init_column())
@@ -540,6 +540,11 @@ class Index(SchemaItem):
class SchemaEngine(object):
"""a factory object used to create implementations for schema objects. This object
is the ultimate base class for the engine.SQLEngine class."""
+
+ def __init__(self):
+ # a dictionary that stores Table objects keyed off their name (and possibly schema name)
+ self.tables = {}
+
def reflecttable(self, table):
"""given a table, will query the database and populate its Column and ForeignKey
objects."""