o
    ED©iØ  ã                   @   sD   d dl mZ d dlmZ ddlmZ ddlmZ G dd„ deƒZ	dS )	é   )ÚClient)Údefinesé   )ÚCursor)ÚInterfaceErrorc                       sx   e Zd ZdZddejejejejf‡ fdd„	Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Z‡  ZS )Ú
Connectiona)  
    Creates new Connection for accessing ClickHouse database.

    Connection is just wrapper for handling multiple cursors (clients) and
    do not initiate actual connections to the ClickHouse server.

    See parameters description in
    :data:`~clickhouse_driver.connection.Connection`.
    Nc                    sN   g | _ || _|| _|| _|| _|| _|| _|| _d| _d | _	t
t| ƒ ¡  d S )NF)ÚcursorsÚdsnÚuserÚpasswordÚhostÚportÚdatabaseÚconnection_kwargsÚ	is_closedÚ_hostsÚsuperr   Ú__init__)Úselfr	   r   r
   r   r   r   Úkwargs©Ú	__class__© ú[/var/www/Datamplify/venv/lib/python3.10/site-packages/clickhouse_driver/dbapi/connection.pyr      s   zConnection.__init__c                 C   s   d  t| ƒ| j¡S )Nz,<connection object at 0x{0:x}; closed: {1:}>)ÚformatÚidr   ©r   r   r   r   Ú__repr__"   s   
ÿzConnection.__repr__c                 C   s   | S ©Nr   r   r   r   r   Ú	__enter__(   s   zConnection.__enter__c                 C   s   |   ¡  d S r   )Úclose)r   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__+   s   zConnection.__exit__c                 C   s<   | j durt | j ¡S t| jf| j| j| j| jdœ| j¤ŽS )z1
        :return: a new Client instance.
        N)r   r
   r   r   )	r	   r   Úfrom_urlr   r   r
   r   r   r   r   r   r   r   Ú_make_client.   s   
þþzConnection._make_clientc                 C   s   | j D ]}| ¡  qd| _dS )aM  
        Close the connection now. The connection will be unusable from this
        point forward; an :data:`~clickhouse_driver.dbapi.Error` (or subclass)
        exception will be raised if any operation is attempted with the
        connection. The same applies to all cursor objects trying to use the
        connection.
        TN)r   r    r   )r   Úcursorr   r   r   r    9   s   


zConnection.closec                 C   ó   dS ©zB
        Do nothing since ClickHouse has no transactions.
        Nr   r   r   r   r   ÚcommitF   ó   zConnection.commitc                 C   r(   r)   r   r   r   r   r   ÚrollbackL   r+   zConnection.rollbackc                 C   sX   | j rtdƒ‚|  ¡ }| jdu r|jj| _n| j|j_|pt}||| ƒ}| j |¡ |S )z·
        :param cursor_factory: Argument can be used to create non-standard
                               cursors.
        :return: a new cursor object using the connection.
        zconnection already closedN)	r   r   r&   r   Ú
connectionÚhostsr   r   Úappend)r   Úcursor_factoryÚclientr'   r   r   r   r'   R   s   


zConnection.cursorr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚDEFAULT_USERÚDEFAULT_PASSWORDÚDEFAULT_PORTÚDEFAULT_DATABASEr   r   r   r$   r&   r    r*   r,   r'   Ú__classcell__r   r   r   r   r      s    	þr   N)
r1   r   Ú r   r'   r   Úerrorsr   Úobjectr   r   r   r   r   Ú<module>   s
    