diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-18 18:14:06 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-18 18:14:06 +0000 |
| commit | a20222fc22059df30b09b49621a784b54919613a (patch) | |
| tree | 99d99b2516fa81520ae1878e31e638f188ccc40f /lib/sqlalchemy | |
| parent | 223bd3688dfd01f9dff973cbf9b3d92f39df4c21 (diff) | |
| download | sqlalchemy-a20222fc22059df30b09b49621a784b54919613a.tar.gz | |
- 0.5.0rc3, doh
- The internal notion of an "OID" or "ROWID" column has been
removed. It's basically not used by any dialect, and the
possibility of its usage with psycopg2's cursor.lastrowid
is basically gone now that INSERT..RETURNING is available.
- Removed "default_order_by()" method on all FromClause
objects.
- profile/compile/select test is 8 function calls over on buildbot 2.4 for some reason, will adjust after checking
the results of this commit
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/databases/informix.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/oracle.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 22 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/base.py | 17 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/schema.py | 23 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 12 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 40 |
9 files changed, 16 insertions, 121 deletions
diff --git a/lib/sqlalchemy/databases/informix.py b/lib/sqlalchemy/databases/informix.py index 423226c18..27554d37e 100644 --- a/lib/sqlalchemy/databases/informix.py +++ b/lib/sqlalchemy/databases/informix.py @@ -242,9 +242,6 @@ class InfoDialect(default.DefaultDialect): def create_execution_context(self , *args, **kwargs): return InfoExecutionContext(self, *args, **kwargs) - def oid_column_name(self, column): - return "rowid" - def table_names(self, connection, schema): s = "select tabname from systables" return [row[0] for row in connection.execute(s)] @@ -396,7 +393,7 @@ class InfoCompiler(compiler.DefaultCompiler): # TODO: dont modify the original select, generate a new one a = [ __label(c) for c in select._raw_columns ] for c in select._order_by_clause.clauses: - if ( __label(c) not in a ) and getattr( c , 'name' , '' ) != 'oid': + if ( __label(c) not in a ): select.append_column( c ) return compiler.DefaultCompiler.visit_select(self, select) @@ -415,11 +412,7 @@ class InfoCompiler(compiler.DefaultCompiler): return compiler.DefaultCompiler.visit_function( self , func ) def visit_clauselist(self, list, **kwargs): - try: - li = [ c for c in list.clauses if c.name != 'oid' ] - except: - li = [ c for c in list.clauses ] - return ', '.join([s for s in [self.process(c) for c in li] if s is not None]) + return ', '.join([s for s in [self.process(c) for c in list.clauses] if s is not None]) class InfoSchemaGenerator(compiler.SchemaGenerator): def get_column_specification(self, column, first_pk=False): diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index eb02d4505..3f2540ac0 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -325,12 +325,6 @@ class OracleDialect(default.DefaultDialect): def type_descriptor(self, typeobj): return sqltypes.adapt_type(typeobj, colspecs) - def oid_column_name(self, column): - if not isinstance(column.table, (sql.TableClause, sql.Select)): - return None - else: - return "rowid" - def create_xid(self): """create a two-phase transaction ID. diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index aeed41078..1c410af53 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -292,19 +292,6 @@ class PGExecutionContext(default.DefaultExecutionContext): else: return base.ResultProxy(self) - def post_exec(self): - if self.compiled.isinsert and self.last_inserted_ids is None: - if not self.dialect.use_oids: - pass - # will raise invalid error when they go to get them - else: - table = self.compiled.statement.table - if self.cursor.lastrowid is not None and table is not None and len(table.primary_key): - s = sql.select(table.primary_key, table.oid_column == self.cursor.lastrowid) - row = self.connection.execute(s).fetchone() - self._last_inserted_ids = [v for v in row] - super(PGExecutionContext, self).post_exec() - class PGDialect(default.DefaultDialect): name = 'postgres' supports_alter = True @@ -316,9 +303,8 @@ class PGDialect(default.DefaultDialect): supports_pk_autoincrement = False default_paramstyle = 'pyformat' - def __init__(self, use_oids=False, server_side_cursors=False, **kwargs): + def __init__(self, server_side_cursors=False, **kwargs): default.DefaultDialect.__init__(self, **kwargs) - self.use_oids = use_oids self.server_side_cursors = server_side_cursors def dbapi(cls): @@ -382,12 +368,6 @@ class PGDialect(default.DefaultDialect): else: return self.context.last_inserted_ids - def oid_column_name(self, column): - if self.use_oids: - return "oid" - else: - return None - def has_table(self, connection, table_name, schema=None): # seems like case gets folded in pg_class... if schema is None: diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 35f07b784..70c3f74ec 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -298,9 +298,6 @@ class SQLiteDialect(default.DefaultDialect): def create_execution_context(self, connection, **kwargs): return SQLiteExecutionContext(self, connection, **kwargs) - def oid_column_name(self, column): - return "oid" - def is_disconnect(self, e): return isinstance(e, self.dbapi.ProgrammingError) and "Cannot operate on a closed database." in str(e) diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 1e72bc14b..8e8a7528b 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -128,23 +128,6 @@ class Dialect(object): raise NotImplementedError() - def oid_column_name(self, column): - """Return the oid column name for this Dialect - - May return ``None`` if the dialect can't o won't support - OID/ROWID features. - - The [sqlalchemy.schema#Column] instance which represents OID - for the query being compiled is passed, so that the dialect - can inspect the column and its parent selectable to determine - if OID/ROWID is not selected for a particular selectable - (i.e. Oracle doesnt support ROWID for UNION, GROUP BY, - DISTINCT, etc.) - """ - - raise NotImplementedError() - - def server_version_info(self, connection): """Return a tuple of the database's version number.""" diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index a3ae6d456..a90142702 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -75,9 +75,6 @@ class DefaultDialect(base.Dialect): if len(ident) > self.max_identifier_length: raise exc.IdentifierError("Identifier '%s' exceeds maximum length of %d characters" % (ident, self.max_identifier_length)) - def oid_column_name(self, column): - return None - def do_begin(self, connection): """Implementations might want to put logic here for turning autocommit on/off, etc. diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d66a51de4..334c277b4 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -491,10 +491,6 @@ class Column(SchemaItem, expression._ColumnClause): Strings and text() will be converted into a ``DefaultClause`` object upon initialization. - _is_oid - Defaults to False: used internally to indicate that this column is - used as the quasi-hidden "oid" column - index Defaults to False: indicates that this column is indexed. The name of the index is autogenerated. to specify indexes with explicit @@ -566,7 +562,6 @@ class Column(SchemaItem, expression._ColumnClause): self.key = kwargs.pop('key', name) self.primary_key = kwargs.pop('primary_key', False) self.nullable = kwargs.pop('nullable', not self.primary_key) - self._is_oid = kwargs.pop('_is_oid', False) self.default = kwargs.pop('default', None) self.server_default = kwargs.pop('server_default', None) self.server_onupdate = kwargs.pop('server_onupdate', None) @@ -640,12 +635,9 @@ class Column(SchemaItem, expression._ColumnClause): self.metadata = table.metadata if getattr(self, 'table', None) is not None: raise exc.ArgumentError("this Column already has a table!") - if not self._is_oid: - self._pre_existing_column = table._columns.get(self.key) - table._columns.replace(self) - else: - self._pre_existing_column = None + self._pre_existing_column = table._columns.get(self.key) + table._columns.replace(self) if self.primary_key: table.primary_key.replace(self) @@ -703,7 +695,7 @@ class Column(SchemaItem, expression._ColumnClause): This is used in ``Table.tometadata``. """ - return Column(self.name, self.type, self.default, key = self.key, primary_key = self.primary_key, nullable = self.nullable, _is_oid = self._is_oid, quote=self.quote, index=self.index, autoincrement=self.autoincrement, *[c.copy() for c in self.constraints]) + return Column(self.name, self.type, self.default, key = self.key, primary_key = self.primary_key, nullable = self.nullable, quote=self.quote, index=self.index, autoincrement=self.autoincrement, *[c.copy() for c in self.constraints]) def _make_proxy(self, selectable, name=None): """Create a *proxy* for this column. @@ -713,14 +705,13 @@ class Column(SchemaItem, expression._ColumnClause): """ fk = [ForeignKey(f._colspec) for f in self.foreign_keys] - c = Column(name or self.name, self.type, self.default, key = name or self.key, primary_key = self.primary_key, nullable = self.nullable, _is_oid = self._is_oid, quote=self.quote, *fk) + c = Column(name or self.name, self.type, self.default, key = name or self.key, primary_key = self.primary_key, nullable = self.nullable, quote=self.quote, *fk) c.table = selectable c.proxies = [self] c._pre_existing_column = self._pre_existing_column - if not c._is_oid: - selectable.columns.add(c) - if self.primary_key: - selectable.primary_key.add(c) + selectable.columns.add(c) + if self.primary_key: + selectable.primary_key.add(c) [c._init_items(f) for f in fk] return c diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 573453499..6d3769906 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -148,7 +148,7 @@ class DefaultCompiler(engine.Compiled): # actually present in the generated SQL self.bind_names = {} - # a stack. what recursive compiler doesn't have a stack ? :) + # stack which keeps track of nested SELECT statements self.stack = [] # relates label names in the final SQL to @@ -236,15 +236,7 @@ class DefaultCompiler(engine.Compiled): def visit_column(self, column, result_map=None, **kwargs): - if column._is_oid: - name = self.dialect.oid_column_name(column) - if name is None: - if len(column.table.primary_key) != 0: - pk = list(column.table.primary_key)[0] - return self.visit_column(pk, result_map=result_map, **kwargs) - else: - return None - elif not column.is_literal: + if not column.is_literal: name = self._truncated_identifier("colident", column.name) else: name = column.name diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 8f611c05e..2663c61a1 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1689,9 +1689,6 @@ class FromClause(Selectable): def _get_from_objects(self, **modifiers): return [] - def default_order_by(self): - return [self.oid_column] - def count(self, whereclause=None, **params): """return a SELECT COUNT generated against this ``FromClause``.""" @@ -1769,8 +1766,6 @@ class FromClause(Selectable): col, intersect = None, None target_set = column.proxy_set cols = self.c - if self.oid_column: - cols += [self.oid_column] for c in cols: i = c.proxy_set.intersection(target_set) if i and \ @@ -1793,7 +1788,7 @@ class FromClause(Selectable): # from the item. this is because FromClause subclasses, when # cloned, need to reestablish new "proxied" columns that are # linked to the new item - for attr in ('_columns', '_primary_key' '_foreign_keys', '_oid_column', '_embedded_columns', '_all_froms'): + for attr in ('_columns', '_primary_key' '_foreign_keys', '_embedded_columns', '_all_froms'): if hasattr(self, attr): delattr(self, attr) @@ -1810,7 +1805,6 @@ class FromClause(Selectable): columns = c = _expr_attr_func('_columns') primary_key = _expr_attr_func('_primary_key') foreign_keys = _expr_attr_func('_foreign_keys') - oid_column = _expr_attr_func('_oid_column') def _export_columns(self): """Initialize column collections.""" @@ -1820,7 +1814,6 @@ class FromClause(Selectable): self._columns = ColumnCollection() self._primary_key = ColumnSet() self._foreign_keys = set() - self._oid_column = None self._populate_column_collection() def _populate_column_collection(self): @@ -1949,7 +1942,6 @@ class _TextClause(ClauseElement): supports_execution = True _hide_froms = [] - oid_column = None def __init__(self, text = "", bind=None, bindparams=None, typemap=None, autocommit=False): self._bind = bind @@ -2356,7 +2348,6 @@ class Join(FromClause): (c for c in columns if c.primary_key), self.onclause)) self._columns.update((col._label, col) for col in columns) self._foreign_keys.update(itertools.chain(*[col.foreign_keys for col in columns])) - self._oid_column = self.left.oid_column def _copy_internals(self, clone=_clone): self._reset_exported() @@ -2462,8 +2453,6 @@ class Alias(FromClause): def _populate_column_collection(self): for col in self.element.columns: col._make_proxy(self) - if self.element.oid_column is not None: - self._oid_column = self.element.oid_column._make_proxy(self) def _copy_internals(self, clone=_clone): self._reset_exported() @@ -2636,12 +2625,11 @@ class _ColumnClause(_Immutable, ColumnElement): ``_ColumnClause``. """ - def __init__(self, text, selectable=None, type_=None, _is_oid=False, is_literal=False): + def __init__(self, text, selectable=None, type_=None, is_literal=False): ColumnElement.__init__(self) self.key = self.name = text self.table = selectable self.type = sqltypes.to_instance(type_) - self._is_oid = _is_oid self.__label = None self.is_literal = is_literal @@ -2690,9 +2678,9 @@ class _ColumnClause(_Immutable, ColumnElement): # propigate the "is_literal" flag only if we are keeping our name, # otherwise its considered to be a label is_literal = self.is_literal and (name is None or name == self.name) - c = _ColumnClause(name or self.name, selectable=selectable, _is_oid=self._is_oid, type_=self.type, is_literal=is_literal) + c = _ColumnClause(name or self.name, selectable=selectable, type_=self.type, is_literal=is_literal) c.proxies = [self] - if attach and not self._is_oid: + if attach: selectable.columns[c.name] = c return c @@ -2712,7 +2700,6 @@ class TableClause(_Immutable, FromClause): def __init__(self, name, *columns): super(TableClause, self).__init__() self.name = self.fullname = name - self._oid_column = _ColumnClause('oid', self, _is_oid=True) self._columns = ColumnCollection() self._primary_key = ColumnSet() self._foreign_keys = set() @@ -2942,15 +2929,6 @@ class CompoundSelect(_SelectBaseMixin, FromClause): proxy = cols[0]._make_proxy(self, name=self.use_labels and cols[0]._label or None) proxy.proxies = cols - oid_proxies = [ - c for c in [f.oid_column for f in self.selects] if c is not None - ] - - if oid_proxies: - col = oid_proxies[0]._make_proxy(self) - col.proxies = oid_proxies - self._oid_column = col - def _copy_internals(self, clone=_clone): self._reset_exported() self.selects = [clone(s) for s in self.selects] @@ -3283,16 +3261,6 @@ class Select(_SelectBaseMixin, FromClause): def _populate_column_collection(self): for c in self.__exportable_columns(): c._make_proxy(self, name=self.use_labels and c._label or None) - - oid_proxies = [c for c in - [f.oid_column for f in self.locate_all_froms() - if f is not self] if c is not None - ] - - if oid_proxies: - col = oid_proxies[0]._make_proxy(self) - col.proxies = oid_proxies - self._oid_column = col def self_group(self, against=None): """return a 'grouping' construct as per the ClauseElement specification. |
