Commit Graph

1528 Commits

Author SHA1 Message Date
Mike Bayer f247bb2000 Documentation updates for ResultProxy -> Result
This is based off of
I8091919d45421e3f53029b8660427f844fee0228 and includes
all documentation-only changes as a separate merge,
once the parent is merged.

Change-Id: I711adea23df0f9f0b1fe7c76210bd2de6d31842d
2020-05-01 22:37:59 -04:00
Mike Bayer aded39f68c Propose Result as immediate replacement for ResultProxy
As progress is made on the _future.Result, including breaking
it out such that DBAPI behaviors are local to specific
implementations, it becomes apparent that the Result object
is a functional superset of ResultProxy and that basic
operations like fetchone(), fetchall(), and fetchmany()
behave pretty much exactly the same way on the new object.
Reorganize things so that ResultProxy is now referred to
as LegacyCursorResult, which subclasses CursorResult
that represents the DBAPI-cursor version of Result,
making use of a multiple inheritance pattern so that
the functionality of Result is also available in non-DBAPI
contexts, as will be necessary for some ORM
patterns.

Additionally propose the composition system for Result
that will form the basis for ORM-alternative result
systems such as horizontal sharding and dogpile cache.
As ORM results will soon be coming directly from
instances of Result, these extensions will instead
build their own ResultFetchStrategies that perform
the special steps to create composed or cached
result sets.

Also considering at the moment not emitting deprecation
warnings for fetchXYZ() methods; the immediate issue
is Keystone tests are calling upon it, but as the
implementations here are proving to be not in any
kind of conflict with how Result works, there's
not too much issue leaving them around and deprecating
at some later point.

References: #5087
References: #4395
Fixes: #4959
Change-Id: I8091919d45421e3f53029b8660427f844fee0228
2020-05-01 16:09:24 -04:00
mike bayer f911e191d6 Merge "Deprecate `DISTINCT ON` when not targeting PostgreSQL" 2020-04-20 17:15:54 +00:00
Federico Caselli 07d6d211f2 Deprecate `DISTINCT ON` when not targeting PostgreSQL
Deprecate usage of ``DISTINCT ON`` in dialect other than PostgreSQL.
Previously this was silently ignored.
Deprecate old usage of string distinct in MySQL dialect

Fixes: #4002
Change-Id: I38fc64aef75e77748083c11d388ec831f161c9c9
2020-04-20 11:28:51 -04:00
Gord Thompson 50cee43fbc Clean up .execute in test/sql/test_functions.py
Change-Id: I2bc7a50893f90c6ea7e119a8558731ee32965871
2020-04-20 07:46:24 -06:00
Mike Bayer 2f617f56f2 Create initial 2.0 engine implementation
Implemented the SQLAlchemy 2 :func:`.future.create_engine` function which
is used for forwards compatibility with SQLAlchemy 2.   This engine
features always-transactional behavior with autobegin.

Allow execution options per statement execution.  This includes
that the before_execute() and after_execute() events now accept
an additional dictionary with these options, empty if not
passed; a legacy event decorator is added for backwards compatibility
which now also emits a deprecation warning.

Add some basic tests for execution, transactions, and
the new result object.   Build out on a new testing fixture
that swaps in the future engine completely to start with.

Change-Id: I70e7338bb3f0ce22d2f702537d94bb249bd9fb0a
Fixes: #4644
2020-04-16 13:35:55 -04:00
Mike Bayer 8725d89aba Pass connection to TablesTest.insert_data()
towards the goal of reducing verbosity and repetition
in test fixtures as well as that we are moving to
connection only for execution, move the insert_data()
classmethod to accept a connection and adjust all
fixtures to use it.

