mò !&ÜGc@s¦dklZlZlZlZlZdklZdkl Z dddgZ de fd„ƒYZ ei e ƒe _de fd„ƒYZde fd„ƒYZd S( (ssqlsutils exceptionsssql_utilslogging(smapper(sOperationContexttQueryt QueryContexttSelectionContextcBs|tZdZeeeeed„Zd„Zd„Zed„ƒZeeƒZ d„Z d„Z d„Z d„Z d „Zed „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zed„Zeed„Zeed„Zd„Zd„Zd„Zd„Zd„Zed„Zd„Z ee!ed„Z"ed„Z#d„Z$d„Z%ed „Z&d!„Z'RS("s@encapsulates the object-fetching operations provided by Mappers.c Kst|tƒoti|d|ƒ|_n|iƒ|_|pg|_|ii ƒiƒ|_|i d|ii ƒ|_ |i d|ii ƒ|_ ||_tiƒ|_|dj o|ii|ƒn|ii|iiƒ||_t|idƒpetiƒ} xF|ii|iD]1} | ii| ti| id| iƒjƒq$W| |i_n|ii|_x|iD]}|i |ƒq‚WdS(Nt entity_nametalways_refreshtorder_byt _get_clausettype(!t isinstancetclass_or_mapperRtmappert class_mapperRtselftcompilet with_optionstget_select_mappertkwargstpopRRtlockmodet_ExtensionCarriert extensiontNonetappendtsessiont_sessionthasattrtsqltand_Rt pks_by_tablettablet primary_keytclausest bindparamt_labeltoptt process_query( R R RRRRRRR"RR((t8/home/holguin2/public_html/spyce/sqlalchemy/orm/query.pyt__init__s.    / cCs|ii|ƒdS(N(R Rtinserttext(R R'((R$t_insert_extension'scCs,|idjo|iiƒSn|iSdS(N(R RRR t get_session(R ((R$t _get_session*scCs |iiS(N(tsR t select_table(R+((R$t/scKsU|ii|||}|tij o|Sn|ii|ƒ}|i |||S(sêreturn 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.N( R RtgettidentRtretR tEXT_PASSt identity_keytkeyt_get(R R/RR0R3((R$R.2s cKs‹|ii|||}|tij o|Sn|ii|ƒ}|i ||dt |}|djotidt|ƒƒ‚n|S(s\return an instance of the object based on the given identifier. If not found, raises an exception. The method will *remove all pending changes* to the object already existing in the Session. The ident argument is a scalar or tuple of primary key column values in the order of the table def's primary key columns.treloads!No instance found for identity %sN(R RtloadR/RR0R R1R2R3R4tTruetinstanceRt exceptionstInvalidRequestErrortrepr(R R/RR0R8R3((R$R6=s cOsl|ii|||Ž}|tij o|Sn|i|i ||Žddƒ}|o |dSndSdS(s”return a single object instance based on the given key/value criterion. this is either the first value in the result list, or None if the list is empty. the keys are mapped to property or column names mapped by this mapper's Table, and the values are coerced into a WHERE clause separated by AND operators. If the local property/column names dont contain the key, a search will be performed against this mapper's immediate list of relations as well, forming the appropriate join conditions if a matching property is located. e.g. u = usermapper.get_by(user_name = 'fred') tlimitiiN( R Rtget_bytargstparamsR0R R1tselect_whereclausetjoin_bytxR(R R>R?R0RB((R$R=Ls ! cOsI|ii|||Ž}|tij o|Sn|i|i ||ŽƒS(s return an array of object instances based on the given clauses and key/value criterion. *args is a list of zero or more ClauseElements which will be connected by AND operators. **params is a set of zero or more key/value parameters which are converted into ClauseElements. the keys are mapped to property or column names mapped by this mapper's Table, and the values are coerced into a WHERE clause separated by AND operators. If the local property/column names dont contain the key, a search will be performed against this mapper's immediate list of relations as well, forming the appropriate join conditions if a matching property is located. e.g. result = usermapper.select_by(user_name = 'fred') N( R Rt select_byR>R?R0R R1R@RA(R R>R?R0((R$RCcs c Os¯d}x/|D]'} |djo | }q || M}q Wxp|iƒD]b\}}|i |ƒ\}}|i d|j|i |ƒ@}|djo |}qE||M}qEW|S(sxreturn a ClauseElement representing the WHERE clause that would normally be sent to select_whereclause() by select_by().iN(RtclauseR>targR?t iteritemsR3tvalueR t _locate_proptkeystproptcolumnstjoin_viatc( R R>R?RIRDRMRGRJR3RE((R$RAvs      cswdk‰g‰tiƒ‰‡‡‡‡‡d†‰ˆ|p|iƒ}|djot i dˆƒ‚nˆ|gS(Ncs|ˆjodSnˆi|ƒ|iiˆƒof|iˆ}t|ˆi ƒo|i|i }nt|ˆi ƒoˆid|iƒn|Snjxf|iiƒD]Q}t|ˆi ƒpq«nˆ|iƒ}|oˆid|iƒ|Sq«q«WdSdS(Ni(tmapper_tseenRtaddtpropsthas_keyR3RJRt propertiestSynonymPropertytnametPropertyLoaderRIR&tvaluestsearch_for_propR RB(RNRJRB(RXRIR3RORS(R$RXŒs&    sCant locate property named '%s'(RSRItutiltSetRORXtstartR R tpRR9R:R3(R R3R[RXR\RIRORS((R3RIRORXRSR$RHˆs   cCs"|i|ƒ\}}|i|ƒS(sügiven the key name of a property, will recursively descend through all child properties from this Query's mapper to locate the property, and will return a ClauseElement representing a join from this Query's mapper to the endmost mapper.N(R RHR3RIR\RL(R R3RIR\((R$tjoin_to¦scCsg|i}d}xQ|D]I}|i|}|djo|iƒ}n||iƒM}|i}qW|S(sgiven a list of keys that represents a path from this Query's mapper to a related mapper based on names of relations from one mapper to the next, returns a ClauseElement representing a join from this Query's mapper to the endmost mapper. N( R R RRDRIR3RQRJtget_join(R RIR RDRJR3((R$RL­s    cOs|i||ŽS(s‡works like select_by(), but only returns the first result by itself, or None if no objects returned. Synonymous with get_by()N(R R=R>R?(R R>R?((R$tselectfirst_by¾scOsy|i|i||Žddƒ}t|ƒdjo |dSn6t|ƒdjotidƒ‚ntidƒ‚dS(sXworks like selectfirst_by(), but throws an error if not exactly one result was returned.R<iiis!No rows returned for selectone_bys'Multiple rows returned for selectone_byN( R R@RAR>R?R0tlenR9R:(R R>R?R0((R$t selectone_byÃs! cOs|i|i||ŽƒS(s¢returns the count of instances based on the given clauses and key/value criterion. The criterion is constructed in the same way as the select_by() method.N(R tcountRAR>R?(R R>R?((R$tcount_byÍscOs7d|d<|i||Ž}|o |dSndSdS(sjworks like select(), but only returns the first result by itself, or None if no objects returned.iR<iN(R?R R@R>R0R(R R>R?R0((R$t selectfirstÒs   cOswt|i||Ždd!ƒ}t|ƒdjo |dSn6t|ƒdjotidƒ‚ntidƒ‚dS(sUworks like selectfirst(), but throws an error if not exactly one result was returned.iiis!No rows returned for selectone_bys$Multiple rows returned for selectoneN( tlistR tselectR>R?R0R`R9R:(R R>R?R0((R$t selectoneÜs cKs€|ii|d||}|tij o|Sny|iƒ}Wn&t j o|i d||SnX|i ||SdS(säselects instances of the object from the database. arg can be any ClauseElement, which will form the criterion with which to load the objects. For more advanced usage, arg can also be a Select statement object, which will be executed and its resulting rowset used to build new object instances. in this case, the developer must insure that an adequate set of columns exists in the rowset with which to build new object instances.REt whereclauseN( R RRfRERR0R R1t _selectableR+tAttributeErrorR@tselect_statement(R RERR0R+((R$Rfæs cKs%|i||}|i|d|ƒS(s_given a WHERE criterion, create a SELECT statement, execute and return the resulting instances.R?N(R R RhRt statementt_select_statementR?(R RhR?RRl((R$R@ûsc Ks|idgƒ} g} x<g}| D]}|ti|ƒq&~D]}| |7} qCW|i | jo| i |i ƒn|i |o.t i|i g||idƒiƒ}nH|ii|i }t it iit|ƒdƒg|d| |}|ii|i|d|ƒS(sggiven a WHERE criterion, create a SELECT COUNT statement, execute and return the resulting count value.tfrom_objtgetcountiR?N(RRRnt alltablest_[1]RBtsql_utilt TableFindertlR RRt _nestableRRfRhtaliasRbR+R RRtfuncReRtscalarR?( R RhR?RRRtRqR+RBRnRp((R$Rbs+.4cKs|i|d|ƒS(sRgiven a ClauseElement-based statement, execute and return the resulting instances.R?N(R RmRlR?(R RlR?((R$RkscKs"ti|ƒ}|i|d|ƒS(sSgiven a literal string-based statement, execute and return the resulting instances.R?N(RttextttR texecuteR?(R RyR?Rz((R$t select_textscOst|i|id|ƒS(sDreturn a new Query object, applying the given list of MapperOptions.RN(RR R RR>(R R>R((R$toptionsscCst|i|id|ƒS(s:return a new Query object with the specified locking mode.RN(RR R Rtmode(R R~((R$t with_lockmodescsrˆidƒo!ˆd‰‡‡d†}|Sn>ˆidƒo!ˆd‰‡‡d†}|Sn tˆƒ‚dS(Nt select_by_i csˆihˆ|<S(N(R RCR3RE(RE(R R3(R$tfoo&stget_by_icsˆihˆ|<S(N(R R=R3RE(RE(R R3(R$R+s(R3t startswithRRj(R R3R((R R3R$t __getattr__#s  cOsD|ii|i|d|ƒ}z|i||SWd|i ƒXdS(sNexecute the given ClauseElement-based statement against this Query's session/mapper, return the resulting list of instances. After execution, closes the ResultProxy and its underlying resources. This method is one step above the instances() method, which takes the executed statement's ResultProxy directly.R?N( R RR{R t clauseelementR?tresultt instancesRtclose(R R…R?R>RR†((R$R{1s cOsI|idƒ|i} t|i| d|i|} ti gƒ} |o1g}x(|D]}|iti gƒƒqWWnxb|iƒD]T} |ii| | | ƒd}x/|D]'}|i| | ||ƒ|d7}q±WqˆWx$| iiƒD]}| i|ƒqðW|o0| igg} |D]}| |iq"~ Sn| iSdS(screturn a list of mapped instances corresponding to the rows in a given "cursor" (i.e. ResultProxy).s instances()RiiN(R t_Query__log_debugRRR RRtcontextRYtUniqueAppenderR†tmapperst otherresultstmRtcursortfetchalltrowt _instancetit identity_mapRWRGt_register_persistenttdataRqto(R RRŒRRR—RŽRGR“RR†RŠRqR‘((R$R‡<s0   0c CsK|p|i}| oF|i o;|djo.y|ii|ƒSWq^tj oq^Xn|djo|d}nt i |ƒ}d}h}xQ|ii|iD]<}||||i