diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-11 16:37:49 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-11 16:37:49 -0400 |
| commit | 47ef5ed5f72b9d65a48780ee561ae84e8b05becb (patch) | |
| tree | 61f6ebb1646aebf0e89cac0a67d3ef27fb008f02 /lib/sqlalchemy | |
| parent | fc157ed8c57b7fcfea6b76688d4733c87c4f8e82 (diff) | |
| download | sqlalchemy-47ef5ed5f72b9d65a48780ee561ae84e8b05becb.tar.gz | |
- The functionality of result.rowcount is now disabled
by default, and can be re-enabled using the 'enable_rowcount'
flag with create_engine(), as well as the 'enable_rowcount'
execution context flag on a per-execute basis. This because
cursor.rowcount requires cursor access (can't be evaluated
lazily since the result auto-closes) and also incurs an
expensive round-trip.
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/firebird/kinterbasdb.py | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/lib/sqlalchemy/dialects/firebird/kinterbasdb.py b/lib/sqlalchemy/dialects/firebird/kinterbasdb.py index 9984d32a2..890ba83fe 100644 --- a/lib/sqlalchemy/dialects/firebird/kinterbasdb.py +++ b/lib/sqlalchemy/dialects/firebird/kinterbasdb.py @@ -13,21 +13,34 @@ The connection URL is of the form Kinterbasedb backend specific keyword arguments are: -type_conv - select the kind of mapping done on the types: by default SQLAlchemy +* type_conv - select the kind of mapping done on the types: by default SQLAlchemy uses 200 with Unicode, datetime and decimal support (see details__). -concurrency_level - set the backend policy with regards to threading issues: by default +* concurrency_level - set the backend policy with regards to threading issues: by default SQLAlchemy uses policy 1 (see details__). +* enable_rowcount - False by default, this enables the usage of "cursor.rowcount" with the + Kinterbasdb dialect. When disabled, SQLAlchemy's ResultProxy will + return -1 for result.rowcount. The rationale here is that Kinterbasdb + requires a second round trip to the database when .rowcount is called - + since SQLA's resultproxy automatically closes the cursor after a + non-result-returning statement, rowcount must be called, if at all, + before the result object is returned. The behavior can also be + controlled on a per-execution basis using the `enable_rowcount` + option with :meth:`execution_options()`:: + + conn = engine.connect().execution_options(enable_rowcount=True) + r = conn.execute(stmt) + print r.rowcount + __ http://sourceforge.net/projects/kinterbasdb __ http://firebirdsql.org/index.php?op=devel&sub=python __ http://kinterbasdb.sourceforge.net/dist_docs/usage.html#adv_param_conv_dynamic_type_translation __ http://kinterbasdb.sourceforge.net/dist_docs/usage.html#special_issue_concurrency """ -from sqlalchemy.dialects.firebird.base import FBDialect, FBCompiler +from sqlalchemy.dialects.firebird.base import FBDialect, \ + FBCompiler, FBExecutionContext from sqlalchemy import util, types as sqltypes class _FBNumeric_kinterbasdb(sqltypes.Numeric): @@ -38,11 +51,21 @@ class _FBNumeric_kinterbasdb(sqltypes.Numeric): else: return value return process - + +class FBExecutionContext_kinterbasdb(FBExecutionContext): + @property + def rowcount(self): + if self.execution_options.get('enable_rowcount', + self.dialect.enable_rowcount): + return self.cursor.rowcount + else: + return -1 + class FBDialect_kinterbasdb(FBDialect): driver = 'kinterbasdb' supports_sane_rowcount = False supports_sane_multi_rowcount = False + execution_ctx_cls = FBExecutionContext_kinterbasdb supports_native_decimal = True @@ -54,12 +77,14 @@ class FBDialect_kinterbasdb(FBDialect): ) - def __init__(self, type_conv=200, concurrency_level=1, **kwargs): + def __init__(self, type_conv=200, concurrency_level=1, enable_rowcount=False, **kwargs): super(FBDialect_kinterbasdb, self).__init__(**kwargs) - + self.enable_rowcount = enable_rowcount self.type_conv = type_conv self.concurrency_level = concurrency_level - + if enable_rowcount: + self.supports_sane_rowcount = True + @classmethod def dbapi(cls): k = __import__('kinterbasdb') |
