3
ŠãdeÓ†  ã               @   sx  d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZ dd
lm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( dZ)yXddl*Z*ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 dZ)W n6 e:k
�rb Z; ze:de;› d�ƒe;‚W Y ddZ;[;X nX G dd„ deƒZ<dS )z'Connection class using the C Extension.é    N)ÚAnyÚDictÚListÚOptionalÚSequenceÚTupleÚTypeÚUnioné   )Úversion)ÚMySQLConnectionAbstract)ÚCharacterSetÚ
ClientFlagÚ	FieldFlagÚ
ServerFlagÚShutdownType)ÚMySQLConverter)ÚInterfaceErrorÚInternalErrorÚOperationalErrorÚProgrammingErrorÚget_mysql_exception)ÚMySQLProtocol)ÚCextEofPacketTypeÚCextResultTypeÚDescriptionTypeÚParamsSequenceOrDictTypeÚRowTypeÚStatsPacketTypeÚ
StrOrBytesF)ÚMySQLInterfaceErrorÚMySQLPrepStmt)ÚCMySQLCursorÚCMySQLCursorBufferedÚCMySQLCursorBufferedDictÚCMySQLCursorBufferedNamedTupleÚCMySQLCursorBufferedRawÚCMySQLCursorDictÚCMySQLCursorNamedTupleÚCMySQLCursorPreparedÚCMySQLCursorPreparedDictÚCMySQLCursorPreparedNamedTupleÚCMySQLCursorPreparedRawÚCMySQLCursorRawTz2MySQL Connector/Python C Extension not available (ú)c                   s–  e Zd ZdZeddœ‡ fdd„Zddœdd„Zddœd	d
„Zee	dœdd„ƒZ
eddœdd„ZdŒeddœdd„Zeedœdd„ƒZejeddœdd„ƒZeedœdd„ƒZejeddœdd„ƒZee	dœdd„ƒZddœdd„Zddœdd„ZeZedœd d!„Zedœd"d#„Zd�ee	e	dd'œd(d)„Zedd*œd+d,„Zeee d-œd.d/„Zeee	 dœd0d1„ƒZdŽee	 eeee   ee ee! e"ee ee# f d2œd3d4„Z$d�eeee   ee ee! e"ee e#f d5œd6d7„Z%ee dœd8d9„Z&ddœd:d;„Z'ddœd<d=„Z(ddœd>d?„Z)edd@œdAdB„Z*d�ee! e+dCœdDdE„Z,ee# dœdFdG„Z-e.e!dHœdIdJ„Z/e!eee0e#e+f  dKœdLdM„Z1e!ddNœdOdP„Z2e!ddNœdQdR„Z3d‘eee eeee0e#e+f  dSœdTdU„Z4e4Z5d’ee ee ee ee6e7  ee ee e7dVœdWdX„Z8ee	dœdYdZ„ƒZ9ee	dœd[d\„ƒZ:eedœd]d^„ƒZ;eedœd_d`„ƒZ<eedœdadb„ƒZ=e>e0e?e. e@ee.f f dcœddde„ZAddœdfdg„ZBd“eeee	eeeee ee ddjœ
dkdl„ZCedœdmdn„ZDe	ee# doœdpdq„ZEddœdrds„ZFd”ee	 ddtœdudv„ZGeHdœdwdx„ZIe	ddyœdzd{„ZJedœd|d}„ZKedœd~d„ZLeed€œd�d‚„ZMeeeedƒœd„d…„ZNd•edd†œd‡dˆ„ZOd–ee@eef  ee@eef  dd‰œdŠd‹„ZP‡  ZQS )—ÚCMySQLConnectionz6Class initiating a MySQL Connection using Connector/C.N)ÚkwargsÚreturnc                s’   t stdƒ‚d| _g | _tjjtjjtjjt	j
ƒƒdddƒ| _tjƒ dkrntjj| jƒsntjjdƒrhdnd| _d| _tƒ jƒ  |rŽ| jf |Ž dS )	ZInitializationz0MySQL Connector/Python C Extension not availableNZmysqlÚvendorZpluginÚLinuxz/usr/lib64/mysql/pluginz/usr/lib/mysql/plugin)ÚHAVE_CMYSQLÚRuntimeErrorÚ_cmysqlÚ_columnsÚosÚpathÚjoinÚdirnameÚabspathÚ_mysql_connectorÚ__file__Ú_plugin_dirÚplatformÚsystemÚexistsÚ	converterÚsuperÚ__init__Úconnect)Úselfr0   )Ú	__class__© úV/var/www/agendate/envp3/lib/python3.6/site-packages/mysql/connector/connection_cext.pyrE   ]   s"    
zCMySQLConnection.__init__)r1   c             C   sZ   t jjdƒ}|d dkrd}nd}| jjd|djdd	„ t jdd
… D ƒƒtjƒ 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 rI   )Ústr)Ú.0ÚxrI   rI   rJ   ú
<listcomp>†   s    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)rG   Zlicense_chunksZclient_licenserI   rI   rJ   Ú_add_default_conn_attrsz   s    z(CMySQLConnection._add_default_conn_attrsc          	   C   sR   | j jƒ | j jƒ | j jƒ dddd| j jƒ dœ| _| j| jd ƒ| _tj	| jƒ dS )z<Gather information of the MySQL server before authenticationN)ÚprotocolÚserver_version_originalZserver_threadidÚcharsetÚserver_statusÚauth_pluginZ	auth_dataZcapabilitiesr[   )
r6   Zget_proto_infoZget_server_infoÚ	thread_idZst_server_capabilitiesZ
_handshakeZ_check_server_versionZ_server_versionr   Zset_mysql_version)rG   rI   rI   rJ   Ú_do_handshake‹   s    zCMySQLConnection._do_handshakec             C   s
   | j jƒ S )z6Returns the server status attribute of MYSQL structure)r6   Zst_server_status)rG   rI   rI   rJ   Ú_server_status�   s    zCMySQLConnection._server_status)r9   r1   c             C   s   | j r| j j|ƒ dS )zJset local_infile_in_path

        Set allow_local_infile_in_path.
        N)r6   Z!set_load_data_local_infile_option)rG   r9   rI   rI   rJ   Úset_allow_local_infile_in_path¢   s    z/CMySQLConnection.set_allow_local_infile_in_pathT)Úvaluer1   c             C   s.   || _ | jr| jj|ƒ | jr*| jj|ƒ dS )zuToggle unicode mode

        Set whether we return string fields as unicode or not.
        Default is True.
        N)Ú_use_unicoder6   Úuse_unicoderC   Úset_unicode)rG   rc   rI   rI   rJ   rf   «   s
    zCMySQLConnection.set_unicodec             C   s   | j dƒd }|dkS )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r
   )Ú