Change-Id: I3bf534acca0d5f4cda1d4da8ae91f1155b829b09
2020-04-15 11:12:59 -04:00
mike bayer c9a27eac31 Merge "Clean up .execute in test/sql/test_returning.py" 2020-04-14 18:58:50 +00:00
mike bayer cc3c83a33a Merge "Clean up .execute in test/sql/test_query.py" 2020-04-14 18:57:34 +00:00
mike bayer 1ca0316cd7 Merge "Clean up .execute in test/sql/test_deprecations.py" 2020-04-14 18:54:24 +00:00
mike bayer 21dbd8aa0a Merge "Clean up .execute in test/sql/test_resultset.py" 2020-04-14 18:53:35 +00:00
Gord Thompson f947d744d0 Clean up .execute in test/sql/test_returning.py
Change-Id: I390b0c9926345f9f4deec06b51d1a11a18a72ca9
2020-04-14 05:59:46 -06:00
mike bayer 70fd8df5e3 Merge "Clean up .execute in test/sql/test_types.py" 2020-04-13 15:47:19 +00:00
mike bayer 2900ec572b Merge "Repair find tables" 2020-04-13 15:30:05 +00:00
Gord Thompson 4349e6ec97 Clean up .execute in test/sql/test_types.py
Change-Id: I917264ecefcc7e2fd60e7170a0a0ad83d8167571
2020-04-13 08:27:09 -06:00
Gord Thompson b4a835044d Clean up .execute in test/sql/test_query.py
Change-Id: I3f3a3b3f7a7ec67ef475a9792372e1c9a600fafb
2020-04-12 19:33:57 -06:00
Gord Thompson a731c005b8 Clean up .execute in test/sql/test_deprecations.py
Change-Id: I488f0992d5f26e164a903cbced11422046403647
2020-04-12 16:12:35 -06:00
Gord Thompson 6eb11d8777 Clean up .execute in test/sql/test_resultset.py
Change-Id: Ie4bb2b8e94361d15a3f1f1c21ce1c59cff1cf735
2020-04-12 13:37:48 -06:00
Federico Caselli 35b74d8a33 Add `comment attribute to :class:.Column __repr__` method.
Fixes #4138

Change-Id: Ia93f7d7b1d2f38509421725fbe152a2ff163d5f3
2020-04-11 20:50:37 +02:00
Mike Bayer 046934083b Repair CTE a in b tests
In I27cac9bd265c86ff2a3381ff9f844f60ef991cfc we modernized
the default tests and converted the "a in b" CTE tests to combinations,
however apparently the existing tests were not testing all
combinations and had repeats instead.   The combinations
decorator has made this much easier to spot, so use
the correct combinations that were originally intended.

Change-Id: Icd904887bff00c31525497d0b1508fabaf052dc9
2020-04-10 14:28:54 -04:00
mike bayer 1ff644d2f1 Merge "Remove code deprecated before version 1.1" 2020-04-10 17:52:47 +00:00
Mike Bayer fe59191303 Modernize test_defaults
Use modern execution patterns, goal is so that these same tests
can work for the future engine

break sequence tests into test_sequences suite

sequence tests that are testing implicit execution patterns
at least move into their own suite that will go into test_deprecations
eventually.

Change-Id: I27cac9bd265c86ff2a3381ff9f844f60ef991cfc
2020-04-10 10:47:15 -04:00
Mike Bayer 0aa38a9737 Repair find tables
The recipe given out on the ML for improving ABC
fails in 1.4 due to find_tables() missing out on subqueries,
which is due to the refactor of Alias into multiple sub-types.

Change-Id: Idd2803b26a84b28db28e0b8c328b8f24550577e4
2020-04-09 12:55:23 -04:00
Federico Caselli a9b068ae56 Remove code deprecated before version 1.1
- Remove deprecated method ``get_primary_keys` in the :class:`.Dialect` and
  :class:`.Inspector` classes.
- Remove deprecated event ``dbapi_error`` and the method ``ConnectionEvents.dbapi_error`.
- Remove support for deprecated engine URLs of the form ``postgres://``.
- Remove deprecated dialect ``mysql+gaerdbms``.
- Remove deprecated parameter ``quoting`` from :class:`.mysql.ENUM`
  and :class:`.mysql.SET` in the ``mysql`` dialect.
