summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
Commit message (Collapse)AuthorAgeFilesLines
* Refactor for cx_Oracle version 6oracle_numericMike Bayer2017-09-113-23/+13
| | | | | | | | | Drops support for cx_Oracle prior to version 5.x, reworks numeric and binary support. Fixes: #4064 Change-Id: Ib9ae9aba430c15cd2a6eeb4e5e3fd8e97b5fe480
* Add new sane_rowcount_w_returning flagMike Bayer2017-08-311-0/+4
| | | | | | | | | | | | | | | | | Added a new class of "rowcount support" for dialects that is specific to when "RETURNING", which on SQL Server looks like "OUTPUT inserted", is in use, as the PyODBC backend isn't able to give us rowcount on an UPDATE or DELETE statement when OUTPUT is in effect. This primarily affects the ORM when a flush is updating a row that contains server-calcluated values, raising an error if the backend does not return the expected row count. PyODBC now states that it supports rowcount except if OUTPUT.inserted is present, which is taken into account by the ORM during a flush as to whether it will look for a rowcount. ORM tests are implicit in existing tests run against PyODBC Fixes: #4062 Change-Id: Iff17cbe4c7a5742971ed85a4d58660c18cc569c2
* Don't do recovery operations under Empty/AttributeErrorMike Bayer2017-08-251-4/+15
| | | | | | | | | | | | Made some adjustments to :class:`.Pool` and :class:`.Connection` such that recovery logic is not run underneath exception catches for ``pool.Empty``, ``AttributeError``, since when the recovery operation itself fails, Python 3 creates a misleading stack trace referring to the ``Empty`` / ``AttributeError`` as the cause, when in fact these exception catches are part of control flow. Change-Id: Id3ed9a8f96ce4ccb4009c94af30ddc2ddb9818b9 Fixes: #4028
* - modernize the mysql connection timeout docsMike Bayer2017-08-221-0/+4
| | | | | Change-Id: Icb0474509539c1eb7536544749f2a48b4972078a (cherry picked from commit 4ce46fb0a085c1cc739e21881cc25567e663f8dc)
* Ensure Oracle index w/ col DESC etc. is reflectedMike Bayer2017-08-141-0/+1
| | | | | | | | | | | | | | | | | | | | Fixed bug where an index reflected under Oracle with an expression like "column DESC" would not be returned, if the table also had no primary key, as a result of logic that attempts to filter out the index implicitly added by Oracle onto the primary key columns. Reworked the "filter out the primary key index" logic in oracle get_indexes() to be clearer. This changeset also adds an internal check to ColumnCollection to accomodate for the case of a column being added twice, as well as adding a private _table argument to Index such that reflection can specify the Table explicitly. The _table argument can become part of public API in a later revision or release if needed. Change-Id: I745711e03b3e450b7f31185fc70e10d3823063fa Fixes: #4042
* Add support for CACHE and ORDER to sequencesDavid Moore2017-07-051-1/+1
| | | | | | | | | | | Added new keywords :paramref:`.Sequence.cache` and :paramref:`.Sequence.order` to :class:`.Sequence`, to allow rendering of the CACHE parameter understood by Oracle and PostgreSQL, and the ORDER parameter understood by Oracle. Pull request courtesy David Moore. Change-Id: I082c3f8ef56ef89dbaad5da9d5695be5313b0614 Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/96
* Add new "expanding" feature to bindparam()Mike Bayer2017-04-071-3/+110
| | | | | | | | | | | | | | | | Added a new kind of :func:`.bindparam` called "expanding". This is for use in ``IN`` expressions where the list of elements is rendered into individual bound parameters at statement execution time, rather than at statement compilation time. This allows both a single bound parameter name to be linked to an IN expression of multiple elements, as well as allows query caching to be used with IN expressions. The new feature allows the related features of "select in" loading and "polymorphic in" loading to make use of the baked query extension to reduce call overhead. This feature should be considered to be **experimental** for 1.2. Fixes: #3953 Change-Id: Ie708414a3ab9c0af29998a2c7f239ff7633b1f6e
* ResultProxy won't autoclose connection until state flag is setMike Bayer2017-04-033-12/+19
| | | | | | | | | | | | | | Changed the mechanics of :class:`.ResultProxy` to unconditionally delay the "autoclose" step until the :class:`.Connection` is done with the object; in the case where Postgresql ON CONFLICT with RETURNING returns no rows, autoclose was occurring in this previously non-existent use case, causing the usual autocommit behavior that occurs unconditionally upon INSERT/UPDATE/DELETE to fail. Change-Id: I235a25daf4381b31f523331f810ea04450349722 Fixes: #3955 (cherry picked from commit 8ee363e4917b0dcd64a83b6d26e465c9e61e0ea5) (cherry picked from commit f52fb5282a046d26b6ee2778e03b995eb117c2ee)
* Apply type processing to untyped preexec default clauseMike Bayer2017-03-301-1/+5
| | | | | | | | | | | | | | | | Fixed bug where a SQL-oriented Python-side column default could fail to be executed properly upon INSERT in the "pre-execute" codepath, if the SQL itself were an untyped expression, such as plain text. The "pre- execute" codepath is fairly uncommon however can apply to non-integer primary key columns with SQL defaults when RETURNING is not used. Tests exist here to ensure typing is applied to a typed expression for default, but in the case of an untyped SQL value, we know the type from the column, so apply this. Change-Id: I5d8b391611c137b9f700115a50a2bf5b30abfe94 Fixes: #3923
* Add safe_reraise() + warnings only to Connection._autorollbackMike Bayer2017-03-271-1/+2
| | | | | | | | | | | | Added an exception handler that will warn for the "cause" exception on Py2K when the "autorollback" feature of :class:`.Connection` itself raises an exception. In Py3K, the two exceptions are naturally reported by the interpreter as one occurring during the handling of the other. This is continuing with the series of changes for rollback failure handling that were last visited as part of :ticket:`2696` in 1.0.12. Change-Id: I600ba455a14ebaea27c6189889181f97c632f179 Fixes: #3946
* Integrate "pre-ping" into connection pool.Mike Bayer2017-03-203-1/+32
| | | | | | | | | | | | | | | Added native "pessimistic disconnection" handling to the :class:`.Pool` object. The new parameter :paramref:`.Pool.pre_ping`, available from the engine as :paramref:`.create_engine.pool_pre_ping`, applies an efficient form of the "pre-ping" recipe featured in the pooling documentation, which upon each connection check out, emits a simple statement, typically "SELECT 1", to test the connection for liveness. If the existing connection is no longer able to respond to commands, the connection is transparently recycled, and all other connections made prior to the current timestamp are invalidated. Change-Id: I89700d0075e60abd2250e54b9bd14daf03c71c00 Fixes: #3919
* New features from python 2.7Катаев Денис2017-03-172-4/+4
| | | | | | | After bump minimum supported version to 2.7 (1da9d3752160430c91534a8868ceb8c5ad1451d4), we can use new syntax. Change-Id: Ib064c75a00562e641d132f9c57e5e69744200e05 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/347
* Implement comments for tables, columnsFrazer McLean2017-03-173-1/+55
| | | | | | | | | | | | | | Added support for SQL comments on :class:`.Table` and :class:`.Column` objects, via the new :paramref:`.Table.comment` and :paramref:`.Column.comment` arguments. The comments are included as part of DDL on table creation, either inline or via an appropriate ALTER statement, and are also reflected back within table reflection, as well as via the :class:`.Inspector`. Supported backends currently include MySQL, Postgresql, and Oracle. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #1546 Change-Id: Ib90683850805a2b4ee198e420dc294f32f15d35d
* Consult compiled paramstyle on execute_compiledMike Bayer2017-03-151-1/+1
| | | | | | | | | | | | Fixed bug where in the unusual case of passing a :class:`.Compiled` object directly to :meth:`.Connection.execute`, the dialect with which the :class:`.Compiled` object were generated was not consulted for the paramstyle of the string statement, instead assuming it would match the dialect-level paramstyle, causing mismatches to occur. Change-Id: I114e4db2183fbb75bb7c0b0641f5a161855696ee Fixes: #3938
* Add "empty in" strategies; default to "static"Mike Bayer2017-03-142-0/+30
| | | | | | | | | | | | | | | The longstanding behavior of the :meth:`.Operators.in_` and :meth:`.Operators.not_in_` operators emitting a warning when the right-hand condition is an empty sequence has been revised; a new flag :paramref:`.create_engine.empty_in_strategy` allows an empty "IN" expression to generate a simple boolean expression, or to invoke the previous behavior of dis-equating the expression to itself, with or without a warning. The default behavior is now to emit the simple boolean expression, allowing an empty IN to be evaulated without any performance penalty. Change-Id: I65cc37f2d7cf65a59bf217136c42fee446929352 Fixes: #3907
* Accept FetchedValue, text() for column "default" valueMike Bayer2017-02-011-17/+17
| | | | | | | | | | | | | Fixed bug whereby the :meth:`.DDLEvents.column_reflect` event would not allow a non-textual expression to be passed as the value of the "default" for the new column, such as a :class:`.FetchedValue` object to indicate a generic triggered default or a :func:`.sql.expression.text` construct. Clarified the documentation in this regard as well. Fixes: #3905 Change-Id: I829796c3e9f87f375149bebee7eef133a6876d4d
* Better hide engine passwordValery Yundin2017-01-161-1/+1
| | | | | | | | | | Avoid putting engine password in the exception message in `MetaData.reflect` (since exception messages often appear in logs). Use the same redacted `__repr__` implementation in `TLEngine` as in its base class `Engine` Change-Id: Ic0a7baea917a9c8d87dffdd82ef566673ab08e02 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/327
* Support python3.6Mike Bayer2017-01-133-11/+11
| | | | | | | | | | | Corrects some warnings and adds tox config. Adds DeprecationWarning to the error category. Large sweep for string literals w/ backslashes as this is common in docstrings Co-authored-by: Andrii Soldatenko Fixes: #3886 Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
* update for 2017 copyrightMike Bayer2017-01-0410-10/+10
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* Add _extend_on deduplicating set for metadata.reflect()Mike Bayer2016-11-232-5/+16
| | | | | | | | | | | | | The "extend_existing" option of :class:`.Table` reflection would cause indexes and constraints to be doubled up in the case that the parameter were used with :meth:`.MetaData.reflect` (as the automap extension does) due to tables being reflected both within the foreign key path as well as directly. A new de-duplicating set is passed through within the :meth:`.MetaData.reflect` sequence to prevent double reflection in this way. Change-Id: Ibf6650c1e76a44ccbe15765fd79df2fa53d6bac7 Fixes: #3861
* Merge "Remove non-working Connection.default_schema_name() method"mike bayer2016-11-101-3/+0
|\
| * Remove non-working Connection.default_schema_name() methodBenjamin Dopplinger2016-11-101-3/+0
| | | | | | | | | | | | | | | | | | | | | | The method `engine.base.Connection.default_schema_name` is broken since 4b532e2 (this was when `engine.dialect.get_default_schema_name` was replaced with `engine.dialect.default_schema_name`). The method is unused and also is not functional for end-user use, so remove it for now. Change-Id: I6ffbd9ce1b9b54ff6df63ed45d7d33591f183933 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/321
* | Add support for server side cursors to mysqldb and pymysqlRoman Podoliaka2016-11-102-3/+45
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows to skip buffering of the results on the client side, e.g. the following snippet: table = sa.Table( 'testtbl', sa.MetaData(), sa.Column('id', sa.Integer, primary_key=True), sa.Column('a', sa.Integer), sa.Column('b', sa.String(512)) ) table.create(eng, checkfirst=True) with eng.connect() as conn: result = conn.execute(table.select().limit(1)).fetchone() if result is None: for _ in range(1000): conn.execute( table.insert(), [{'a': random.randint(1, 100000), 'b': ''.join(random.choice(string.ascii_letters) for _ in range(100))} for _ in range(1000)] ) with eng.connect() as conn: for row in conn.execution_options(stream_results=True).execute(table.select()): pass now uses ~23 MB of memory instead of ~327 MB on CPython 3.5.2 and PyMySQL 0.7.9. psycopg2 implementation and execution options (stream_results, server_side_cursors) are reused. Change-Id: I4dc23ce3094f027bdff51b896b050361991c62e2
* spelling: Postgresql -> PostgreSQLVille Skyttä2016-10-085-7/+7
|
* Spelling fixesVille Skyttä2016-10-083-5/+5
|
* Propagate execution_options at compile stageMike Bayer2016-10-051-2/+2
| | | | | | | | Compiler can now set up execution options and additionally will propagate autocommit from embedded CTEs. Change-Id: I19db7b8fe4d84549ea95342e8d2040189fed1bbe Fixes: #3805
* Check row for None with implicit returning PK to accommodate ON CONFLICTMike Bayer2016-10-041-1/+5
| | | | | | | | | | An adjustment to ON CONFLICT such that the "inserted_primary_key" logic is able to accommodate the case where there's no INSERT or UPDATE and there's no net change. The value comes out as None in this case, rather than failing on an exception. Change-Id: I0794e95c3ca262cb1ab2387167d96b8984225fce Fixes: #3813
* Handle BaseException in all _handle_dbapi_errorMike Bayer2016-09-213-30/+39
| | | | | | | | | | | | | | | | | Tests illustrate that exceptions like GreenletExit and even KeyboardInterrupt can corrupt the state of a DBAPI connection like that of pymysql and mysqlclient. Intercept BaseException errors within the handle_error scheme and invalidate just the connection alone in this case, but not the whole pool. The change is backwards-incompatible with a program that currently intercepts ctrl-C within a database transaction and wants to continue working on that transaction. Ensure the event hook can be used to reverse this behavior. Change-Id: Ifaa013c13826d123eef34e32b7e79fff74f1b21b Fixes: #3803
* Additions to support HAAlchemy pluginMike Bayer2016-09-163-2/+18
| | | | | | | | | | | | | | | | | | | - add a connect=True key to connection record to support pre-loading of _ConnectionRecord objects - ensure _ConnectionRecord.close() leaves the record in a good state for reopening - add _ConnectionRecord.record_info for persistent storage - add "in_use" accessor based on fairy_ref being present or not - allow for the exclusions system and SuiteRequirements to be usable without the full plugin_base setup. - move some Python-env requirements to the importable requirements.py module. - allow starttime to be queried - add additional events for engine plugins - have "dialect" be a first-class parameter to the pool, ensure the engine strategy supplies it up front Change-Id: Ibf549f7a1766e49d335cd6f5e26bacfaef9a8229
* Check for supports_execution at ClauseElement baseMike Bayer2016-08-312-5/+4
| | | | | | | | | | Raise a more descriptive exception / message when ClauseElement or non-SQLAlchemy objects that are not "executable" are erroneously passed to ``.execute()``; a new exception ObjectNotExecutableError is raised consistently in all cases. Change-Id: I2dd393121e2c7e5b6b9e40286a2f25670876e8e4 Fixes: #3786
* Work w/ prefetch even for selects, if presentMike Bayer2016-07-121-22/+37
| | | | | | | | | | | | | | | | | | | Fixed bug in new CTE feature for update/insert/delete stated as a CTE inside of an enclosing statement (typically SELECT) whereby oninsert and onupdate values weren't called upon for the embedded statement. This is accomplished by consulting prefetch for all statements. The collection is also broken into separate insert/update collections so that we don't need to consult toplevel self.isinsert to determine if the prefetch is for an insert or an update. What we don't yet test for are CTE combinations that have both insert/update in one statement, though these should now work in theory provided the underlying database supports such a statement. Change-Id: I3b6a860e22c86743c91c56a7ec751ff706f66f64 Fixes: #3745
* Implemented CHECK constraint reflection for SQLite and PostgreSQLAlex Grönholm2016-06-012-0/+66
| | | | | | Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Ie6cf2d2958d1c567324db9e08fef2d3186e97350 Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/80
* Merge remote-tracking branch 'origin/pr/270'Mike Bayer2016-05-241-1/+1
|\
| * Spelling fixes: "the a"Ville Skyttä2016-05-051-1/+1
| |
* | Merge remote-tracking branch 'origin/pr/274'Mike Bayer2016-05-241-1/+1
|\ \
| * | Fix typo in config result.py docspr/274vytotas2016-05-161-1/+1
| |/
* | Support "blank" schema when MetaData.schema is setMike Bayer2016-05-181-0/+1
|/ | | | | | | | | | | | | Previously, it was impossible to have a Table that has None for a schema name when the "schema" parameter on MetaData was set. A new symbol sqlalchemy.schema.BLANK_SCHEMA is added which indicates that the schema name should unconditionally be set to None. In particular, this value must be passed within cross-schema foreign key reflection, so that a Table which is in the "default" schema can be represented properly. Fixes: #3716 Change-Id: I3d24f99c22cded206c5379fd32a225e74edb7a8e
* Don't double-process ResultMetaData for BufferedColumnResultProxyMike Bayer2016-04-271-9/+15
| | | | | | | | | | | | Fixed a bug in the result proxy used mainly by Oracle when binary and other LOB types are in play, such that when query / statement caching were used, the type-level result processors, notably that required by the binary type itself but also any other processor, would become lost after the first run of the statement due to it being removed from the cached result metadata. Change-Id: I751940866cffb4f48de46edc8137482eab59790c Fixes: #3699
* Fix result set handling for case insensitive dupe colsMike Bayer2016-04-211-0/+1
| | | | | | | | | | | Fixed bug where when using ``case_sensitive=False`` with an :class:`.Engine`, the result set would fail to correctly accomodate for duplicate column names in the result set, causing an error when the statement is executed in 1.0, and preventing the "ambiguous column" exception from functioning in 1.1. Change-Id: If582bb9fdd057e4da3ae42f7180b17d1a1a2d98e Fixes: #3690
* Fix some broken links in docspr/255Ville Skyttä2016-04-041-1/+1
|
* - make sure negative row indexes are based on the size of theMike Bayer2016-03-301-1/+4
| | | | | | number of columns we're actually reporting on - add more tests for negative row index - changelog/migration
* Merge remote-tracking branch 'origin/pr/231' into pr231Mike Bayer2016-03-301-1/+8
|\
| * - properly handle negative indexes in RowProxy.__getitem__()pr/231Lele Gaifax2016-01-281-1/+8
| |
* | - Added basic isolation level support to the SQL Server dialectsMike Bayer2016-03-151-0/+2
| | | | | | | | | | | | via :paramref:`.create_engine.isolation_level` and :paramref:`.Connection.execution_options.isolation_level` parameters. fixes #3534
* | - reworked the way the "select_wraps_for" expression isMike Bayer2016-02-201-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | handled within visit_select(); this attribute was added in the 1.0 series to accommodate the subquery wrapping behavior of SQL Server and Oracle while also working with positional column targeting and no longer relying upon "key fallback" in order to target columns in such a statement. The IBM DB2 third-party dialect also has this use case, but its implementation is using regular expressions to rewrite the textual SELECT only and does not make use of a "wrapped" select at this time. The logic no longer attempts to reconcile proxy set collections as this was not deterministic, and instead assumes that the select() and the wrapper select() match their columns postionally, at least for the column positions they have in common, so it is now very simple and safe. fixes #3657. - as a side effect of #3657 it was also revealed that the strategy of calling upon a ResultProxy._getter was not correctly calling into NoSuchColumnError when an expected column was not present, and instead returned None up to loading.instances() to produce NoneType failures; added a raiseerr argument to _getter() which is called when we aren't expecting None, fixes #3658.
* | - All string formatting of bound parameter sets and result rows forMike Bayer2016-02-171-3/+3
| | | | | | | | | | | | | | | | | | logging, exception, and ``repr()`` purposes now truncate very large scalar values within each collection, including an "N characters truncated" notation, similar to how the display for large multiple-parameter sets are themselves truncated. fixes #2837
* | - happy new yearMike Bayer2016-01-2910-10/+10
|/
* - reinstate "dont set up integer index in keymap if we're on cexts",Mike Bayer2016-01-271-5/+10
| | | | | and this time also fix the cext itself to properly handle int vs. long on py2k
* Revert "- dont set up integer index in keymap if we're on cexts"Mike Bayer2016-01-271-10/+5
| | | | | | This reverts commit de0d144a395c31eb74084177df95a4858b830f88. Apparently the test suite is not using the cextensions correctly at the moment.
* - dont set up integer index in keymap if we're on cextsMike Bayer2016-01-271-5/+10
|