U ê üe1˜ã@sìdZddlmZddlZddlZddlmZddlmZm Z ddl m Z m Z m Z mZmZmZddlmZdd lmZdd lmZmZmZmZmZmZmZmZmZmZdd l m!Z!m"Z"dd l#m$Z$dd l%m&Z&ddl'm(Z(Gdd„de(ƒZ)dS)z/Implementing communication with MySQL servers. é)ÚIOBaseNé)Úget_auth_plugin)ÚPY2Úisstr)Ú ClientFlagÚ ServerCmdÚ ServerFlagÚ flag_is_setÚ ShutdownTypeÚNET_BUFFER_LENGTH)Úerrors)ÚMySQLConverter) Ú CursorBaseÚ MySQLCursorÚMySQLCursorRawÚMySQLCursorBufferedÚMySQLCursorBufferedRawÚMySQLCursorPreparedÚMySQLCursorDictÚMySQLCursorBufferedDictÚMySQLCursorNamedTupleÚMySQLCursorBufferedNamedTuple)ÚMySQLUnixSocketÚMySQLTCPSocket)Ú MySQLProtocol)Ú int4store)ÚMySQLConnectionAbstractcsäeZdZdZ‡fdd„Zdd„Zdod d „Zdpd d „Zdqd d„Zdd„Z dd„Z dd„Z e Z drdd„Z dsdd„Zdd„Zedd„ƒZdd „Zd!d"„Zd#d$„Zd%d&„Zdtd'd(„Zdud)d*„Zd+d,„Zd-d.„Zdvd/d0„Zd1d2„Zd3d4„Zd5d6„Zdwd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dxdBdC„Z#edDdE„ƒZ$e$j%dFdE„ƒZ$dGdH„Z&dydIdJ„Z'dzdLdM„Z(d{dNdO„Z)edPdQ„ƒZ*d|dRdS„Z+dTdU„Z,dVdW„Z-dXdY„Z.dZd[„Z/d\d]„Z0d^d_„Z1d`da„Z2d}dcdd„Z3dedf„Z4dgdh„Z5didj„Z6dkdl„Z7dmdn„Z8‡Z9S)~ÚMySQLConnectionzConnection to a MySQL Servercsòd|_d|_d|_tt|ƒj||Žt|_t  ¡|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_i|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_!d|_"d|_#d|_$d|_%t&|ƒdkrî|j'f|ŽdS)Né!FÚz 127.0.0.1iê rT)(Ú _protocolÚ_socketÚ _handshakeÚsuperrÚ__init__rÚ_converter_classrÚ get_defaultÚ _client_flagsÚ _charset_idZ _sql_modeZ _time_zoneZ _autocommitÚ_userÚ _passwordÚ _databaseZ_hostZ_portZ _unix_socketZ _client_hostZ _client_portÚ_sslÚ _force_ipv6Z _use_unicodeZ _get_warningsZ_raise_on_warningsÚ_connection_timeoutÚ _bufferedZ_unread_resultÚ_have_next_resultÚ_rawÚ_in_transactionZ_prepared_statementsÚ _ssl_activeÚ _auth_pluginZ_pool_config_versionÚlenÚconnect)ÚselfÚargsÚkwargs©Ú __class__©úo/opt/hc_python/lib64/python3.8/site-packages/../../../lib/python3.8/site-packages/mysql/connector/connection.pyr%5sF  zMySQLConnection.__init__c Cs |j ¡}|ddkr t |¡‚d|_z|j |¡}Wn2tk rh}zt d  |¡¡‚W5d}~XYnX|  |d¡|_ |dt j @r–| t j g¡||_dS)z'Get the handshake from the MySQL serverééÿNzFailed parsing handshake; {0}Zserver_version_originalZ capabilities)r"Úrecvr Ú get_exceptionr#r!Zparse_handshakeÚ ExceptionÚInterfaceErrorÚformatZ_check_server_versionÚ_server_versionrZ PLUGIN_AUTHZset_client_flags)r8ÚpacketÚ handshakeÚerrr=r=r>Ú _do_handshakeas    ÿÿzMySQLConnection._do_handshakeNrrc Csšd|_|tj@rD|rD|jj||d}|j |¡|jjf|Žd|_|jj|j ||||||j|j d}|j |¡|  ||¡|tj @s–|r–|  |¡dS)aeAuthenticate with the MySQL server Authentication happens in two parts. We first send a response to the handshake. The MySQL server will then send either an AuthSwitchRequest or an error packet. Raises NotSupportedError when we get the old, insecure password reply back. Raises any error coming from MySQL. F)ÚcharsetÚ client_flagsT©rHÚusernameÚpasswordÚdatabaserKrLÚ ssl_enabledZ auth_plugin)r4rZSSLr!Z make_auth_sslr"ÚsendZ switch_to_sslZ make_authr#r5Ú_auth_switch_requestÚCONNECT_WITH_DBÚ cmd_init_db)r8rNrOrPrLrKZ ssl_optionsrGr=r=r>Ú_do_authvs. ÿ û   zMySQLConnection._do_authcCsº|j ¡}|ddkr.t|ƒdkr.t d¡‚nˆ|ddkr |j |¡\}}t|ƒ|||jd}|  ¡}|j  |¡|j ¡}|ddkr’|  |¡S|j  |¡}n|ddkr¶t  |¡‚dS) z®Handle second part of authentication Raises NotSupportedError when we get the old, insecure password reply back. Raises any error coming from MySQL. r?éþéz‡Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manual)rOrQrr@N)r"rAr6r ÚNotSupportedErrorr!Zparse_auth_switch_requestrr4Z auth_responserRÚ _handle_okZparse_auth_more_datarB)r8rNrOrGZnew_auth_pluginZ auth_dataÚauthÚresponser=r=r>rS—s, ÿ  ÿÿ     z$MySQLConnection._auth_switch_requestcCsFd}|jr"tjdkr"t|jd}nt|j|j|jd}| |j ¡|S)zÉGet connection based on configuration This method will return the appropriated connection object using the connection parameters. Returns subclass of MySQLBaseSocket. NÚnt)Ú unix_socket)ÚhostÚportZ force_ipv6) r^ÚosÚnamerrZ server_hostZ server_portr.Zset_connection_timeoutr/)r8ZprtclsÚconnr=r=r>Ú_get_connection³sþ zMySQLConnection._get_connectioncCsxtƒ|_| ¡|_|j ¡| ¡| |j|j|j |j |j |j ¡|  |j¡|j tj@rt|jj|j_|jj|j_dS)z–Open the connection to the MySQL server This method sets up and opens the connection to the MySQL server. Raises on errors. N)rr!rdr"Úopen_connectionrJrVr*r+r,r(r)r-Zset_converter_classr&rZCOMPRESSZrecv_compressedrAZsend_compressedrR©r8r=r=r>Ú_open_connectionÅs   þ   z MySQLConnection._open_connectionc Cs8|js dSz|j ¡Wnttjfk r2YnXdS)z.Shut down connection to MySQL Server. N)r"ÚshutdownÚAttributeErrorr ÚErrorrfr=r=r>rhØs zMySQLConnection.shutdownc Cs@|js dSz| ¡|j ¡Wnttjfk r:YnXdS)z Disconnect from the MySQL serverN)r"Úcmd_quitZclose_connectionrir rjrfr=r=r>ÚcloseãszMySQLConnection.closeTcCs\| ¡z"|j |j ||p|¡||¡Wntk rHt d¡‚YnX|sRdS|j ¡S)a4Send a command to the MySQL server This method sends a command with an optional argument. If packet is not None, it will be sent and the argument will be ignored. The packet_number is optional and should usually not be used. Some commands might not result in the MySQL server returning a response. If a command does not return anything, you should set expect_response to False. The _send_cmd method will then return None instead of a MySQL packet. Returns a MySQL packet or None. úMySQL Connection not available.N) Úhandle_unread_resultr"rRr!Ú make_commandrir ÚOperationalErrorrA)r8ÚcommandÚargumentZ packet_numberrGÚexpect_responseZcompressed_packet_numberr=r=r>Ú _send_cmdïsþzMySQLConnection._send_cmdFcCsª| ¡t|dƒstdƒ‚z2| td¡}|rJ|j |¡| td¡}q*Wntk rjt  d¡‚YnX|r z|j d¡Wntk ržt  d¡‚YnX|j  ¡S)a4Send data to the MySQL server This method accepts a file-like object and sends its data as is to the MySQL server. If the send_empty_packet is True, it will send an extra empty package (for example when using LOAD LOCAL DATA INFILE). Returns a MySQL packet. Úreadzexpecting a file-like objectérmó) rnÚhasattrÚ ValueErrorrur r"rRrir rprA)r8Ú data_fileÚsend_empty_packetÚbufr=r=r>Ú _send_data s$   ÿ zMySQLConnection._send_datacCs ttj|ƒ|_ttj|ƒ|_dS)aHandle the server flags found in MySQL packets This method handles the server flags send by MySQL OK and EOF packets. It, for example, checks whether there exists more result sets or whether there is an ongoing transaction. N)r r ZMORE_RESULTS_EXISTSr1ZSTATUS_IN_TRANSr3)r8Úflagsr=r=r>Ú_handle_server_status-sÿz%MySQLConnection._handle_server_statuscCs|jS)z'MySQL session has started a transaction)r3rfr=r=r>Úin_transaction8szMySQLConnection.in_transactioncCsN|ddkr*|j |¡}| |d¡|S|ddkr@t |¡‚t d¡‚dS)aHandle a MySQL OK packet This method handles a MySQL OK packet. When the packet is found to be an Error packet, an error will be raised. If the packet is neither an OK or an Error packet, errors.InterfaceError will be raised. Returns a dict() r?rÚ status_flagr@zExpected OK packetN)r!Zparse_okrr rBrD)r8rGZok_pktr=r=r>rZ=s    zMySQLConnection._handle_okcCsN|ddkr*|j |¡}| |d¡|S|ddkr@t |¡‚t d¡‚dS)a Handle a MySQL EOF packet This method handles a MySQL EOF packet. When the packet is found to be an Error packet, an error will be raised. If the packet is neither and OK or an Error packet, errors.InterfaceError will be raised. Returns a dict() r?rWrr@zExpected EOF packetN)r!Z parse_eofrr rBrD)r8rGÚeofr=r=r>Ú _handle_eofNs    zMySQLConnection._handle_eofc Csxzt|dƒ}WnTtk rbz|j d¡Wntk rLt d¡‚YnXt d |¡¡‚YnX|  |j |dd¡S)z'Handle a LOAD DATA INFILE LOCAL requestÚrbrwrmzFile '{0}' could not be readT)r{) ÚopenÚIOErrorr"rRrir rprDrErZr})r8Úfilenamerzr=r=r>Ú_handle_load_data_infile_sÿ ÿ  ÿz(MySQLConnection._handle_load_data_infilecCs|rt|ƒdkrt d¡‚n~|ddkr2| |¡S|ddkrntrTt|dd…ƒ}n|dd… ¡}| |¡S|ddkr„| |¡S|ddkršt  |¡‚|j   |¡}|r´t |t ƒs¾t d ¡‚dg|}td|ƒD]}|j  |j ¡|j¡||<qÒ| |j ¡¡}d |_||d œS) aHandle a MySQL Result This method handles a MySQL result, for example, after sending the query command. OK and EOF packets will be handled and returned. If the packet is an Error packet, an errors.Error-exception will be raised. The dictionary returned of: - columns: column information - eof: the EOF-packet information Returns a dict() r?úEmpty responseréûrXNrWr@úIllegal result set.T)Úcolumnsr‚)r6r rDrZrÚstrÚdecoderˆrƒrBr!Úparse_column_countÚ isinstanceÚintÚrangeÚ parse_columnr"rAÚpython_charsetÚ unread_result)r8rGr‡Ú column_countrŒÚir‚r=r=r>Ú_handle_resultps2            ÿ zMySQLConnection._handle_resultcCs0|jd||d\}}t|ƒr(|d|fSd|fS)aTGet the next rows returned by the MySQL server This method gets one row from the result set after sending, for example, the query command. The result is a tuple consisting of the row and the EOF packet. If no row was available in the result set, the row data will be None. Returns a tuple. r)ÚcountÚbinaryrŒrN)Úget_rowsr6)r8ršrŒÚrowsr‚r=r=r>Úget_row›s  zMySQLConnection.get_rowc Cs®|jst d¡‚z2|r*|j |j||¡}n|jj|j|j|d}Wn.tjk rp}zd|_|‚W5d}~XYnX|ddk rª|d}|  d|krš|dn|d¡d|_|S)aGet all rows returned by the MySQL server This method gets all rows returned by the MySQL server after sending, for example, the query command. The result is a tuple consisting of a list of rows and the EOF packet. Returns a tuple() zNo result set available.)r™FNéÿÿÿÿrZ server_status) r•r Ú InternalErrorr!Zread_binary_resultr"Zread_text_resultrFrjr)r8r™ršrŒrœrIZekr=r=r>r›ªs$  ÿ zMySQLConnection.get_rowscCs|jr| ¡dS)zConsume results N)r•r›rfr=r=r>Úconsume_resultsÇszMySQLConnection.consume_resultscCs| | tj| d¡¡¡S)zëChange the current database This method changes the current (default) database by sending the INIT_DB command. The result is a dictionary containing the OK packet information. Returns a dict() úutf-8)rZrtrZINIT_DBÚencode)r8rPr=r=r>rUÍs ÿzMySQLConnection.cmd_init_dbcCs<t|tƒs| d¡}| | tj|¡¡}|jr8t  d¡‚|S)a Send a query to the MySQL server This method send the query to the MySQL server and returns the result. If there was a text result, a tuple will be returned consisting of the number of columns and a list containing information about these columns. When the query doesn't return a text result, the OK or EOF packet information as dictionary will be returned. In case the result was an error, exception errors.Error will be raised. Returns a tuple() r¡z8Use cmd_query_iter for statements with multiple queries.) rÚbytesr¢r˜rtrÚQUERYr1r rD)r8ÚqueryÚrawÚbufferedZ raw_as_stringÚresultr=r=r>Ú cmd_queryÙs  ÿzMySQLConnection.cmd_queryccsft|tƒs*t|ƒr"t| d¡ƒ}nt|ƒ}| | tj|¡¡V|jrb|  ¡| |j   ¡¡Vq@dS)atSend one or more statements to the MySQL server Similar to the cmd_query method, but instead returns a generator object to iterate through results. It sends the statements to the MySQL server and through the iterator you can get the results. statement = 'SELECT 1; INSERT INTO t1 VALUES (); SELECT 2' for result in cnx.cmd_query(statement, iterate=True): if 'columns' in result: columns = result['columns'] rows = cnx.get_rows() else: # do something useful with INSERT result Returns a generator. r¡N) rÚ bytearrayrr¢r˜rtrr¤r1rnr"rA)r8Z statementsr=r=r>Úcmd_query_iteròs zMySQLConnection.cmd_query_itercCs| | tjt|ƒ¡¡S)aÚSend the Refresh command to the MySQL server This method sends the Refresh command to the MySQL server. The options argument should be a bitwise value using constants.RefreshOption. Usage example: RefreshOption = mysql.connector.RefreshOption refresh = RefreshOption.LOG | RefreshOption.THREADS cnx.cmd_refresh(refresh) The result is a dictionary with the OK packet information. Returns a dict() )rZrtrZREFRESHr)r8Úoptionsr=r=r>Ú cmd_refreshsÿzMySQLConnection.cmd_refreshcCs*| ¡|j tj¡}|j |dd¡|S)aClose the current connection with the server This method sends the QUIT command to the MySQL server, closing the current connection. Since the no response can be returned to the client, cmd_quit() will return the packet it send. Returns a str() r)rnr!rorZQUITr"rR©r8rGr=r=r>rk"s zMySQLConnection.cmd_quitcCs<|rt |¡st d¡‚|}ntj}| | tjt |ƒ¡¡S)aZShut down the MySQL Server This method sends the SHUTDOWN command to the MySQL server and is only possible if the current user has SUPER privileges. The result is a dictionary containing the OK packet information. Note: Most applications and scripts do not the SUPER privilege. Returns a dict() zInvalid shutdown type) r Úget_infor rDZSHUTDOWN_DEFAULTrƒrtrÚSHUTDOWNr)r8Z shutdown_typeZatyper=r=r>Ú cmd_shutdown1s    ÿzMySQLConnection.cmd_shutdowncCs8| ¡|j tj¡}|j |dd¡|j |j ¡¡S)zâSend the statistics command to the MySQL Server This method sends the STATISTICS command to the MySQL server. The result is a dictionary with various statistical information. Returns a dict() r) rnr!rorZ STATISTICSr"rRZparse_statisticsrAr®r=r=r>Úcmd_statisticsEszMySQLConnection.cmd_statisticscCs| | tjt|ƒ¡¡S)zÞKill a MySQL process This method send the PROCESS_KILL command to the server along with the process ID. The result is a dictionary with the OK packet information. Returns a dict() )rZrtrZ PROCESS_KILLr)r8Z mysql_pidr=r=r>Úcmd_process_killSs ÿz MySQLConnection.cmd_process_killcCs| | tj¡¡S)aFSend the DEBUG command This method sends the DEBUG command to the MySQL server, which requires the MySQL user to have SUPER privilege. The output will go to the MySQL server error log and the result of this method is a dictionary with EOF packet information. Returns a dict() )rƒrtrÚDEBUGrfr=r=r>Ú cmd_debug_s zMySQLConnection.cmd_debugcCs| | tj¡¡S)aSend the PING command This method sends the PING command to the MySQL server. It is used to check if the the connection is still valid. The result of this method is dictionary with OK packet information. Returns a dict() )rZrtrZPINGrfr=r=r>Úcmd_pingks zMySQLConnection.cmd_pingr c Cs˜| ¡|jrt d¡‚|jj|j|||||j|j|j d}|j   |dd¡|  ||¡}z|jt j@st|rt| |¡Wn‚YnX||_| ¡|S)zÑChange the current logged in user This method allows to change the current logged in user information. The result is a dictionary with OK packet information. Returns a dict() z.Change user is not supported with compression.rMr)rnZ _compressr rYr!Zmake_change_userr#r(r4r5r"rRrSrrTrUr)Ú_post_connection)r8rNrOrPrKrGZ ok_packetr=r=r>Úcmd_change_uservs2  û  ÿzMySQLConnection.cmd_change_usercCs| d¡dS)zGet the current databasezSELECT DATABASE()r)Ú info_queryrfr=r=r>rP›szMySQLConnection.databasecCs| d|¡dS)zSet the current databasezUSE %sN)r©)r8Úvaluer=r=r>rP scCs z | ¡WnYdSXdS)a2Reports whether the connection to MySQL Server is available This method checks whether the connection to MySQL is available. It is similar to ping(), but unlike the ping()-method, either True or False is returned and no exception is raised. Returns True or False. FT)r¶rfr=r=r>Ú is_connected¥s  zMySQLConnection.is_connectedc Cs®| ¡st d¡‚z | ¡Wn.tjk rL| |j|j|j|j ¡YnX|  ¡}|r€|  ¡D]\}}|  d  |¡|f¡qb|rª|  ¡D]\}}|  d  |¡|f¡qŒdS)aÇClears the current active session This method resets the session state, if the MySQL server is 5.7.3 or later active session will be reset without re-authenticating. For other server versions session will be reset by re-authenticating. It is possible to provide a sequence of variables and their values to be set after clearing the session. This is possible for both user defined variables and session variables. This method takes two arguments user_variables and session_variables which are dictionaries. Raises OperationalError if not connected, InternalError if there are unread results and InterfaceError on errors. rmzSET @`{0}` = %szSET SESSION `{0}` = %sN)r»r rpÚcmd_reset_connectionrYr¸r*r+r,r)ÚcursorÚitemsÚexecuterE)r8Zuser_variablesZsession_variablesÚcurÚkeyrºr=r=r>Ú reset_session´s    ÿ zMySQLConnection.reset_sessionrc Cs’d}||krŽ|d}z | ¡| ¡| ¡r2WqŽWnDtk rx}z&||krhd |t|ƒ¡}t |¡‚W5d}~XYnX|dkrt  |¡qdS)a×Attempt to reconnect to the MySQL server The argument attempts should be the number of times a reconnect is tried. The delay argument is the number of seconds to wait between each retry. You may want to set the number of attempts higher and use delay when you expect the MySQL server to be down for maintenance or when you expect the network to be temporary unavailable. Raises InterfaceError on errors. rrz4Can not reconnect to MySQL after {0} attempt(s): {1}N) Ú disconnectr7r»rCrErr rDÚtimeÚsleep)r8ÚattemptsÚdelayÚcounterrIÚmsgr=r=r>Ú reconnectÕs" ÿzMySQLConnection.reconnectcCs<z | ¡Wn*|r(|j||dn t d¡‚YnXdS)aîCheck availability of the MySQL server When reconnect is set to True, one or more attempts are made to try to reconnect to the MySQL server using the reconnect()-method. delay is the number of seconds to wait between each retry. When the connection is not available, an InterfaceError is raised. Use the is_connected()-method if you just want to check the connection without raising an error. Raises InterfaceError on errors. )rÆrÇz%Connection to MySQL is not available.N)r¶rÊr rD)r8rÊrÆrÇr=r=r>Úpingòs  zMySQLConnection.pingcCs(z |jdWStk r"YdSXdS)zMySQL connection IDZserver_threadidN)r#ÚKeyErrorrfr=r=r>Ú connection_id s zMySQLConnection.connection_idc s"| ¡| ¡st d¡‚|dk r>t|tƒs6t d¡‚||ƒS|dk rJ|n|j}|dk r\|n|j}d‰|dkrvˆdO‰|dkr†ˆdO‰|dkr–ˆdO‰|dkr¦ˆd O‰|dkr¶ˆd O‰t t t t t ttttd œ }z|ˆ|ƒWStk rd ‰td d ‡‡fdd„tdƒDƒ¡ƒ‚YnXdS)aïInstantiates and returns a cursor By default, MySQLCursor is returned. Depending on the options while connecting, a buffered and/or raw cursor is instantiated instead. Also depending upon the cursor options, rows can be returned as dictionary or named tuple. Dictionary and namedtuple based cursors are available with buffered output but not raw. It is possible to also give a custom cursor through the cursor_class parameter, but it needs to be a subclass of mysql.connector.cursor.CursorBase. Raises ProgrammingError when cursor_class is not a subclass of CursorBase. Raises ValueError when cursor is not available. Returns a cursor-object rmNz6Cursor class needs be to subclass of cursor.CursorBaserTrér?érv) rrrÎér?rXrÏé rv)r§r¦Ú dictionaryÚ named_tupleÚpreparedz*Cursor not available with given criteria: z, cs$g|]}ˆd|>@dkrˆ|‘qS)rrr=)Ú.0r—©r9Z cursor_typer=r>Ú Osÿz*MySQLConnection.cursor..rX)rnr»r rpÚ issubclassrZProgrammingErrorr0r2rrrrrrrrrrÌryÚjoinr’)r8r§r¦rÔZ cursor_classrÒrÓÚtypesr=rÖr>r½sN  ÿ÷ ÿzMySQLConnection.cursorcCs| d¡dS)zCommit current transactionZCOMMITN)Ú_execute_queryrfr=r=r>ÚcommitRszMySQLConnection.commitcCs|jr| ¡| d¡dS)zRollback current transactionZROLLBACKN)r•r›rÛrfr=r=r>ÚrollbackVszMySQLConnection.rollbackcCs| ¡| |¡dS)a Execute a query This method simply calls cmd_query() after checking for unread result. If there are still unread result, an errors.InterfaceError is raised. Otherwise whatever cmd_query() returns is returned. Returns a dict() N)rnr©)r8r¥r=r=r>rÛ]s zMySQLConnection._execute_querycCs|jdd}| |¡| ¡S)z%Send a query which only returns 1 rowT)r§)r½r¿Zfetchone)r8r¥r½r=r=r>r¹is  zMySQLConnection.info_querycCs<|ddkr|j |¡S|ddkr.t |¡‚t d¡‚dS)aEHandle a MySQL Binary Protocol OK packet This method handles a MySQL Binary Protocol OK packet. When the packet is found to be an Error packet, an error will be raised. If the packet is neither an OK or an Error packet, errors.InterfaceError will be raised. Returns a dict() r?rr@zExpected Binary OK packetN)r!Zparse_binary_prepare_okr rBrDr®r=r=r>Ú_handle_binary_okos    z!MySQLConnection._handle_binary_okcCsÐ|rt|ƒdkrt d¡‚nB|ddkr2| |¡S|ddkrH| |¡S|ddkr^t |¡‚|j |¡}|rxt|t ƒs‚t d¡‚dg|}t d|ƒD]}|j  |j   ¡|j¡||<q–| |j   ¡¡}|||fS)a Handle a MySQL Result This method handles a MySQL result, for example, after sending the query command. OK and EOF packets will be handled and returned. If the packet is an Error packet, an errors.Error-exception will be raised. The tuple returned by this method consist of: - the number of columns in the result, - a list of tuples with information about the columns, - the EOF packet information as a dictionary. Returns tuple() or dict() r?r‰rrWr@r‹N)r6r rDrZrƒrBr!rrr‘r’r“r"rAr”)r8rGr–rŒr—r‚r=r=r>Ú_handle_binary_results&          ÿ z%MySQLConnection._handle_binary_resultcCsÌ| tj|¡}| |¡}g|d<g|d<|ddkrxtd|dƒD]$}|d |j |j  ¡|j ¡¡qB|  |j  ¡¡|ddkrÈtd|dƒD]$}|d |j |j  ¡|j ¡¡q’|  |j  ¡¡|S)z£Prepare a MySQL statement This method will send the PREPARE command to MySQL together with the given statement. Returns a dict() rŒÚ parametersZ num_paramsrZ num_columns) rtrZ STMT_PREPARErÞr’Úappendr!r“r"rAr”rƒ)r8Z statementrGr¨Ú_r=r=r>Úcmd_stmt_prepare¤s*  ÿÿ ÿÿz MySQLConnection.cmd_stmt_preparer=c Cs²t|ƒ}i}|rxt|ƒD]^\}}t||tƒrd}zd||jk}Wntk rXYnX| ||||¡|f||<q|j ||t |ƒ|||j ¡} |j t j | d} | | ¡} | S)z"Execute a prepared MySQL statementTÚb)rG)ÚlistÚ enumeraterrÚmoderiÚcmd_stmt_send_long_datar!Zmake_stmt_executeÚtuplerKrtrZ STMT_EXECUTErß) r8Ú statement_idÚdataràr~Zlong_data_usedÚparam_idrâršZexecute_packetrGr¨r=r=r>Úcmd_stmt_executeÀs2ÿ þ z MySQLConnection.cmd_stmt_executecCs|jtjt|ƒdddS)zÃDeallocate a prepared MySQL statement This method deallocates the prepared statement using the statement_id. Note that the MySQL server does not return anything. F)rsN)rtrZ STMT_CLOSEr©r8rêr=r=r>Úcmd_stmt_closeØsÿzMySQLConnection.cmd_stmt_closec Cs|d}d}|jj}zH| |¡}|rV||||ƒ}|jtj|dd|t|ƒ7}| |¡}qWntk rvt  d¡‚YnX|S)a.Send data for a column This methods send data for a column (for example BLOB) for statement identified by statement_id. The param_id indicate which parameter the data belongs too. The data argument should be a file-like object. Since MySQL does not send anything back, no error is raised. When the MySQL server is not reachable, an OperationalError is raised. cmd_stmt_send_long_data should be called before cmd_stmt_execute. The total bytes send is returned. Returns int. i rF)rGrsrm) r!Z_prepare_stmt_send_long_datarurtrZSTMT_SEND_LONG_DATAr6rir rp) r8rêrìrëÚ chunk_sizeÚ total_sentZprepare_packetr|rGr=r=r>rèâs   ÿ z'MySQLConnection.cmd_stmt_send_long_datacCs| | tjt|ƒ¡¡dS)z–Reset data for prepared statement sent as long data The result is a dictionary with OK packet information. Returns a dict() N)rZrtrZ STMT_RESETrrîr=r=r>Úcmd_stmt_resets ÿzMySQLConnection.cmd_stmt_resetcCs2|jdkrt d¡‚| | tj¡¡| ¡dS)zÉResets the session state without re-authenticating Works only for MySQL server 5.7.3 or later. The result is a dictionary with OK packet information. Returns a dict() )rXérÐzFMySQL version 5.7.2 and earlier does not support COM_RESET_CONNECTION.N)rFr rYrZrtrZRESET_CONNECTIONr·rfr=r=r>r¼s  z$MySQLConnection.cmd_reset_connectioncCs$|jr| ¡n|jr t d¡‚dS)z'Check whether there is an unread resultzUnread result foundN)Zcan_consume_resultsr r•r rŸrfr=r=r>rns z$MySQLConnection.handle_unread_result)NNNrrN)NN)N)NrNTr)F)FN)NFN)FFF)N)r r r r)NN)rr)Frr)NNNNNN)r=r=r):Ú__name__Ú __module__Ú __qualname__Ú__doc__r%rJrVrSrdrgrhrlrÃrtr}rÚpropertyr€rZrƒrˆr˜rr›r rUr©r«r­rkr±r²r³rµr¶r¸rPÚsetterr»rÂrÊrËrÍr½rÜrÝrÛr¹rÞrßrãrírïrèròr¼rnÚ __classcell__r=r=r;r>r3sŠ ,ÿ !    ÿ    +       ÿ %   !   ÿ A %  # r)*r÷ÚiorrarÄZauthenticationrZcatch23rrÚ constantsrrr r r r r r Ú conversionrr½rrrrrrrrrrÚnetworkrrÚprotocolrÚutilsrZ abstractsrrr=r=r=r>Ús     0