Commit Graph

1007 Commits

Author SHA1 Message Date
Mike Bayer ceaa6047ef - More fixes to SQLite "join rewriting"; the fix from 🎫2967
implemented right before the release of 0.9.3 affected the case where
a UNION contained nested joins in it.   "Join rewriting" is a feature
with a wide range of possibilities and is the first intricate
"SQL rewriting" feature we've introduced in years, so we're sort of
going through a lot of iterations with it (not unlike eager loading
back in the 0.2/0.3 series, polymorphic loading in 0.4/0.5). We should
be there soon so thanks for bearing with us :).
fixes #2969   re: #2967
- solve the issue of join rewriting inspecting various types of
from objects without using isinstance(), by adding some new
underscored inspection flags to the FromClause hierarchy.
2014-02-20 16:14:29 -05:00
Mike Bayer a4f1d2ec6e skip this on oracle 2014-02-19 20:15:30 -05:00
Mike Bayer 69d1d08dc3 - re: #2967, also fixed a somewhat related issue where join rewriting would fail
on the columns clause of the SELECT statement if the targets were
aliased tables, as opposed to individual aliased columns.
2014-02-19 19:12:40 -05:00
Mike Bayer 25831872db - Fixed bug in SQLite "join rewriting" where usage of an exists() construct
would fail to be rewritten properly, such as when the exists is
mapped to a column_property in an intricate nested-join scenario. #2967
2014-02-19 19:04:04 -05:00
Mike Bayer 77ed036525 - Fixed bug where calling :meth:.Insert.values with an empty list
or tuple would raise an IndexError.   It now produces an empty
insert construct as would be the case with an empty dictionary.
2014-02-19 15:18:22 -05:00
Mike Bayer 036cb93abf - Fixed bug where :meth:.in_() would go into an endless loop if
erroneously passed a column expression whose comparator included
the ``__getitem__()`` method, such as a column that uses the
:class:`.postgresql.ARRAY` type. [ticket:2957]
2014-02-13 15:19:12 -05:00
Mike Bayer bf934018a5 - for TextAsFrom, put the "inner" columns in the result map directly.
Have also considered linking column.label() to the "column" itself being
in the result map but this reveals some naming collision problems (that
also seem to be very poorly tested...).   This should be as far as
we want to go right now with [ticket:2932].
2014-02-10 19:17:00 -05:00
Mike Bayer 5c188f6c1c - More issues with [ticket:2932] first resolved in 0.9.2 where
using a column key of the form ``<tablename>_<columnname>``
matching that of an aliased column in the text would still not
match at the ORM level, which is ultimately due to a core
column-matching issue.  Additional rules have been added so that the
column ``_label`` is taken into account when working with a
:class:`.TextAsFrom` construct or with literal columns.
[ticket:2932]
2014-02-05 19:25:13 -05:00
Mike Bayer c5dccd82da - Fixed regression in new "naming convention" feature where conventions
would fail if the referred table in a foreign key contained a schema
name.  Pull request courtesy Thomas Farvour. pullreq github:67
2014-02-05 16:54:31 -05:00
Mike Bayer 16cd07c4f8 - Fixed bug where so-called "literal render" of :func:.bindparam
constructs would fail if the bind were constructed with a callable,
rather than a direct value.  This prevented ORM expressions
from being rendered with the "literal_binds" compiler flag.
2014-02-05 12:03:46 -05:00
Mike Bayer 2d4b457924 - The behavior of :meth:.Table.tometadata has been adjusted such that
the schema target of a :class:`.ForeignKey` will not be changed unless
that schema matches that of the parent table.  That is, if
a table "schema_a.user" has a foreign key to "schema_b.order.id",
the "schema_b" target will be maintained whether or not the
"schema" argument is passed to :meth:`.Table.tometadata`.  However
if a table "schema_a.user" refers to "schema_a.order.id", the presence
of "schema_a" will be updated on both the parent and referred tables.
This is a behavioral change hence isn't likely to be backported to
0.8; it is assumed that the previous behavior is pretty buggy
however and that it's unlikely anyone was relying upon it.

Additionally, a new parameter has been added
:paramref:`.Table.tometadata.referred_schema_fn`.  This refers to a
callable function which will be used to determine the new referred
schema for any :class:`.ForeignKeyConstraint` encountered in the
tometadata operation.  This callable can be used to revert to the
previous behavior or to customize how referred schemas are treated
on a per-constraint basis.  [ticket:2913]

