a
    còf¤x  ã                
   @   sü   d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
mZmZ ddlmZmZ ddlmZ dZzDddlZdd	lmZmZmZmZmZmZmZmZmZ dd
lmZ W n6 eyâ Z  zed !e"e ƒ¡ƒ‚W Y dZ [ ndZ [ 0 0 dZG dd„ deƒZ#dS )z'Connection class using the C Extension
é    Né   )ÚerrorsÚversion)ÚCharacterSetÚ	FieldFlagÚ
ServerFlagÚShutdownTypeÚ
ClientFlag)ÚMySQLConnectionAbstractÚMySQLCursorAbstract)ÚMySQLProtocolF)	ÚCMySQLCursorÚCMySQLCursorRawÚCMySQLCursorBufferedÚCMySQLCursorBufferedRawÚCMySQLCursorPreparedÚCMySQLCursorDictÚCMySQLCursorBufferedDictÚCMySQLCursorNamedTupleÚCMySQLCursorBufferedNamedTuple)ÚMySQLInterfaceErrorz6MySQL Connector/Python C Extension not available ({0})Tc                       sú  e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zedd	„ ƒZd
d„ Z	dkdd„Z
edd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZedd„ ƒZdd„ Zdd„ ZeZdd„ Zdd„ Zdld"d#„Zd$d%„ Zd&d'„ Zed(d)„ ƒZdmd+d,„Zdnd-d.„Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zdod9d:„Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dpdEdF„Z%e%Z&dqdGdH„Z'edIdJ„ ƒZ(edKdL„ ƒZ)edMdN„ ƒZ*edOdP„ ƒZ+edQdR„ ƒZ,dSdT„ Z-dUdV„ Z.drdYdZ„Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dsdadb„Z3dcdd„ Z4dedf„ Z5dtdgdh„Z6dudidj„Z7‡  Z8S )vÚCMySQLConnectionz5Class initiating a MySQL Connection using Connector/Cc                    sr   t stdƒ‚d| _g | _tj tj tj t	j
¡¡ddd¡| _d| _tt| ƒjf i |¤Ž |rn| jf i |¤Ž dS )ZInitializationz0MySQL Connector/Python C Extension not availableNÚmysqlÚvendorÚplugin)ÚHAVE_CMYSQLÚRuntimeErrorÚ_cmysqlÚ_columnsÚosÚpathÚjoinÚdirnameÚabspathÚ_mysql_connectorÚ__file__Ú_plugin_dirÚ	converterÚsuperr   Ú__init__Úconnect)ÚselfÚkwargs©Ú	__class__© ú\/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/mysql/connector/connection_cext.pyr)   F   s    ÿþzCMySQLConnection.__init__c              
   C   sZ   t j d¡}|d dkrd}nd}| j d|d dd	„ t jdd
… D ƒ¡t ¡ dœ¡ dS )z!Add default connection attributesú r   ZGPLv2zGPL-2.0Z
Commercialzmysql-connector-pythonÚ.c                 S   s   g | ]}t |ƒ‘qS r/   )Ústr)Ú.0Úxr/   r/   r0   Ú
<listcomp>c   ó    z<CMySQLConnection._add_default_conn_attrs.<locals>.<listcomp>é   )Z_connector_nameZ_connector_licenseZ_connector_versionZ_source_hostN)	r   ÚLICENSEÚsplitÚ_conn_attrsÚupdater!   ÚVERSIONÚsocketÚgethostname)r+   Zlicense_chunksZclient_licenser/   r/   r0   Ú_add_default_conn_attrsW   s    ÿûz(CMySQLConnection._add_default_conn_attrsc              	   C   sF   | j  ¡ | j  ¡ | j  ¡ dddd| j  ¡ dœ| _|  | jd ¡| _dS )z<Gather information of the MySQL server before authenticationN)ÚprotocolÚserver_version_originalZserver_threadidÚcharsetÚserver_statusÚauth_pluginZ	auth_dataZcapabilitiesrB   )r   Zget_proto_infoZget_server_infoÚ	thread_idZst_server_capabilitiesZ
_handshakeZ_check_server_versionÚ_server_version©r+   r/   r/   r0   Ú_do_handshakeg   s    øÿzCMySQLConnection._do_handshakec                 C   s
   | j  ¡ S )z6Returns the server status attribute of MYSQL structure)r   Zst_server_statusrH   r/   r/   r0   Ú_server_statusx   s    zCMySQLConnection._server_statusc                 C   s   | j r| j  |¡ dS )zJset local_infile_in_path

        Set allow_local_infile_in_path.
        N)r   Z!set_load_data_local_infile_option)r+   r    r/   r/   r0   Úset_allow_local_infile_in_path}   s    z/CMySQLConnection.set_allow_local_infile_in_pathTc                 C   s.   || _ | jr| j |¡ | jr*| j |¡ dS )zuToggle unicode mode

        Set whether we return string fields as unicode or not.
        Default is True.
        N)Ú_use_unicoder   Úuse_unicoder'   Úset_unicode©r+   Úvaluer/   r/   r0   rN   †   s
    zCMySQLConnection.set_unicodec                 C   s   |   d¡d }|dkrdS dS )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r   TF©Ú