info_query)rG   rc   rI   rI   rJ   Ú
autocommit·   s    zCMySQLConnection.autocommitc             C   sT   y| j j|ƒ || _W n8 tk
rN } zt|j|j|jd�|‚W Y dd}~X nX dS )zToggle autocommit)ÚmsgÚerrnoÚsqlstateN)r6   rh   Z_autocommitr    r   ri   rj   rk   )rG   rc   ÚerrrI   rI   rJ   rh   ½   s    
c             C   s   | j dƒd S )zGet the current databasezSELECT DATABASE()r   )rg   )rG   rI   rI   rJ   ÚdatabaseÈ   s    zCMySQLConnection.databasec             C   sN   y| j j|ƒ W n8 tk
rH } zt|j|j|jd�|‚W Y dd}~X nX dS )zSet the current database)ri   rj   rk   N)r6   Ú	select_dbr    r   ri   rj   rk   )rG   rc   rl   rI   rI   rJ   rm   Í   s    c             C   s   | j tj@ S )z'MySQL session has started a transaction)ra   r   ZSTATUS_IN_TRANS)rG   rI   rI   rJ   Úin_transaction×   s    zCMySQLConnection.in_transactionc             C   s  t j| jƒd }tj| j| j|| jp&d| j| j	| j
d�| _| jtjƒsLi | _| j| j| j| j| j| j| j| j| j| j| jtjƒd| j| j| j| j| j| jdœ}| j j!dƒ}|d k	rÈ|j"dd� dj#|ƒ}| j j!dƒd k	rú| j j!dƒd }| j j!dƒd	 }nd }d }|d k	�r"d
|k�r"| �r"d}| j$�s~|j%| j j!dƒ| j j!dƒ| j j!dƒ|||| j j!dƒ�pbd| j j!dƒ�prd| j$dœ	ƒ t&j'dk�rž| j(dk�ržd|d< y.| jj)f |Ž | j*| j_+| j,�rÊ| j*| j,_-W n: t.k
�r } zt/|j0|j1|j2d�|‚W Y d d }~X nX | j3ƒ  d S )Nr   )ÚbufferedÚrawÚcharset_nameZconnection_timeoutre   r^   Z
plugin_dirT)ÚhostÚuserÚpasswordÚ	password1Ú	password2Ú	password3rm   ÚportZclient_flagsZunix_socketÚcompressÚssl_disabledZ
conn_attrsZlocal_infileZload_data_local_dirÚoci_config_fileÚoci_config_profileZfido_callbackÚ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_suitesr~   Ztls_cipher_suitesZssl_verify_certZssl_verify_identityr{   ÚntZMySQLKerberosAuthPluginZuse_kerberos_gssapi)ri   rj   rk   )4r   Úget_infoÚ_charset_idr=   ZMySQLÚ	_bufferedÚ_rawZ_connection_timeoutrd   Z_auth_pluginr?   r6   Zisset_client_flagr   ZCONNECT_ARGSrT   Ú_hostÚ_userÚ	_passwordÚ
_password1Ú
_password2Ú
_password3Ú	_databaseÚ_portZ_client_flagsÚ_unix_socketZCOMPRESSZ_allow_local_infileZ_allow_local_infile_in_pathÚ_oci_config_fileÚ_oci_config_profileZ_fido_callbackÚ_sslÚgetÚsortr:   Z_ssl_disabledrU   r8   ÚnameZ_auth_plugin_classrF   Ú_converter_str_fallbackÚconverter_str_fallbackrC   Zstr_fallbackr    r   ri   rj   rk   r`   )rG   rr   Z
cnx_kwargsr~   Zssl_ciphersuitesr�   rl   rI   rI   rJ   Ú_open_connectionÜ   s‚    








z!CMySQLConnection._open_connectionc             C   sZ   | j rVy| jƒ  | j jƒ  W n8 tk
rT } zt|j|j|jd�|‚W Y dd}~X nX dS )z Disconnect from the MySQL server)ri   rj   rk   N)r6   Úfree_resultÚcloser    r   ri   rj   rk   )rG   rl   rI   rI   rJ   r�   .  s    zCMySQLConnection.closec             C   s   | j jƒ  S )z8Return True if the connection to MySQL Server is closed.)r6   Ú	connected)rG   rI   rI   rJ   Ú	is_closed;  s    zCMySQLConnection.is_closedc             C   s   | j r| jƒ  | j jƒ S dS )z;Reports whether the connection to MySQL Server is availableF)r6   Úhandle_unread_resultÚping)rG   rI   rI   rJ   Úis_connected?  s    
zCMySQLConnection.is_connectedFr
   r   )Ú	reconnectÚattemptsÚdelayr1   c             C   sT   | j ƒ  y| jjƒ }W n tk
r*   Y n
X |r4dS |rH| j||d� ntdƒ‚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.
        N)r¤   r¥   z$Connection to MySQL is not available)r    r6   r¡   ÚAttributeErrorr£   r   )rG   r£   r¤   r¥   rž   rI   rI   rJ   r¡   G  s    zCMySQLConnection.ping)r\   r1   c             C   s   | j j|ƒ dS )z;Sets the default character set name for current connection.N)r6   Zset_character_set)rG   r\   rI   rI   rJ   Úset_character_set_named  s    z'CMySQLConnection.set_character_set_name)Úqueryr1   c             C   sŠ   f }yH| j j|ƒ | j jr@| j jƒ }| j jƒ r@| j jƒ  tdƒ‚| j jƒ  W n8 tk
r„ } zt|j|j	|j
d�|‚W Y dd}~X nX |S )z%Send a query which only returns 1 rowz'Query should not return more than 1 row)ri   rj   rk   N)r6   r¨   Úhave_result_setÚ	fetch_rowrœ   r   r    r   ri   rj   rk   )rG   r¨   Z	first_rowrl   rI   rI   rJ   rg   h  s    


zCMySQLConnection.info_queryc             C   s$   y
| j jƒ S  tk
r   Y nX dS )zMySQL connection IDN)r6   r_   r    )rG   rI   rI   rJ   Úconnection_idz  s
    
zCMySQLConnection.connection_id)ÚcountÚbinaryÚcolumnsrq   Ú	prep_stmtr1   c             C   s¤  |r
|j n| j}| jo|s"tdƒ‚|dkr0| j}g }|dk	rL|dkrLtdƒ‚d}yì|r\|jn| jj}	| jrv| jjdƒ |	ƒ }
x„|
�r | j rØ| jrØt	|
ƒ}
x4t
|
ƒD ](\}}|s¤| jj| j| |
| ƒ|
|< q¤W t|
ƒ}
|j|
ƒ |d7 }|rø||krøP |	ƒ }
q~W |
�s6| j|ƒd }|�r,|jƒ  d| _n| jƒ  nd}W n^ tk
�rš } z@|�rl|jƒ  tt|ƒƒ|‚| jƒ  t|j|j|jd	�|‚W Y dd}~X nX ||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
   ÚeofF)ri   rj   rk   )r©   Úunread_resultr6   r   r‰   r¦   rª   rC   rq   ÚlistÚ	enumerateZ	to_pythonr7   ÚtupleÚappendÚfetch_eof_columnsrœ   Ú_unread_resultr    r   rM   r   ri   rj   rk   )rG   r¬   r­   r®   rq   r¯   r±   ÚrowsÚcounterrª   ÚrowÚiÚ_Ú_eofrl   rI   rI   rJ   Úget_rows„  sV    	
 


zCMySQLConnection.get_rows)r­   r®   rq   r¯   r1   c             C   sJ   y0| j d||||d�\}}|r*|d |fS d|fS  tk
rD   dS X dS )z.Get the next rows returned by the MySQL serverr
   )r¬   r­   r®   rq   r¯   r   N)NN)r¾   Ú
IndexError)rG   r­   r®   rq   r¯   r¸   r°   rI   rI   rJ   Úget_rowÃ  s    zCMySQLConnection.get_rowc             C   s   | j r| j jƒ  | j jƒ S dS )zReads the next resultN)r6   Úconsume_resultÚnext_result)rG   rI   rI   rJ   rÂ   Ú  s    

zCMySQLConnection.next_resultc             C   s   | j r| j jƒ  dS )zFrees the resultN)r6   rœ   )rG   rI   rI   rJ   rœ   á  s    zCMySQLConnection.free_resultc             C   s   | j r| jƒ  | j jƒ  dS )zCommit current transactionN)r6   r    Úcommit)rG   rI   rI   rJ   rÃ   æ  s    zCMySQLConnection.commitc             C   s   | j r| j jƒ  | j jƒ  dS )zRollback current transactionN)r6   rÁ   Úrollback)rG   rI   rI   rJ   rÄ   ì  s    
zCMySQLConnection.rollback)rm   r1   c             C   sN   y| j j|ƒ W n8 tk
rH } zt|j|j|jd�|‚W Y dd}~X nX dS )zChange the current database)ri   rj   rk   N)r6   rn   r    r   ri   rj   rk   )rG   rm   rl   rI   rI   rJ   Úcmd_init_dbò  s    zCMySQLConnection.cmd_init_db)r¯   r1   c             C   s¬   |r
|j n| jj }|stdƒ‚|r*|jƒ n| jjƒ }g | _xV|D ]N}| jj|d t|d ƒddddt|d ƒ tj@ t|d ƒt|d ƒf	ƒ q@W | j	| jj
ƒ dœ| jdœS )	z Fetch EOF and column informationzNo result seté   é   Né	   é   )Zstatus_flagÚwarning_count)r°   r®   )r©   r6   r   Zfetch_fieldsr7   rµ   Úintr   ZNOT_NULLra   Úst_warning_count)rG   r¯   r©   ÚfieldsÚcolrI   rI   rJ   r¶   û  s&    


z"CMySQLConnection.fetch_eof_columnsc             C   s4   | j r0| j jƒ | j jƒ | j jƒ | j jƒ | jdœS dS )z Fetch EOF and status information)rÊ   Zfield_countÚ	insert_idÚaffected_rowsr]   N)r6   rÌ   Zst_field_countrÏ   rÐ   ra   )rG   rI   rI   rJ   Úfetch_eof_status  s    
z!CMySQLConnection.fetch_eof_status)Ú	statementr1   c             C   s\   | j stdƒ‚y| j j|ƒ}| j|_|S  tk
rV } ztt|ƒƒ|‚W Y dd}~X nX dS )zPrepares the SQL statementzMySQL Connection not availableN)r6   r   Zstmt_preparer™   rš   r    r   rM   )rG   rÒ   Ústmtrl   rI   rI   rJ   Úcmd_stmt_prepare+  s    z!CMySQLConnection.cmd_stmt_prepare)Ústatement_idÚargsr1   c             G   sj   y|j |Ž  W n0 tk
r> } ztt|ƒƒ|‚W Y dd}~X nX g | _|jsZd| _| jƒ S d| _| j|ƒS )zExecutes the prepared statementNFT)	Zstmt_executer    r   rM   r7   r©   r·   rÑ   r¶   )rG   rÕ   rÖ   rl   rI   rI   rJ   Úcmd_stmt_execute7  s     z!CMySQLConnection.cmd_stmt_execute)rÕ   r1   c             C   s   | j rtdƒ‚|jƒ  dS )zCloses the prepared statementzUnread result foundN)r·   r   Z
stmt_close)rG   rÕ   rI   rI   rJ   Úcmd_stmt_closeI  s    zCMySQLConnection.cmd_stmt_closec             C   s   | j rtdƒ‚|jƒ  dS )zResets the prepared statementzUnread result foundN)r·   r   Z
stmt_reset)rG   rÕ   rI   rI   rJ   Úcmd_stmt_resetO  s    zCMySQLConnection.cmd_stmt_reset)r¨   rq   rp   Úraw_as_stringr1   c             C   sî   | j ƒ  |dkr| j}y0t|tƒs,|jdƒ}| jj||||| jd� W nˆ tk
r~ } zt	|j
|j|jd�|‚W Y dd}~X nR tk
rÎ } z6| jrš| jn| j› d| j› �}td|dfd�|‚W Y dd}~X nX g | _| jjsæ| jƒ S | jƒ S )	z Send a query to the MySQL serverNzutf-8)rq   rp   rÚ   Zquery_attrs)ri   rk   ú:i  zConnection not available.)rj   Úvalues)r    r‰   Ú
isinstanceÚbytesÚencoder6   r¨   Z_query_attrsr    r   rj   ri   rk   r¦   r’   rŠ   r‘   r   r7   r©   rÑ   r¶   )rG   r¨   rq   rp   rÚ   rl   ÚaddrrI   rI   rJ   Ú	cmd_queryU  s2    

zCMySQLConnection.cmd_query)rp   rq   ÚpreparedÚcursor_classÚ
dictionaryÚnamed_tupler1   c                s  | j |ƒ | jƒ stdƒ‚|dk	r<t|tƒs4tdƒ‚|| ƒS |pD| j}|pN| j}d‰|dkrdˆdO ‰|dkrtˆdO ‰|dkr„ˆdO ‰|dkr”ˆd	O ‰|dkr¤ˆd
O ‰ttt	t
ttttttttdœ}y|ˆ | ƒS  tk
�r   d‰ tddj‡ ‡fdd„tdƒD ƒƒ ƒd‚Y nX 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
        zMySQL Connection not available.Nz=Cursor class needs be to subclass of cursor_cext.CMySQLCursorr   Tr
   é   rÆ   rÇ   é   )r   r
   ræ   rQ   rÆ   é   rÇ   rÈ   rç   é   é   é   rp   rq   rä   rå   râ   z*Cursor not available with given criteria: z, c                s$   g | ]}ˆd |> @ dkrˆ | ‘qS )r
   r   rI   )rN   r»   )rÖ   Úcursor_typerI   rJ   rP   Ñ  s    z+CMySQLConnection.cursor.<locals>.<listcomp>rè   )rp   rq   rä   rå   râ   )r    r¢   r   Ú
issubclassr"   r   rˆ   r‰   r#   r-   r&   r'   r$   r(   r%   r)   r,   r*   r+   ÚKeyErrorÚ
ValueErrorr:   Úrange)rG   rp   rq   râ   rã   rä   rå   ÚtypesrI   )rÖ   rì   rJ   Úcursor  sR    %



 zCMySQLConnection.cursorc             C   s   | j jstdƒ‚| j jƒ S )z,Returns number of rows of current result setzNo result set)r6   r©   r   Únum_rows)rG   rI   rI   rJ   ró   Ô  s    zCMySQLConnection.num_rowsc             C   s   | j s
dS | j jƒ S )zReturns number of warningsr   )r6   rÊ   )rG   rI   rI   rJ   rÊ   Ü  s    zCMySQLConnection.warning_countc             C   s   | j s
dS | j jS )z"Check if a result set is availableF)r6   r©   )rG   rI   rI   rJ   Úresult_set_availableä  s    z%CMySQLConnection.result_set_availablec             C   s   | j S )z)Check if there are unread results or rows)rô   )rG   rI   rI   rJ   r±   ì  s    zCMySQLConnection.unread_resultc             C   s
   | j jƒ S )zCheck if there are more results)r6   Úmore_results)rG   rI   rI   rJ   rõ   ñ  s    zCMySQLConnection.more_results)Úparamsr1   c                sÖ   g }t |ttfƒr:ˆ jr,‡ fdd„|D ƒ}qÒˆ jj|Ž }n˜t |tƒr¶i }ˆ jrŠxd|jƒ D ],\}}ˆ jjˆ jj	ˆ jj
|ƒˆ jƒƒ||< qXW qÒxF|jƒ D ]\}}ˆ jj|ƒd ||< q”W 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 jˆ j j|ƒˆ jƒƒ‘qS rI   )rC   ÚquoteÚescapeÚto_mysqlÚ	_sql_mode)rN   rc   )rG   rI   rJ   rP     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´   rC   r6   Zconvert_to_mysqlÚdictÚitemsr÷   rø   rù   rú   r   ÚtypeÚ__name__)rG   rö   Úresultr„   rc   rI   )rG   rJ   Úprepare_for_mysqlö  s$    



z"CMySQLConnection.prepare_for_mysqlc             C   s   | j jƒ  dS )zlConsume the current result

        This method consume the result by reading (consuming) all rows.
        N)r6   rÁ   )rG   rI   rI   rJ   Úconsume_results!  s    z CMySQLConnection.consume_resultsÚ é-   )
Úusernameru   rm   r\   rv   rw   rx   r|   r}   r1   c
             C   sj   y| j j||||||||	ƒ W n8 tk
rV }
 zt|
j|
j|
jd�|
‚W Y dd}
~
X nX || _| jƒ  dS )z!Change the current logged in user)ri   rj   rk   N)	r6   Zchange_userr    r   ri   rj   rk   r‡   Ú_post_connection)rG   r  ru   rm   r\   rv   rw   rx   r|   r}   rl   rI   rI   rJ   Úcmd_change_user(  s     
z CMySQLConnection.cmd_change_userc             C   s   | j jƒ }|r| jƒ  |S )zÖResets the session state without re-authenticating

        Reset command only works on MySQL server 5.7.3 or later.
        The result is True for a successful reset otherwise False.

        Returns bool
        )r6   Zreset_connectionr  )rG   ÚresrI   rI   rJ   Úcmd_reset_connectionI  s    
z%CMySQLConnection.cmd_reset_connection)Úoptionsr1   c             C   sZ   y| j ƒ  | jj|ƒ W n8 tk
rP } zt|j|j|jd�|‚W Y dd}~X nX | jƒ S )z,Send the Refresh command to the MySQL server)ri   rj   rk   N)	r    r6   Zrefreshr    r   ri   rj   rk   rÑ   )rG   r
  rl   rI   rI   rJ   Úcmd_refreshV  s    zCMySQLConnection.cmd_refreshc             C   s   | j ƒ  dS )z,Close the current connection with the serverN)r�   )rG   rI   rI   rJ   Úcmd_quitb  s    zCMySQLConnection.cmd_quit)Úshutdown_typer1   c             C   s†   | j stdƒ‚|r*tj|ƒs$tdƒ‚|}ntj}y| j j|ƒ W n8 tk
rx } zt|j	|j
|jd�|‚W Y dd}~X nX | jƒ  dS )zShut down the MySQL ServerzMySQL Connection not availablezInvalid shutdown type)ri   rj   rk   N)r6   r   r   r†   r   ZSHUTDOWN_DEFAULTÚshutdownr    r   ri   rj   rk   r�   )rG   r  Úlevelrl   rI   rI   rJ   Úcmd_shutdownf  s    
zCMySQLConnection.cmd_shutdownc             C   sd   | j ƒ  y| jjƒ }tƒ j|dd�S  ttfk
r^ } zt|j|j	|j
d�|‚W Y dd}~X nX dS )z'Return statistics from the MySQL serverF)Zwith_header)ri   rj   rk   N)r    r6   Ústatr   Zparse_statisticsr    r   r   ri   rj   rk   )rG   r  rl   rI   rI   rJ   Úcmd_statisticsz  s    
zCMySQLConnection.cmd_statistics)Ú	mysql_pidr1   c             C   s&   t |tƒstdƒ‚| jd|› �ƒ dS )zKill a MySQL processzMySQL PID must be intzKILL N)rÝ   rË   rï   rg   )rG   r  rI   rI   rJ   Úcmd_process_kill†  s    
z!CMySQLConnection.cmd_process_killc             C   s   t ‚dS )zSend the DEBUG commandN)ÚNotImplementedError)rG   rI   rI   rJ   Ú	cmd_debugŒ  s    zCMySQLConnection.cmd_debugc             C   s   t ‚dS )zSend the PING commandN)r  )rG   rI   rI   rJ   Úcmd_ping�  s    zCMySQLConnection.cmd_ping)Ú
statementsr1   c             C   s   t ‚dS )z/Send one or more statements to the MySQL serverN)r  )rG   r  rI   rI   rJ   Úcmd_query_iter”  s    zCMySQLConnection.cmd_query_iter)rÕ   Úparam_idÚdatar1   c             C   s   t ‚dS )zSend data for a columnN)r  )rG   rÕ   r  r  rI   rI   rJ   Úcmd_stmt_send_long_data˜  s    z(CMySQLConnection.cmd_stmt_send_long_data)râ   r1   c             C   s4   |dkr| j n| j}| jr$| jƒ  n|r0tdƒ‚dS )z'Check whether there is an unread resultTzUnread result foundN)r·   r±   Zcan_consume_resultsr  r   )rG   râ   r±   rI   rI   rJ   r    ž  s
    
z%CMySQLConnection.handle_unread_result)Úuser_variablesÚsession_variablesr1   c             C   sâ   | j ƒ stdƒ‚| jƒ sfy0| j| j| j| j| j| j| j	| j
| j| jƒ	 W n tk
rd   | jƒ  Y nX |sn|rÞ| jƒ }|r¦x*|jƒ D ]\}}|jd|› d�|fƒ q„W |rÖx*|jƒ D ]\}}|jd|› d�|fƒ q´W |jƒ  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.
        zMySQL Connection not available.zSET @`z` = %szSET SESSION `N)r¢   r   r	  r  r‹   rŒ   r�   r‡   r�   rŽ   r�   r“   r”   r   r£   rò   rý   Úexecuter�   )rG   r  r  Úcurr„   rc   rI   rI   rJ   Úreset_session¦  s2    zCMySQLConnection.reset_session)T)Fr
   r   )NFNNN)FNNN)N)NFF)NNNNNN)	r  r  r  r  r  r  r  NN)N)F)NN)Rrÿ   Ú
__module__Ú__qualname__Ú__doc__r   rE   rY   r`   ÚpropertyrË   ra   rM   rb   Úboolrf   rh   Úsetterrm   ro   r›   r�   Z
disconnectrŸ   r¢   r¡   r§   r   r   r   rg   r«   r   r   r!   r   r   r¾   rÀ   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  r  r   r  r  r  r  r  r  r    r!  Ú__classcell__rI   rI   )rH   rJ   r/   Z   sÌ   	
	R     :   
!	  "     *M")	        
 r/   )=r$  r8   r@   rW   Útypingr   r   r   r   r   r   r   r	   r  r   Ú	abstractsr   Ú	constantsr   r   r   r   r   Ú
conversionr   Úerrorsr   r   r   r   r   rZ   r   rñ   r   r   r   r   r   r   r   r4   r=   r    r!   Zcursor_cextr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   ÚImportErrorÚexcr/   rI   rI   rI   rJ   Ú<module>   s,   ($
8