- rework the tests in test.sql.test_metadata, all the "tometadata" tests
now under new class ToMetaDataTest
2014-02-02 14:37:43 -05:00
Mike Bayer 29de1077b3 - Fixed bug in new :class:.TextAsFrom construct where :class:.Column-
oriented row lookups were not matching up to the ad-hoc :class:`.ColumnClause`
objects that :class:`.TextAsFrom` generates, thereby making it not
usable as a target in :meth:`.Query.from_statement`.  Also fixed
:meth:`.Query.from_statement` mechanics to not mistake a :class:`.TextAsFrom`
for a :class:`.Select` construct.  This bug is also an 0.9 regression
as the :meth:`.Text.columns` method is called to accommodate the
:paramref:`.text.typemap` argument. [ticket:2932]
2014-02-02 11:06:08 -05:00
Mike Bayer 5b0919f3f5 - Added a new feature which allows automated naming conventions to be
applied to :class:`.Constraint` and :class:`.Index` objects.  Based
on a recipe in the wiki, the new feature uses schema-events to set up
names as various schema objects are associated with each other.  The
events then expose a configuration system through a new argument
:paramref:`.MetaData.naming_convention`.  This system allows production
of both simple and custom naming schemes for constraints and indexes
on a per-:class:`.MetaData` basis.  [ticket:2923]

commit 7e65e52c086652de3dd3303c723f98f09af54db8
Author: Mike Bayer <mike_mp@zzzcomputing.com>
Date:   Sat Feb 1 15:09:04 2014 -0500

    - first pass at new naming approach