info_queryrO   r/   r/   r0   Ú
autocommit’   s    zCMySQLConnection.autocommitc              
   C   sV   z| j  |¡ || _W n: tyP } z"tj|j|j|jd�‚W Y d}~n
d}~0 0 dS )zToggle autocommit©ÚmsgÚerrnoÚsqlstateN)	r   rS   Z_autocommitr   r   Úget_mysql_exceptionrU   rV   rW   )r+   rP   Úexcr/   r/   r0   rS   ˜   s    
ÿc                 C   s   |   d¡d S )zGet the current databasezSELECT DATABASE()r   rQ   rH   r/   r/   r0   Údatabase¢   s    zCMySQLConnection.databasec                 C   s   | j  |¡ dS )zSet the current databaseN)r   Ú	select_dbrO   r/   r/   r0   rZ   §   s    c                 C   s   | j tj@ S )z'MySQL session has started a transaction)rJ   r   ZSTATUS_IN_TRANSrH   r/   r/   r0   Úin_transaction¬   s    zCMySQLConnection.in_transactionc                 C   sð  t  | j¡d }tj| j| j|| jp&d| j| j	| j
d�| _|  tj¡sLi | _| j| j| j| j| j| j| j| j| j| j|  tj¡d| j| j| j| jdœ}| j d¡}|d urÀ|j dd� d !|¡}| j d¡d urò| j d¡d }| j d¡d	 }nd }d }|d u�rd
|v �r|�sd}| j"�st| #| j d¡| j d¡| j d¡|||| j d¡�pXd| j d¡�phd| j"dœ	¡ z2| jj$f i |¤Ž | j%| j_&| j'�r¤| j%| j'_(W n< t)�yâ } z"t*j+|j,|j-|j.d�‚W Y d }~n
d }~0 0 |  /¡  d S )Nr   )ÚbufferedÚrawÚcharset_nameZconnection_timeoutrM   rE   Z
plugin_dirT)ÚhostÚuserÚpasswordÚ	password1Ú	password2Ú	password3rZ   ÚportZclient_flagsZunix_socketÚcompressÚssl_disabledZ
conn_attrsZlocal_infileZload_data_local_dirÚoci_config_fileÚtls_versions)Úreverseú,Útls_ciphersuitesr   zTLSv1.3ZTLS_AES_256_GCM_SHA384ÚcaÚcertÚkeyZverify_certFZverify_identity)	Zssl_caZssl_certZssl_keyZssl_cipher_suitesrj   Ztls_cipher_suitesZssl_verify_certZssl_verify_identityrh   rT   )0r   Úget_infoÚ_charset_idr$   ÚMySQLÚ	_bufferedÚ_rawZ_connection_timeoutrL   Z_auth_pluginr&   r   Zisset_client_flagr	   ZCONNECT_ARGSr;   Ú_hostÚ_userÚ	_passwordÚ
_password1Ú
_password2Ú
_password3Ú	_databaseÚ_portZ_client_flagsÚ_unix_socketZCOMPRESSZ_allow_local_infileZ_allow_local_infile_in_pathÚ_oci_config_fileÚ_sslÚgetÚsortr!   Z_ssl_disabledr<   r*   Ú_converter_str_fallbackÚconverter_str_fallbackr'   Zstr_fallbackr   r   rX   rU   rV   rW   rI   )r+   r_   Z
cnx_kwargsrj   Zssl_ciphersuitesrm   rY   r/   r/   r0   Ú_open_connection±   s€    ù
ð
ÿ


