Commit Graph

25 Commits

Author SHA1 Message Date
Mike Bayer 1fcbc17b7d Support hybrids/composites with bulk updates
The :meth:`.Query.update` method can now accommodate both
hybrid attributes as well as composite attributes as a source
of the key to be placed in the SET clause.   For hybrids, an
additional decorator :meth:`.hybrid_property.update_expression`
is supplied for which the user supplies a tuple-returning function.

Change-Id: I15e97b02381d553f30b3301308155e19128d2cfb
Fixes: #3229
2017-03-22 17:44:56 -04:00
Mike Bayer c90f0a49f3 - Added support for parameter-ordered SET clauses in an UPDATE
statement.  This feature is available by passing the
:paramref:`~.sqlalchemy.sql.expression.update.preserve_parameter_order`
flag either to the core :class:`.Update` construct or alternatively
adding it to the :paramref:`.Query.update.update_args` dictionary at
the ORM-level, also passing the parameters themselves as a list of 2-tuples.
Thanks to Gorka Eguileor for implementation and tests.
adapted from pullreq github:200
2015-11-28 14:30:05 -05:00
Mike Bayer c19ea20875 Merge remote-tracking branch 'origin/pr/164' into pr164 2015-04-03 17:48:19 -04:00
Mike Bayer fe19227641 - :class:.Query doesn't support joins, subselects, or special
FROM clauses when using the :meth:`.Query.update` or
:meth:`.Query.delete` methods; instead of silently ignoring these
fields if methods like :meth:`.Query.join` or
:meth:`.Query.select_from` has been called, an error is raised.
In 0.9.10 this only emits a warning.
fixes #3349
- don't needlessly call _compile_context() and build up a
whole statement that we never need.  Construct QueryContext
as it's part of the event contract, but don't actually call upon
mapper attributes; use more direct systems of determining the
update or delete table.
- don't realy need _no_select_modifiers anymore
2015-04-01 19:37:43 -04:00
Amir Sadoughi 3365a4f78e Allow kwargs to be passed through update()
This is useful to be able to pass in mysql_limit=1 from using the
ORM.
2015-03-20 17:04:29 -05:00
Mike Bayer 61a4a89d99 - The :meth:.Query.update method will now convert string key
names in the given dictionary of values into mapped attribute names
against the mapped class being updated.  Previously, string names
were taken in directly and passed to the core update statement without
any means to resolve against the mapped entity.  Support for synonyms
and hybrid attributes as the subject attributes of
:meth:`.Query.update` are also supported.
fixes #3228
2014-10-16 14:36:56 -04:00
Mike Bayer a02664869c - fix imports
- pep8
2014-10-16 13:30:51 -04:00
Mike Bayer 7c6a45c480 - The :func:~.expression.column and :func:~.expression.table
constructs are now importable from the "from sqlalchemy" namespace,
just like every other Core construct.
- The implicit conversion of strings to :func:`.text` constructs
when passed to most builder methods of :func:`.select` as
well as :class:`.Query` now emits a warning with just the
plain string sent.   The textual conversion still proceeds normally,
however.  The only method that accepts a string without a warning
are the "label reference" methods like order_by(), group_by();
these functions will now at compile time attempt to resolve a single
string argument to a column or label expression present in the
selectable; if none is located, the expression still renders, but
you get the warning again. The rationale here is that the implicit
conversion from string to text is more unexpected than not these days,
and it is better that the user send more direction to the Core / ORM
when passing a raw string as to what direction should be taken.
Core/ORM tutorials have been updated to go more in depth as to how text
is handled.
fixes #2992
2014-09-01 20:19:54 -04:00
Mike Bayer 450453ab1a -do an autoflake8 here 2014-07-08 19:22:44 -04:00
Mike Bayer e38bb315fd - The "evaulator" for query.update()/delete() won't work with multi-table
updates, and needs to be set to `synchronize_session=False` or
`synchronize_session='fetch'`; this now raises an exception, with a
message to change the synchronize setting.  This will be only a warning
in 0.9.7.  fixes #3117
2014-07-08 19:08:42 -04:00
Mike Bayer 50d19f55d2 - add some more rules to make sure all tests run if DBs are available 2014-03-24 12:49:22 -04: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 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer 9dd08c2eca Fixed regression where query.update() would produce
an error if an object matched by the "fetch"
synchronization strategy wasn't locally present.
Courtesy Scott Torborg. [ticket:2602]
2012-11-12 12:44:42 -05:00
Scott Torborg 52e8dcda6d added test of synchronize_session='fetch' on rows which are not already in the session, and patch to fix failure 2012-11-10 15:01:30 -08:00
Mike Bayer 40af03f887 - add some UPDATE..FROM tests and also some new reqs 2012-10-12 13:20:56 -04:00
Mike Bayer 6704bd40e8 - start adding ORM-level tests for plain UPDATE..FROM scenarios. 2012-10-12 12:17:03 -04:00
Mike Bayer be40b51cb0 getting everything to pass again 2012-09-27 16:33:54 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 0c101f764d - MySQL's update does work. add some logic to compiler to convert from ORM column to Table column 2012-08-20 18:28:32 -04:00
Mike Bayer 2ccd77e5dc - [feature] The Query.update() method is now
more lenient as to the table
being updated.  Plain Table objects are better
supported now, and additional a joined-inheritance
subclass may be used with update(); the subclass
table will be the target of the update,
and if the parent table is referenced in the
WHERE clause, the compiler will call upon
UPDATE..FROM syntax as allowed by the dialect
to satisfy the WHERE clause.  Target columns
must still be in the target table i.e.
does not support MySQL's multi-table update
feature (even though this is in Core).
PG's DELETE..USING is also not available
in Core yet.
2012-08-20 18:18:17 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer f10c2f3dc3 - refactor query.update() and query.delete() to use a pure
template method pattern using new class hierarchy BulkUD
in sqlalchemy.orm.persistence
2012-04-29 18:53:29 -04:00
Mike Bayer fbf0c60800 fix tests so that document related is in a separate fixture base 2011-04-07 13:38:12 -04:00
Mike Bayer 708a25e76a - Some fixes to "evaulate" and "fetch" evaluation
when query.update(), query.delete() are called.
The retrieval of records is done after autoflush
in all cases, and before update/delete is
emitted, guarding against unflushed data present
as well as expired objects failing during
the evaluation.  [ticket:2122]
2011-04-07 12:49:29 -04:00