2014-02-01 18:21:04 -05:00
Mike Bayer 32a1db3685 add a skip for oracle on this 2014-02-01 13:22:43 -05:00
Mike Bayer 6b3ecd14ea - Added a new parameter :paramref:.Operators.op.is_comparison. This
flag allows a custom op from :meth:`.Operators.op` to be considered
as a "comparison" operator, thus usable for custom
:paramref:`.relationship.primaryjoin` conditions.
2014-01-31 19:14:08 -05:00
Mike Bayer b360dbf7eb - Fixed bug whereby SQLite compiler failed to propagate compiler arguments
such as "literal binds" into a CAST expression.
- Fixed bug whereby binary type would fail in some cases
if used with a "test" dialect, such as a DefaultDialect or other
dialect with no DBAPI.
- Fixed bug where "literal binds" wouldn't work with a bound parameter
that's a binary type.  A similar, but different, issue is fixed
in 0.8.
2014-01-31 17:57:17 -05:00
Mike Bayer 8afb69ced8 - Fixed regression whereby the "annotation" system used by the ORM was leaking
into the names used by standard functions in :mod:`sqlalchemy.sql.functions`,
such as ``func.coalesce()`` and ``func.max()``.  Using these functions
in ORM attributes and thus producing annotated versions of them could
corrupt the actual function name rendered in the SQL. [ticket:2927]
2014-01-29 17:33:28 -05:00
Mike Bayer 00e78f5f76 - better way to do it 2014-01-29 14:57:18 -05:00
Mike Bayer 7d56e4f135 - add TypeError handling to the tests here, ensure TypeError
for the control is a TypeError for the row, as is raised on py3k when
less/greater operators are used on incompatible types
2014-01-29 14:55:58 -05:00
Mike Bayer d4c908ded1 - Fixed 0.9 regression where the new sortable support for :class:.RowProxy
would lead to ``TypeError`` when compared to non-tuple types as it attempted
to apply tuple() to the "other" object unconditionally.  The
full range of Python comparison operators have now been implemented on
:class:`.RowProxy`, using an approach that guarantees a comparison
system that is equivalent to that of a tuple, and the "other" object
is only coerced if it's an instance of RowProxy. [ticket:2924]
2014-01-28 23:43:14 -05:00
Mike Bayer 15b23c7f71 - Fixed an 0.9 regression where the automatic aliasing applied by
:class:`.Query` and in other situations where selects or joins
were aliased (such as joined table inheritance) could fail if a
user-defined :class:`.Column` subclass were used in the expression.
In this case, the subclass would fail to propagate ORM-specific
"annotations" along needed by the adaptation.  The "expression
annotations" system has been corrected to account for this case.
[ticket:2918]
2014-01-23 14:49:04 -05:00
Mike Bayer 1732414076 - Added new test coverage for so-called "down adaptions" of SQL types,
where a more specific type is adapted to a more generic one - this
use case is needed by some third party tools such as ``sqlacodegen``.
The specific cases that needed repair within this test suite were that
of :class:`.mysql.ENUM` being downcast into a :class:`.types.Enum`,
and that of SQLite date types being cast into generic date types.
The ``adapt()`` method needed to become more specific here to counteract
the removal of a "catch all" ``**kwargs`` collection on the base
:class:`.TypeEngine` class that was removed in 0.9. [ticket:2917]
2014-01-22 15:38:00 -05:00
Mike Bayer b9318c9863 - Fixed the multiple-table "UPDATE..FROM" construct, only usable on
MySQL, to correctly render the SET clause among multiple columns
with the same name across tables.  This also changes the name used for
the bound parameter in the SET clause to "<tablename>_<colname>" for
the non-primary table only; as this parameter is typically specified
using the :class:`.Column` object directly this should not have an
impact on applications.   The fix takes effect for both
:meth:`.Table.update` as well as :meth:`.Query.update` in the ORM.
[ticket:2912]
2014-01-20 21:17:42 -05:00
Mike Bayer 49f1807f8f - simplify the mechanics of PrimaryKeyConstraint with regards to reflection;
reflection now updates the PKC in place.
- support the use case of the empty PrimaryKeyConstraint in order to specify
constraint options; the columns marked as primary_key=True will now be gathered
into the columns collection, rather than being ignored. [ticket:2910]
- add validation such that column specification should only take place
in the PrimaryKeyConstraint directly, or by using primary_key=True flags;
if both are present, they have to match exactly, otherwise the condition is
assumed to be ambiguous, and a warning is emitted; the old behavior of
using the PKC columns only is maintained.
2014-01-20 18:06:18 -05:00
Mike Bayer 3dc9f9b3db - alter behavior such that dialect_kwargs is still immutable, but
now represents exactly the kwargs that were passed, and not the defaults.
the defaults are still in dialect_options.  This allows repr() schemes such as that
of alembic to not need to look through and compare for defaults.
2014-01-19 16:32:36 -05:00
Mike Bayer 8e1a4fdced - some test fixes
- clean up some shenanigans in reflection
2014-01-19 00:34:37 -05:00
Mike Bayer 1af8e2491d - implement kwarg validation and type system for dialect-specific
arguments; [ticket:2866]
- add dialect specific kwarg functionality to ForeignKeyConstraint, ForeignKey
2014-01-18 19:26:56 -05:00
Mike Bayer 6e4fd0aea8 Merge branch 'patch-msql-pkc-clustered' of bitbucket.org:dharland/sqlalchemy into m 2014-01-18 15:06:08 -05:00
Mike Bayer 931655f417 cx_oracle is now "conditional" on py2k 2014-01-17 18:52:14 -05:00
donkopotamus cf8e5e3cf5 Bug Fix: Stop generating bad sql if an empty UniqueConstraint() is given 2014-01-17 11:00:24 +13:00
Mike Bayer 196f7ee6cc - conjunctions like and_() and or_() can now accept generators as arguments. 2014-01-05 14:11:12 -05:00
Mike Bayer 2537773d1e a few oracle test failures 2013-12-28 18:24:43 -05:00
Mike Bayer cac7320eeb - adjust the behavior of cast() to only provide a type for the bindparam()
if we are coercing straight from string.  [ticket:2899]
- rework the tests here to be individual
2013-12-28 16:37:54 -05:00
Mike Bayer 65bd6ec966 - Fixed issue where a primary key column that has a Sequence on it,
yet the column is not the "auto increment" column, either because
it has a foreign key constraint or ``autoincrement=False`` set,
would attempt to fire the Sequence on INSERT for backends that don't
support sequences, when presented with an INSERT missing the primary
key value.  This would take place on non-sequence backends like
SQLite, MySQL. [ticket:2896]
2013-12-20 10:26:09 -05:00
Mike Bayer 5f76f29c15 - Fixed bug with :meth:.Insert.from_select method where the order
of the given names would not be taken into account when generating
the INSERT statement, thus producing a mismatch versus the column
names in the given SELECT statement.  Also noted that
:meth:`.Insert.from_select` implies that Python-side insert defaults
cannot be used, since the statement has no VALUES clause. [ticket:2895]
2013-12-19 16:02:14 -05:00
Mike Bayer 2692238f45 - Improvements to the system by which SQL types generate within
``__repr__()``, particularly with regards to the MySQL integer/numeric/
character types which feature a wide variety of keyword arguments.
The ``__repr__()`` is important for use with Alembic autogenerate
for when Python code is rendered in a migration script.
[ticket:2893]
2013-12-18 18:26:15 -05:00
Mike Bayer f701f87c13 - skip this test for oracle 2013-12-18 14:02:40 -05:00
Mike Bayer be06bcf3b9 - remove very ancient TypeEngine constructor, not used by anything 2013-12-17 17:56:03 -05:00
Mike Bayer 80b6591dbe - The :func:.cast function, when given a plain literal value,
will now apply the given type to the given literal value on the
bind parameter side according
to the type given to the cast.   This essentially replaces what would
normally be the detected type of the literal value.   This only
takes effect if the auto-detected type of the literal value is either
"nulltype" (e.g. couldn't detect)
or a type that is of the same "affinity" as the cast type.
The net change here is that the :func:`.cast` function includes more
of the functionality already present in the :func:`.type_coerce` function.
2013-12-17 15:38:35 -05:00
Mike Bayer 207aaf2f41 - for [ticket:2651], leaving CheckConstraint alone, preferring to keep
backwards compatibility.  A note about backslashing escapes is added.
Because the Text() construct now supports bind params better, the example
given in the code raises an exception now, so that should cover us.
The exception itself has been enhanced to include the key name of the
bound param.  We're backporting this to 0.8 but 0.8 doesn't have the
text->bind behavior that raises.
2013-12-16 19:32:10 -05:00
Mike Bayer d5384d6011 - implement "literal binds" for the text() clause, [ticket:2882] 2013-12-11 20:00:39 -05:00
Mike Bayer 84af7e6c22 - The :class:.ForeignKey class more aggressively checks the given
column argument.   If not a string, it checks that the object is
at least a :class:`.ColumnClause`, or an object that resolves to one,
and that the ``.table`` attribute, if present, refers to a
:class:`.TableClause` or subclass, and not something like an
:class:`.Alias`.  Otherwise, a :class:`.ArgumentError` is raised.
[ticket:2883]
2013-12-11 19:48:27 -05:00
Mike Bayer b653fb3a23 - The precedence rules for the :meth:.ColumnOperators.collate operator
have been modified, such that the COLLATE operator is now of lower
precedence than the comparison operators.  This has the effect that
a COLLATE applied to a comparison will not render parenthesis
around the comparison, which is not parsed by backends such as
MSSQL.  The change is backwards incompatible for those setups that
were working around the issue by applying :meth:`.Operators.collate`
to an individual element of the comparison expression,
rather than the comparison expression as a whole. [ticket:2879]
2013-12-05 19:03:31 -05:00
Mike Bayer 207fafe7e3 - add support for bindparam() called from AsFromText
- get PG dialect to work around "no nonexistent binds" rule for now,
though we might want to reconsider this behavior
2013-11-29 19:06:33 -05:00
Mike Bayer 6c83ef761b - New improvements to the :func:.text construct, including
more flexible ways to set up bound parameters and return types;
in particular, a :func:`.text` can now be turned into a full
FROM-object, embeddable in other statements as an alias or CTE
using the new method :meth:`.TextClause.columns`.
[ticket:2877]
2013-11-29 15:05:19 -05:00
Mike Bayer 31cecebd48 - add support for specifying tables or entities for "of"
- implement Query with_for_update()
- rework docs and tests
2013-11-28 23:23:27 -05:00
Mike Bayer 4aaf3753d7 - fix up rendering of "of"
- move out tests, dialect specific out of compiler, compiler tests use new API,
legacy API tests in test_selecatble
- add support for adaptation of ForUpdateArg, alias support in compilers
2013-11-28 22:25:09 -05:00
Mike Bayer bb60a8ad94 - work in progress, will squash 2013-11-28 12:37:15 -05:00
Mike Bayer f112dc1d53 - Fixed bug where SQL statement would be improperly ASCII-encoded
when a pre-DBAPI :class:`.StatementError` were raised within
:meth:`.Connection.execute`, causing encoding errors for
non-ASCII statements.  The stringification now remains within
Python unicode thus avoiding encoding errors. [ticket:2871]
2013-11-22 18:35:36 -05:00
Mike Bayer 9499b88f85 fix [ticket:2868] some more 2013-11-21 15:39:05 -05:00