[Sqlalchemy-commits] [1030] sqlalchemy/branches/sql_rearrangement/test: basic idea within sql packag
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-02-25 02:48:06
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1030] sqlalchemy/branches/sql_rearrangement/test: basic idea within sql package</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1030</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-02-24 20:47:53 -0600 (Fri, 24 Feb 2006)</dd> </dl> <h3>Log Message</h3> <pre>basic idea within sql package</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchessql_rearrangementlibsqlalchemy__init__py">sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/__init__.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementlibsqlalchemyansisqlpy">sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/ansisql.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementlibsqlalchemyenginepy">sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/engine.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementlibsqlalchemyschemapy">sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/schema.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementlibsqlalchemysqlpy">sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/sql.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementtestselectpy">sqlalchemy/branches/sql_rearrangement/test/select.py</a></li> <li><a href="#sqlalchemybranchessql_rearrangementtesttestbasepy">sqlalchemy/branches/sql_rearrangement/test/testbase.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchessql_rearrangementlibsqlalchemy__init__py"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/__init__.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/__init__.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/__init__.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -6,8 +6,8 @@ </span><span class="cx"> </span><span class="cx"> from engine import * </span><span class="cx"> from types import * </span><ins>+from sql import * </ins><span class="cx"> from schema import * </span><span class="cx"> from exceptions import * </span><del>-from sql import * </del><span class="cx"> import mapping as mapperlib </span><span class="cx"> from mapping import * </span></span></pre></div> <a id="sqlalchemybranchessql_rearrangementlibsqlalchemyansisqlpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/ansisql.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/ansisql.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/ansisql.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -257,11 +257,11 @@ </span><span class="cx"> l = co.label(co._label) </span><span class="cx"> l.accept_visitor(self) </span><span class="cx"> inner_columns[co._label] = l </span><del>- elif select.issubquery and isinstance(co, Column): </del><ins>+ elif select.issubquery and isinstance(co, sql.ColumnClause) and co.table is not None: </ins><span class="cx"> # SQLite doesnt like selecting from a subquery where the column </span><span class="cx"> # names look like table.colname, so add a label synonomous with </span><span class="cx"> # the column name </span><del>- l = co.label(co.key) </del><ins>+ l = co.label(co.text) </ins><span class="cx"> l.accept_visitor(self) </span><span class="cx"> inner_columns[self.get_str(l.obj)] = l </span><span class="cx"> else: </span><span class="lines">@@ -355,6 +355,10 @@ </span><span class="cx"> def visit_table(self, table): </span><span class="cx"> self.froms[table] = table.fullname </span><span class="cx"> self.strings[table] = "" </span><ins>+ + def visit_tableclause(self, table): + self.froms[table] = table.name + self.strings[table] = "" </ins><span class="cx"> </span><span class="cx"> def visit_join(self, join): </span><span class="cx"> # TODO: ppl are going to want RIGHT, FULL OUTER and NATURAL joins. </span></span></pre></div> <a id="sqlalchemybranchessql_rearrangementlibsqlalchemyenginepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/engine.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/engine.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/engine.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -16,8 +16,7 @@ </span><span class="cx"> of DBAPI, and is the central switching point for abstracting different kinds of database </span><span class="cx"> behavior into a consistent set of behaviors. It provides a variety of factory methods </span><span class="cx"> to produce everything specific to a certain kind of database, including a Compiler, </span><del>-schema creation/dropping objects, and TableImpl and ColumnImpl objects to augment the -behavior of table metadata objects. </del><ins>+schema creation/dropping objects. </ins><span class="cx"> </span><span class="cx"> The term "database-specific" will be used to describe any object or function that has behavior </span><span class="cx"> corresponding to a particular vendor, such as mysql-specific, sqlite-specific, etc. </span><span class="lines">@@ -315,28 +314,6 @@ </span><span class="cx"> """given a Table object, reflects its columns and properties from the database.""" </span><span class="cx"> raise NotImplementedError() </span><span class="cx"> </span><del>- def tableimpl(self, table, **kwargs): - """returns a new sql.TableImpl object to correspond to the given Table object. - A TableImpl provides SQL statement builder operations on a Table metadata object, - and a subclass of this object may be provided by a SQLEngine subclass to provide - database-specific behavior.""" - return sql.TableImpl(table) - - def columnimpl(self, column): - """returns a new sql.ColumnImpl object to correspond to the given Column object. - A ColumnImpl provides SQL statement builder operations on a Column metadata object, - and a subclass of this object may be provided by a SQLEngine subclass to provide - database-specific behavior.""" - return sql.ColumnImpl(column) - - def indeximpl(self, index): - """returns a new sql.IndexImpl object to correspond to the given Index - object. An IndexImpl provides SQL statement builder operations on an - Index metadata object, and a subclass of this object may be provided - by a SQLEngine subclass to provide database-specific behavior. - """ - return sql.IndexImpl(index) - </del><span class="cx"> def get_default_schema_name(self): </span><span class="cx"> """returns the currently selected schema in the current connection.""" </span><span class="cx"> return None </span></span></pre></div> <a id="sqlalchemybranchessql_rearrangementlibsqlalchemyschemapy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/schema.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/schema.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/schema.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -14,7 +14,7 @@ </span><span class="cx"> the schema package "plugs in" to the SQL package. </span><span class="cx"> </span><span class="cx"> """ </span><del>- </del><ins>+import sql </ins><span class="cx"> from util import * </span><span class="cx"> from types import * </span><span class="cx"> from exceptions import * </span><span class="lines">@@ -29,30 +29,15 @@ </span><span class="cx"> for item in args: </span><span class="cx"> if item is not None: </span><span class="cx"> item._set_parent(self) </span><del>- - def accept_visitor(self, visitor): - """all schema items implement an accept_visitor method that should call the appropriate - visit_XXXX method upon the given visitor object.""" - raise NotImplementedError() - </del><span class="cx"> def _set_parent(self, parent): </span><span class="cx"> """a child item attaches itself to its parent via this method.""" </span><span class="cx"> raise NotImplementedError() </span><del>- </del><span class="cx"> def hash_key(self): </span><span class="cx"> """returns a string that identifies this SchemaItem uniquely""" </span><span class="cx"> return "%s(%d)" % (self.__class__.__name__, id(self)) </span><del>- </del><span class="cx"> def __repr__(self): </span><span class="cx"> return "%s()" % self.__class__.__name__ </span><span class="cx"> </span><del>- def __getattr__(self, key): - """proxies method calls to an underlying implementation object for methods not found - locally""" - if not self.__dict__.has_key('_impl'): - raise AttributeError(key) - return getattr(self._impl, key) - </del><span class="cx"> def _get_table_key(engine, name, schema): </span><span class="cx"> if schema is not None and schema == engine.get_default_schema_name(): </span><span class="cx"> schema = None </span><span class="lines">@@ -95,7 +80,7 @@ </span><span class="cx"> return table </span><span class="cx"> </span><span class="cx"> </span><del>-class Table(SchemaItem): </del><ins>+class Table(sql.TableClause, SchemaItem): </ins><span class="cx"> """represents a relational database table. </span><span class="cx"> </span><span class="cx"> Be sure to look at sqlalchemy.sql.TableImpl for additional methods defined on a Table.""" </span><span class="lines">@@ -134,14 +119,11 @@ </span><span class="cx"> the same table twice will result in an exception. </span><span class="cx"> </span><span class="cx"> """ </span><del>- self.name = name - self.columns = OrderedProperties() - self.c = self.columns - self.foreign_keys = [] - self.primary_key = [] </del><ins>+ super(Table, self).__init__(name) + self._foreign_keys = [] + self._primary_key = [] </ins><span class="cx"> self.engine = engine </span><span class="cx"> self.schema = kwargs.pop('schema', None) </span><del>- self._impl = self.engine.tableimpl(self, **kwargs) </del><span class="cx"> if self.schema is not None: </span><span class="cx"> self.fullname = "%s.%s" % (self.schema, self.name) </span><span class="cx"> else: </span><span class="lines">@@ -174,30 +156,38 @@ </span><span class="cx"> self.c = self.columns </span><span class="cx"> self.foreign_keys = [] </span><span class="cx"> self.primary_key = [] </span><del>- self._impl = self.engine.tableimpl(self) </del><span class="cx"> self._init_items(*args) </span><span class="cx"> </span><span class="cx"> def append_item(self, item): </span><span class="cx"> """appends a Column item or other schema item to this Table.""" </span><span class="cx"> self._init_items(item) </span><del>- </del><ins>+ + def append_column(self, column): + if not column.hidden: + self._columns[column.key] = self + if column.primary_key: + self.primary_key.append(column) + column.table = self + column.type = self.engine.type_descriptor(column.type) + </ins><span class="cx"> def _set_parent(self, schema): </span><span class="cx"> schema.tables[self.name] = self </span><span class="cx"> self.schema = schema </span><del>- </del><span class="cx"> def accept_visitor(self, visitor): </span><span class="cx"> """traverses the given visitor across the Column objects inside this Table, </span><span class="cx"> then calls the visit_table method on the visitor.""" </span><span class="cx"> for c in self.columns: </span><span class="cx"> c.accept_visitor(visitor) </span><span class="cx"> return visitor.visit_table(self) </span><del>- </del><span class="cx"> def deregister(self): </span><span class="cx"> """removes this table from it's engines table registry. this does not </span><span class="cx"> issue a SQL DROP statement.""" </span><span class="cx"> key = _get_table_key(self.engine, self.name, self.schema) </span><span class="cx"> del self.engine.tables[key] </span><del>- </del><ins>+ def create(self, **params): + self.engine.create(self) + def drop(self, **params): + self.engine.drop(self) </ins><span class="cx"> def toengine(self, engine, schema=None): </span><span class="cx"> """returns a singleton instance of this Table with a different engine""" </span><span class="cx"> try: </span><span class="lines">@@ -211,7 +201,7 @@ </span><span class="cx"> args.append(c.copy()) </span><span class="cx"> return Table(self.name, engine, schema=schema, *args) </span><span class="cx"> </span><del>-class Column(SchemaItem): </del><ins>+class Column(sql.ColumnClause, SchemaItem): </ins><span class="cx"> """represents a column in a database table.""" </span><span class="cx"> def __init__(self, name, type, *args, **kwargs): </span><span class="cx"> """constructs a new Column object. Arguments are: </span><span class="lines">@@ -244,8 +234,8 @@ </span><span class="cx"> hidden=False : indicates this column should not be listed in the table's list of columns. Used for the "oid" </span><span class="cx"> column, which generally isnt in column lists. </span><span class="cx"> """ </span><del>- self.name = str(name) # in case of incoming unicode - self.type = type </del><ins>+ name = str(name) # in case of incoming unicode + super(Column, self).__init__(name, None) </ins><span class="cx"> self.args = args </span><span class="cx"> self.key = kwargs.pop('key', name) </span><span class="cx"> self.primary_key = kwargs.pop('primary_key', False) </span><span class="lines">@@ -257,10 +247,20 @@ </span><span class="cx"> self._parent = None </span><span class="cx"> if len(kwargs): </span><span class="cx"> raise ArgumentError("Unknown arguments passed to Column: " + repr(kwargs.keys())) </span><ins>+ + if self.default is not None: + self.default = ColumnDefault(self.default) + self.default._set_parent(self) + + self._init_items(*self.args) </ins><span class="cx"> </span><span class="cx"> original = property(lambda s: s._orig or s) </span><span class="cx"> parent = property(lambda s:s._parent or s) </span><span class="cx"> engine = property(lambda s: s.table.engine) </span><ins>+ columns = property(lambda self:[self.column]) + + def _get_from_objects(self): + return [self.table] </ins><span class="cx"> </span><span class="cx"> def __repr__(self): </span><span class="cx"> return "Column(%s)" % string.join( </span><span class="lines">@@ -282,16 +282,7 @@ </span><span class="cx"> def _set_parent(self, table): </span><span class="cx"> if getattr(self, 'table', None) is not None: </span><span class="cx"> raise ArgumentError("this Column already has a table!") </span><del>- if not self.hidden: - table.columns[self.key] = self - if self.primary_key: - table.primary_key.append(self) - self.table = table - if self.table.engine is not None: - self.type = self.table.engine.type_descriptor(self.type) - - self._impl = self.table.engine.columnimpl(self) - </del><ins>+ table.append_column(self) </ins><span class="cx"> if self.default is not None: </span><span class="cx"> self.default = ColumnDefault(self.default) </span><span class="cx"> self._init_items(self.default) </span><span class="lines">@@ -320,7 +311,6 @@ </span><span class="cx"> selectable.columns[c.key] = c </span><span class="cx"> if self.primary_key: </span><span class="cx"> selectable.primary_key.append(c) </span><del>- c._impl = self.engine.columnimpl(c) </del><span class="cx"> if fk is not None: </span><span class="cx"> c._init_items(fk) </span><span class="cx"> return c </span><span class="lines">@@ -334,21 +324,6 @@ </span><span class="cx"> self.foreign_key.accept_visitor(visitor) </span><span class="cx"> visitor.visit_column(self) </span><span class="cx"> </span><del>- def __lt__(self, other): return self._impl.__lt__(other) - def __le__(self, other): return self._impl.__le__(other) - def __eq__(self, other): return self._impl.__eq__(other) - def __ne__(self, other): return self._impl.__ne__(other) - def __gt__(self, other): return self._impl.__gt__(other) - def __ge__(self, other): return self._impl.__ge__(other) - def __add__(self, other): return self._impl.__add__(other) - def __sub__(self, other): return self._impl.__sub__(other) - def __mul__(self, other): return self._impl.__mul__(other) - def __and__(self, other): return self._impl.__and__(other) - def __or__(self, other): return self._impl.__or__(other) - def __div__(self, other): return self._impl.__div__(other) - def __truediv__(self, other): return self._impl.__truediv__(other) - def __invert__(self, other): return self._impl.__invert__(other) - def __str__(self): return self._impl.__str__() </del><span class="cx"> </span><span class="cx"> class ForeignKey(SchemaItem): </span><span class="cx"> """defines a ForeignKey constraint between two columns. ForeignKey is </span><span class="lines">@@ -499,9 +474,12 @@ </span><span class="cx"> "%s is from %s not %s" % (column, </span><span class="cx"> column.table, </span><span class="cx"> self.table)) </span><del>- # set my _impl from col.table.engine - self._impl = self.table.engine.indeximpl(self) - </del><ins>+ def create(self): + self._engine.create(self.index) + def drop(self): + self._engine.drop(self.index) + def execute(self): + self.create() </ins><span class="cx"> def accept_visitor(self, visitor): </span><span class="cx"> visitor.visit_index(self) </span><span class="cx"> def __str__(self): </span></span></pre></div> <a id="sqlalchemybranchessql_rearrangementlibsqlalchemysqlpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/sql.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/sql.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/lib/sqlalchemy/sql.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -13,7 +13,7 @@ </span><span class="cx"> import string, re, random </span><span class="cx"> types = __import__('types') </span><span class="cx"> </span><del>-__all__ = ['text', 'column', 'func', 'select', 'update', 'insert', 'delete', 'join', 'and_', 'or_', 'not_', 'union', 'union_all', 'desc', 'asc', 'outerjoin', 'alias', 'subquery', 'literal', 'bindparam', 'exists'] </del><ins>+__all__ = ['text', 'table', 'column', 'func', 'select', 'update', 'insert', 'delete', 'join', 'and_', 'or_', 'not_', 'union', 'union_all', 'desc', 'asc', 'outerjoin', 'alias', 'subquery', 'literal', 'bindparam', 'exists'] </ins><span class="cx"> </span><span class="cx"> def desc(column): </span><span class="cx"> """returns a descending ORDER BY clause element, e.g.: </span><span class="lines">@@ -160,11 +160,13 @@ </span><span class="cx"> """returns a Label object for the given selectable, used in the column list for a select statement.""" </span><span class="cx"> return Label(name, obj) </span><span class="cx"> </span><del>-def column(table, text): </del><ins>+def column(text, table=None): </ins><span class="cx"> """returns a textual column clause, relative to a table. this differs from using straight text </span><del>- or text() in that the column is treated like a regular column, i.e. gets added to a Selectable's list - of columns.""" </del><ins>+ or text() in that the column is treated like a regular column, i.e. gets added to a Selectable's list of columns.""" </ins><span class="cx"> return ColumnClause(text, table) </span><ins>+ +def table(name, *columns): + return TableClause(name, *columns) </ins><span class="cx"> </span><span class="cx"> def bindparam(key, value = None, type=None): </span><span class="cx"> """creates a bind parameter clause with the given key. </span><span class="lines">@@ -222,15 +224,16 @@ </span><span class="cx"> return CompoundSelect(keyword, *selects, **kwargs) </span><span class="cx"> </span><span class="cx"> def _is_literal(element): </span><del>- return not isinstance(element, ClauseElement) and not isinstance(element, schema.SchemaItem) </del><ins>+ return not isinstance(element, ClauseElement) </ins><span class="cx"> </span><span class="cx"> def is_column(col): </span><del>- return isinstance(col, schema.Column) or isinstance(col, ColumnElement) </del><ins>+ return isinstance(col, ColumnElement) </ins><span class="cx"> </span><del>-class ClauseVisitor(schema.SchemaVisitor): </del><ins>+class ClauseVisitor(object): </ins><span class="cx"> """builds upon SchemaVisitor to define the visiting of SQL statement elements in </span><span class="cx"> addition to Schema elements.""" </span><span class="cx"> def visit_columnclause(self, column):pass </span><ins>+ def visit_tableclause(self, column):pass </ins><span class="cx"> def visit_fromclause(self, fromclause):pass </span><span class="cx"> def visit_bindparam(self, bindparam):pass </span><span class="cx"> def visit_textclause(self, textclause):pass </span><span class="lines">@@ -363,6 +366,8 @@ </span><span class="cx"> except AttributeError: </span><span class="cx"> pass </span><span class="cx"> for f in self._get_from_objects(): </span><ins>+ if f is self: + continue </ins><span class="cx"> engine = f.engine </span><span class="cx"> if engine is not None: </span><span class="cx"> return engine </span><span class="lines">@@ -980,17 +985,23 @@ </span><span class="cx"> return "Label(%s, %s)" % (self.name, self.obj.hash_key()) </span><span class="cx"> </span><span class="cx"> class ColumnClause(ColumnElement): </span><del>- """represents a textual column clause in a SQL statement. allows the creation - of an additional ad-hoc column that is compiled against a particular table.""" </del><ins>+ """represents a textual column clause in a SQL statement. ColumnClause operates + in two modes, one where its just any text that will be placed into the select statement, + and "column" mode, where it represents a column attached to a table.""" </ins><span class="cx"> </span><span class="cx"> def __init__(self, text, selectable=None): </span><span class="cx"> self.text = text </span><span class="cx"> self.table = selectable </span><span class="cx"> self.type = sqltypes.NullTypeEngine() </span><del>- </del><ins>+ def _get_label(self): + if self.table is not None: + return self.table.name + "_" + self.text + else: + return self.text </ins><span class="cx"> name = property(lambda self:self.text) </span><span class="cx"> key = property(lambda self:self.text) </span><del>- _label = property(lambda self:self.text) </del><ins>+ _label = property(_get_label) + default_label = property(lambda s:s._label) </ins><span class="cx"> </span><span class="cx"> def accept_visitor(self, visitor): </span><span class="cx"> visitor.visit_columnclause(self) </span><span class="lines">@@ -1014,78 +1025,26 @@ </span><span class="cx"> selectable.columns[c.key] = c </span><span class="cx"> return c </span><span class="cx"> </span><del>-class ColumnImpl(ColumnElement): - """gets attached to a schema.Column object.""" - - def __init__(self, column): - self.column = column - self.name = column.name - - if column.table.name: - self._label = column.table.name + "_" + self.column.name - else: - self._label = self.column.name </del><ins>+class TableClause(FromClause): + def __init__(self, name, *columns): + super(TableClause, self).__init__(name) + self.name = self.id = name + self._columns = util.OrderedProperties() + for c in columns: + self.append_column(c) </ins><span class="cx"> </span><del>- engine = property(lambda s: s.column.engine) - default_label = property(lambda s:s._label) - original = property(lambda self:self.column.original) - parent = property(lambda self:self.column.parent) - columns = property(lambda self:[self.column]) - - def label(self, name): - return Label(name, self.column) - - def copy_container(self): - return self.column - - def compare(self, other): - """compares this ColumnImpl's column to the other given Column""" - return self.column is other - - def _group_parenthesized(self): - return False - - def _get_from_objects(self): - return [self.column.table] - - def _bind_param(self, obj): - if self.column.table.name is None: - return BindParamClause(self.name, obj, shortname = self.name, type = self.column.type) - else: - return BindParamClause(self.column.table.name + "_" + self.name, obj, shortname = self.name, type = self.column.type) - def _compare_self(self): - """allows ColumnImpl to return its Column object for usage in ClauseElements, all others to - just return self""" - return self.column - def _compare_type(self, obj): - return self.column.type - - def compile(self, engine = None, parameters = None, typemap=None): - if engine is None: - engine = self.engine - if engine is None: - raise InvalidRequestError("no SQLEngine could be located within this ClauseElement.") - return engine.compile(self.column, parameters=parameters, typemap=typemap) - -class TableImpl(FromClause): - """attached to a schema.Table to provide it with a Selectable interface - as well as other functions - """ - - def __init__(self, table): - self.table = table - self.id = self.table.name - </del><ins>+ def append_column(self, c): + self._columns[c.text] = c + c.table = self </ins><span class="cx"> def _oid_col(self): </span><span class="cx"> # OID remains a little hackish so far </span><span class="cx"> if not hasattr(self, '_oid_column'): </span><del>- if self.table.engine.oid_column_name() is not None: </del><ins>+ if self.engine.oid_column_name() is not None: </ins><span class="cx"> self._oid_column = schema.Column(self.table.engine.oid_column_name(), sqltypes.Integer, hidden=True) </span><span class="cx"> self._oid_column._set_parent(self.table) </span><span class="cx"> else: </span><span class="cx"> self._oid_column = None </span><span class="cx"> return self._oid_column </span><del>- </del><span class="cx"> def _orig_columns(self): </span><span class="cx"> try: </span><span class="cx"> return self._orig_cols </span><span class="lines">@@ -1097,47 +1056,40 @@ </span><span class="cx"> if oid is not None: </span><span class="cx"> self._orig_cols[oid.original] = oid </span><span class="cx"> return self._orig_cols </span><del>- - oid_column = property(_oid_col) - engine = property(lambda s: s.table.engine) - columns = property(lambda self: self.table.columns) - primary_key = property(lambda self:self.table.primary_key) - foreign_keys = property(lambda self:self.table.foreign_keys) </del><ins>+ columns = property(lambda s:s._columns) + c = property(lambda s:s._columns) + primary_key = property(lambda s:s._primary_key) + foreign_keys = property(lambda s:s._foreign_keys) </ins><span class="cx"> original_columns = property(_orig_columns) </span><ins>+ </ins><span class="cx"> </span><span class="cx"> def _exportable_columns(self): </span><span class="cx"> raise NotImplementedError() </span><del>- </del><span class="cx"> def _group_parenthesized(self): </span><span class="cx"> return False </span><del>- </del><span class="cx"> def _process_from_dict(self, data, asfrom): </span><span class="cx"> for f in self._get_from_objects(): </span><span class="cx"> data.setdefault(f.id, f) </span><span class="cx"> if asfrom: </span><span class="cx"> data[self.id] = self.table </span><span class="cx"> def count(self, whereclause=None, **params): </span><del>- return select([func.count(1).label('count')], whereclause, from_obj=[self.table], **params) </del><ins>+ return select([func.count(1).label('count')], whereclause, from_obj=[self], **params) </ins><span class="cx"> def join(self, right, *args, **kwargs): </span><del>- return Join(self.table, right, *args, **kwargs) </del><ins>+ return Join(self, right, *args, **kwargs) </ins><span class="cx"> def outerjoin(self, right, *args, **kwargs): </span><del>- return Join(self.table, right, isouter = True, *args, **kwargs) </del><ins>+ return Join(self, right, isouter = True, *args, **kwargs) </ins><span class="cx"> def alias(self, name=None): </span><del>- return Alias(self.table, name) </del><ins>+ return Alias(self, name) </ins><span class="cx"> def select(self, whereclause = None, **params): </span><del>- return select([self.table], whereclause, **params) </del><ins>+ return select([self], whereclause, **params) </ins><span class="cx"> def insert(self, values = None): </span><del>- return insert(self.table, values=values) </del><ins>+ return insert(self, values=values) </ins><span class="cx"> def update(self, whereclause = None, values = None): </span><del>- return update(self.table, whereclause, values) </del><ins>+ return update(self, whereclause, values) </ins><span class="cx"> def delete(self, whereclause = None): </span><del>- return delete(self.table, whereclause) - def create(self, **params): - self.table.engine.create(self.table) - def drop(self, **params): - self.table.engine.drop(self.table) </del><ins>+ return delete(self, whereclause) </ins><span class="cx"> def _get_from_objects(self): </span><del>- return [self.table] </del><ins>+ return [self] </ins><span class="cx"> </span><span class="cx"> class SelectBaseMixin(object): </span><span class="cx"> """base class for Select and CompoundSelects""" </span><span class="lines">@@ -1457,25 +1409,3 @@ </span><span class="cx"> self.whereclause.accept_visitor(visitor) </span><span class="cx"> visitor.visit_delete(self) </span><span class="cx"> </span><del>-class IndexImpl(ClauseElement): - - def __init__(self, index): - self.index = index - self.name = index.name - self._engine = self.index.table.engine - - table = property(lambda s: s.index.table) - columns = property(lambda s: s.index.columns) - - def hash_key(self): - return self.index.hash_key() - def accept_visitor(self, visitor): - visitor.visit_index(self.index) - def compare(self, other): - return self.index is other - def create(self): - self._engine.create(self.index) - def drop(self): - self._engine.drop(self.index) - def execute(self): - self.create() </del></span></pre></div> <a id="sqlalchemybranchessql_rearrangementtestselectpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/sql_rearrangement/test/select.py (1029 => 1030)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/sql_rearrangement/test/select.py 2006-02-25 01:12:33 UTC (rev 1029) +++ sqlalchemy/branches/sql_rearrangement/test/select.py 2006-02-25 02:47:53 UTC (rev 1030) </span><span class="lines">@@ -1,60 +1,61 @@ </span><span class="cx"> </span><span class="cx"> from sqlalchemy import * </span><span class="cx"> import sqlalchemy.ansisql as ansisql </span><del>-import sqlalchemy.databases.postgres as postgres -import sqlalchemy.databases.oracle as oracle -import sqlalchemy.databases.sqlite as sqlite </del><ins>+#import sqlalchemy.databases.postgres as postgres +#import sqlalchemy.databases.oracle as oracle +#import sqlalchemy.databases.sqlite as sqlite </ins><span class="cx"> </span><span class="cx"> db = ansisql.engine() </span><span class="cx"> </span><span class="cx"> from testbase import PersistTest </span><span class="cx"> import unittest, re </span><span class="cx"> </span><del>- -table = Table('mytable', db, - Column('myid', Integer, key = 'id'), - Column('name', String, key = 'name'), - Column('description', String, key = 'description'), </del><ins>+table1 = table('mytable', + column('myid'), + column('name'), + column('description'), </ins><span class="cx"> ) </span><span class="cx"> </span><del>-table2 = Table( - 'myothertable', db, - Column('otherid', Integer, key='id'), - Column('othername', String, key='name'), </del><ins>+table2 = table( + 'myothertable', + column('otherid'), + column('othername'), </ins><span class="cx"> ) </span><span class="cx"> </span><del>-table3 = Table( - 'thirdtable', db, - Column('userid', Integer, key='id'), - Column('otherstuff', Integer), </del><ins>+table3 = table( + 'thirdtable', + column('userid'), + column('otherstuff'), </ins><span class="cx"> ) </span><span class="cx"> </span><del>-table4 = Table( - 'remotetable', db, - Column('rem_id', Integer, primary_key=True), - Column('datatype_id', Integer), - Column('value', String(20)), - schema = 'remote_owner' </del><ins>+table4 = table( + 'remotetable', + column('rem_id'), + column('datatype_id'), + column('value'), +# schema = 'remote_owner' </ins><span class="cx"> ) </span><span class="cx"> </span><del>-users = Table('users', db, - Column('user_id', Integer, primary_key = True), - Column('user_name', String(40)), - Column('password', String(10)), </del><ins>+users = table('users', + column('user_id'), + column('user_name'), + column('password'), </ins><span class="cx"> ) </span><span class="cx"> </span><del>-addresses = Table('addresses', db, - Column('address_id', Integer, primary_key = True), - Column('user_id', Integer, ForeignKey("users.user_id")), - Column('street', String(100)), - Column('city', String(80)), - Column('state', String(2)), - Column('zip', String(10)) </del><ins>+addresses = table('addresses', + column('address_id'), + column('user_id'), + column('street'), + column('city'), + column('state'), + column('zip') </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> class SQLTest(PersistTest): </span><span class="cx"> def runtest(self, clause, result, engine = None, params = None, checkparams = None): </span><ins>+ if engine is None: + engine = db </ins><span class="cx"> c = clause.compile(engine, params) </span><span class="cx"> self.echo("\nSQL String:\n" + str(c) + repr(c.get_params())) </span><span class="cx"> self.echo("\nHash Key:\n" + clause.hash_key()) </span><span class="lines">@@ -67,12 +68,10 @@ </span><span class="cx"> self.assert_(c.get_params() == checkparams, "params dont match") </span><span class="cx"> </span><span class="cx"> class SelectTest(SQLTest): </span><del>- - </del><span class="cx"> def testtableselect(self): </span><del>- self.runtest(table.select(), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable") </del><ins>+ self.runtest(table1.select(), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable") </ins><span class="cx"> </span><del>- self.runtest(select([table, table2]), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, \ </del><ins>+ self.runtest(select([table1, table2]), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, \ </ins><span class="cx"> myothertable.othername FROM mytable, myothertable") </span><span class="cx"> </span><span class="cx"> def testsubquery(self): </span><span class="lines">@@ -83,37 +82,37 @@ </span><span class="cx"> # """""" </span><span class="cx"> #) </span><span class="cx"> </span><del>- s = select([table], table.c.name == 'jack') </del><ins>+ s = select([table1], table1.c.name == 'jack') </ins><span class="cx"> print [key for key in s.c.keys()] </span><span class="cx"> self.runtest( </span><span class="cx"> select( </span><span class="cx"> [s], </span><del>- s.c.id == 7 </del><ins>+ s.c.myid == 7 </ins><span class="cx"> ) </span><span class="cx"> , </span><del>- "SELECT id, name, description FROM (SELECT mytable.myid AS id, mytable.name AS name, mytable.description AS description FROM mytable WHERE mytable.name = :mytable_name) WHERE id = :id") </del><ins>+ "SELECT myid, name, description FROM (SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable WHERE mytable.name = :mytable_name) WHERE myid = :myid") </ins><span class="cx"> </span><del>- sq = select([table]) </del><ins>+ sq = select([table1]) </ins><span class="cx"> self.runtest( </span><span class="cx"> sq.select(), </span><del>- "SELECT id, name, description FROM (SELECT mytable.myid AS id, mytable.name AS name, mytable.description AS description FROM mytable)" </del><ins>+ "SELECT myid, name, description FROM (SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable)" </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> sq = subquery( </span><span class="cx"> 'sq', </span><del>- [table], </del><ins>+ [table1], </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> self.runtest( </span><del>- sq.select(sq.c.id == 7), - "SELECT sq.id, sq.name, sq.description FROM \ -(SELECT mytable.myid AS id, mytable.name AS name, mytable.description AS description FROM mytable) AS sq WHERE sq.id = :sq_id" </del><ins>+ sq.select(sq.c.myid == 7), + "SELECT sq.myid, sq.name, sq.description FROM \ +(SELECT mytable.myid AS myid, mytable.name AS name, mytable.description AS description FROM mytable) AS sq WHERE sq.myid = :sq_myid" </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> sq = subquery( </span><span class="cx"> 'sq', </span><del>- [table, table2], - and_(table.c.id ==7, table2.c.id==table.c.id), </del><ins>+ [table1, table2], + and_(table1.c.myid ==7, table2.c.otherid==table1.c.myid), </ins><span class="cx"> use_labels = True </span><span class="cx"> ) </span><span class="cx"> </span><span class="lines">@@ -140,14 +139,14 @@ </span><span class="cx"> </span><span class="cx"> def testand(self): </span><span class="cx"> self.runtest( </span><del>- select(['*'], and_(table.c.id == 12, table.c.name=='asdf', table2.c.name == 'foo', "sysdate() = today()")), </del><ins>+ select(['*'], and_(table1.c.id == 12, table1.c.name=='asdf', table2.c.name == 'foo', "sysdate() = today()")), </ins><span class="cx"> "SELECT * FROM mytable, myothertable WHERE mytable.myid = :mytable_myid AND mytable.name = :mytable_name AND myothertable.othername = :myothertable_othername AND sysdate() = today()" </span><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> def testor(self): </span><span class="cx"> self.runtest( </span><span class="cx"> select([table], and_( </span><del>- table.c.id == 12, </del><ins>+ table1.c.id == 12, </ins><span class="cx"> or_(table2.c.name=='asdf', table2.c.name == 'foo', table2.c.id == 9), </span><span class="cx"> "sysdate() = today()", </span><span class="cx"> )), </span><span class="lines">@@ -157,7 +156,7 @@ </span><span class="cx"> </span><span class="cx"> def testoperators(self): </span><span class="cx"> self.runtest( </span><del>- table.select((table.c.id != 12) & ~(table.c.name=='john')), </del><ins>+ table1.select((table1.c.id != 12) & ~(table1.c.name=='john')), </ins><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND NOT (mytable.name = :mytable_name)" </span><span class="cx"> ) </span><span class="cx"> </span><span class="lines">@@ -167,7 +166,7 @@ </span><span class="cx"> </span><span class="cx"> def testmultiparam(self): </span><span class="cx"> self.runtest( </span><del>- select(["*"], or_(table.c.id == 12, table.c.id=='asdf', table.c.id == 'foo')), </del><ins>+ select(["*"], or_(table1.c.id == 12, table1.c.id=='asdf', table1.c.id == 'foo')), </ins><span class="cx"> "SELECT * FROM mytable WHERE mytable.myid = :mytable_myid OR mytable.myid = :mytable_myid_1 OR mytable.myid = :mytable_myid_2" </span><span class="cx"> ) </span><span class="cx"> </span><span class="lines">@@ -187,15 +186,15 @@ </span><span class="cx"> "SELECT myothertable.othername, count(myothertable.otherid) FROM myothertable GROUP BY myothertable.othername ORDER BY myothertable.othername" </span><span class="cx"> ) </span><span class="cx"> def testalias(self): </span><del>- # test the alias for a table. column names stay the same, table name "changes" to "foo". </del><ins>+ # test the alias for a table1. column names stay the same, table name "changes" to "foo". </ins><span class="cx"> self.runtest( </span><span class="cx"> select([alias(table, 'foo')]) </span><span class="cx"> ,"SELECT foo.myid, foo.name, foo.description FROM mytable AS foo") </span><span class="cx"> </span><span class="cx"> # create a select for a join of two tables. use_labels means the column names will have </span><span class="cx"> # labels tablename_columnname, which become the column keys accessible off the Selectable object. </span><del>- # also, only use one column from the second table and all columns from the first table. - q = select([table, table2.c.id], table.c.id == table2.c.id, use_labels = True) </del><ins>+ # also, only use one column from the second table and all columns from the first table1. + q = select([table, table2.c.id], table1.c.id == table2.c.id, use_labels = True) </ins><span class="cx"> </span><span class="cx"> # make an alias of the "selectable". column names stay the same (i.e. the labels), table name "changes" to "t2view". </span><span class="cx"> a = alias(q, 't2view') </span><span class="lines">@@ -269,7 +268,7 @@ </span><span class="cx"> and_( </span><span class="cx"> "foo.id = foofoo(lala)", </span><span class="cx"> "datetime(foo) = Today", </span><del>- table.c.id == table2.c.id, </del><ins>+ table1.c.id == table2.c.id, </ins><span class="cx"> ) </span><span class="cx"> ), </span><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, sysdate(), foo, bar, lala \ </span><span class="lines">@@ -288,12 +287,12 @@ </span><span class="cx"> "SELECT :literal + :literal_1 FROM mytable", engine=db) </span><span class="cx"> </span><span class="cx"> def testfunction(self): </span><del>- self.runtest(func.lala(3, 4, literal("five"), table.c.id) * table2.c.id, </del><ins>+ self.runtest(func.lala(3, 4, literal("five"), table1.c.id) * table2.c.id, </ins><span class="cx"> "lala(:lala, :lala_1, :literal, mytable.myid) * myothertable.otherid", engine=db) </span><span class="cx"> </span><span class="cx"> def testjoin(self): </span><span class="cx"> self.runtest( </span><del>- join(table2, table, table.c.id == table2.c.id).select(), </del><ins>+ join(table2, table, table1.c.id == table2.c.id).select(), </ins><span class="cx"> "SELECT myothertable.otherid, myothertable.othername, mytable.myid, mytable.name, \ </span><span class="cx"> mytable.description FROM myothertable JOIN mytable ON mytable.myid = myothertable.otherid" </span><span class="cx"> ) </span><span class="lines">@@ -301,15 +300,15 @@ </span><span class="cx"> self.runtest( </span><span class="cx"> select( </span><span class="cx"> [table], </span><del>- from_obj = [join(table, table2, table.c.id == table2.c.id)] </del><ins>+ from_obj = [join(table, table2, table1.c.id == table2.c.id)] </ins><span class="cx"> ), </span><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable JOIN myothertable ON mytable.myid = myothertable.otherid") </span><span class="cx"> </span><span class="cx"> self.runtest( </span><span class="cx"> select( </span><del>- [join(join(table, table2, table.c.id == table2.c.id), table3, table.c.id == table3.c.id) </del><ins>+ [join(join(table, table2, table1.c.id == table2.c.id), table3, table1.c.id == table3.c.id) </ins><span class="cx"> ]), </span><del>- "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable JOIN myothertable ON mytable.myid = myothertable.otherid JOIN thirdtable ON mytable.myid = thirdtable.userid" </del><ins>+ "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable1.userid, thirdtable1.otherstuff FROM mytable JOIN myothertable ON mytable.myid = myothertable.otherid JOIN thirdtable ON mytable.myid = thirdtable1.userid" </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> self.runtest( </span><span class="lines">@@ -321,24 +320,24 @@ </span><span class="cx"> self.runtest( </span><span class="cx"> select([table, table2, table3], </span><span class="cx"> </span><del>- from_obj = [join(table, table2, table.c.id == table2.c.id).outerjoin(table3, table.c.id==table3.c.id)] </del><ins>+ from_obj = [join(table, table2, table1.c.id == table2.c.id).outerjoin(table3, table1.c.id==table3.c.id)] </ins><span class="cx"> </span><del>- #from_obj = [outerjoin(join(table, table2, table.c.id == table2.c.id), table3, table.c.id==table3.c.id)] </del><ins>+ #from_obj = [outerjoin(join(table, table2, table1.c.id == table2.c.id), table3, table1.c.id==table3.c.id)] </ins><span class="cx"> ) </span><del>- ,"SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable JOIN myothertable ON mytable.myid = myothertable.otherid LEFT OUTER JOIN thirdtable ON mytable.myid = thirdtable.userid" </del><ins>+ ,"SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable1.userid, thirdtable1.otherstuff FROM mytable JOIN myothertable ON mytable.myid = myothertable.otherid LEFT OUTER JOIN thirdtable ON mytable.myid = thirdtable1.userid" </ins><span class="cx"> ) </span><span class="cx"> self.runtest( </span><span class="cx"> select([table, table2, table3], </span><del>- from_obj = [outerjoin(table, join(table2, table3, table2.c.id == table3.c.id), table.c.id==table2.c.id)] </del><ins>+ from_obj = [outerjoin(table, join(table2, table3, table2.c.id == table3.c.id), table1.c.id==table2.c.id)] </ins><span class="cx"> ) </span><del>- ,"SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable LEFT OUTER JOIN (myothertable JOIN thirdtable ON myothertable.otherid = thirdtable.userid) ON mytable.myid = myothertable.otherid" </del><ins>+ ,"SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable1.userid, thirdtable1.otherstuff FROM mytable LEFT OUTER JOIN (myothertable JOIN thirdtable ON myothertable.otherid = thirdtable1.userid) ON mytable.myid = myothertable.otherid" </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> def testunion(self): </span><span class="cx"> x = union( </span><del>- select([table], table.c.id == 5), - select([table], table.c.id == 12), - order_by = [table.c.id], </del><ins>+ select([table], table1.c.id == 5), + select([table], table1.c.id == 12), + order_by = [table1.c.id], </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> self.runtest(x, "SELECT mytable.myid, mytable.name, mytable.description \ </span><span class="lines">@@ -355,7 +354,7 @@ </span><span class="cx"> , </span><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description \ </span><span class="cx"> FROM mytable UNION SELECT myothertable.otherid, myothertable.othername \ </span><del>-FROM myothertable UNION SELECT thirdtable.userid, thirdtable.otherstuff FROM thirdtable") </del><ins>+FROM myothertable UNION SELECT thirdtable1.userid, thirdtable1.otherstuff FROM thirdtable") </ins><span class="cx"> </span><span class="cx"> </span><span class="cx"> def testouterjoin(self): </span><span class="lines">@@ -367,12 +366,12 @@ </span><span class="cx"> query = select( </span><span class="cx"> [table, table2], </span><span class="cx"> and_( </span><del>- table.c.name == 'fred', - table.c.id == 10, </del><ins>+ table1.c.name == 'fred', + table1.c.id == 10, </ins><span class="cx"> table2.c.name != 'jack', </span><span class="cx"> "EXISTS (select yay from foo where boo = lar)" </span><span class="cx"> ), </span><del>- from_obj = [ outerjoin(table, table2, table.c.id == table2.c.id) ] </del><ins>+ from_obj = [ outerjoin(table, table2, table1.c.id == table2.c.id) ] </ins><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> self.runtest(query, </span><span class="lines">@@ -394,8 +393,8 @@ </span><span class="cx"> def testbindparam(self): </span><span class="cx"> self.runtest(select( </span><span class="cx"> [table, table2], </span><del>- and_(table.c.id == table2.c.id, - table.c.name == bindparam('mytablename'), </del><ins>+ and_(table1.c.id == table2.c.id, + table1.c.name == bindparam('mytablename'), </ins><span class="cx"> ) </span><span class="cx"> ), </span><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername \ </span><span class="lines">@@ -404,22 +403,22 @@ </span><span class="cx"> </span><span class="cx"> # check that the bind params sent along with a compile() call </span><span class="cx"> # get preserved when the params are retreived later </span><del>- s = select([table], table.c.id == bindparam('test')) </del><ins>+ s = select([table], table1.c.id == bindparam('test')) </ins><span class="cx"> c = s.compile(parameters = {'test' : 7}) </span><span class="cx"> self.assert_(c.get_params() == {'test' : 7}) </span><span class="cx"> </span><span class="cx"> def testcorrelatedsubquery(self): </span><span class="cx"> self.runtest( </span><del>- table.select(table.c.id == select([table2.c.id], table.c.name == table2.c.name)), </del><ins>+ table1.select(table1.c.id == select([table2.c.id], table1.c.name == table2.c.name)), </ins><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = (SELECT myothertable.otherid AS id FROM myothertable WHERE mytable.name = myothertable.othername)" </span><span class="cx"> ) </span><span class="cx"> </span><span class="cx"> self.runtest( </span><del>- table.select(exists([1], table2.c.id == table.c.id)), </del><ins>+ table1.select(exists([1], table2.c.id == table1.c.id)), </ins><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE EXISTS (SELECT 1 FROM myothertable WHERE myothertable.otherid = mytable.myid)" </span><span class="cx"> ) </span><span class="cx"> </span><del>- talias = table.alias('ta') </del><ins>+ talias = table1.alias('ta') </ins><span class="cx"> s = subquery('sq2', [talias], exists([1], table2.c.id == talias.c.id)) </span><span class="cx"> self.runtest( </span><span class="cx"> select([s, table]) </span><span class="lines">@@ -431,21 +430,21 @@ </span><span class="cx"> """SELECT users.user_id, users.user_name, users.password, s.street FROM users, (SELECT addresses.street AS street FROM addresses WHERE addresses.user_id = users.user_id) AS s""") </span><span class="cx"> </span><span class="cx"> def testin(self): </span><del>- self.runtest(select([table], table.c.id.in_(1, 2, 3)), </del><ins>+ self.runtest(select([table], table1.c.id.in_(1, 2, 3)), </ins><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid IN (:mytable_myid, :mytable_myid_1, :mytable_myid_2)") </span><span class="cx"> </span><del>- self.runtest(select([table], table.c.id.in_(select([table2.c.id]))), </del><ins>+ self.runtest(select([table], table1.c.id.in_(select([table2.c.id]))), </ins><span class="cx"> "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid IN (SELECT myothertable.otherid AS id FROM myothertable)") </span><span class="cx"> </span><span class="cx"> def testlateargs(self): </span><span class="cx"> """tests that a SELECT clause will have extra "WHERE" clauses added to it at compile time if extra arguments </span><span class="cx"> are sent""" </span><span class="cx"> </span><del>- self.runtest(table.select(), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name = :mytable_name AND mytable.myid = :mytable_myid", params={'id':'3', 'name':'jack'}) </del><ins>+ self.runtest(table1.select(), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name = :mytable_name AND mytable.myid = :mytable_myid", params={'id':'3', 'name':'jack'}) </ins><span class="cx"> </span><del>- self.runtest(table.select(table.c.name=='jack'), "SELECT mytable.myid, mytable.name, mytable.... [truncated message content] |