U wf_•<ã@sÒdZddlZddlmZe d dddg¡ejejB¡ZGd d „d ƒZ Gd d „d ƒZ Gd d„dƒZ Gdd„dƒZ Gdd„dƒZ Gdd„de e e ƒZGdd„de e e ƒZGdd„de e e ƒZGdd„de e e ƒZdS)zyMySQLdb Cursors This module implements Cursors of various types for MySQLdb. By default, MySQLdb uses the Cursor class. éNé)ÚProgrammingErrorÚz'\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)z6(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))z(\s*(?:ON DUPLICATE.*)?);?\s*\Zc@seZdZdZdZddlmZmZmZm Z m Z m Z m Z m Z mZmZmZdZdd„Zdd „Zd d „Zd d „Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd-dd„Zd d!„Zd"d#„Z d.d%d&„Z!d'd(„Z"d/d)d*„Z#d+d,„Z$eZeZe Z e Z e Z e Z e Z eZeZeZdS)0Ú BaseCursoraA base for Cursor classes. Useful attributes: description A tuple of DB API 7-tuples describing the columns in the last executed query; see PEP-249 for details. description_flags Tuple of column flags for last query, one entry per column in the result set. Values correspond to those in MySQLdb.constants.FLAG. See MySQL documentation (C API) for more information. Non-standard extension. arraysize default number of rows fetchmany() will fetch ir) Ú MySQLErrorÚWarningÚErrorÚInterfaceErrorÚ DatabaseErrorÚ DataErrorÚOperationalErrorÚIntegrityErrorÚ InternalErrorrÚNotSupportedErrorNcCs@||_d|_d|_d|_d|_d|_d|_d|_d|_d|_ dS)Néÿÿÿÿr) Ú connectionÚ descriptionÚdescription_flagsÚrowcountÚ arraysizeÚ _executedÚ lastrowidÚ_resultÚ rownumberÚ_rows)Úselfr©rúg/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-exc8n9q4/MySQLdb/cursors.pyÚ__init__AszBaseCursor.__init__cCs4z |jdkrW¢dS| ¡rqW5d|_d|_XdS)z6Close the cursor. No further queries will be possible.N)rrÚnextset©rrrrÚcloseNs zBaseCursor.closecCs|S©Nrr rrrÚ __enter__YszBaseCursor.__enter__cGs~| ¡dSr")r!)rÚexc_inforrrÚ__exit__\szBaseCursor.__exit__csz|j‰|j‰‡‡fdd„‰t|ttfƒrBt‡‡fdd„|Dƒƒ}n0t|tƒrf‡‡fdd„| ¡Dƒ}n ˆˆ|ƒƒ}d‰|S)NcsHt|tƒr| ˆ¡St|tƒr,ttˆ|ƒƒSt|tƒrDttˆ|ƒƒS|Sr")Ú isinstanceÚstrÚencodeÚtupleÚmapÚlist)Úx)ÚencodingÚ ensure_bytesrrr.ds    z-BaseCursor._escape_args..ensure_bytesc3s|]}ˆˆ|ƒƒVqdSr"r©Ú.0Úarg©r.ÚliteralrrÚ nsz*BaseCursor._escape_args..cs"i|]\}}ˆ|ƒˆˆ|ƒƒ“qSrr)r0ÚkeyÚvalr2rrÚ psÿz+BaseCursor._escape_args..)r-r3r&r)r+ÚdictÚitems)rÚargsÚconnÚretr)r-r.r3rÚ _escape_args`s   þ zBaseCursor._escape_argscCs|jstdƒ‚dS)Nzexecute() first)rrr rrrÚ_check_executed|szBaseCursor._check_executedcCs@|jr| ¡| ¡}| ¡}|dkr*dS| |¡| ¡dS)z`Advance to the next result set. Returns None if there are no more result sets. rNr)rÚfetchallÚ_get_dbZ next_resultÚ_do_get_resultÚ_post_get_result)rÚdbÚnrrrrr€s zBaseCursor.nextsetcCsV| ¡|_}|dkr$d|_|_n| ¡|_| ¡|_| ¡|_d|_|  ¡|_ dS©Nr) Ú _get_resultrrrZdescribeZ field_flagsZ affected_rowsrrZ insert_idr)rrCÚresultrrrrA�s   zBaseCursor._do_get_resultcCsdSr"rr rrrrBœszBaseCursor._post_get_resultcGsdS©z!Does nothing, required by DB API.Nr©rr:rrrÚ setinputsizesŸszBaseCursor.setinputsizescGsdSrHrrIrrrÚsetoutputsizes¢szBaseCursor.setoutputsizescCs|j}|dkrtdƒ‚|S)Nz cursor closed)rr)rÚconrrrr@¥szBaseCursor._get_dbc Csæ| ¡r q| ¡}t|tƒr(| |j¡}|dk rÆt|tƒrzi}| ¡D],\}}t|tƒrd| |j¡}| |¡||<qF|}nt t |j|ƒƒ}z ||}Wn.t k rÄ}zt t|ƒƒ‚W5d}~XYnXt|t tfƒsØt‚| |¡}|S)a‰Execute a query. query -- string, query to execute on server args -- optional sequence or mapping, parameters to use with query. Note: If args is a sequence, then %s must be used as the parameter placeholder in the query. If a mapping is used, %(key)s must be used as the placeholder. Returns integer represents rows affected, if any N)rr@r&r'r(r-r8r9r3r)r*Ú TypeErrorrÚbytesÚ bytearrayÚAssertionErrorÚ_query) rÚqueryr:rCÚnargsr5ÚitemÚmÚresrrrÚexecute«s*        zBaseCursor.executec s˜|sdSt ˆ¡}|rx| d¡d}| d¡ ¡}| d¡p>d}|ddkrX|d d ks\t‚ˆ ||||ˆjˆ ¡j¡St ‡‡fd d „|Dƒƒˆ_ ˆj S) axExecute a multi-row query. :param query: query to execute on server :param args: Sequence of sequences or mappings. It is used as parameter. :return: Number of rows affected, if any. This method improves performance on multiple-row INSERT and REPLACE. Otherwise it is equivalent to looping over args with execute(). Nrréérrú(rú)c3s|]}ˆ ˆ|¡VqdSr")rWr/©rRrrrr4ïsz)BaseCursor.executemany..) ÚRE_INSERT_VALUESÚmatchÚgroupÚrstriprPÚ_do_execute_manyÚmax_stmt_lengthr@r-Úsumr)rrRr:rUZq_prefixZq_valuesZ q_postfixrr\rÚ executemanyÑs$  ú zBaseCursor.executemanyc Csø| ¡}|j}t|tƒr"| |¡}t|tƒr6| |¡}t|tƒrJ| |¡}t|ƒ} t|ƒ}||t|ƒ|ƒ} | | 7} d} |D]^} ||| |ƒ} t| ƒt| ƒt|ƒd|krÊ| |  | |¡7} t|ƒ} n| d7} | | 7} q|| |  | |¡7} | |_ | S)Nrró,) r@r=r&r'r(rOÚiterÚnextÚlenrWr) rÚprefixÚvaluesZpostfixr:rbr-r;ÚescapeZsqlÚvÚrowsr1rrrraòs.         zBaseCursor._do_execute_manyrcs˜| ¡‰tˆtƒrˆ ˆj¡‰|rbdˆd‰dd ‡‡fdd„t|ƒDƒ¡}| |¡| ¡dˆd ‡fdd „t t |ƒƒDƒ¡f}| |¡|S) aExecute stored procedure procname with args procname -- string, name of procedure to execute on server args -- Sequence of parameters to use with procedure Returns the original args. Compatibility warning: PEP-249 specifies that any modified parameters must be returned. This is currently impossible as they are only available by storing them in a server variable and then retrieved by a query. Since stored procedures return zero or more result sets, there is no reliable way to get at OUT or INOUT parameters via callproc. The server variables are named @_procname_n, where procname is the parameter above and n is the position of the parameter (from zero). Once all result sets generated by the procedure have been fetched, you can issue a SELECT @_procname_0, ... query using .execute() to get any OUT or INOUT values. Compatibility warning: The act of calling a stored procedure itself creates an empty result set. This appears after any result sets generated by the procedure. This is non-standard behavior with respect to the DB-API. Be sure to use nextset() to advance through all result sets; otherwise you may get disconnected. s@_s_%d=%ssSET %srec3s$|]\}}ˆ|ˆ |¡fVqdSr")r3)r0Úindexr1)rCÚfmtrrr4/sz&BaseCursor.callproc..s CALL %s(%s)csg|]}dˆ|f‘qS)s@_%s_%dr)r0Úi)ÚprocnamerrÚ 7sz'BaseCursor.callproc..) r@r&r'r(r-ÚjoinÚ enumeraterQrÚrangerh)rrqr:Úqr)rCrorqrÚcallprocs    ÿ  þ zBaseCursor.callproccCs6| ¡}d|_| |¡| |¡| ¡||_|jSr")r@rrRrArBrr)rrvrCrrrrQ<s  zBaseCursor._querycCs|js dS|j ||j¡S)Nr)rZ fetch_rowÚ _fetch_type)rÚsizerrrÚ _fetch_rowEszBaseCursor._fetch_rowcCs t|jdƒSr")rfÚfetchoner rrrÚ__iter__JszBaseCursor.__iter__)N)r)r)%Ú__name__Ú __module__Ú __qualname__Ú__doc__rbÚ _exceptionsrrrr r r r r rrrrrr!r#r%r=r>rrArBrJrKr@rWrdrarwrQrzr|rrrrrsB4    &! . rc@sLeZdZdZdd„Zdd„Zdd„Zdd d „Zd d „Zddd„Z dd„Z dS)ÚCursorStoreResultMixInaThis is a MixIn class which causes the entire result set to be stored on the client side, i.e. it uses mysql_store_result(). If the result set can be very large, consider adding a LIMIT clause to your query, or using CursorUseResultMixIn instead.cCs | ¡ ¡Sr")r@Z store_resultr rrrrF_sz"CursorStoreResultMixIn._get_resultcCs| d¡|_d|_dSrE)rzrrr rrrrBbs z'CursorStoreResultMixIn._post_get_resultcCs8| ¡|jt|jƒkrdS|j|j}|jd|_|S)z]Fetches a single row from the cursor. None indicates that no more rows are available.Nr)r>rrhr©rrGrrrr{fs   zCursorStoreResultMixIn.fetchoneNcCs>| ¡|j|p|j}|j|j|…}t|t|jƒƒ|_|S©z…Fetch up to size rows from the cursor. Result set may be smaller than size. If size is not defined, cursor.arraysize is used.)r>rrrÚminrh)rryÚendrGrrrÚ fetchmanyps z CursorStoreResultMixIn.fetchmanycCs6| ¡|jr |j|jd…}n|j}t|jƒ|_|S)ú*Fetchs all available rows from the cursor.N)r>rrrhrƒrrrr?ys  zCursorStoreResultMixIn.fetchallÚrelativecCsb| ¡|dkr|j|}n|dkr*|}ntdt|ƒƒ‚|dksP|t|jƒkrXtdƒ‚||_dS)aScroll the cursor in the result set to a new position according to mode. If mode is 'relative' (default), value is taken as offset to the current position in the result set, if set to 'absolute', value states an absolute target position.r‰Úabsolutezunknown scroll mode %srz out of rangeN)r>rrÚreprrhrÚ IndexError)rÚvalueÚmodeÚrrrrÚscrollƒs zCursorStoreResultMixIn.scrollcCs,| ¡|jr|j|jd…p"|j}t|ƒSr")r>rrrfrƒrrrr|•szCursorStoreResultMixIn.__iter__)N)r‰) r}r~rr€rFrBr{r‡r?r�r|rrrrr‚Ys  r‚c@sFeZdZdZdd„Zdd„Zddd„Zd d „Zd d „Zd d„Z e Z dS)ÚCursorUseResultMixInaThis is a MixIn class which causes the result set to be stored in the server and sent row-by-row to client side, i.e. it uses mysql_use_result(). You MUST retrieve the entire result set and close() the cursor before additional queries can be performed on the connection.cCs | ¡ ¡Sr")r@Z use_resultr rrrrF£sz CursorUseResultMixIn._get_resultcCs.| ¡| d¡}|sdS|jd|_|dS)z%Fetches a single row from the cursor.rNr)r>rzr©rr�rrrr{¦s   zCursorUseResultMixIn.fetchoneNcCs,| ¡| |p|j¡}|jt|ƒ|_|Sr„)r>rzrrrh)rryr�rrrr‡¯szCursorUseResultMixIn.fetchmanycCs&| ¡| d¡}|jt|ƒ|_|S)rˆr)r>rzrrhr’rrrr?·s zCursorUseResultMixIn.fetchallcCs|Sr"rr rrrr|¾szCursorUseResultMixIn.__iter__cCs| ¡}|dkrt‚|Sr")r{Ú StopIteration)rÚrowrrrrgÁszCursorUseResultMixIn.next)N) r}r~rr€rFr{r‡r?r|rgÚ__next__rrrrr‘›s r‘c@seZdZdZdZdS)ÚCursorTupleRowsMixInzwThis is a MixIn class that causes all rows to be returned as tuples, which is the standard form required by DB API.rN©r}r~rr€rxrrrrr–Êsr–c@seZdZdZdZdS)ÚCursorDictRowsMixInznThis is a MixIn class that causes all rows to be returned as dictionaries. This is a non-standard feature.rNr—rrrrr˜Ñsr˜c@seZdZdZdS)ÚCursorzjThis is the standard Cursor class that returns rows as tuples and stores the result set in the client.N©r}r~rr€rrrrr™Øsr™c@seZdZdZdS)Ú DictCursorzeThis is a Cursor class that returns rows as dictionaries and stores the result set in the client.Nršrrrrr›Ýsr›c@seZdZdZdS)ÚSSCursorz_This is a Cursor class that returns rows as tuples and stores the result set in the server.Nršrrrrrœâsrœc@seZdZdZdS)Ú SSDictCursorzeThis is a Cursor class that returns rows as dictionaries and stores the result set in the server.Nršrrrrr�çsr�)r€Úrer�rÚcompilersÚ IGNORECASEÚDOTALLr]rr‚r‘r–r˜r™r›rœr�rrrrÚs, ýÿ ø AB/