U e@sdZddlmZddlZddlZddlmZddlmZddl m Z dZ e d e ejejBejBZe d ejejBejBZe d e ejejBejBZe d ejejBejBZe d Ze dejZe dZe dZdZGdddeZddZGdddeZGdddeZGdddeZ GdddeZ!Gddde Z"Gd d!d!eZ#Gd"d#d#eZ$Gd$d%d%eZ%Gd&d'd'e$e Z&Gd(d)d)e%e Z'dS)*zCursor classes ) namedtupleN)errors)MySQLCursorAbstract)PY2z \/\*.*?\*\/z'({0})|(["'`][^"'`]*?({0})[^"'`]*?["'`])z<\s*ON\s+DUPLICATE\s+KEY(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$z&({0}|\s)*INSERT({0}|\s)*INTO.+VALUES.*z.*VALUES\s*(\(.*\)).*s(%s)sV % \((?P[^)]+)\) (?P[diouxXeEfFgGcrs%]) s*;(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)s+%s(?=(?:[^"'`]*["'`][^"'`]*["'`])*[^"'`]*$)zNo result set to fetch fromc@s,eZdZdZddZddZeddZdS) _ParamSubstitutorz4 Substitutes parameters into SQL statement. cCs||_d|_dSNr)paramsindex)selfr r k/opt/hc_python/lib64/python3.8/site-packages/../../../lib/python3.8/site-packages/mysql/connector/cursor.py__init__Csz_ParamSubstitutor.__init__cCsH|j}|jd7_zt|j|WStk rBtdYnXdS)Nrz+Not enough parameters for the SQL statement)r bytesr IndexErrorrProgrammingError)r matchobjr r r r __call__Gsz_ParamSubstitutor.__call__cCst|j|jS)z8Returns number of parameters remaining to be substituted)lenr r r r r r remainingPsz_ParamSubstitutor.remainingN)__name__ __module__ __qualname____doc__rrpropertyrr r r r r?s  rcs&fdd}t|tr |dn|S)ah >>> _bytestr_format_dict(b'%(a)s', {b'a': b'foobar'}) b'foobar >>> _bytestr_format_dict(b'%%(a)s', {b'a': b'foobar'}) b'%%(a)s' >>> _bytestr_format_dict(b'%%%(a)s', {b'a': b'foobar'}) b'%%foobar' >>> _bytestr_format_dict(b'%(x)s %(y)s', ... {b'x': b'x=%(y)s', b'y': b'y=%(x)s'}) b'x=%(y)s y=%(x)s' csvd}|}|ddkrd}|ddkrJtr:|ddn|d}|}|dkrdtd|dtrr|dS|S)NZconversion_type%sZ mapping_keyutf-8z Unsupported conversion_type: {0}) groupdictrencode ValueErrorformatdecode)rvaluegroupskey value_dictr r replacebs  z%_bytestr_format_dict..replacer)RE_PY_MAPPING_PARAMsubrr#)Zbytestrr(r)r r'r _bytestr_format_dictVs  r,cseZdZdZdZfddZd%ddZdd Zd&d d Zd d Z ddZ d'ddZ ddZ ddZ ddZd(ddZd)ddZedd Zed!d"Zed#d$ZZS)* CursorBasez Base for defining MySQLCursor. This class is a skeleton and defines methods and members as required for the Python Database API Specification v2.0. It's better to inherite from MySQLCursor. Fcs*d|_d|_d|_d|_tt|dS)Nr) _description _rowcount_last_insert_id arraysizesuperr-rr __class__r r r}s zCursorBase.__init__r cCsdS)aCalls a stored procedue with the given arguments The arguments will be set during this session, meaning they will be called like ___arg where is an enumeration (+1) of the arguments. Coding Example: 1) Definining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN SET pProd := pFac1 * pFac2; END 2) Executing in Python: args = (5,5,0) # 0 is to hold pprod cursor.callproc('multiply', args) print(cursor.fetchone()) Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong. Nr )r procnameargsr r r callprocszCursorBase.callproccCsdS)zClose the cursor.Nr rr r r closeszCursorBase.closecCsdS)Executes the given operation Executes the given operation substituting any markers with the given parameters. For example, getting all rows where id is 5: cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,)) The multi argument should be set to True when executing multiple statements in one operation. If not set and multiple results are found, an InterfaceError will be raised. If warnings where generated, and connection.get_warnings is True, then self._warnings will be a list containing these warnings. Returns an iterator when multi is True, otherwise None. Nr )r operationr multir r r executeszCursorBase.executecCsdS)aExecute the given operation multiple times The executemany() method will execute the operation iterating over the list of parameters in seq_params. Example: Inserting 3 new employees and their phone number data = [ ('Jane','555-001'), ('Joe', '555-001'), ('John', '555-003') ] stmt = "INSERT INTO employees (name, phone) VALUES ('%s','%s')" cursor.executemany(stmt, data) INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax. Results are discarded. If they are needed, consider looping over data using the execute() method. Nr )r r;Z seqparamsr r r executemanyszCursorBase.executemanycCsdSQReturns next row of a query result set Returns a tuple or None. Nr rr r r fetchoneszCursorBase.fetchonercCsdS)a Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list. The number of rows returned can be specified using the size argument, which defaults to one Nr )r sizer r r fetchmanyszCursorBase.fetchmanycCsdS)zRReturns all rows of a query result set Returns a list of tuples. Nr rr r r fetchallszCursorBase.fetchallcCsdSzNot Implemented.Nr rr r r nextsetszCursorBase.nextsetcCsdSrEr )r sizesr r r setinputsizesszCursorBase.setinputsizesNcCsdSrEr )r rBcolumnr r r setoutputsizeszCursorBase.setoutputsizeTcCsdS)Reset the cursor to defaultNr r freer r r resetszCursorBase.resetcCs|jS)aReturns description of columns in a result This property returns a list of tuples describing the columns in in a result set. A tuple is described as follows:: (column_name, type, None, None, None, None, null_ok, column_flags) # Addition to PEP-249 specs Returns a list of tuples. )r/rr r r descriptionszCursorBase.descriptioncCs|jS)aReturns the number of rows produced or affected This property returns the number of rows produced by queries such as a SELECT, or affected rows when executing DML statements like INSERT or UPDATE. Note that for non-buffered cursors it is impossible to know the number of rows produced before having fetched them all. For those, the number of rows will be -1 right after execution, and incremented when fetching rows. Returns an integer. )r0rr r r rowcount szCursorBase.rowcountcCs|jS)aReturns the value generated for an AUTO_INCREMENT column Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement or None when there is no such value available. Returns a long value or None. r1rr r r lastrowids zCursorBase.lastrowid)r )r F)r)N)T)rrrr_rawrr8r9r=r>rArCrDrFrHrJrNrrOrPrR __classcell__r r r4r r-rs(        r-c@seZdZdZdCddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdDd d!Zd"d#Zd$d%Zd&d'ZdEd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZdFd7d8Zd9d:Zed;d<Z ed=d>Z!ed?d@Z"dAdBZ#dS)G MySQLCursoraDefault cursor for interacting with MySQL This cursor will execute statements and handle the result. It will not automatically fetch all rows. MySQLCursor should be inherited whenever other functionallity is required. An example would to change the fetch* member functions to return dictionaries instead of lists of values. Implements the Python Database API Specification v2.0 (PEP-249) NcCsPt|d|_g|_d|_d|_d|_d|_g|_d|_ |dk rL| |dS)NNNrF) r-r _connection_stored_results_nextrow _warnings_warning_count _executed_executed_list_binary_set_connectionr connectionr r r r3s zMySQLCursor.__init__cCs t|jdS)zm Iteration over the result set which calls self.fetchone() and returns the next row. N)iterrArr r r __iter__AszMySQLCursor.__iter__c CsDzt||_|jWn$ttfk r>tjddYnXdS)zSet the connectioni)errnoN)weakrefproxyrWZ is_connectedAttributeError TypeErrorrInterfaceErrorr`r r r r_Hs  zMySQLCursor._set_connectioncCs<d|_d|_g|_d|_d|_d|_d|_g|_|dS)rKr.rVNr) r0rYrXrZr[r/r\r]rNrr r r _reset_resultPszMySQLCursor._reset_resultcCs&z |jjWStk r YdSXdS)z'Check whether there is an unread resultFN)rW unread_resultrgrr r r _have_unread_result\s zMySQLCursor._have_unread_resultcCs|S)z'Used for iterating over the result set.)__next__rr r r nextcszMySQLCursor.nextcCs4z |}Wntjk r&tYnX|s0t|S)zm Used for iterating over the result set. Calles self.fetchone() to get the next row. )rArri StopIterationr rowr r r rmgs  zMySQLCursor.__next__cCs*|jdkrdS|j|d|_dS)zQClose the cursor Returns True when successful, otherwise False. NFT)rWhandle_unread_resultrjrr r r r9ts   zMySQLCursor.closec Cszr|jjj}|jjj}|jjj}i}t|D]>\}}|}||}||}||}trb|||<q0|||<q0Wn0t k r} zt d| W5d} ~ XYnX|SdS)z,Process query parameters given as dictionaryz)Failed processing pyformat-parameters; %sN) rW converterto_mysqlescapequotelistitemsrr Exceptionrr) r r rtrurvresr&r$converrr r r _process_params_dicts$    z MySQLCursor._process_params_dictc sz\|}|jjj|jjj|jjjfdd|D}fdd|D}fdd|D}Wn0tk r}ztd|W5d}~XYn Xt|SdS)zProcess query parameters.csg|] }|qSr r .0i)rtr r sz/MySQLCursor._process_params..csg|] }|qSr r r~)rur r rscsg|] }|qSr r r~)rvr r rsz'Failed processing format-parameters; %sN) rWrsrtrurvryrrtuple)r r rzr|r )rurvrtr _process_paramss   zMySQLCursor._process_paramsc Csz"|d|_|d|_|d|_Wn6ttfk rX}ztd|W5d}~XYnX||j j dkr|j rt |j dd|j dd dS) z@Handles result of execute() when there is no result set affected_rowsZ insert_id warning_countz"Failed handling non-resultset; {0}NTrr) r0r1r[KeyErrorrhrrr"_handle_warningsrWraise_on_warningsrZget_mysql_exception)r rzr|r r r _handle_noresultsets   zMySQLCursor._handle_noresultsetcCsdS)zHandles result set This method handles the result set and is called after reading and storing column information in _handle_result(). For non-buffering cursors, this method is usually doing nothing. Nr rr r r _handle_resultsetszMySQLCursor._handle_resultsetcCsbt|tstdd|kr8|d|_d|j_|n&d|krTd|j_||n tddS)z Handle the result after a command was send. The result can be either an OK-packet or a dictionary containing column/eof information. Raises InterfaceError when result is not a dict() or result is invalid. zResult was not a dict()columnsTrFzInvalid resultN) isinstancedictrrir/rWrkrr)r resultr r r _handle_results     zMySQLCursor._handle_resultccspt|j}d}t|}|||z|||_|d7}Wntk rb|d|_YnX|VqdS)aWGenerator returns MySQLCursor objects for multiple statements This method is only used when multiple statements are executed by the execute() method. It uses zip() to make an iterator from the given query_iter (result of MySQLConnection.cmd_query_iter()) and the list of statements that were executed. rrN)RE_SQL_SPLIT_STMTSsplitr\rnrjrstripr)r Z query_iterZ executed_listrrr r r _execute_iters   zMySQLCursor._execute_iterFc Cs\|sdS|jstd|j|d}z&t|ttfsN||jj }n|}Wn4t t fk r}ztt |W5d}~XYnX|dk rt|t rt|||}n.remove_commentsrzBFailed rewriting statement for multi-row INSERT. Check SQL syntax.rrr,Nz"Failed executing the operation; %s)rer+RE_SQL_ON_DUPLICATERE_SQL_COMMENTsearchRE_SQL_INSERT_VALUESrrirr rWcharsetrrr,r}rrrrrappendr)joinr\rrrErrorry) r r; seq_paramsrtmpmatchesfmtvaluesrr rr|r r r _batch_insert/sP        zMySQLCursor._batch_insertc Cs|r|s dS|jz t|}Wntk r@tdYnXtt|rz|s\d|_ dS| ||}|dk rz| |Sd}z:|D]0}| |||j r| r|||j 7}qWnBttfk r}ztd|W5d}~XYnYnX||_ dS)aExecute the given operation multiple times The executemany() method will execute the operation iterating over the list of parameters in seq_params. Example: Inserting 3 new employees and their phone number data = [ ('Jane','555-001'), ('Joe', '555-001'), ('John', '555-003') ] stmt = "INSERT INTO employees (name, phone) VALUES ('%s','%s)" cursor.executemany(stmt, data) INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax. Results are discarded. If they are needed, consider looping over data using the execute() method. Nz)Parameters for query must be an Iterable.rz#Failed executing the operation; {0})rWrrrbrhrrrrRE_SQL_INSERT_STMTr0rr= with_rowsrlrDr!rir")r r;r_rrowcntr r|r r r r>gs<       zMySQLCursor.executemanycCs t|jS)zReturns an iterator for stored results This method returns an iterator over results which are stored when callproc() is called. The iterator will provide MySQLCursorBuffered instances. Returns a iterator. )rbrXrr r r stored_resultss zMySQLCursor.stored_resultsr c Cs|rt|tstdt|ttfs,tdd}g|_g}zpg}g}|rt|D]|\}}|j||dd} || t|tr|d| |d| d| |dfqR|| | d| |fqRd |d |} |j j } |j | D]n} d |j _ |jrt|j } nt|j } d | | _| | | jd k rR| j|_d| kr|| q| |j _ |rdd |}| |||_|WS||_WdSWnLtjk rYn4tk r}ztd|W5d }~XYnXd S)aCalls a stored procedure with the given arguments The arguments will be set during this session, meaning they will be called like ___arg where is an enumeration (+1) of the arguments. Coding Example: 1) Defining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN SET pProd := pFac1 * pFac2; END 2) Executing in Python: args = (5, 5, 0) # 0 is to hold pprod cursor.callproc('multiply', args) print(cursor.fetchone()) For OUT and INOUT parameters the user should provide the type of the parameter as well. The argument should be a tuple with first item as the value of the parameter to pass and second argument the type of the argument. In the above example, one can call callproc method like: args = (5, 5, (0, 'INT')) cursor.callproc('multiply', args) The type of the argument given in the tuple will be used by the MySQL CAST function to convert the values in the corresponding MySQL type (See CAST in MySQL Reference for more information) Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong. zprocname must be a stringzargs must be a sequencez@_{name}_arg{index}r)namer z CAST({0} AS {1})z SET {0}=%srz CALL {0}({1}),Fz(a result of {0})Nrz SELECT {0}r z"Failed calling stored routine; {0})rrr!rrwrX enumerater"rr=rrWZ_consume_resultsrrSMySQLCursorBufferedRawZ _get_selfMySQLCursorBufferedr\rrZrArrryri)r r6r7ZargfmtresultsargnamesZargtypesidxargargnamecallZcan_consume_resultsrrselectr|r r r r8s`$           zMySQLCursor.callproccCs|jS)zReturns the value generated for an AUTO_INCREMENT column Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Returns a long value or None. rQrr r r getlastrowid szMySQLCursor.getlastrowidc Csrg}z,|jjdd}|d|}|Wn0tk r`}ztd|W5d}~XYnXt|rn|SdS)z Fetch warnings doing a SHOW WARNINGS. Can be called after getting the result. Returns a result set or None when there were no warnings. F)rawz SHOW WARNINGSzFailed getting warnings; %sN) rWcursorr=rDr9ryrrir)r rzcurr|r r r _fetch_warningss  zMySQLCursor._fetch_warningscCs |jjdkr|jr||_dS)z7Handle possible warnings after all results are consumedTN)rWZ get_warningsr[rrZrr r r r+szMySQLCursor._handle_warningscCsVd|j_d|_|d|_||jjdkrR|jrRt|jdd|jdddS) zHandle EOF packetFrVrTrrrN) rWrkrYr[rrrZrrr eofr r r _handle_eof0s  zMySQLCursor._handle_eofcCs|s dSd}|jdkr4|jj|j|jd\}}n |j\}}|r|jj|j|jd|_|jd}|dk rt|||jdkrd|_n|jd7_|r|||S)zQReturns the next row in the result set Returns a tuple or None. NrVbinaryrrr.)rlrYrWget_rowr^rOrr0)r rqrr r r _fetch_row:s.       zMySQLCursor._fetch_rowcCs2|}|r.t|jdr*|jj||jS|SdS)r@rsN)rhasattrrWrs row_to_pythonrOrpr r r rAXs zMySQLCursor.fetchonecCsBg}|p |j}|dkr>|r>|d8}|}|r||q|SNrr)r2rlrArr rBrzZcntrqr r r rCes  zMySQLCursor.fetchmanycsstdj\}}jdr<|djdtjdrfjjj fdd|D} |t |}|dkrj dkrd_ j |7_ |S)NNo result set to fetch from.rrscsg|]}|jqSr rOrrqrr r r rxsz(MySQLCursor.fetchall..r.) rlrrirWget_rowsrYinsertrrsrrrr0r rowsrrPr rr rDos     zMySQLCursor.fetchallcCs|js dStdd|jDS)ztReturns column names This property returns the columns names as a tuple. Returns a tuple. r cSsg|] }|dqS)rr )rdr r r rsz,MySQLCursor.column_names..)rOrrr r r column_namesszMySQLCursor.column_namesc CsH|jdkrdSz|jdWSttfk rB|jYSXdS)zReturns the executed statement This property returns the executed statement. When multiple statements were executed, the current statement in the iterator will be returned. Nr)r\rr#rgrrr r r statements  zMySQLCursor.statementcCs|js dSdS)zReturns whether the cursor could have rows returned This property returns True when column descriptions are available and possibly also rows, which will need to be fetched. Returns True or False. FTrrr r r rs zMySQLCursor.with_rowscCsjd}|jrTz|jd}Wntk r4|j}YnXt|dkrX|ddd}nd}|j|jj|dS)Nz{class_name}: {stmt}r(z..z(Nothing executed yet)) class_namer)r\r#rgrr"r5r)r rZexecutedr r r __str__s  zMySQLCursor.__str__)N)NF)r )N)$rrrrrrcr_rjrlrnrmr9r}rrrrrr=rr>rr8rrrrrrArCrDrrrrrr r r r rU'sF     >88 a      rUc@sReZdZdZdddZddZddd Zd d Zd d ZdddZ e ddZ dS)rz*Cursor which fetches rows within execute()NcCst||d|_d|_dSr)rUr_rows _next_rowr`r r r rs zMySQLCursorBuffered.__init__cCsJ|j\|_}t|j|_||d|_z d|j_Wn YnXdS)NrF)rWrrrr0rrrkrr r r rs   z%MySQLCursorBuffered._handle_resultsetTcCs d|_dSNrrLr r r rNszMySQLCursorBuffered.resetcCs:d}z|j|j}WnYdSX|jd7_|SdS)Nr)rrrpr r r rszMySQLCursorBuffered._fetch_rowcCst|jdkrtdg}t|jdrT|j|jdD]}||jj||j q4n|j|jd}t |j|_|S)Nrrs) rrrirrWrrrsrrOrr rzrqr r r rDs      zMySQLCursorBuffered.fetchallcCs:g}|p |j}|dkr6|d8}|}|r||q|Sr)r2rArrr r r rCs  zMySQLCursorBuffered.fetchmanycCs |jdk Srrrr r r rszMySQLCursorBuffered.with_rows)N)T)N) rrrrrrrNrrDrCrrr r r r rs    rc@s$eZdZdZdZddZddZdS)MySQLCursorRawzS Skips conversion from MySQL datatypes to Python types when fetching rows. TcCs|}|r|SdSrrrpr r r rAszMySQLCursorRaw.fetchonecCsx|std|j\}}|jdr<|d|jd||t|}|dkrf|j dkrfd|_ |j |7_ |S)Nrrr.) rlrrirWrrYrrrr0rr r r rDs   zMySQLCursorRaw.fetchallN)rrrrrSrArDr r r r rsrc@s0eZdZdZdZddZddZeddZd S) rz Cursor which skips conversion from MySQL datatypes to Python types when fetching rows and fetches rows within execute(). TcCs|}|r|SdSrrrpr r r rAszMySQLCursorBufferedRaw.fetchonecCs.|jdkrtddd|j|jdDS)NrcSsg|]}|qSr r )rrr r r r sz3MySQLCursorBufferedRaw.fetchall..)rrrirrr r r rDs  zMySQLCursorBufferedRaw.fetchallcCs |jdk Srrrr r r r"sz MySQLCursorBufferedRaw.with_rowsN) rrrrrSrArDrrr r r r rs rcsteZdZdZdfdd ZddZfddZdd d Zd d ZdddZ ddZ ddZ dddZ ddZ ZS)MySQLCursorPreparedz+Cursor using MySQL Prepared Statements Ncs2tt||d|_d|_d|_d|_d|_dS)NrT)r3rrrr _preparedr^ _have_resultr`r4r r r*s zMySQLCursorPrepared.__init__cOs tdS)zQCalls a stored procedue Not supported with MySQLCursorPrepared. N)rZNotSupportedError)r r7kwargsr r r r82szMySQLCursorPrepared.callproccsL|jr:z|j|jdWntjk r2YnXd|_tt|dS)zzClose the cursor This method will try to deallocate the prepared statement and close the cursor. statement_idN)rrWcmd_stmt_closerrr3rr9rr4r r r99szMySQLCursorPrepared.closecCsdS)zConvert row data from MySQL to Python types The conversion is done while reading binary data in the protocol module. Nr )r rowdatadescr r r _row_to_pythonHsz"MySQLCursorPrepared._row_to_pythoncCs@t|tr$d|j_d|_||n|d|_d|j_d|_dS)zHandle result after executionFrTN)rrrWrkrrr/)r rzr r r rPs   z"MySQLCursorPrepared._handle_resultr Fc Cs8||jk r|jr"|j|jd||_zt|tsB||jj}Wn4tt fk rx}zt t |W5d}~XYnXd|krt td|}z|j||_Wnt jk rd|_YnX|j|jd|jdr|sdSt|jdt|kr t j ddd|jj|jd||jdd }||dS) aPrepare and execute a MySQL Prepared Statement This method will preare the given operation and execute it using the optionally given parameters. If the cursor instance already had a prepared statement, it is first closed. rNs%s? parametersiz:Incorrect number of arguments executing prepared statement)rdmsg)datar)r\rrWrrrr rrrrrrrr+RE_SQL_FIND_PARAMZcmd_stmt_preparerZcmd_stmt_resetrZcmd_stmt_executer)r r;r r<r|rzr r r r=[s<   zMySQLCursorPrepared.executec Csd}z:|D]0}||||jr0|r0|||j7}q WnDttfk rv}ztdj |dW5d}~XYnYnX||_dS)aDPrepare and execute a MySQL Prepared Statement many times This method will prepare the given operation and execute with each tuple found the list seq_params. If the cursor instance already had a prepared statement, it is first closed. executemany() simply calls execute(). rz'Failed executing the operation; {error})errorN) r=rrlrDr0r!rhrrir")r r;rrr r|r r r r>s   zMySQLCursorPrepared.executemanycCs |p dSr?rrr r r rAszMySQLCursorPrepared.fetchonecCsBg}|p |j}|dkr>|r>|d8}|}|r||q|Sr)r2rlrrrr r r rCs  zMySQLCursorPrepared.fetchmanycCsB|std|jj|j|jd\}}t||_| ||S)Nrr) rlrrirWrr^rOrr0r)r rrr r r rDs    zMySQLCursorPrepared.fetchall)N)N)r F)N)rrrrrr8r9rrr=r>rArCrDrTr r r4r r's   . rc@s*eZdZdZd ddZddZddZdS) MySQLCursorDictz Cursor fetching rows as dictionaries. The fetch methods of this class will return dictionaries instead of tuples. Each row is a dictionary that looks like: row = { "col1": value1, "col2": value2 } NcCs:t|jdr|jj||}n|}|r6tt|j|SdS)zWConvert a MySQL text result row to Python types Returns a dictionary. rsN)rrWrsrrziprr rrrqr r r rs  zMySQLCursorDict._row_to_pythoncCs|}|r|||jSdS/Returns next row of a query result set NrrrOrpr r r rAszMySQLCursorDict.fetchonecssttj\}}jdr<|djdfdd|D}|t |}|dkrxj dkrxd_ j |7_ |S)/Returns all rows of a query result set rcsg|]}|jqSr rrOrrr r rsz,MySQLCursorDict.fetchall..r. rlrriERR_NO_RESULT_TO_FETCHrWrrYrrrr0r rrrzrPr rr rDs    zMySQLCursorDict.fetchall)NrrrrrrArDr r r r rs rc@s*eZdZdZd ddZddZddZdS) MySQLCursorNamedTuplez Cursor fetching rows as named tuple. The fetch methods of this class will return namedtuples instead of tuples. Each row is returned as a namedtuple and the values can be accessed as: row.col1, row.col2 NcCsBt|jdr|jj||}n|}|r>td|j|_|j|SdS)zXConvert a MySQL text result row to Python types Returns a named tuple. rsRowN)rrWrsrrrZ named_tuplerr r r rs  z$MySQLCursorNamedTuple._row_to_pythoncCs.|}|r*t|jdr&|||jS|SdS)rrsN)rrrWrrOrpr r r rA s  zMySQLCursorNamedTuple.fetchonecssttj\}}jdr<|djdfdd|D}|t |}|dkrxj dkrxd_ j |7_ |S)rrcsg|]}|jqSr rrrr r rsz2MySQLCursorNamedTuple.fetchall..r.rrr rr rDs    zMySQLCursorNamedTuple.fetchall)Nrr r r r rs  rc@s eZdZdZddZddZdS)MySQLCursorBufferedDictz8 Buffered Cursor fetching rows as dictionaries. cCs|}|r|||jSdSrrrpr r r rA-sz MySQLCursorBufferedDict.fetchonecCsR|jdkrttg}|j|jdD]}||||jq(t|j|_|SrN rrrirrrrrOrrr r r rD5s   z MySQLCursorBufferedDict.fetchallNrrrrrArDr r r r r)src@s eZdZdZddZddZdS)MySQLCursorBufferedNamedTuplez7 Buffered Cursor fetching rows as named tuple. cCs|}|r|||jSdSrrrpr r r rAFsz&MySQLCursorBufferedNamedTuple.fetchonecCsR|jdkrttg}|j|jdD]}||||jq(t|j|_|Srr rr r r rDNs   z&MySQLCursorBufferedNamedTuple.fetchallNr r r r r r Bsr )(r collectionsrrrerrZ abstractsrZcatch23rZ SQL_COMMENTcompiler"IMSrrrrrXr*rrrobjectrr,r-rUrrrrrrrr r r r r sf     6=47