[Jc @sdZddklZddklZddklZlZlZl Z ddkl Z ddk l Z ddklZddklZlZlZddk lZlZlZlZlZdd klZlZlZlZlZlZlZl Z l!Z"d d d gZ#eZ$d Z%d e&fdYZ'de&fdYZ(de(fdYZ)de(fdYZ*ei+e'd e&fdYZ,dei-fdYZ.da/ei0i1Z2dZ3dS(sThe Query class and support. Defines the :class:`~sqlalchemy.orm.query.Query` class, the central construct used by the ORM to construct database queries. The ``Query`` class should not be confused with the :class:`~sqlalchemy.sql.expression.Select` class, which defines database SELECT operations at the SQL (non-ORM) level. ``Query`` differs from ``Select`` in that it returns ORM-mapped objects and interacts with an ORM session, whereas the ``Select`` construct interacts directly with the database to return iterable result sets. i(tchain(t itemgetter(tsqltutiltlogtschema(texc(R(t expressiontvisitorst operators(t attributest interfacestmappert object_mappert evaluator( t AliasedClasst ORMAdaptert_entity_descriptort _entity_infot_is_aliased_classt_is_mapped_classt _orm_columnst_orm_selectabletjointQueryt QueryContexttaliasedcstifd}|S(sMark a method as generative.csI|di}xD]}|||iqW|||d||S(Nii(t_clonet func_name(tfntargstkwtselft assertion(t assertions(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytgenerate/s (Rt decorator(R"R#((R"s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt _generative,scBsceZdZdddZdddZdZdZdZdZ dZ dZ d Z d Z d Zed Zd ZdZdZdZedZdZdZdddZdddZdZdZdZdZdZdZ dddddddddZ!dZ"edZ#dZ$d Z%ed!Z&ed"Z'ed#Z(ed$Z)eeddddd%Z*ed&Z+d'Z,e-e.i/d(d)Z0ed*Z1ed+Z2ed,Z3ddd-Z4eddd.Z5d/Z6e6Z7ed0Z8d1Z9e9Z:d2Z;ed3Z<d4Z=d5Z>ed6Z?ed7Z@ed8ZAeee d9ZBd:ZCeee e.iDd;d<d=ZEeee e.iDd;d<d>ZFeee d?ZGd@ZHdAZIdBZJdCZKdDZLdEZMe.iDd;d<dFZNe.iDd;d<dGZOeee dHZPeedIZQeedJZRdKZSeedLZTeedMZUeedNZVeedOZWdPZXeedQZYdRZZdSZ[dTZ\dUZ]dVZ^dddWZ_e.i/e_Z`dddddddddddXZaedYZbedZZcd[Zdddeed\Zfd]d^Zgd_d`ZheidaZjdbZkdcZlRS(es@Encapsulates the object-fetching operations provided by Mappers.cCs%||_g|_d|_t|_t|_t|_d|_d|_ d|_ h|_ d|_ d|_ t|_d|_t|_t|_d|_d|_t|_t|_t|_h|_d|_d|_d|_d|_h|_d|_d|_ t|_!|i"|dS(N(((#tsessiont _with_optionstNonet _lockmodetFalset _order_byt _group_byt _distinctt_offsett_limitt _statementt_paramst _yield_pert _criteriontsett _correlatet _joinpointt _with_labelstTruet_enable_eagerloadst_Query__joinable_tablest_havingt_populate_existingt_version_checkt _autoflusht _attributest _current_patht_only_load_propst_refresh_statet _from_objt_polymorphic_adapterst_filter_aliasest_from_obj_aliast_Query__currenttablest _set_entities(R tentitiesR&((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__init__;s>                              cCs[|djo t}ng|_x$ti|D]}|||q0W|i|idS(N(R(t _QueryEntityt _entitiesRtto_listt_Query__setup_aliasizers(R RItentity_wrappertent((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRH]s   c Cs't|do|ii|_}nh|_}x|D]}x|iD]}||jot|\}}}| o<|io2|i}|i|ti ||i d} n1|oti ||i } d}n d}} || |||f||WdS(Nt_mapper_adapter_map( thasattrRQtcopyRIRtwith_polymorphict_with_polymorphic_mapperst)_Query__mapper_loads_polymorphically_withtsql_utilt ColumnAdaptert_equivalent_columnsR(t setup_entity( R RItdRPtentityR t selectabletis_aliased_classRTtadapter((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__setup_aliasizersfs&       cCsZxS|iD]H}||i||ip4|ip*|idj p|idj p |iotid|nd|_d|_|_t |_ |_|_ h|_ dS(Ns<Query.%s() being called on a Query with existing criterion. (( R3R0RCR/R(R.R,RRR*R+R-t_Query__joined_tables(R tmeth((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__no_criterion_condition s   cCs2|iotid|n|i|dS(Ns<Query.%s() being called on a Query with existing criterion. (R+RRt_Query__no_criterion_condition(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__no_clauseelement_conditions cCs%|iotid|ndS(Ns[Query.%s() being called on a Query with an existing full statement - can't apply criterion.(R0RR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__no_statement_conditions cCsA|idj p|idj otid||fndS(NsQuery.%s() being called on a Query which already has LIMIT or OFFSET applied. To modify the row-limited results of a Query, call from_self() first. Otherwise, call %s() before limit() or offset() are applied.(R/R(R.RR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__no_limit_offset!s  cCsZ|o ||_n|o ||_n|o ||_n|ot||_n|S(N(R<R=RBR4RA(R tpopulate_existingt version_checktonly_load_propst refresh_state((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt __get_options)s   cCs.|i}|i|}|ii|_|S(N(t __class__t__new__t__dict__RS(R tclstq((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR4s cCs&|id|iiihtd6S(s4The full SELECT statement represented by this Query.tlabelsRz(t_compile_contextR7t statementt _annotateR8(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR:scCs|itiiS(sreturn the full SELECT statement represented by this Query, embedded within an Alias. Eager JOIN generation within the query is disabled. (tenable_eagerloadsR*RRi(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytsubquery@scCs|itiS(N(RR*R(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__clause_element__HscCs ||_dS(sZControl whether or not eager joins are rendered. When set to False, the returned Query will not render eager joins regardless of eagerload() options or mapper-level lazy=False configurations. This is used primarily when nesting the Query's statement into a subquery or other selectable. N(R9(R tvalue((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRKs cCs t|_dS(sApply column labels to the return value of Query.statement. Indicates that this Query's `statement` accessor should return a SELECT statement that applies labels to all columns in the form _; this is commonly used to disambiguate columns from multiple tables which have the same name. When the `Query` actually issues SQL to load rows, it always uses column labeling. N(R8R7(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt with_labelsZscCs|iS(s#The WHERE criterion for this Query.(R3(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt whereclausejscCs ||_dS(s indicate that this query applies to objects loaded within a certain path. Used by deferred loaders (see strategies.py) which transfer query options from an originating query to a newly generated query intended for the deferred load. N(R@(R tpath((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt_with_current_pathos cCs,|i}|i||d|d|dS(sLoad columns for descendant mappers of this Query's mapper. Using this method will ensure that each descendant mapper's tables are included in the FROM clause, and will allow filter() criterion to be used against those tables. The resulting instances will also have those columns already loaded so that no "post fetch" of those columns will be required. :param cls_or_mappers: a single class or mapper, or list of class/mappers, which inherit from this Query's mapper. Alternatively, it may also be the string ``'*'``, in which case all descending mappers will be added to the FROM clause. :param selectable: a table or select() statement that will be used in place of the generated FROM clause. This argument is required if any of the desired mappers use concrete table inheritance, since SQLAlchemy currently cannot generate UNIONs among tables automatically. If used, the ``selectable`` argument must represent the full set of tables and columns mapped by every desired mapper. Otherwise, the unaccounted mapped columns will result in their table being appended directly to the FROM clause which will usually lead to incorrect results. :param discriminator: a column to be used as the "discriminator" column for the given selectable. If not given, the polymorphic_on attribute of the mapper will be used, if any. This is useful for mappers that don't have polymorphic loading behavior by default, such as concrete table mappers. R]t discriminatorN(Rtset_with_polymorphic(R tcls_or_mappersR]RR\((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRTzs cCs ||_dS(sYield only ``count`` rows at a time. WARNING: use this method with caution; if the same instance is present in more than one batch of rows, end-user changes to attributes will be overwritten. In particular, it's usually impossible to use this setting with eagerly loaded collections (i.e. any lazy=False) since those collections will be cleared for a new load when encountered in a subsequent result batch. N(R2(R tcount((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt yield_perscCsHt|do|i}n|idi|}|i||S(sReturn an instance of the object based on the given identifier, or None if not found. The `ident` argument is a scalar or tuple of primary key column values in the order of the table def's primary key columns. t__composite_values__s5get() can only be used against a single mapped class.(RRRRtidentity_key_from_primary_keyt_get(R tidenttkey((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRus sIDeprecated. Use sqlalchemy.orm.with_parent in conjunction with filter().cKs[t|}|i|dt}|i}|iti|dt}t||i|S(s<Return a new Query with criterion corresponding to a parent instance. Return a newly constructed Query object, with criterion corresponding to a relationship to the given parent instance. instance a persistent or detached instance which is related to class represented by this query. property string name of the property which relates this query's class to the instance. \**kwargs all extra keyword arguments are propagated to the constructor of Query. tresolve_synonymstvalue_is_parent( R t get_propertyR8R tcompareR teqRtfilter(RtinstancetpropertytkwargsR tpropttargett criterion((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytquery_from_parents   cGs#|iid|D|_dS(Ncssx|]}t|VqWdS(N(R(t.0ts((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pys s (R5tunion(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt correlatescCs ||_dS(s%Return a Query with a specific 'autoflush' setting. Note that a Session with autoflush=False will not autoflush, even if this flag is set to True at the Query level. Therefore this flag is usually used only to disable autoflush for a specific Query. N(R>(R tsetting((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt autoflushs cCs t|_dS(sReturn a Query that will refresh all instances loaded. This includes all entities accessed from the database, including secondary entities, eagerly-loaded collection items. All changes present on entities which are already present in the session will be reset and the entities will all be marked "clean". An alternative to populate_existing() is to expire the Session fully using session.expire_all(). N(R8R<(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRsc Csddkl}t|}|djoqx|iD]4}t||io|i|ijoPq3q3Wt i d|ii i |i i fn|i|dt}|i|iti|dtS(sJAdd a join criterion corresponding to a relationship to the given parent instance. instance a persistent or detached instance which is related to class represented by this query. property string name of the property which relates this query's class to the instance. if None, the method will attempt to find a suitable property. Currently, this method only works with immediate parent relationships, but in the future may be enhanced to work across a chain of parent mappers. i(t propertiess\Could not locate a property which relates instances of class '%s' to instances of class '%s'RRN(tsqlalchemy.ormRR R(titerate_propertiesRgtPropertyLoaderR RRRtclass_t__name__RRR8RRR R(R RRRR R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt with_parents   ) /cCsO|ot||}nt|i|_t||}|i|gdS(sAadd a mapped entity to the list of result columns to be returned.N(RtlistRLt _MapperEntityRN(R R\RiRe((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt add_entitys cGsL|iitiid}|i|}|o|i|n|S(sreturn a Query that selects from this Query's SELECT statement. \*entities - optional list of entities which will replace those being selected. N(RRR*RRR(t_from_selectableRH(R RIt fromclauseR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt from_self!s !cCsHd|_|_t|_|_|_d|_|_|i |dS(N( R(R0R3R*R+R,R-R/R.t_Query__set_select_from(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR0scGsR|p tdS|i}|i|dt|ip d|_nt|S(sTReturn an iterator yielding result tuples corresponding to the given list of columnsROi ((titerRRHt _ColumnEntityR2(R tcolumnsR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytvalues7s    cCs6y|i|idSWntj odSXdS(sDReturn a scalar result corresponding to the given column expression.iN(Rtnextt StopIterationR((R tcolumn((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRCscCsFt|i|_t|i}t|||i|i|dS(sEAdd a SQL ColumnElement to the list of result columns to be returned.N(RRLRRRN(R Rtl((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt add_columnJs cGs|it|S(sVReturn a new Query object, applying the given list of MapperOptions. (t_Query__optionsR*(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytoptionsUscGs|it|S(N(RR8(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt_conditional_options\scGs|ii|_g}ti|D] }||q&~}|i||_|o"x=|D]}|i|qZWnx|D]}|i|q|WdS(N(R?RSRtflatten_iteratorR'tprocess_query_conditionallyt process_query(R t conditionalRt_[1]totoptstopt((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt __options_s*cCs ||_dS(s:Return a new Query object with the specified locking mode.N(R)(R tmode((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt with_lockmodemscOstt|djo|i|dn't|djotidn|ii|_|ii|dS(s|add values for bind parameters which may have been specified in filter(). parameters may be specified using \**kwargs, or optionally a single dictionary as the first positional argument. The reason for both is that \**kwargs is convenient, however some parameter dictionaries contain unicode keys in which case \**kwargs cannot be used. iisFparams() takes zero or one positional argument, which is a dictionary.N(RRRt ArgumentErrorR1RS(R RR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytparamsss cCst|toti|}n|dj o't|ti otidn|i|t t }|i dj o|i |@|_ n ||_ dS(sapply the given filtering criterion to the query and return the newly resulting ``Query`` the criterion is any sql.ClauseElement applicable to the WHERE clause of a select. sHfilter() argument must be of type sqlalchemy.sql.ClauseElement or stringN( Rgt basestringRttextR(t ClauseElementRRRR8R3(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs!cKs\g}|iD],\}}|t|i|d|jq~}|iti|S(sZapply the given filtering criterion to the query and return the newly resulting ``Query``.i(t iteritemsRRRRtand_(R RRRRtclauses((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt filter_bys?tlist_deprecationtpendingcGst|djo|ddjo d|_nwg}|D]%}||iti|ttq<~}|itjp|idjo ||_n|i||_dS(sZapply one or more ORDER BY criterion to the query and return the newly resulting ``Query``iiN(RR(R+RRt_literal_as_textR8R*(R RRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytorder_bys $ 9  c Gsttg}|D]}|t|q~}g}|D]%}||iti|ttq>~}|itjo ||_n|i||_dS(sZapply one or more GROUP BY criterion to the query and return the newly resulting ``Query``N( RRRRRR R8R,R*(R RRtct_[2]R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytgroup_bys 39 cCst|toti|}n|dj o't|ti otidn|i|t t }|i dj o|i |@|_ n ||_ dS(sOapply a HAVING criterion to the query and return the newly resulting ``Query``.sHhaving() argument must be of type sqlalchemy.sql.ClauseElement or stringN( RgRRRR(RRRRR8R;(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pythavings!cGs#|iti|gt|S(sProduce a UNION of this Query against one or more queries. e.g.:: q1 = sess.query(SomeClass).filter(SomeClass.foo=='bar') q2 = sess.query(SomeClass).filter(SomeClass.bar=='foo') q3 = q1.union(q2) The method accepts multiple Query objects so as to control the level of nesting. A series of ``union()`` calls such as:: x.union(y).union(z).all() will nest on each ``union()``, and produces:: SELECT * FROM (SELECT * FROM (SELECT * FROM X UNION SELECT * FROM y) UNION SELECT * FROM Z) Whereas:: x.union(y, z).all() produces:: SELECT * FROM (SELECT * FROM X UNION SELECT * FROM y UNION SELECT * FROM Z) (RRRR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscGs#|iti|gt|S(sProduce a UNION ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RRt union_allR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscGs#|iti|gt|S(sProduce an INTERSECT of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RRt intersectR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscGs#|iti|gt|S(sProduce an INTERSECT ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RRt intersect_allR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscGs#|iti|gt|S(sProduce an EXCEPT of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RRtexcept_R(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscGs#|iti|gt|S(sProduce an EXCEPT ALL of this Query against one or more queries. Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See that method for usage examples. (RRt except_allR(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRscOsn|idt|idt}}|o#tddi|in|i|dtd|d|S(ss Create a join against this ``Query`` object's criterion and apply generatively, returning the newly resulting ``Query``. Each element in \*props may be: * a string property name, i.e. "rooms". This will join along the relation of the same name from this Query's "primary" mapper, if one is present. * a class-mapped attribute, i.e. Houses.rooms. This will create a join from "Houses" table to that of the "rooms" relation. * a 2-tuple containing a target class or selectable, and an "ON" clause. The ON clause can be the property name/ attribute like above, or a SQL expression. e.g.:: # join along string attribute names session.query(Company).join('employees') session.query(Company).join('employees', 'tasks') # join the Person entity to an alias of itself, # along the "friends" relation PAlias = aliased(Person) session.query(Person).join((Palias, Person.friends)) # join from Houses to the "rooms" attribute on the # "Colonials" subclass of Houses, then join to the # "closets" relation on Room session.query(Houses).join(Colonials.rooms, Room.closets) # join from Company entities to the "employees" collection, # using "people JOIN engineers" as the target. Then join # to the "computers" collection on the Engineer entity. session.query(Company).join((people.join(engineers), 'employees'), Engineer.computers) # join from Articles to Keywords, using the "keywords" attribute. # assume this is a many-to-many relation. session.query(Article).join(Article.keywords) # same thing, but spelled out entirely explicitly # including the association table. session.query(Article).join( (article_keywords, Articles.id==article_keywords.c.article_id), (Keyword, Keyword.id==article_keywords.c.keyword_id) ) \**kwargs include: aliased - when joining, create anonymous aliases of each table. This is used for self-referential joins or multiple joins to the same table. Consider usage of the aliased(SomeClass) construct as a more explicit approach to this. from_joinpoint - when joins are specified using string property names, locate the property from the mapper found in the most recent previous join() call, instead of from the root entity. Rtfrom_joinpointsunknown arguments: %st,t outerjointcreate_aliases(RpR*t TypeErrorRtiterkeyst _Query__join(R tpropsRRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR%s>%#cOsn|idt|idt}}|o#tddi|in|i|dtd|d|S(sCreate a left outer join against this ``Query`` object's criterion and apply generatively, retunring the newly resulting ``Query``. Usage is the same as the ``join()`` method. RRsunknown arguments: %sRRR(RpR*RRRRR8(R RRRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRhs%#c Cs[t|i|_|ii|_|p|ind}}d}xti|D]}t} t} |} d} } }}t |t o|\}}nd}t |t i t fo|}|}n6t |t i t fo|}|}n |}|}t |t i odt|dd} |i} |}| p |i} n| o | }n | i}|p |}qnrt |t oJ| p|i} nt| |\}} | i}|p |}qn| p|i} n| oO|ioEt| \}}}ti|i|\}}|p |}qFn|p6x3|iD]$}|i| o|i}PqWqWWn|p't |t i o|i}qn|ptidn| ot |ti o | }nt|\}}}|dj o;|dj o.|i | otid||fn| o|o |}n|o| o||jou|i!|i"p&tid|i#|i"i#fnt |t$i%p|i&}nt'||}t(} q|ot'|}t(} q|i)pt |i"t$i*ot'|}t(} t(} q| o| i+|ijoA| i,dj o*| i,|ijotid|qYqYn| i,o|ii-| i,n|ii-| i+| o | }q| i}qn| o"t.|d|i/d|i0}nt |t$i1o3| o|i2|}n|i3|tt(}n| p(|| jp|i4o||idj}t5|||d |d |}| o7||_0| o#|i6|t.|d|i/qqYqYW|dj o,t7|i}|||>> session.query(Item).scalar() >>> session.query(Item.id).scalar() 1 >>> session.query(Item.id).filter(Item.id < 0).scalar() None >>> session.query(Item.id, Item.name).scalar() 1 >>> session.query(func.count(Parent.id)).scalar() 20 This results in an execution of the underlying query. iN(RRgR&t IndexErrorR((R RV((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytscalars cCsK|i}t|i_|io|i o|iin|i|S(N(RR8Rt use_labelsR>R<R&t_execute_and_instances(R tcontext((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__iter__s   cCs:|ii|id|id|i}|i||S(NRR (R&texecuteRR1Rt instances(R t querycontexttresult((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR_s*c #s#|i}|djot|nt_tt|i}|ot|i dj}|o!|o d}qt i }nd}|od|i di j}t g}|i D]} || i||q~\} } |pGtdt| D} titdtf| } | i| _nxtoh_h_|io"|i|i} | pPqn |i} |o/g}x| D]| d|qWnt|o2g}| D]|| dq~}n;g}| D]&|| fd| Dq~}|o||}nioP|ioFiijo3iiii|iiiin|iix3ii D]"\}\}}|i||qWx|D] VqW|ipPqDqDWdS( s Given a ResultProxy cursor as returned by connection.execute(), return an ORM result as an iterator. e.g.:: result = engine.execute("select * from users") for u in session.query(User).instances(result): print u icSsti|tiS((Rt unique_listt IdentitySet(tx((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt(st append_resulticss<x5|].\}}|o|tt|fVqqWdS(N(RR(Rtitlabel((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pys 3s  tRowTuplec3s"x|]}|VqWdS(N((Rtproc(R`trow(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pys Ks N(!R&R(Rt _new_runidtrunidtboolRRRRLRRfRtzipt row_processortdictt enumeratettypeRR&R3R8tprogresstpartialsR2t fetchmanytfetchallRRAtcommitRpt_finalize_loadedtitems(R tcursort_Query__contextR&tfilteredt single_entityRt custom_rowsRt query_entitytprocessRtrowtupletfetchtrowsRt_[3]tiitdict_tattrs((RoR`s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRcsf     ?      23'  cCs|p|i}|i o| o|ii o|djoyj|ii|}ti|}|i o9y |Wqt i j o|ii |dSXn|SWqt j oqXn|djo|dj o|d}qnti|}|djo|i}|idn |i}|dj o|i} h} | i\} } |i| tt} | |_xut| iD]d\} }y|| | | |is RRRRi(#R)R<Rtalways_refreshR(R&t identity_mapR tinstance_statetexpiredRXtObjectDeletedErrort_remove_newly_deletedtKeyErrorRRMRRt _get_clauseRR8R*R3Rvt primary_keyRR\RRRR1t_Query__get_optionsRrR+RS(R RRRtlockmodeRRtstateRR RRt _get_paramsRkR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRas`1              )       cCsDh|id6|id6|id6|ipdd6|ipdd6S(NRPRQRRRR(R/R.R-R,R(R;(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt _select_argss    cCsE|i}|iddj p&|iddj p|idtS(NRPRQRR(RRuR(R*(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt_should_nest_selectables c st|igfd}|itidtiidtg}|iD]}|||qJ~ddS(sIApply this query's criterion to a SELECT COUNT statement. If column expressions or LIMIT/OFFSET/DISTINCT are present, the query "SELECT count(1) FROM (SELECT ...)" is issued, so that the result matches the total number of rows this query would return. For mapped entities, the primary key columns of each is written to the columns clause of the nested SELECT statement. For a Query which is only against mapped entities, a simpler "SELECT count(1) FROM table1, table2, ... WHERE criterion" is issued. cs3t|to |iiStd<|igSdS(Ni(RgRR RR8R(RP(t should_nest(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytent_colss  t1t nested_colsRi(Rt_col_aggregateRtliteral_columntfuncRRRL(R RRRP((Rs8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs  0c Csjt|}x!|iD]}|i||qW|iot|i}n |i}|i||i}|o|p |g}n t|}ti ||d|dt |i } | i } ti || i |p|gi| } n(ti ||g|d||i } |io|i o|iin|ii| d|id|iS(NRlR^RR (RRLt setup_contextt from_clauseRtfromst_adjust_for_single_inheritanceRRtselectR8RRitcorresponding_columnRFR>R<R&R]R1R( R tcolRRRR`R\RlRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs(        $ 5'Rc Cs|tddgjotidn|it}|i}t|iidjpt|iidt i  otidn|iid}|i }|djoEy"t i }|i|i}Wqt ij o d}qXnti||i}|djo7|ii|i}|i|d|ii} n|io|in|i|d|i} |djo|ii} g} |iiD]:\\} }}t| | o||o | |qq~ }x|D]}|iti |qWnu|djog|i}xX| D]L}|i!t"|}||ijo!|iti |i|q@q@Wnx'|i#D]}|i$|||| qW| i%S(sZPerform a bulk delete query. Deletes rows matched by this query from the database. :param synchronize_session: chooses the strategy for the removal of matched objects from the session. Valid values are: False don't synchronize the session. This option is the most efficient and is reliable once the session is expired, which typically occurs after a commit(). Before the expiration, objects may still remain in the session which were in fact deleted which can lead to confusing results if they are accessed via get() or already loaded collections. 'fetch' performs a select query before the delete to find objects that are matched by the delete query and need to be removed from the session. Matched objects are removed from the session. 'fetch' is the default strategy. 'evaluate' experimental feature. Tries to evaluate the querys criteria in Python straight on the objects in the session. If evaluation of the criteria isn't implemented, the 'fetch' strategy will be used as a fallback. The expression evaluator currently doesn't account for differing string collations between the database and Python. Returns the number of rows deleted, excluding any cascades. The method does *not* offer in-Python cascading of relations - it is assumed that ON DELETE CASCADE is configured for any foreign key references which require it. The Session needs to be expired (occurs automatically after commit(), or call expire_all()) in order for the state of dependent objects subject to delete or delete-orphan cascade to be correctly represented. Also, the ``before_delete()`` and ``after_delete()`` :class:`~sqlalchemy.orm.interfaces.MapperExtension` methods are not called from this method. For a delete hook here, use the ``after_bulk_delete()`` :class:`~sqlalchemy.orm.interfaces.MapperExtension` method. tevaluateRsNValid strategies for session synchronization are False, 'evaluate' and 'fetch'iis=Only deletion via a single table query is currently supportedR(&R*RRRRRRRRgRtTableR&RtEvaluatorCompilerRRtUnevaluatableErrorRtdeletetwith_only_columnsRRbR1R{R>RRRRt issubclassRR RRRt extensionstafter_bulk_deletetrowcount(R tsynchronize_sessionR`t primary_tableR&tevaluator_compilerteval_conditiont delete_stmtt select_stmtt matched_rowsRet target_clsRRtpktobjtobjs_to_expunget target_mapperRt identity_keytext((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRsN, 7    "  &1  ) texpirec Css|tddgjotidn|it}|i}t|iidjpt|iidt i  otidn|iid}|i }|djoypt i }|i|i}h}xE|iD]7\} } ti| } |iti| || RRRRR3RR Rt instance_dictt unmodifiedt intersectionR|Rtexpire_attributesR4t differenceRRRtafter_bulk_updateR(R RRR`RR&RRtvalue_evaluatorsRRt update_stmtRRReRRRRtevaluated_keysRRt to_evaluateRRRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRDsd. 7    $ "   (  ) cCst|}|io|S|io]y-hdd6td6dd6td6|i}Wqtj otid|iqXnt}x!|i D]}|i ||qW|i i }|i ot|i }n |i}|i||ip0|iotidq(tidn|o|io|io=ttg}|iD]}|ti|qW~} nd|_g} ti|i| |id|d |d td |i|i} |io| i|i} n| i} |i } ti!| | |_"ti| g|i#d |d |} | } x&|D]}ti$| ||i%} qKW| i&| |io | i'|i"i(|in| i'|i)n|ip d|_n|i*oV|ioLttg}|iD]}|ti|q~} |i| 7_n||i i 7}ti|i|i#|id|d |d |d td |i|i} |io| i|i} n|i)o| i'|i)n| |_|S( NtreadRtnowaitt update_nowaitsUnknown lockmode '%s'syNo column-based properties specified for refresh operation. Use session.expire() to reload collections and related items.s4Query contains no columns with which to SELECT from.RlR^RRt for_update(+RRR)R8R*R(RRRRLRt eager_joinsRRRRRtprimary_columnsRARRRRRWt find_columnsRRRRR5RRiRjRXR_tsecondary_columnst splice_joinststop_ont append_fromtappend_order_bytcopy_and_processteager_order_byR-(R RR`RR\RRRRtorder_by_col_exprtinnerRmRRt eager_joinR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs           =       %     9      c Csx|iiD]v\}\}}}}}|i}|oK|o|i|}n|i|tt}ti|i||_qqWdS(s@Apply single-table-inheritance filtering. For all distinct single-table-inheritance mappers represented in the columns clause of this query, add criterion to the WHERE clause of the given QueryContext such that only the appropriate subtypes are selected from the total results. N( RQRt_single_table_criterionR1RR*RRR( R R`R\R R_RRktwt single_crit((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR"s  cCst|iiS(N(tstrRR(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt__str__3sN(mRt __module__t__doc__R(RJRHRNRVRRoRqR%RRRR%RRRRRRRRRRRRRjRt"_Query__no_clauseelement_conditiont_Query__no_statement_conditiont_Query__no_limit_offsetRRRRRRRRRRTRRut classmethodRt deprecatedRRRRRRRt _from_selfRRt_valuesRRRRRRRRR taccepts_a_list_as_starargsRRRRRRRRRRRRRDRFRORGRPRQRRRSRURWR[R]RaR_Rctiterate_instancesRRRRR*RRRR8RRR(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR8s "                       "             C            M:   ^ p n RKcBs eZdZdZdZRS(s:represent an entity column returned within a Query result.cOsV|tjo<|d}t|t ot|o t}qIt}nti|S(Ni(RKRgRRRRtobjectR(RRRR\((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR:s     cCs+|ii|i}|ii|_|S(N(RRRRS(R R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRCs(RRRRR(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRK7s RcBsVeZdZdZdZdZdZdZdZdZ dZ RS( s mapper/class/AliasedClass entitycCs6|i |_|ii||g|_||_dS(N(RLRRRIR(R tqueryR\((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRJKs  cCs||_|ii|_||_||_||_d|_||_|o||_|_ |_ n|i |_||_ |_ dS(N( R RR_R]t_with_polymorphicR(t_polymorphic_discriminatorR^t path_entityR\Rt base_mapper(R R\R R_RlR^RT((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRZRs       cCs|djo|i|idS|ii||\}}||_||_|ip"||_|i|||_ ndS(N( R(RqR t_with_polymorphic_argsRRR^R]RoR_(R RRR]RtmappersRl((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR`s     cCs/t|o||ijS|i|ijSdS(N(RRR(R R\((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR)os cCsd}|i o&|io|ii|id}n| o|io |i}n|o*|io|i|i}q|}n |i}|S(N(R(R^RDRuR R_RFtwrap(R RR`R_RV((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt_get_entity_clausesus    c sT|i||}|io|o|i|i}n|p |i}n| o,|iioti|i|ii}n|i oF|ii ||i f|d|i d|i d|id|in(|ii ||i f|d|i|ofd}nfd}|io|ii}n|iii}||fS(NRRRtpolymorphic_discriminatorcs||dS(N((R`RoRe(t _instance(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pytmainscs |dS(N(R((R`Ro(R(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs(RR_RR t_requires_row_aliasingRWRXR]RYRt_instance_processorRRRARRR^R\t_sa_label_nameRR(R RR`RR_Rtentname((Rs8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRts(    c Cs6|i||}|ii|i|itjoI|iio<|ii|_|o"|iti |i|_q~nxo|ii |i D]X}|i o|i |i joqn|i|||if|d|i d|iqW|io8|o|i|i}n |i}|ii|ndS(NRtcolumn_collection(RRRR]RR*R t adapt_listRRMt_iterate_polymorphic_propertiesRRARtsetupRRRR(R RR`R_Rtpd((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs,&    cCs t|iS(N(RR (R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs( RRRRJRZRR)RRtRR(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRHs      $ RcBsMeZdZdZdZdZdZdZdZdZ RS(sColumn/expression based entity.cst|toti|}|i|_nEt|tio|i|_|i }nt |dd|_t|t i  oYt|doIx0|iD]%}||joPnt||qW||j odSnt|ti ptid|n|ip|id}n|ii|||_t|_t|itifdti|hD|_|iot |id|_!n d|_!dS(NRt_select_iterablesInvalid column expression '%r'c3sGx@|]9}d|ijo#i|io|idVqqWdS(RN(R{Rt _from_objects(RR|(t actual_froms(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pys s i("RgRRRtnamet _result_labelR R*RRRR(Rt ColumnElementRRRRRRt_labelRlRLRRR4RRRt OrderedSetRtiterateRIRR(R RRR((Rs8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRJs: $         cCs||_|ii|dS(N(R]RR0(R R\R R_RlR^RT((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRZ s cCsCt|o||ijSt|i o|ii|iSdS(N(RRRR+(R R\((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR) s cCs|i|ttS(N(RR*R8(R RtexprR`((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyt#_resolve_expr_against_query_aliasesscsR|i||i||io|iinfd}||ifS(Ncs|S(N((R`Ro(R(s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRns(RRR_RR (R RR`RRn((Rs8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRts  cCsD|i||i|}|it|i7_|ii|dS(N(RRRRRR(R RR`R((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR!scCs t|iS(N(RR(R ((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR&s( RRRRJRZR)RRtRR(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRs 7    cBseZdZRS(cCsk|ioJt|itio$|ii o|ii|_q|i|_nud|_|i|_ |i |_ |i |_ |i o=g}ti|i D]}|ti|q~|_ n||_|i|_|i|_|i|_|i|_g|_g|_g|_|i|_h|_g|_d|_ t!|i"|_#|i$i%|_&dS(N('R0RgRRhR^t apply_labelsRR(RCRR3RR+RRRMR RR&R<RR=RRBRRRRR9RRRR_R4R'RR?RSR (R RRR((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRJ,s0 $     =            (RRRJ(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyR+st AliasOptioncBseZdZdZRS(cCs ||_dS(N(Ri(R Ri((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRJMscCsQt|ito|iii|i}n |i}ti||_dS(N(RgRiRRRbRWRXRF(R RRi((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRPs (RRRJR(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRKs lcCs.tiztd7atSWdtiXdS(Ni(t_id_locktacquiret_runidtrelease(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyRp[s   N(4Rt itertoolsRtoperatorRt sqlalchemyRRRRRRRRXtsqlalchemy.sqlRWRRR R R R R Rtsqlalchemy.orm.utilRRRRRRRRRR2t__all__RR%RRRKRRt class_loggerRt MapperOptionRRt threadingtLockRRp(((s8/usr/lib/python2.6/site-packages/sqlalchemy/orm/query.pyts:"(@ Z