U e?@sdZddlZddlmZeddddgejejBZGd d d Z Gd d d Z Gd ddZ GdddZ GdddZ Gddde e e ZGddde e e ZGddde e e ZGddde e e ZdS)zyMySQLdb Cursors This module implements Cursors of various types for MySQLdb. By default, MySQLdb uses the Cursor class. N)ProgrammingErrorz'\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)z6(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))z(\s*(?:ON DUPLICATE.*)?);?\s*\Zc@s&eZdZdZdZddlmZmZmZm Z m Z m Z m Z m Z mZmZmZdZddZdd Zd d Zd d ZddZddZddZddZddZddZddZddZd1ddZd2d d!Zd3d"d#Z d$d%Z!d&d'Z"d4d)d*Z#d+d,Z$d5d-d.Z%d/d0Z&eZeZe Z e Z e Z e Z e Z eZeZeZdS)6 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) MySQLErrorWarningErrorInterfaceError DatabaseError DataErrorOperationalErrorIntegrityError InternalErrorrNotSupportedErrorNcCs@||_d|_d|_d|_d|_d|_d|_d|_d|_d|_ dS)Nrr) connection descriptiondescription_flagsrowcount arraysize _executed lastrowid_result rownumber_rows)selfrr?/opt/hc_python/lib64/python3.8/site-packages/MySQLdb/cursors.py__init__AszBaseCursor.__init__cCsZd|_d|_d|_d|_|jr.|jd|_|j}|dkr@dS|dkrV|q@dSNr) rrrrrdiscardr next_resultZdiscard_resultrconrrr_discardNs  zBaseCursor._discardcCs2z|jdkrWdS|W5d|_d|_XdS)z6Close the cursor. No further queries will be possible.N)rrr#rrrrclosebs   zBaseCursor.closecCs|SNrr$rrr __enter__lszBaseCursor.__enter__cGs~|dSr&)r%)rexc_inforrr__exit__oszBaseCursor.__exit__cCs|jstddS)Nzexecute() first)rrr$rrr_check_executedsszBaseCursor._check_executedcCs@|jr||}|}|dkr*dS|||dS)z`Advance to the next result set. Returns None if there are no more result sets. Nr)rfetchall_get_dbr _do_get_result_post_get_result)rdbnrrrrnextsetws zBaseCursor.nextsetcCsV||_}|dkr$d|_|_n||_||_||_d|_| |_ dSr) _get_resultrrrZdescribeZ field_flagsZ affected_rowsrrZ insert_idr)rr0resultrrrr.s   zBaseCursor._do_get_resultcCsdSr&rr$rrrr/szBaseCursor._post_get_resultcGsdSz!Does nothing, required by DB API.Nrrargsrrr setinputsizesszBaseCursor.setinputsizescGsdSr5rr6rrrsetoutputsizesszBaseCursor.setoutputsizescCs|j}|dkrtd|S)Nz cursor closed)rrr!rrrr-szBaseCursor._get_dbcCs4||||}t|ttfs&t||}|S)aExecute 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 )r#_mogrify isinstancebytes bytearrayAssertionError_query)rqueryr7Zmogrified_queryresrrrexecutes   zBaseCursor.executec Cs|}t|tr||j}|dk rt|trpi}|D],\}}t|trZ||j}||||<q<|}ntt |j|}z ||}Wn.t k r}zt t|W5d}~XYnX|S)z Return query after binding args.N) r-r;strencodeencodingdictitemsliteraltuplemap TypeErrorr)rr@r7r0nargskeyitemmrrrr:s"      zBaseCursor._mogrifycCs||||jS)aReturn query after binding args. query -- string, query to mogrify 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 string representing query that would be executed by the server )r:decoder-rE)rr@r7rrrmogrifys zBaseCursor.mogrifyc s|sdSt}|rx|dd}|d}|dp>d}|ddkrX|d d ks\t||||jjSt 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(). Nrrrr(r+)c3s|]}|VqdSr&)rB).0argr@rrr sz)BaseCursor.executemany..) RE_INSERT_VALUESmatchgrouprstripr>_do_execute_manymax_stmt_lengthr-rEsumr)rr@r7rOZq_prefixZq_valuesZ q_postfixrrXr executemanys$   zBaseCursor.executemanyc Cst|tr||}t|tr(||}t|tr<||}t|}t|}||t|}||7}d} |D]\} ||| }t|t|t|d|kr| |||7} t|}n|d7}||7}ql| |||7} | |_ | S)Nrr,) r;rCrDr=iterr:nextlenrBr) rprefixvaluesZpostfixr7r_rEsqlvrowsrWrrrr^s*          zBaseCursor._do_execute_manyrcs|ttrj|rbddddfddt|D}|||ddfdd t t |Df}|||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 %srbc3s$|]\}}||fVqdSr&)rH)rVindexrW)r0fmtrrrY8sz&BaseCursor.callproc..s CALL %s(%s)csg|]}d|fqS)s@_%s_%dr)rVi)procnamerr @sz'BaseCursor.callproc..) r-r;rCrDrEjoin enumerater?r2rangere)rrnr7qr)r0rlrnrcallprocs       zBaseCursor.callproccCsB|}d|_d|_d|_|||||||_|jSr&)r-rrrr@r.r/r)rrsr0rrrr?Es  zBaseCursor._querycCs|js dS|j||jS)Nr)rZ fetch_row _fetch_type)rsizerrr _fetch_rowPszBaseCursor._fetch_rowcCs t|jdSr&)rcfetchoner$rrr__iter__UszBaseCursor.__iter__)N)N)N)r)r)'__name__ __module__ __qualname____doc__r_ _exceptionsrrrr r r r r rrrrrr#r%r'r)r*r2r.r/r8r9r-rBr:rQrar^rtr?rwryrrrrrsF4      ! . rc@sLeZdZdZddZddZddZdd d Zd d ZdddZ ddZ 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$rrrr3jsz"CursorStoreResultMixIn._get_resultcCs|d|_d|_dSr)rwrrr$rrrr/ms z'CursorStoreResultMixIn._post_get_resultcCs8||jt|jkrdS|j|j}|jd|_|S)z]Fetches a single row from the cursor. None indicates that no more rows are available.Nr)r*rrerrr4rrrrxqs   zCursorStoreResultMixIn.fetchoneNcCs>||j|p|j}|j|j|}t|t|j|_|SzFetch up to size rows from the cursor. Result set may be smaller than size. If size is not defined, cursor.arraysize is used.)r*rrrminre)rrvendr4rrr fetchmany{s z CursorStoreResultMixIn.fetchmanycCs6||jr |j|jd}n|j}t|j|_|S)+Fetches all available rows from the cursor.N)r*rrrerrrrr,s  zCursorStoreResultMixIn.fetchallrelativecCsb||dkr|j|}n|dkr*|}ntdt||dksP|t|jkrXtd||_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.rabsolutezunknown scroll mode %srz out of rangeN)r*rrreprrer IndexError)rvaluemoderrrrscrolls zCursorStoreResultMixIn.scrollcCs,||jr|j|jdp"|j}t|Sr&)r*rrrcrrrrryszCursorStoreResultMixIn.__iter__)N)r) rzr{r|r}r3r/rxrr,rryrrrrrds  rc@sFeZdZdZddZddZdddZd d Zd d Zd dZ 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$rrrr3sz CursorUseResultMixIn._get_resultcCs.||d}|sdS|jd|_|dS)z%Fetches a single row from the cursor.rNr)r*rwrrrrrrrxs   zCursorUseResultMixIn.fetchoneNcCs,|||p|j}|jt||_|Sr)r*rwrrre)rrvrrrrrszCursorUseResultMixIn.fetchmanycCs&||d}|jt||_|S)rr)r*rwrrerrrrr,s zCursorUseResultMixIn.fetchallcCs|Sr&rr$rrrryszCursorUseResultMixIn.__iter__cCs|}|dkrt|Sr&)rx StopIteration)rrowrrrrdszCursorUseResultMixIn.next)N) rzr{r|r}r3rxrr,ryrd__next__rrrrrs rc@seZdZdZdZdS)CursorTupleRowsMixInzwThis is a MixIn class that causes all rows to be returned as tuples, which is the standard form required by DB API.rNrzr{r|r}rurrrrrsrc@seZdZdZdZdS)CursorDictRowsMixInznThis is a MixIn class that causes all rows to be returned as dictionaries. This is a non-standard feature.rNrrrrrrsrc@seZdZdZdS)CursorzjThis is the standard Cursor class that returns rows as tuples and stores the result set in the client.Nrzr{r|r}rrrrrsrc@seZdZdZdS) DictCursorzeThis is a Cursor class that returns rows as dictionaries and stores the result set in the client.Nrrrrrrsrc@seZdZdZdS)SSCursorz_This is a Cursor class that returns rows as tuples and stores the result set in the server.Nrrrrrrsrc@seZdZdZdS) SSDictCursorzeThis is a Cursor class that returns rows as dictionaries and stores the result set in the server.Nrrrrrrsr)r}rer~rcompilerp IGNORECASEDOTALLrZrrrrrrrrrrrrrs,   LB/