ö
ÿz!CMySQLConnection._open_connectionc              
   C   s\   | j rXz|  ¡  | j  ¡  W n: tyV } z"tj|j|j|jd�‚W Y d}~n
d}~0 0 dS )z Disconnect from the MySQL serverrT   N)	r   Úfree_resultÚcloser   r   rX   rU   rV   rW   ©r+   rY   r/   r/   r0   r‡   ö   s    ÿzCMySQLConnection.closec                 C   s   | j  ¡  S )z8Return True if the connection to MySQL Server is closed.)r   Ú	connectedrH   r/   r/   r0   Ú	is_closed  s    zCMySQLConnection.is_closedc                 C   s   | j r| j  ¡ S dS )z;Reports whether the connection to MySQL Server is availableF)r   ÚpingrH   r/   r/   r0   Úis_connected  s    
zCMySQLConnection.is_connectedFr   r   c                 C   sP   d}z| j  ¡ }W n ty$   Y n
0 |r.dS |rB| j||d� n
t |¡‚dS )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.
        z$Connection to MySQL is not availableN)ÚattemptsÚdelay)r   r‹   ÚAttributeErrorÚ	reconnectr   ÚInterfaceError)r+   r�   r�   rŽ   Úerrmsgr‰   r/   r/   r0   r‹     s    zCMySQLConnection.pingc                 C   s   | j  |¡ dS )zDSets the default character set name for current connection.
        N)r   Zset_character_set)r+   rC   r/   r/   r0   Úset_character_set_name)  s    z'CMySQLConnection.set_character_set_namec                 C   sN   | j  |¡ d}| j jr@| j  ¡ }| j  ¡ r@| j  ¡  t d¡‚| j  ¡  |S )z%Send a query which only returns 1 rowr/   z'Query should not return more than 1 row)r   ÚqueryÚhave_result_setÚ	fetch_rowr†   r   r‘   )r+   r”   Ú	first_rowr/   r/   r0   rR   .  s    


ÿ
zCMySQLConnection.info_queryc                 C   s$   z| j  ¡ W S  ty   Y n0 dS )zMySQL connection IDN)r   rF   r   rH   r/   r/   r0   Úconnection_id<  s
    zCMySQLConnection.connection_idNc              
   C   sž  |r
|j n| j}| jr|s$t d¡‚|du r2| j}g }|durN|dkrNtdƒ‚d}zà|r^|jn| jj}	| jrx| j 	d¡ |	ƒ }
|
rø| jsÐ| jrÐt
|
ƒ}
t|
ƒD ](\}}|sž| j | j| |
| ¡|
|< qžt|
ƒ}
| |
¡ |d7 }|rð||krðqø|	ƒ }
q~|
�s,|  |¡d }|�r"| ¡  d| _n|  ¡  nd}W nb t�y” } zH|�rb| ¡  t t|ƒ¡‚n|  ¡  tj|j|j|jd	�‚W Y d}~n
d}~0 0 ||fS )
z8Get all or a subset of rows returned by the MySQL serverzNo result set availableNr   z$count should be 1 or higher, or NoneTr   ÚeofFrT   )r•   Úunread_resultr   r   ÚInternalErrorru   r�   r–   r'   r^   ÚlistÚ	enumerateZ	to_pythonr   ÚtupleÚappendÚfetch_eof_columnsr†   Ú_unread_resultr   r‘   r3   rX   rU   rV   rW   )r+   ÚcountÚbinaryÚcolumnsr^   Ú	prep_stmtrš   ÚrowsÚcounterr–   ÚrowÚiÚ_Ú_eofrY   r/   r/   r0   Úget_rowsF  s`    
ÿ