- Remove deprecated function ``comparable_property``. and function
  ``comparable_using`` in the declarative extension.
- Remove deprecated function ``compile_mappers``.
- Remove deprecated method ``collection.linker``.
- Remove deprecated method ``Session.prune`` and parameter ``Session.weak_identity_map``.
  This change also removes the class ``StrongInstanceDict``.
- Remove deprecated parameter ``mapper.order_by``.
- Remove deprecated parameter ``Session._enable_transaction_accounting`.
- Remove deprecated parameter ``Session.is_modified.passive``.
- Remove deprecated class ``Binary``. Please use :class:`.LargeBinary`.
- Remove deprecated methods ``Compiled.compile``, ``ClauseElement.__and__`` and
  ``ClauseElement.__or__`` and attribute ``Over.func``.
- Remove deprecated ``FromClause.count`` method.
- Remove deprecated parameter ``Table.useexisting``.
- Remove deprecated parameters ``text.bindparams`` and ``text.typemap``.

- Remove boolean support for the ``passive`` parameter in ``get_history``.
- Remove deprecated ``adapt_operator`` in ``UserDefinedType.Comparator``.

Fixes: #4643
Change-Id: Idcd390c77bf7b0e9957907716993bdaa3f1a1763
2020-04-09 00:33:22 +02:00
Mike Bayer 9243f6feea Ensure length parameter of Enum is adapted to new objects
Ensure length parameter added to Enum in
Iea05dc8cd9e33959bb968b394fb10a7dd068c873 is correctly propagated
to new enum objects adapted from this one.

Fixes: #5183

`

Change-Id: I7f20d926f73ec8260938963df87e29894c7e55e2
2020-04-06 16:19:23 -04:00
mike bayer 2d6146192f Merge "Add length parameter in Enum" 2020-04-06 20:11:20 +00:00
Federico Caselli a902660f71 Add length parameter in Enum
The `Enum` type now supports the parameter `Enum.length`
to specify the length of the VARCHAR column to create when using
non native enums by setting `Enum.native_enum` to `False`

Fixes: #5183
Change-Id: Iea05dc8cd9e33959bb968b394fb10a7dd068c873
2020-04-06 20:02:28 +02:00
mike bayer 45dd5654a1 Merge "fix typo on testing.skip_if assertion" 2020-04-06 16:51:32 +00:00
Mike Bayer 49b6c50016 Repair caching / traversals for values
The test suite wasn't running the copy_internals most fixtures,
enable that and try to get all cases working.

Set up selectable.values to do tuple conversion within compilation
step.  at the same time, disable caching for selectable.values
for the moment and make it equivalent to dml_multi_values.

fix cache / compare / copy cases for dml_values and dml_multi_values
which weren't fully tested or covered.

Change-Id: I484ca6e9cb2b66c2e6a321698f2abc0838db1460
2020-04-01 19:25:23 -04:00
Mike Bayer a9b62055bf Try to measure new style caching in the ORM, take two
Supercedes: If78fbb557c6f2cae637799c3fec2cbc5ac248aaf

Trying to see if by making the cache key memoized, we
still can have the older "identity" form of caching
which is the cheapest of all, at the same time as the
newer "cache key each time" version that is not nearly
as cheap; but still much cheaper than no caching at all.

Also needed is a per-execution update of _keymap when
we invoke from a cached select, so that Column objects
that are anonymous or otherwise adapted will match up.
this is analogous to the adaption of bound parameters
from the cache key.

Adds test coverage for the keymap / construct_params()
 changes related to caching.  Also hones performance
to a large extent for statement construction and
cache key generation.

Also includes a new memoized attribute
approach that vastly simplifies the previous approach
of "group_expirable_memoized_property" and finally
integrates cleanly with _clone(), _generate(), etc.
no more hardcoding of attributes is needed, as well
as that most _reset_memoization() calls are no longer
needed as the reset is inherent in a _generate() call;
this also has dramatic performance improvements.

