301
301
def _mapper_entities(self):
302
# TODO: this is wrong, its hardcoded to "primary entity" when
303
# for the case of __all_equivs() it should not be
304
# the name of this accessor is wrong too
305
302
for ent in self._entities:
306
if hasattr(ent, 'primary_entity'):
303
if isinstance(ent, _MapperEntity):
309
306
def _joinpoint_zero(self):
714
718
loading, the full result for all rows is fetched which generally
715
719
defeats the purpose of :meth:`~sqlalchemy.orm.query.Query.yield_per`.
717
Also note that many DBAPIs do not "stream" results, pre-buffering
718
all rows before making them available, including mysql-python and
719
psycopg2. :meth:`~sqlalchemy.orm.query.Query.yield_per` will also
720
set the ``stream_results`` execution
721
option to ``True``, which currently is only understood by psycopg2
722
and causes server side cursors to be used.
721
Also note that while :meth:`~sqlalchemy.orm.query.Query.yield_per`
722
will set the ``stream_results`` execution option to True, currently
723
this is only understood by :mod:`~sqlalchemy.dialects.postgresql.psycopg2` dialect
724
which will stream results using server side cursors instead of pre-buffer
725
all rows for this query. Other DBAPIs pre-buffer all rows before
726
making them available.
725
729
self._yield_per = count
2559
2563
The expression evaluator currently doesn't account for differing
2560
2564
string collations between the database and Python.
2562
Returns the number of rows deleted, excluding any cascades.
2564
The method does *not* offer in-Python cascading of relationships - it
2565
is assumed that ON DELETE CASCADE is configured for any foreign key
2566
references which require it. The Session needs to be expired (occurs
2567
automatically after commit(), or call expire_all()) in order for the
2568
state of dependent objects subject to delete or delete-orphan cascade
2569
to be correctly represented.
2571
Note that the :meth:`.MapperEvents.before_delete` and
2572
:meth:`.MapperEvents.after_delete`
2573
events are **not** invoked from this method. It instead
2574
invokes :meth:`.SessionEvents.after_bulk_delete`.
2566
:return: the count of rows matched as returned by the database's
2567
"row count" feature.
2569
This method has several key caveats:
2571
* The method does **not** offer in-Python cascading of relationships - it
2572
is assumed that ON DELETE CASCADE/SET NULL/etc. is configured for any foreign key
2573
references which require it, otherwise the database may emit an
2574
integrity violation if foreign key references are being enforced.
2576
After the DELETE, dependent objects in the :class:`.Session` which
2577
were impacted by an ON DELETE may not contain the current
2578
state, or may have been deleted. This issue is resolved once the
2579
:class:`.Session` is expired,
2580
which normally occurs upon :meth:`.Session.commit` or can be forced
2581
by using :meth:`.Session.expire_all`. Accessing an expired object
2582
whose row has been deleted will invoke a SELECT to locate the
2583
row; when the row is not found, an :class:`.ObjectDeletedError`
2586
* The :meth:`.MapperEvents.before_delete` and
2587
:meth:`.MapperEvents.after_delete`
2588
events are **not** invoked from this method. Instead, the
2589
:meth:`.SessionEvents.after_bulk_delete` method is provided to act
2590
upon a mass DELETE of entity rows.
2594
:meth:`.Query.update`
2596
:ref:`inserts_and_updates` - Core SQL tutorial
2577
2599
#TODO: cascades need handling.
2610
2632
The expression evaluator currently doesn't account for differing
2611
2633
string collations between the database and Python.
2613
Returns the number of rows matched by the update.
2615
The method does *not* offer in-Python cascading of relationships - it
2616
is assumed that ON UPDATE CASCADE is configured for any foreign key
2617
references which require it.
2619
The Session needs to be expired (occurs automatically after commit(),
2620
or call expire_all()) in order for the state of dependent objects
2621
subject foreign key cascade to be correctly represented.
2623
Note that the :meth:`.MapperEvents.before_update` and
2624
:meth:`.MapperEvents.after_update`
2625
events are **not** invoked from this method. It instead
2626
invokes :meth:`.SessionEvents.after_bulk_update`.
2635
:return: the count of rows matched as returned by the database's
2636
"row count" feature.
2638
This method has several key caveats:
2640
* The method does **not** offer in-Python cascading of relationships - it
2641
is assumed that ON UPDATE CASCADE is configured for any foreign key
2642
references which require it, otherwise the database may emit an
2643
integrity violation if foreign key references are being enforced.
2645
After the UPDATE, dependent objects in the :class:`.Session` which
2646
were impacted by an ON UPDATE CASCADE may not contain the current
2647
state; this issue is resolved once the :class:`.Session` is expired,
2648
which normally occurs upon :meth:`.Session.commit` or can be forced
2649
by using :meth:`.Session.expire_all`.
2651
* As of 0.8, this method will support multiple table updates, as detailed
2652
in :ref:`multi_table_updates`, and this behavior does extend to support
2653
updates of joined-inheritance and other multiple table mappings. However,
2654
the **join condition of an inheritance mapper is currently not
2655
automatically rendered**.
2656
Care must be taken in any multiple-table update to explicitly include
2657
the joining condition between those tables, even in mappings where
2658
this is normally automatic.
2659
E.g. if a class ``Engineer`` subclasses ``Employee``, an UPDATE of the
2660
``Engineer`` local table using criteria against the ``Employee``
2661
local table might look like::
2663
session.query(Engineer).\\
2664
filter(Engineer.id == Employee.id).\\
2665
filter(Employee.name == 'dilbert').\\
2666
update({"engineer_type": "programmer"})
2668
* The :meth:`.MapperEvents.before_update` and
2669
:meth:`.MapperEvents.after_update`
2670
events are **not** invoked from this method. Instead, the
2671
:meth:`.SessionEvents.after_bulk_update` method is provided to act
2672
upon a mass UPDATE of entity rows.
2676
:meth:`.Query.delete`
2678
:ref:`inserts_and_updates` - Core SQL tutorial