þÿ


ÿzCMySQLConnection.get_rowsc                 C   sN   z4| j d||||d�\}}|r,|d |fW S d|fW S  tyH   Y dS 0 dS )z.Get the next rows returned by the MySQL serverr   )r¢   r£   r¤   r^   r¥   r   N)NN)r¬   Ú
IndexError)r+   r£   r¤   r^   r¥   r¦   r™   r/   r/   r0   Úget_row‚  s    
ÿ

zCMySQLConnection.get_rowc                 C   s   | j r| j  ¡  | j  ¡ S dS )zReads the next resultN)r   Úconsume_resultÚnext_resultrH   r/   r/   r0   r°   Ž  s    

zCMySQLConnection.next_resultc                 C   s   | j r| j  ¡  dS )zFrees the resultN)r   r†   rH   r/   r/   r0   r†   •  s    zCMySQLConnection.free_resultc                 C   s   | j r| j  ¡  dS )zCommit current transactionN)r   ÚcommitrH   r/   r/   r0   r±   š  s    zCMySQLConnection.commitc                 C   s   | j r| j  ¡  | j  ¡  dS )zRollback current transactionN)r   r¯   ÚrollbackrH   r/   r/   r0   r²   Ÿ  s    
zCMySQLConnection.rollbackc              
   C   sP   z| j  |¡ W n: tyJ } z"tj|j|j|jd�‚W Y d}~n
d}~0 0 dS )zChange the current databaserT   N)r   r[   r   r   rX   rU   rV   rW   )r+   rZ   rY   r/   r/   r0   Úcmd_init_db¥  s    ÿzCMySQLConnection.cmd_init_dbc                 C   sª   |r
|j n| jj }|s t d¡‚|r,| ¡ n| j ¡ }g | _|D ]N}| j |d t|d ƒddddt|d ƒ tj	@ t|d ƒt|d ƒf	¡ q@| j
| j ¡ dœ| jdœS )	z Fetch EOF and column informationúNo result seté   é   Né	   é   )Zstatus_flagÚwarning_count)r™   r¤   )r•   r   r   r‘   Zfetch_fieldsr   rŸ   Úintr   ZNOT_NULLrJ   Úst_warning_count)r+   r¥   r•   ÚfieldsÚcolr/   r/   r0   r    ­  s4    
ÿ
ÿ


÷þûz"CMySQLConnection.fetch_eof_columnsc                 C   s4   | j r0| j  ¡ | j  ¡ | j  ¡ | j  ¡ | jdœS dS )z Fetch EOF and status information)r¹   Zfield_countÚ	insert_idÚaffected_rowsrD   N)r   r»   Zst_field_countr¾   r¿   rJ   rH   r/   r/   r0   Úfetch_eof_statusÌ  s    ûz!CMySQLConnection.fetch_eof_statusc              
   C   sb   | j st d¡‚z| j  |¡}| j|_|W S  ty\ } zt t|ƒ¡‚W Y d}~n
d}~0 0 dS )zPrepares the SQL statementúMySQL Connection not availableN)	r   r   ÚOperationalErrorZstmt_preparerƒ   r„   r   r‘   r3   )r+   Z	statementÚstmtÚerrr/   r/   r0   Úcmd_stmt_prepareÙ  s    
z!CMySQLConnection.cmd_stmt_preparec              
   G   sl   z|j |Ž  W n2 ty@ } zt t|ƒ¡‚W Y d}~n
