U Yzf_Ϋã@sdZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZmZmZmZmZmZddlmZmZdd lmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&dd l'm(Z(dd l)m*Z*m+Z+ddl,m-Z-Gdd„de-ƒZ.dS)z/Implementing communication with MySQL servers. é)ÚIOBaseNé)Úget_auth_plugin)ÚPY2ÚisstrÚ UNICODE_TYPES)Ú ClientFlagÚ ServerCmdÚ ServerFlagÚ flag_is_setÚ ShutdownTypeÚNET_BUFFER_LENGTH)ÚerrorsÚversion)ÚMySQLConverter) Ú CursorBaseÚ MySQLCursorÚMySQLCursorRawÚMySQLCursorBufferedÚMySQLCursorBufferedRawÚMySQLCursorPreparedÚMySQLCursorDictÚMySQLCursorBufferedDictÚMySQLCursorNamedTupleÚMySQLCursorBufferedNamedTuple)ÚMySQLUnixSocketÚMySQLTCPSocket)Ú MySQLProtocol)Ú int4storeÚlinux_distribution)ÚMySQLConnectionAbstractcsöeZdZdZ‡fdd„Zdd„Zdd„Zdsd d „Zdtd d„Zdudd„Z dd„Z dd„Z dd„Z e Z dvdd„Zdwdd„Zdd„Zedd „ƒZd!d"„Zd#d$„Zd%d&„Zd'd(„Zdxd)d*„Zdyd+d,„Zd-d.„Zd/d0„Zdzd1d2„Zd3d4„Zd5d6„Zd7d8„Zd{d9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dAdB„Z#d|dDdE„Z$edFdG„ƒZ%e%j&dHdG„ƒZ%dIdJ„Z'd}dKdL„Z(d~dNdO„Z)ddPdQ„Z*edRdS„ƒZ+d€dTdU„Z,dVdW„Z-dXdY„Z.dZd[„Z/d\d]„Z0d^d_„Z1d`da„Z2d�dbdc„Z3ddde„Z4d‚dgdh„Z5didj„Z6dkdl„Z7dmdn„Z8dodp„Z9dqdr„Z:‡Z;S)ƒÚMySQLConnectionzConnection to a MySQL Servercsd|_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|_$g|_%|�r z|j&f|ŽWn| '¡d|_‚YnXdS)Né-FÚz 127.0.0.1iê rT)(Ú _protocolÚ_socketÚ _handshakeÚsuperr!Ú__init__rÚ_converter_classrZ 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Ú _bufferedZ_unread_resultÚ_have_next_resultÚ_rawÚ_in_transactionZ_prepared_statementsÚ _ssl_activeÚ _auth_pluginZ_pool_config_versionÚ _columns_descÚconnectÚclose)ÚselfÚargsÚkwargs©Ú __class__©úr/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysql/connector/connection.pyr(<sP zMySQLConnection.__init__c CsütjdkrRdt ¡dkr d}ndt ¡dkr6d}nt ¡}d t ¡d¡}n>t ¡}t ¡d kr|d  d t ¡d¡}nd   t ƒdd …¡}t j   d¡}|ddkr®d}nd}tt ¡ƒ|t ¡d|d  dd„t jdd…Dƒ¡|dœ}|j |¡dS)z&Add the default connection attributes.ÚntZ64rÚx86_64Z32Úi386z Windows-{}rÚDarwinz{}-{}ÚmacOSú-éú ZGPLv2zGPL-2.0Z Commercialzmysql-connector-pythonÚ.cSsg|] }t|ƒ‘qSr?)Ústr)Ú.0Úxr?r?r@Ú ‹sz;MySQLConnection._add_default_conn_attrs..é)Z_pidÚ _platformZ _source_hostZ _client_nameZ_client_licenseZ_client_versionÚ_osN)ÚosÚnameÚplatformÚ architectureÚformatÚ win32_verÚmachineÚsystemÚmac_verÚjoinrrÚLICENSEÚsplitrJÚgetpidÚsocketÚ gethostnameÚVERSIONÚ _conn_attrsÚupdate)r:Z platform_archZos_verZlicense_chunksZclient_licenseZdefault_conn_attrsr?r?r@Ú_add_default_conn_attrsos0     ù z'MySQLConnection._add_default_conn_attrsc Csø|j ¡}|ddkr t |¡‚d|_z|j |¡}Wn8tk rn}ztj|j |j |j d�‚W5d}~XYnX|  |d¡|_ |dtj@s¼|jtjM_|j d¡rÒtjdd d �‚n|jsÒ|jtjO_|dtj@rî| tjg¡||_dS) z'Get the handshake from the MySQL serverééÿN)ÚmsgÚerrnoÚsqlstateZserver_version_originalZ capabilitiesÚ verify_certz1SSL is required but the server doesn't support itiê)rg)r%ÚrecvrÚ get_exceptionr&r$Zparse_handshakeÚ ExceptionZget_mysql_exceptionrfrgrhZ_check_server_versionÚ_server_versionrÚSSLr*r/ÚgetÚInterfaceErrorZ _ssl_disabledZ PLUGIN_AUTHZset_client_flags)r:ÚpacketÚ handshakeÚerrr?r?r@Ú _do_handshake�s0    ÿÿ ÿzMySQLConnection._do_handshakeNrr"c Csòd|_|tj@rš|jj||d�}|j |¡| d¡dk rLd | d¡¡} nd} |j  | d¡| d¡| d ¡| d ¡pzd| d ¡p†d| | d ¡¡d |_|jj |j ||||||j|j |d� }|j |¡|  ||¡|tj@sî|rî| |¡d S)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_flagsÚtls_ciphersuitesNú:r#ÚcaÚcertÚkeyriZverify_identityZ tls_versionsT) rrÚusernameÚpasswordÚdatabaserurvÚ ssl_enabledÚ auth_pluginÚ conn_attrs)r5rrnr$Z make_auth_sslr%ÚsendrorZZ switch_to_sslZ make_authr&r6Ú_auth_switch_requestÚCONNECT_WITH_DBÚ cmd_init_db) r:r|r}r~rvruZ ssl_optionsr�rqrwr?r?r@Ú_do_auth®sF  ÿ   ùú   zMySQLConnection._do_authcCsd}|jp|jd}|j ¡}|ddkrBt|ƒdkrBt d¡‚nN|ddkr�|j |¡\}}t |ƒ|||j d�}|  ¡}|j  |¡|j ¡}|ddkræ|j  |¡}t |ƒ|||j d�}|d kræ|  ¡}|rÜ|j  |¡|j ¡}|dd krü| |¡S|dd k�rt |¡‚dS) z®Handle second part of authentication Raises NotSupportedError when we get the old, insecure password reply back. Raises any error coming from MySQL. Nr€rdéþéz‡Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manual)r}rrZcaching_sha2_passwordrre)r6r&r%rjÚlenrÚNotSupportedErrorr$Zparse_auth_switch_requestrr5Z auth_responser‚Zparse_auth_more_dataÚ _handle_okrk)r:r|r}ÚauthZnew_auth_pluginrqZ auth_dataÚresponser?r?r@rƒÛsH ÿ  ÿÿ    ÿ     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. NrA)Ú unix_socket)ÚhostÚportZ force_ipv6) rŽrQrRrrZ server_hostZ server_portr0Úset_connection_timeoutZ_connection_timeout)r:ZprtclsÚconnr?r?r@Ú_get_connectionsþ zMySQLConnection._get_connectionc Cs¤tƒ|_| ¡|_zv|j ¡| ¡| |j|j|j |j |j |j |j ¡| |j¡|j tj@rz|jj|j_|jj|j_|j d¡Wn| ¡‚YnXdS)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$r“r%Zopen_connectionrtr†r,r-r.r*r+r/raZset_converter_classr)rZCOMPRESSZrecv_compressedrjZsend_compressedr‚r‘r9©r:r?r?r@Ú_open_connections(   þ    z MySQLConnection._open_connectionc Cs8|js dSz|j ¡Wnttjfk r2YnXdS)z.Shut down connection to MySQL Server. N)r%ÚshutdownÚAttributeErrorrÚErrorr”r?r?r@r–/s zMySQLConnection.shutdownc Cs@|js dSz | ¡Wnttjfk r0YnX|j ¡dS)z Disconnect from the MySQL serverN)r%Úcmd_quitr—rr˜Zclose_connectionr”r?r?r@r9:s zMySQLConnection.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%r‚r$Ú make_commandr—rÚOperationalErrorrj)r:ÚcommandZargumentZ packet_numberrqÚexpect_responseZcompressed_packet_numberr?r?r@Ú _send_cmdGsþ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éršó) r›ÚhasattrÚ ValueErrorr¡r r%r‚r—rr�rj)r:Ú data_fileÚsend_empty_packetÚbufr?r?r@Ú _send_dataes$   ÿ 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_EXISTSr2ZSTATUS_IN_TRANSr4)r:Úflagsr?r?r@Ú_handle_server_status…sÿz%MySQLConnection._handle_server_statuscCs|jS)z'MySQL session has started a transaction)r4r”r?r?r@Úin_transaction�szMySQLConnection.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() rdrÚ status_flagrezExpected OK packetN)r$Zparse_okr«rrkrp)r:rqZok_pktr?r?r@r‹•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() rdr‡r­rezExpected EOF packetN)r$Z parse_eofr«rrkrp)r:rqÚeofr?r?r@Ú _handle_eof¦s    zMySQLConnection._handle_eofcCs¬z~z$t|dƒ}| |j|dd�¡WW¢ZStk rzz|j d¡Wntk rdt   d¡‚YnXt   d  |¡¡‚YnXW5z | ¡Wnttfk r¤YnXXdS)z'Handle a LOAD DATA INFILE LOCAL requestÚrbT)r§r£ršzFile '{0}' could not be readN) r9ÚIOErrorÚ NameErrorÚopenr‹r©r%r‚r—rr�rprU)r:Úfilenamer¦r?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¡|j|<qÔ| |j ¡¡}d |_|j|d œS) 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 dictionary returned of: - columns: column information - eof: the EOF-packet information Returns a dict() rdúEmpty responseréûrˆNr‡reúIllegal result set.T)Úcolumnsr®)r‰rrpr‹rrJÚdecoderµr¯rkr$Úparse_column_countÚ isinstanceÚintr7ÚrangeÚ parse_columnr%rjÚpython_charsetÚ unread_result)r:rqr´Ú column_countÚir®r?r?r@Ú_handle_resultÌs2            ÿ zMySQLConnection._handle_resultcCs.|jd|||d�\}}|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¹ÚrawrN)Úget_rows)r:rÆr¹rÇÚrowsr®r?r?r@Úget_row÷s ÿ  zMySQLConnection.get_rowc s|dkrˆj}ˆjst d¡‚zF|rLˆj}|dkr6d}ˆj ˆj|||¡}nˆjjˆjˆj |d�}Wn.tj k r’}zdˆ_|‚W5d}~XYnX|\}} |sØ|s؈j dk rØ|rØt ˆdƒr؈j j‰‡‡fdd „|Dƒ}| dk �rˆ d | krö| d n| d ¡dˆ_|| fS) 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() NzNo result set available.Zutf8mb4Úutf8)rÅFÚ convertercsg|]}ˆ|ˆjƒ‘qSr?)r7)rKÚrow©Ú row_to_pythonr:r?r@rM+sz,MySQLConnection.get_rows..r­Z server_status)r3rÁrÚ InternalErrorrur$Zread_binary_resultr%Zread_text_resultrmr˜r7r¤rÌrÏr«) r:rÅrÆr¹rÇZ prep_stmtrurÉrsZeof_pr?rÎr@rÈsH  ÿ þ ÿ ÿ ÿzMySQLConnection.get_rowscCs|jr| ¡dS)zConsume results N)rÁrÈr”r?r?r@Úconsume_results4szMySQLConnection.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)r‹r r ZINIT_DBÚencode)r:r~r?r?r@r…: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Är r ÚQUERYr2rrp)r:ÚqueryrÇÚbufferedZ raw_as_stringÚresultr?r?r@Ú cmd_queryFs  ÿzMySQLConnection.cmd_queryccsjt|tƒs.t|ƒr&t|tƒr&| d¡}t|ƒ}| | tj|¡¡V|j rf|  ¡| |j   ¡¡VqDdS)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¼Ú bytearrayrrrÓrÄr r rÕr2r›r%rj)r:Z 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() )r‹r r ZREFRESHr)r:Úoptionsr?r?r@Ú cmd_refresh}sÿ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)r›r$rœr ZQUITr%r‚©r:rqr?r?r@r™Ž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_inforrpZSHUTDOWN_DEFAULTr¯r r ZSHUTDOWNr)r:Z shutdown_typeÚatyper?r?r@Ú cmd_shutdown�s    ÿ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) r›r$rœr Z STATISTICSr%r‚Zparse_statisticsrjrÞr?r?r@Úcmd_statistics±szMySQLConnection.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() )r‹r r Z PROCESS_KILLr)r:Z mysql_pidr?r?r@Úcmd_process_kill¿s ÿ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¯r r ÚDEBUGr”r?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() )r‹r r ZPINGr”r?r?r@Úcmd_ping×s 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.)rrr|r}r~rurvrr€r)r›Z _compressrrŠr$Zmake_change_userr&r*r5r6r%r‚rƒrr„r…r+Ú_post_connection)r:r|r}r~rurqZ ok_packetr?r?r@Úcmd_change_userâs2  û  ÿzMySQLConnection.cmd_change_usercCs| d¡dS)zGet the current databasezSELECT DATABASE()r)Ú info_queryr”r?r?r@r~szMySQLConnection.databasecCs| d|¡dS)zSet the current databasezUSE %sN)rÙ)r:Úvaluer?r?r@r~ 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ær”r?r?r@Ú is_connecteds  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. ršzSET @`{0}` = %szSET SESSION `{0}` = %sN)rërr�Úcmd_reset_connectionrŠrèr,r-r.r+ÚcursorÚitemsÚexecuterU)r:Zuser_variablesZsession_variablesÚcurr{rê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) Ú disconnectr8rërlrUrJrrpÚtimeÚsleep)r:ÚattemptsÚdelayÚcounterrsrfr?r?r@Ú reconnectAs" ÿzMySQLConnection.reconnectcCs<z | ¡Wn*|r(|j||d�n 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ørrp)r:rørõrör?r?r@Úping^s  zMySQLConnection.pingcCs(z |jdWStk r"YdSXdS)zMySQL connection IDZserver_threadidN)r&ÚKeyErrorr”r?r?r@Ú connection_idus 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 ršNz6Cursor class needs be to subclass of cursor.CursorBaserTrrGrdér¢) rrrGrNrdrˆrüé r¢)r×rÇÚ dictionaryÚ named_tupleÚpreparedz*Cursor not available with given criteria: z, cs$g|]}ˆd|>@dkrˆ|‘qS)rrr?)rKrér;Z cursor_typer?r@rM»sÿz*MySQLConnection.cursor..rˆ)r›rërr�Ú issubclassrZProgrammingErrorr1r3rrrrrrrrrrúr¥rZr¾)r:r×rÇrZ cursor_classrþrÿÚtypesr?rr@rí}sN  ÿ÷ ÿzMySQLConnection.cursorcCs| d¡dS)zCommit current transactionZCOMMITN)Ú_execute_queryr”r?r?r@Úcommit¾szMySQLConnection.commitcCs|jr| ¡| d¡dS)zRollback current transactionZROLLBACKN)rÁrÈrr”r?r?r@ÚrollbackÂszMySQLConnection.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)r›rÙ)r:rÖr?r?r@rÉs zMySQLConnection._execute_querycCs|jdd�}| |¡| ¡S)z%Send a query which only returns 1 rowT)r×)rírïZfetchone)r:rÖrír?r?r@réÕs  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() rdrrezExpected Binary OK packetN)r$Zparse_binary_prepare_okrrkrprÞr?r?r@Ú_handle_binary_okÛs    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() rdr¶rr‡rer¸N)r‰rrpr‹r¯rkr$r»r¼r½r¾r¿r%rjrÀ)r:rqrÂr¹rÃr®r?r?r@Ú_handle_binary_resultës&          ÿ z%MySQLConnection._handle_binary_resultcCs0|j ||¡}d|_|jtj|dd�d|_dS)z³Fetch a MySQL statement Result Set This method will send the FETCH command to MySQL together with the given statement id and the number of rows to fetch. F©rŸTN)r$Zmake_stmt_fetchrÁr r Z STMT_FETCH)r:Ú statement_idrÉrqr?r?r@Úcmd_stmt_fetchszMySQLConnection.cmd_stmt_fetchcCsÌ| 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) r r Z STMT_PREPARErr¾Úappendr$r¿r%rjrÀr¯)r:Z statementrqrØÚ_r?r?r@Úcmd_stmt_prepares*  ÿÿ ÿÿ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)rq)ÚlistÚ enumerater¼rÚmoder—Úcmd_stmt_send_long_datar$Zmake_stmt_executeÚtuplerur r Z STMT_EXECUTEr) r:r Údatar rªZlong_data_usedÚparam_idrrÆZexecute_packetrqrØr?r?r@Úcmd_stmt_execute7s2ÿ þ z MySQLConnection.cmd_stmt_executecCs|jtjt|ƒdd�dS)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. Fr N)r r Z STMT_CLOSEr©r:r r?r?r@Úcmd_stmt_closeOsÿ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)rqrŸrš) r$Z_prepare_stmt_send_long_datar¡r r ZSTMT_SEND_LONG_DATAr‰r—rr�) r:r rrÚ chunk_sizeÚ total_sentZprepare_packetr¨rqr?r?r@rYs   ÿ 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)r‹r r Z STMT_RESETrrr?r?r@Úcmd_stmt_reset|s ÿ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() )rˆérNzFMySQL version 5.7.2 and earlier does not support COM_RESET_CONNECTION.N)rmrrŠr‹r r ZRESET_CONNECTIONrçr”r?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ÁrrÐr”r?r?r@r›•s z$MySQLConnection.handle_unread_result)NNNrr"NN)NN)N)NrNTr)F)FNN)NFNNN)FFF)N)r#r#r#r")NN)rr)Frr)NNNNNN)r)r?r?r)<Ú__name__Ú __module__Ú __qualname__Ú__doc__r(rcrtr†rƒr“r•r–r9ròr r©r«Úpropertyr¬r‹r¯rµrÄrÊrÈrÑr…rÙrÛrÝr™rárârãrårærèr~Úsetterrërñrørùrûrírrrrérrr rrrrrrìr›Ú __classcell__r?r?r=r@r!:s” 3!ÿ - (   ÿ    + ÿ -     ÿ %   !   ÿ A %   # r!)/r"ÚiorrQrSr^róZauthenticationrZcatch23rrrÚ constantsrr r r r r r#rrÚ conversionrrírrrrrrrrrrÚnetworkrrÚprotocolrÚutilsrrZ abstractsr r!r?r?r?r@Ús     0