Change-Id: I95c560ffcbfa30b26644999412fb6a385125f663
2020-04-01 16:12:23 -04:00
Federico Caselli c99f6781d3 fix typo on testing.skip_if assertion
Change-Id: I3f2eeffb0b59971a6025f9ce69250d6421751d16
2020-04-01 19:15:49 +02:00
mike bayer ffcc16b114 Merge "String compiler can now literal compile datetime objects" 2020-03-30 13:57:08 +00:00
mike bayer 73f7f85d9d Merge "Add a third labeling mode for SELECT statements" 2020-03-30 13:06:04 +00:00
Mike Bayer a65d5c250e Add a third labeling mode for SELECT statements
Enhanced the disambiguating labels feature of the
:func:`~.sql.expression.select` construct such that when a select statement
is used in a subquery, repeated column names from different tables are now
automatically labeled with a unique label name, without the need to use the
full "apply_labels()" feature that conbines tablename plus column name.
The disambigated labels are available as plain string keys in the .c
collection of the subquery, and most importantly the feature allows an ORM
:func:`.orm.aliased` construct against the combination of an entity and an
arbitrary subquery to work correctly, targeting the correct columns despite
same-named columns in the source tables, without the need for an "apply
labels" warning.

The existing labeling style is now called
LABEL_STYLE_TABLENAME_PLUS_COL.  This labeling style will remain used
throughout the ORM as has been the case for over a decade, however,
the new disambiguation scheme could theoretically replace this scheme
entirely.  The new scheme would dramatically alter how SQL looks
when rendered from the ORM to be more succinct but arguably harder
to read.

The tablename_columnname scheme used by Join.c is unaffected here,
as that's still hardcoded to that scheme.

Fixes: #5221
Change-Id: Ib47d9e0f35046b3afc77bef6e65709b93d0c3026
2020-03-29 22:27:41 -04:00
Federico Caselli 4bd4b483e0 Remove support for python 3.4
Also remove no longer used compat code

Change-Id: Ifda239fd84b425e43f4028cb55a5b3b8efa4dfc6
2020-03-30 00:35:33 +02:00
Federico Caselli 83eb1b23cb String compiler can now literal compile datetime objects
Add ability to literal compile a :class:`DateTime`, :class:`Date`
or :class:"Time" when using the string dialect for debugging purposes.
This change does not impact real dialect implementation that retain
their current behavior.

Fixes: #5052
Change-Id: Ia3fad2be905c6d35b0106b9a2388c7508f067e90
2020-03-29 18:08:40 -04:00
mike bayer 7ab1a62d88 Merge "Implement SQL VALUES in core." 2020-03-24 19:55:44 +00:00
mike bayer fa1f67a01e Merge "Convert schema_translate to a post compile" 2020-03-24 19:53:14 +00:00
Mike Bayer cadfc608d6 Convert schema_translate to a post compile
Revised the :paramref:`.Connection.execution_options.schema_translate_map`
feature such that the processing of the SQL statement to receive a specific
schema name occurs within the execution phase of the statement, rather than
at the compile phase.   This is to support the statement being efficiently
cached.   Previously, the current schema being rendered into the statement
for a particular run would be considered as part of the cache key itself,
meaning that for a run against hundreds of schemas, there would be hundreds
of cache keys, rendering the cache much less performant.  The new behavior
is that the rendering is done in a similar  manner as the "post compile"
rendering added in 1.4 as part of 🎫`4645`, 🎫`4808`.

Fixes: #5004
Change-Id: Ia5c89eb27cc8dc2c5b8e76d6c07c46290a7901b6
2020-03-24 14:25:41 -04:00
Gord Thompson 8e3a05ab98 Implement SQL VALUES in core.
Added a core :class:`Values` object that enables a VALUES construct
to be used in the FROM clause of an SQL statement for databases that
support it (mainly PostgreSQL and SQL Server).

Fixes: #4868
Closes: #5030
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5030
Pull-request-sha: 84684038a8