d}~0 0 g | _|js\d| _|  ¡ S d| _|  	|¡S )zExecutes the prepared statementNFT)
Zstmt_executer   r   r‘   r3   r   r•   r¡   rÀ   r    )r+   r¥   ÚargsrÄ   r/   r/   r0   Úcmd_stmt_executeæ  s    $z!CMySQLConnection.cmd_stmt_executec                 C   s   | j rt d¡‚| ¡  dS )zCloses the prepared statementúUnread result foundN)r¡   r   r›   Z
stmt_close©r+   r¥   r/   r/   r0   Úcmd_stmt_closeö  s    
zCMySQLConnection.cmd_stmt_closec                 C   s   | j rt d¡‚| ¡  dS )zResets the prepared statementrÈ   N)r¡   r   r›   Z
stmt_resetrÉ   r/   r/   r0   Úcmd_stmt_resetü  s    
zCMySQLConnection.cmd_stmt_resetc              
   C   sä   |   ¡  |du r| j}z0t|tƒs,| d¡}| jj||||| jd� W n~ ty€ } z"t	j
|j|j|jd�‚W Y d}~nNd}~0  tyÄ   | jrš| j}n| jd t| jƒ }t	jd|dfd�‚Y n0 g | _| jjsÜ|  ¡ S |  ¡ S )	z Send a query to the MySQL serverNzutf-8)r^   r]   Úraw_as_stringZquery_attrs)rU   rW   ú:i  zConnection not available.)rV   Úvalues)Úhandle_unread_resultru   Ú
isinstanceÚbytesÚencoder   r”   Z_query_attrsr   r   rX   rV   rU   rW   r�   r~   rv   r3   r}   rÂ   r   r•   rÀ   r    )r+   r”   r^   r]   rÌ   rY   Úaddrr/   r/   r0   Ú	cmd_query  s4    

ý
ÿÿzCMySQLConnection.cmd_queryc              
      s  |   |¡ |  ¡ st d¡‚|dur@t|tƒs8t d¡‚|| ƒS |pH| j}|pR| j}d‰|du rhˆdO ‰|du rxˆdO ‰|du rˆˆdO ‰|du r˜ˆd	O ‰|du r¨ˆd
O ‰t	t
tttttttdœ	}z|ˆ | ƒW S  t�y   d‰ tdd ‡ ‡fdd„tdƒD ƒ¡ ƒ‚Y n0 dS )aÅ  Instantiates and returns a cursor using C Extension

        By default, CMySQLCursor 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_cext.CMySQLCursor.

        Raises ProgrammingError when cursor_class is not a subclass of
        CursorBase. Raises ValueError when cursor is not available.

        Returns instance of CMySQLCursor or subclass.

        :param buffered: Return a buffering cursor
        :param raw: Return a raw cursor
        :param prepared: Return a cursor which uses prepared statements
        :param cursor_class: Use a custom cursor class
        :param dictionary: Rows are returned as dictionary
        :param named_tuple: Rows are returned as named tuple
        :return: Subclass of CMySQLCursor
        :rtype: CMySQLCursor or subclass
        úMySQL Connection not available.Nz=Cursor class needs be to subclass of cursor_cext.CMySQLCursorr   Tr   é   rµ   r¶   é   )	r   r   rÖ   r8   rµ   é   r¶   r·   r×   )r]   r^   Ú
dictionaryÚnamed_tupleÚpreparedz*Cursor not available with given criteria: z, c                    s$   g | ]}ˆd |> @ dkrˆ | ‘qS )r   r   r/   )r4   r©   ©rÆ   Zcursor_typer/   r0   r6   i  s   ÿz+CMySQLConnection.cursor.<locals>.<listcomp>rØ   )rÏ   rŒ   r   rÂ   Ú
issubclassr   ÚProgrammingErrorrt   ru   r   r   r   r   r   r   r   r   r   ÚKeyErrorÚ
ValueErrorr!   Úrange)r+   r]   r^   rÛ   Zcursor_classrÙ   rÚ   Útypesr/   rÜ   r0   Úcursor"  sN    


ÿ

