[Sqlalchemy-commits] sqlalchemy: Ridding the world of a few wasteful imports.
Brought to you by:
zzzeek
From: <co...@sq...> - 2010-12-20 04:18:12
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/672580f8a102 changeset: 7173:672580f8a102 user: Michael Trier <mt...@gm...> date: Sun Dec 19 23:16:50 2010 -0500 description: Ridding the world of a few wasteful imports. Subject: sqlalchemy: merge tip details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/33c8e78ec635 changeset: 7174:33c8e78ec635 user: Michael Trier <mt...@gm...> date: Sun Dec 19 23:17:55 2010 -0500 description: merge tip diffstat: lib/sqlalchemy/connectors/mxodbc.py | 3 - lib/sqlalchemy/connectors/pyodbc.py | 1 - lib/sqlalchemy/dialects/mssql/adodbapi.py | 1 + lib/sqlalchemy/dialects/mssql/base.py | 7 +- lib/sqlalchemy/dialects/mssql/information_schema.py | 2 +- lib/sqlalchemy/dialects/mssql/mxodbc.py | 6 +-- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 2 +- lib/sqlalchemy/dialects/oracle/zxjdbc.py | 2 +- lib/sqlalchemy/dialects/postgresql/base.py | 4 +- lib/sqlalchemy/dialects/postgresql/pg8000.py | 1 - lib/sqlalchemy/dialects/postgresql/psycopg2.py | 7 +- lib/sqlalchemy/dialects/postgresql/pypostgresql.py | 1 - lib/sqlalchemy/dialects/sqlite/base.py | 8 +-- lib/sqlalchemy/dialects/sqlite/pysqlite.py | 3 +- lib/sqlalchemy/engine/base.py | 37 ++++++++++----- lib/sqlalchemy/engine/default.py | 50 ++++++++++---------- lib/sqlalchemy/sql/compiler.py | 35 +++++++------- test/sql/test_query.py | 3 +- 18 files changed, 84 insertions(+), 89 deletions(-) diffs (truncated from 495 to 300 lines): diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/connectors/mxodbc.py --- a/lib/sqlalchemy/connectors/mxodbc.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/connectors/mxodbc.py Sun Dec 19 23:17:55 2010 -0500 @@ -15,11 +15,8 @@ import sys import re import warnings -from sqlalchemy.util.compat import decimal from sqlalchemy.connectors import Connector -from sqlalchemy import types as sqltypes -import sqlalchemy.processors as processors class MxODBCConnector(Connector): driver='mxodbc' diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/connectors/pyodbc.py --- a/lib/sqlalchemy/connectors/pyodbc.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/connectors/pyodbc.py Sun Dec 19 23:17:55 2010 -0500 @@ -4,7 +4,6 @@ import sys import re import urllib -import decimal class PyODBCConnector(Connector): driver='pyodbc' diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/mssql/adodbapi.py --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py Sun Dec 19 23:17:55 2010 -0500 @@ -2,6 +2,7 @@ The adodbapi dialect is not implemented for 0.6 at this time. """ +import datetime from sqlalchemy import types as sqltypes, util from sqlalchemy.dialects.mssql.base import MSDateTime, MSDialect import sys diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/mssql/base.py --- a/lib/sqlalchemy/dialects/mssql/base.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/mssql/base.py Sun Dec 19 23:17:55 2010 -0500 @@ -118,20 +118,19 @@ SQL Server 2005 """ -import datetime, decimal, inspect, operator, sys, re -import itertools +import datetime, operator, re from sqlalchemy import sql, schema as sa_schema, exc, util from sqlalchemy.sql import select, compiler, expression, \ operators as sql_operators, \ - functions as sql_functions, util as sql_util + util as sql_util from sqlalchemy.engine import default, base, reflection from sqlalchemy import types as sqltypes -from sqlalchemy import processors from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, DECIMAL, NUMERIC, \ FLOAT, TIMESTAMP, DATETIME, DATE, BINARY,\ VARBINARY, BLOB + from sqlalchemy.dialects.mssql import information_schema as ischema MS_2008_VERSION = (10,) diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/mssql/information_schema.py --- a/lib/sqlalchemy/dialects/mssql/information_schema.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py Sun Dec 19 23:17:55 2010 -0500 @@ -1,6 +1,6 @@ # TODO: should be using the sys. catalog with SQL Server, not information schema -from sqlalchemy import Table, MetaData, Column, ForeignKey +from sqlalchemy import Table, MetaData, Column from sqlalchemy.types import String, Unicode, Integer, TypeDecorator ischema = MetaData() diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/mssql/mxodbc.py --- a/lib/sqlalchemy/dialects/mssql/mxodbc.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py Sun Dec 19 23:17:55 2010 -0500 @@ -45,15 +45,11 @@ """ -import re -import sys from sqlalchemy import types as sqltypes -from sqlalchemy import util from sqlalchemy.connectors.mxodbc import MxODBCConnector from sqlalchemy.dialects.mssql.pyodbc import MSExecutionContext_pyodbc -from sqlalchemy.dialects.mssql.base import (MSExecutionContext, MSDialect, - MSSQLCompiler, +from sqlalchemy.dialects.mssql.base import (MSDialect, MSSQLStrictCompiler, _MSDateTime, _MSDate, TIME) diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/oracle/cx_oracle.py --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py Sun Dec 19 23:17:55 2010 -0500 @@ -327,7 +327,7 @@ self.out_parameters[name] def create_cursor(self): - c = self._connection.connection.cursor() + c = self._dbapi_connection.cursor() if self.dialect.arraysize: c.arraysize = self.dialect.arraysize diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/oracle/zxjdbc.py --- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py Sun Dec 19 23:17:55 2010 -0500 @@ -109,7 +109,7 @@ return base.ResultProxy(self) def create_cursor(self): - cursor = self._connection.connection.cursor() + cursor = self._dbapi_connection.cursor() cursor.datahandler = self.dialect.DataHandler(cursor.datahandler) return cursor diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/postgresql/base.py --- a/lib/sqlalchemy/dialects/postgresql/base.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/postgresql/base.py Sun Dec 19 23:17:55 2010 -0500 @@ -87,11 +87,9 @@ import re -from sqlalchemy import schema as sa_schema from sqlalchemy import sql, schema, exc, util -from sqlalchemy.engine import base, default, reflection +from sqlalchemy.engine import default, reflection from sqlalchemy.sql import compiler, expression, util as sql_util -from sqlalchemy.sql import operators as sql_operators from sqlalchemy import types as sqltypes try: diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/postgresql/pg8000.py --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py Sun Dec 19 23:17:55 2010 -0500 @@ -21,7 +21,6 @@ yet. """ -from sqlalchemy.engine import default from sqlalchemy import util, exc from sqlalchemy.util.compat import decimal from sqlalchemy import processors diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/postgresql/psycopg2.py --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py Sun Dec 19 23:17:55 2010 -0500 @@ -91,9 +91,8 @@ from sqlalchemy import util, exc from sqlalchemy.util.compat import decimal from sqlalchemy import processors -from sqlalchemy.engine import base, default +from sqlalchemy.engine import base from sqlalchemy.sql import expression -from sqlalchemy.sql import operators as sql_operators from sqlalchemy import types as sqltypes from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, \ PGIdentifierPreparer, PGExecutionContext, \ @@ -172,9 +171,9 @@ # use server-side cursors: # http://lists.initd.org/pipermail/psycopg/2007-January/005251.html ident = "c_%s_%s" % (hex(id(self))[2:], hex(random.randint(0, 65535))[2:]) - return self._connection.connection.cursor(ident) + return self._dbapi_connection.cursor(ident) else: - return self._connection.connection.cursor() + return self._dbapi_connection.cursor() def get_result_proxy(self): # TODO: ouch diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/postgresql/pypostgresql.py --- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py Sun Dec 19 23:17:55 2010 -0500 @@ -7,7 +7,6 @@ """ -from sqlalchemy.engine import default from sqlalchemy import util from sqlalchemy import types as sqltypes from sqlalchemy.dialects.postgresql.base import PGDialect, PGExecutionContext diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/sqlite/base.py --- a/lib/sqlalchemy/dialects/sqlite/base.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/sqlite/base.py Sun Dec 19 23:17:55 2010 -0500 @@ -52,15 +52,13 @@ """ -import datetime, re, time +import datetime, re -from sqlalchemy import schema as sa_schema -from sqlalchemy import sql, exc, pool, DefaultClause +from sqlalchemy import sql, exc from sqlalchemy.engine import default, base, reflection from sqlalchemy import types as sqltypes from sqlalchemy import util -from sqlalchemy.sql import compiler, functions as sql_functions -from sqlalchemy.util import NoneType +from sqlalchemy.sql import compiler from sqlalchemy import processors from sqlalchemy.types import BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL,\ diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/dialects/sqlite/pysqlite.py --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py Sun Dec 19 23:17:55 2010 -0500 @@ -133,8 +133,7 @@ """ from sqlalchemy.dialects.sqlite.base import SQLiteDialect, DATETIME, DATE -from sqlalchemy import schema, exc, pool -from sqlalchemy.engine import default +from sqlalchemy import exc, pool from sqlalchemy import types as sqltypes from sqlalchemy import util diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/engine/base.py --- a/lib/sqlalchemy/engine/base.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/engine/base.py Sun Dec 19 23:17:55 2010 -0500 @@ -889,16 +889,19 @@ try: return self.__connection except AttributeError: - if self.__invalid: - if self.__transaction is not None: - raise exc.InvalidRequestError( - "Can't reconnect until invalid " - "transaction is rolled back") - self.__connection = self.engine.raw_connection() - self.__invalid = False - return self.__connection - raise exc.ResourceClosedError("This Connection is closed") - + return self._revalidate_connection() + + def _revalidate_connection(self): + if self.__invalid: + if self.__transaction is not None: + raise exc.InvalidRequestError( + "Can't reconnect until invalid " + "transaction is rolled back") + self.__connection = self.engine.raw_connection() + self.__invalid = False + return self.__connection + raise exc.ResourceClosedError("This Connection is closed") + @property def _connection_is_valid(self): # use getattr() for is_valid to support exceptions raised in @@ -1214,9 +1217,14 @@ """Execute a schema.ColumnDefault object.""" try: + try: + conn = self.__connection + except AttributeError: + conn = self._revalidate_connection() + dialect = self.dialect ctx = dialect.execution_ctx_cls._init_default( - dialect, self) + dialect, self, conn) except Exception, e: self._handle_dbapi_exception(e, None, None, None, None) raise @@ -1306,7 +1314,12 @@ a :class:`.ResultProxy`.""" try: - context = constructor(dialect, self, *args) + try: + conn = self.__connection + except AttributeError: + conn = self._revalidate_connection() + + context = constructor(dialect, self, conn, *args) except Exception, e: self._handle_dbapi_exception(e, statement, parameters, diff -r 2fb832aa42bb -r 33c8e78ec635 lib/sqlalchemy/engine/default.py --- a/lib/sqlalchemy/engine/default.py Sun Dec 19 20:47:27 2010 -0500 +++ b/lib/sqlalchemy/engine/default.py Sun Dec 19 23:17:55 2010 -0500 @@ -322,14 +322,17 @@ result_map = None compiled = None statement = None + _is_implicit_returning = False + _is_explicit_returning = False @classmethod - def _init_ddl(cls, dialect, connection, compiled_ddl): + def _init_ddl(cls, dialect, connection, dbapi_connection, compiled_ddl): """Initialize execution context for a DDLElement construct.""" self = cls.__new__(cls) self.dialect = dialect - self._connection = self.root_connection = connection + self.root_connection = connection |