Change-Id: Ib8109b63bc1a9dc04ab987c5322ca3375f7e824d
2020-03-24 14:05:19 -04:00
Mike Bayer 0a4f7f38ce Remove deprecated elements from selectable.py; remove lockmode
Removed autocommit and legacy "for update" / "lockmode" elements
from selectable.py / query.py.  lockmode was removed from
selectable in 693938dd6f
however was not removed from the ORM.

Also removes the ignore_nonexistent_tables option on
join().

Change-Id: I0cfcf9e6a8d4ef6432c9e25ef75173b3b3f5fd87
Partially-fixes: #4643
2020-03-23 14:06:13 -04:00
Federico Caselli 9ec7588220 Deprecate plain string in execute and introduce exec_driver_sql
Execution of literal sql string is deprecated in the
:meth:`.Connection.execute` and a warning is raised when used stating
that it will be coerced to :func:`.text` in a future release.
To execute a raw sql string the new connection method
:meth:`.Connection.exec_driver_sql` was added, that will retain the previous
behavior, passing the string to the DBAPI driver unchanged.
Usage of scalar or tuple positional parameters in :meth:`.Connection.execute`
is also deprecated.

Fixes: #4848
Fixes: #5178
Change-Id: I2830181054327996d594f7f0d59c157d477c3aa9
2020-03-21 17:03:45 -04:00
Mike Bayer 693938dd6f Rework select(), CompoundSelect() in terms of CompileState
Continuation of I408e0b8be91fddd77cf279da97f55020871f75a9

- add an options() method to the base Generative construct.
this will be where ORM options can go
- Change Null, False_, True_ to be singletons, so that
we aren't instantiating them and having to use isinstance.
The previous issue with this was that they would produce dupe
labels in SELECT statements.   Apply the duplicate column
logic, newly added in 1.4, to these objects as well as to
non-apply-labels SELECT statements in general as a means of
improving this.
- create a revised system for generating ClauseList compilation
constructs that simplfies up front creation to not actually
use ClauseList; a simple tuple is rendered by the compiler
using the same constrcution rules as what are used for
ClauseList but without creating the actual object.  Apply
to Select, CompoundSelect, revise Update, Delete
- Select, CompoundSelect get an initial CompileState
implementation.  All methods used only within compilation
are moved here
- refine update/insert/delete compile state to not require
an outside boolean
- refine and simplify Select._copy_internals
- rework bind(), which is going away, to not use some
of the internal traversal stuff
- remove "autocommit", "for_update" parameters from Select,
  references #4643
- remove "autocommit" parameter from TextClause ,
  references #4643
- add deprecation warnings for statement.execute(),
engine.execute(), statement.scalar(), engine.scalar().
Fixes: #5193

Change-Id: I04ca0152b046fd42c5054ba10f37e43fc6e5a57b
2020-03-10 16:55:03 -04:00
Mike Bayer 851fb8f5a6 Decouple compiler state from DML objects; make cacheable
Targeting select / insert / update / delete, the goal
is to minimize overhead of construction and generative methods
so that only the raw arguments passed are handled.   An interim
stage that converts the raw state into more compiler-ready state
is added, which is analogous to the ORM QueryContext which will
also be rolled in to be a similar concept, as is currently
being prototyped in I19e05b3424b07114cce6c439b05198ac47f7ac10.
the ORM update/delete BulkUD concept is also going to be rolled
onto this idea.   So while the compiler-ready state object,
here called DMLState, looks a little thin, it's the
base of a bigger pattern that will allow for ORM functionality
to embed itself directly into the compiler, execution
context, and result set objects.

This change targets the DML objects, primarily focused on the
values() method which is the most complex process.   The
work done by values() is minimized as much as possible
while still being able to create a cache key.   Additional
computation is then offloaded to a new object ValuesState
that is handled by the compiler.