÷ÿzCMySQLConnection.cursorc                 C   s   | j jst d¡‚| j  ¡ S )z,Returns number of rows of current result setr´   )r   r•   r   r‘   Únum_rowsrH   r/   r/   r0   rä   l  s    
zCMySQLConnection.num_rowsc                 C   s   | j s
dS | j  ¡ S )zReturns number of warningsr   )r   r¹   rH   r/   r/   r0   r¹   t  s    zCMySQLConnection.warning_countc                 C   s   | j s
dS | j jS )z"Check if a result set is availableF)r   r•   rH   r/   r/   r0   Úresult_set_available|  s    z%CMySQLConnection.result_set_availablec                 C   s   | j S )z)Check if there are unread results or rows)rå   rH   r/   r/   r0   rš   „  s    zCMySQLConnection.unread_resultc                 C   s
   | j  ¡ S )zCheck if there are more results)r   Úmore_resultsrH   r/   r/   r0   ræ   ‰  s    zCMySQLConnection.more_resultsc                    sÈ   t |ttfƒr6ˆ jr(‡ fdd„|D ƒ}qÄˆ jj|Ž }nŽt |tƒr¦i }ˆ jr~| ¡ D ](\}}ˆ j ˆ j 	ˆ j 
|¡¡¡||< qRqÄ| ¡ D ]\}}ˆ j |¡d ||< q†nt dt|ƒj› d|› d�¡‚|S )z¬Prepare parameters for statements

        This method is use by cursors to prepared parameters found in the
        list (or tuple) params.

        Returns dict.
        c              	      s(   g | ] }ˆ j  ˆ j  ˆ j  |¡¡¡‘qS r/   )r'   ÚquoteÚescapeÚto_mysql)r4   rP   rH   r/   r0   r6   ˜  s   ü
ÿÿz6CMySQLConnection.prepare_for_mysql.<locals>.<listcomp>r   zCould not process parameters: ú(z)), it must be of type list, tuple or dict)rÐ   rœ   rž   r'   r   Zconvert_to_mysqlÚdictÚitemsrç   rè   ré   r   rÞ   ÚtypeÚ__name__)r+   ÚparamsÚresultrp   rP   r/   rH   r0   Úprepare_for_mysqlŽ  s*    
û

ÿÿÿz"CMySQLConnection.prepare_for_mysqlc                 C   s   | j  ¡  dS )zlConsume the current result

        This method consume the result by reading (consuming) all rows.
        N)r   r¯   rH   r/   r/   r0   Úconsume_results´  s    z CMySQLConnection.consume_resultsÚ é-   c	           
   
   C   sj   z| j  |||||||¡ W n: tyV }	 z"tj|	j|	j|	jd�‚W Y d}	~	n
d}	~	0 0 || _|  	¡  dS )z!Change the current logged in userrT   N)
r   Zchange_userr   r   rX   rU   rV   rW   rr   Ú_post_connection)
r+   Úusernamerb   rZ   rC   rc   rd   re   ri   rY   r/   r/   r0   Úcmd_change_user»  s     ù	ÿz CMySQLConnection.cmd_change_userc              
   C   sj   | j dk rt d¡‚z| j ¡  W n: ty\ } z"tj|j|j|j	d�‚W Y d}~n
d}~0 0 |  
¡  dS )zpResets the session state without re-authenticating

        Works only for MySQL server 5.7.3 or later.
        ©rØ   é   r8   zFMySQL version 5.7.2 and earlier does not support COM_RESET_CONNECTION.rT   N)rG   r   ÚNotSupportedErrorr   Zreset_connectionr   rX   rU   rV   rW   rõ   rˆ   r/   r/   r0   Úcmd_reset_connectionÐ  s    

ÿz%CMySQLConnection.cmd_reset_connectionc              
   C   sT   z| j  |¡ W n: tyJ } z"tj|j|j|jd�‚W Y d}~n
d}~0 0 |  ¡ S )z,Send the Refresh command to the MySQL serverrT   N)	r   Úrefreshr   r   rX   rU   rV   rW   rÀ   )r+   ÚoptionsrY   r/   r/   r0   Úcmd_refreshá  s    ÿzCMySQLConnection.cmd_refreshc                 C   s   |   ¡  dS )z,Close the current connection with the serverN)r‡   rH   r/   r/   r0   Úcmd_quitë  s    zCMySQLConnection.cmd_quitc              
   C   sŒ   | j st d¡‚|r.t |¡s(t d¡‚|}ntj}z| j  |¡ W n: ty~ } z"tj	|j