Architecturally, a big change here is that insert.values()
and update.values() will generate BindParameter objects for
the values now, which are then carefully received by crud.py
so that they generate the expected names.   This is so that
the values() portion of these constructs is cacheable.
for the "multi-values" version of Insert, this is all skipped
and the plan right now is that a multi-values insert is
not worth caching (can always be revisited).

Using the
coercions system in values() also gets us nicer validation
for free, we can remove the NotAClauseElement thing from
schema, and we also now require scalar_subquery() is called
for an insert/update that uses a SELECT as a column value,
1.x deprecation path is added.

The traversal system is then applied to the DML objects
including tests so that they have traversal, cloning, and
cache key support.  cloning is not a use case for DML however
having it present allows better validation of the structure
within the tests.

Special per-dialect DML is explicitly not cacheable at the moment,
more as a proof of concept that third party DML constructs can
exist as gracefully not-cacheable rather than producing an
incomplete cache key.

A few selected performance improvements have been added as well,
simplifying the immutabledict.union() method and adding
a new SQLCompiler function that can generate delimeter-separated
clauses like WHERE and ORDER BY without having to build
a ClauseList object at all.   The use of ClauseList will
be removed from Select in an upcoming commit.  Overall,
ClaustList is unnecessary for internal use and only adds
overhead to statement construction and will likely be removed
as much as possible except for explcit use of conjunctions like
and_() and or_().

Change-Id: I408e0b8be91fddd77cf279da97f55020871f75a9
2020-03-06 11:01:51 -05:00
Mike Bayer 7fe400f546 Restore crud flags if visiting_cte is set
Fixed bug where a CTE of an INSERT/UPDATE/DELETE that also uses RETURNING
could then not be SELECTed from directly, as the internal state of the
compiler would try to treat the outer SELECT as a DELETE statement itself
and access nonexistent state.

Fixes: #5181
Change-Id: Icba76f2148c8344baa1c04bac4ab6c6d24f23072
2020-03-03 17:23:56 -05:00
Mike Bayer 57dc36a01b Ensure all nested exception throws have a cause
Applied an explicit "cause" to most if not all internally raised exceptions
that are raised from within an internal exception catch, to avoid
misleading stacktraces that suggest an error within the handling of an
exception.  While it would be preferable to suppress the internally caught
exception in the way that the ``__suppress_context__`` attribute would,
there does not as yet seem to be a way to do this without suppressing an
enclosing user constructed context, so for now it exposes the internally
caught exception as the cause so that full information about the context
of the error is maintained.

Fixes: #4849
Change-Id: I55a86b29023675d9e5e49bc7edc5a2dc0bcd4751
2020-03-02 17:24:19 -05:00
Mike Bayer ca2e4f3858 Discontinue dynamic __visit_name__
Removed very antiquated logic that checks if __visit_name__
is a property.  There's no need for this as the compiler can handle
switching between implementations.  Convert _compile_dispatch()
to be fully inlined.

Change-Id: Ic0c7247c2d7dfed93a27f09250a8ed6352370764
2020-03-01 19:32:48 -05:00
Mike Bayer 5d42051c2e Deprecate row.keys() for 2.0, not 1.x
row.keys() is used by any use case that applies dict() to
a row.  Access of elements by string key is also a 2.0 deprecation
not 1.4 so for rudimental dict(row) support make sure that is all
a 2.0 thing.

Fixes current Alembic test suite.

Change-Id: I895496324133d615676cd76bc5f2c5f4a83e9131
2020-02-24 13:54:37 -05:00
mike bayer 955f4a27c3 Merge "Ensure schema-level table includes annotations in caching" 2020-02-24 18:41:56 +00:00
Mike Bayer 996654df34 Ensure schema-level table includes annotations in caching
In 29330ec159 we ensured that annotations are part of cache keys.
However we failed to do so for the schema-level Table which
will definitely need to distinguish between ORM and non-ORM
annotated tables when caching, so ensure this is part of the
cache key.

Change-Id: I8d996873f2d7fa63230ef837db7e69a0101973b2
2020-02-24 10:47:05 -05:00