|j|jd�‚W Y d}~n
d}~0 0 |  ¡  dS )zShut down the MySQL ServerrÁ   zInvalid shutdown typerT   N)r   r   rÂ   r   rq   r‘   ZSHUTDOWN_DEFAULTÚshutdownr   rX   rU   rV   rW   r‡   )r+   Zshutdown_typeÚlevelrY   r/   r/   r0   Úcmd_shutdownï  s    


ÿzCMySQLConnection.cmd_shutdownc              
   C   sj   |   ¡  z| j ¡ }tƒ j|dd�W S  ttjfyd } z"tj|j	|j
|jd�‚W Y d}~n
d}~0 0 dS )z'Return statistics from the MySQL serverF)Zwith_headerrT   N)rÏ   r   Ústatr   Zparse_statisticsr   r   r‘   rX   rU   rV   rW   )r+   r  rY   r/   r/   r0   Úcmd_statistics  s    
ÿzCMySQLConnection.cmd_statisticsc                 C   s&   t |tƒstdƒ‚|  d |¡¡ dS )zKill a MySQL processzMySQL PID must be intzKILL {0}N)rÐ   rº   rà   rR   Úformat)r+   Z	mysql_pidr/   r/   r0   Úcmd_process_kill  s    
z!CMySQLConnection.cmd_process_killc                 C   s6   |du r| j n| j}| jr$|  ¡  n|r2t d¡‚dS )z'Check whether there is an unread resultTrÈ   N)r¡   rš   Zcan_consume_resultsrò   r   r›   )r+   rÛ   rš   r/   r/   r0   rÏ     s    ÿ
z%CMySQLConnection.handle_unread_resultc                 C   sø   |   ¡ st d¡‚z|  ¡  W nh tjtfy†   | jrDt d¡‚n>| jdk rZt d¡‚n(|  | j	| j
| j| j| j| j| j| j¡ Y n0 |s�|rô|  ¡ }|rÂ| ¡ D ]\}}| d |¡|f¡ q¤|rì| ¡ D ]\}}| d |¡|f¡ qÎ| ¡  dS )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Õ   zZReset session is not supported with compression for MySQL server version 5.7.2 or earlier.rø   zJReset session is not supported with MySQL server version 5.7.2 or earlier.zSET @`{0}` = %szSET SESSION `{0}` = %sN)rŒ   r   rÂ   rû   rú   ÚNotImplementedErrorZ	_compressrG   r÷   rw   rx   r|   rr   ry   rz   r{   r   rã   rì   Úexecuter  r‡   )r+   Zuser_variablesZsession_variablesÚcurrp   rP   r/   r/   r0   Úreset_session  s6    
ÿ
ÿý
zCMySQLConnection.reset_session)T)Fr   r   )NFNNN)FNNN)N)NFF)NNNNNN)ró   ró   ró   rô   ró   ró   ró   N)N)F)NN)9rî   Ú
__module__Ú__qualname__Ú__doc__r)   r@   rI   ÚpropertyrJ   rK   rN   rS   ÚsetterrZ   r\   r…   r‡   Z
disconnectrŠ   rŒ   r‹   r“   rR   r˜   r¬   r®   r°   r†   r±   r²   r³   r    rÀ   rÅ   rÇ   rÊ   rË   rÔ   Z_execute_queryrã   rä   r¹   rå   rš   ræ   rñ   rò   r÷   rû   rþ   rÿ   r  r  r  rÏ   r
  Ú__classcell__r/   r/   r-   r0   r   B   s�   
	


	


E	

	  ÿ
<


  ÿ
J




&   þ



	r   )$r  r   r>   Ú	sysconfigró   r   r   Ú	constantsr   r   r   r   r	   Z	abstractsr
   r   rA   r   r   r$   Zcursor_cextr   r   r   r   r   r   r   r   r   r   ÚImportErrorrY   r  r3   r   r/   r/   r/   r0   Ú<module>   s(   ,ÿÿ