o
    y¬´\ä  ã                   @   s¨   d Z ddlZddlmZ 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G dd„ dee	jƒZG dd„ dee	jƒZG dd„ deƒZG dd„ deƒZeZdS )aK  
.. dialect:: firebird+kinterbasdb
    :name: kinterbasdb
    :dbapi: kinterbasdb
    :connectstring: firebird+kinterbasdb://user:password@host:port/path/to/db[?key=value&key=value...]
    :url: http://firebirdsql.org/index.php?op=devel&sub=python

Arguments
----------

The Kinterbasdb backend accepts the ``enable_rowcount`` and ``retaining``
arguments accepted by the :mod:`sqlalchemy.dialects.firebird.fdb` dialect.
In addition, it also accepts the following:

* ``type_conv`` - select the kind of mapping done on the types: by default
  SQLAlchemy uses 200 with Unicode, datetime and decimal support.  See
  the linked documents below for further information.

* ``concurrency_level`` - set the backend policy with regards to threading
  issues: by default SQLAlchemy uses policy 1.  See the linked documents
  below for further information.

.. seealso::

    http://sourceforge.net/projects/kinterbasdb

    http://kinterbasdb.sourceforge.net/dist_docs/usage.html#adv_param_conv_dynamic_type_translation

    http://kinterbasdb.sourceforge.net/dist_docs/usage.html#special_issue_concurrency

é    N)Úmatché   )Ú	FBDialect)ÚFBExecutionContexté   )Útypes)Úutilc                   @   s   e Zd Zdd„ ZdS )Ú_kinterbasdb_numericc                 C   s   dd„ }|S )Nc                 S   s   t | tjƒr
t| ƒS | S ©N)Ú
isinstanceÚdecimalÚDecimalÚstr)Úvalue© r   úZ/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/dialects/firebird/kinterbasdb.pyÚprocess3   s   z4_kinterbasdb_numeric.bind_processor.<locals>.processr   )ÚselfÚdialectr   r   r   r   Úbind_processor2   s   z#_kinterbasdb_numeric.bind_processorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	   1   s    r	   c                   @   ó   e Zd ZdS )Ú_FBNumeric_kinterbasdbN©r   r   r   r   r   r   r   r   <   ó    r   c                   @   r   )Ú_FBFloat_kinterbasdbNr   r   r   r   r   r   @   r   r   c                   @   s   e Zd Zedd„ ƒZdS )ÚFBExecutionContext_kinterbasdbc                 C   s   | j  d| jj¡r| jjS dS )NÚenable_rowcountéÿÿÿÿ)Úexecution_optionsÚgetr   r   ÚcursorÚrowcount)r   r   r   r   r$   E   s
   ÿz'FBExecutionContext_kinterbasdb.rowcountN)r   r   r   Úpropertyr$   r   r   r   r   r   D   s    r   c                       sš   e Zd ZdZdZdZeZdZe	 
ejejeejei¡Z				d‡ fdd„	Zedd	„ ƒZddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚFBDialect_kinterbasdbÚkinterbasdbFTéÈ   r   c                    s@   t t| ƒjdi |¤Ž || _|| _|| _|| _|rd| _d S d S )NTr   )Úsuperr&   Ú__init__r   Ú	type_convÚconcurrency_levelÚ	retainingÚsupports_sane_rowcount)r   r+   r,   r   r-   Úkwargs©Ú	__class__r   r   r*   _   s   
ÿzFBDialect_kinterbasdb.__init__c                 C   s   t dƒS )Nr'   )Ú
__import__)Úclsr   r   r   Údbapio   s   zFBDialect_kinterbasdb.dbapiNc                 C   s   |  ||pg ¡ d S r
   )Úexecute)r   r#   Ú	statementÚ
parametersÚcontextr   r   r   Ú
do_executes   s   z FBDialect_kinterbasdb.do_executec                 C   ó   |  | j¡ d S r
   )Úrollbackr-   ©r   Údbapi_connectionr   r   r   Údo_rollbackx   ó   z!FBDialect_kinterbasdb.do_rollbackc                 C   r:   r
   )Úcommitr-   r<   r   r   r   Ú	do_commit{   r?   zFBDialect_kinterbasdb.do_commitc                 C   s´   |j dd�}| d¡rd|d |d f |d< |d= | |j¡ t |dt¡ | d| j¡}| d| j	¡}| j
d urVt| j
dd ƒ}|d u rLt| j
d	d
ƒ}|sV| j
j||d� g |fS )NÚuser)ÚusernameÚportz%s/%sÚhostr+   r,   ÚinitializedÚ_initializedF)r+   r,   )Útranslate_connect_argsr"   ÚupdateÚqueryr   Úcoerce_kw_typeÚintÚpopr+   r,   r4   ÚgetattrÚinit)r   ÚurlÚoptsr+   r,   rF   r   r   r   Úcreate_connect_args~   s&   
ÿ
ÿz)FBDialect_kinterbasdb.create_connect_argsc                 C   s   |j }|j}|  |¡S )zÆGet the version of the Firebird server used by a connection.

        Returns a tuple of (`major`, `minor`, `build`), three integers
        representing the version of the attached server.
        )Ú
connectionÚserver_versionÚ_parse_version_info)r   rS   ÚfbconnÚversionr   r   r   Ú_get_server_version_info™   s   
z.FBDialect_kinterbasdb._get_server_version_infoc                 C   sl   t d|ƒ}|std| ƒ‚| d¡d kr%tdd„ | ddd¡D ƒd	g ƒS td
d„ | ddd¡D ƒdg ƒS )Nz3\w+-V(\d+)\.(\d+)\.(\d+)\.(\d+)( \w+ (\d+)\.(\d+))?z,Could not determine version from string '%s'é   c                 S   ó   g | ]}t |ƒ‘qS r   ©rL   ©Ú.0Úxr   r   r   Ú
<listcomp>µ   ó    z=FBDialect_kinterbasdb._parse_version_info.<locals>.<listcomp>é   é   é   Úfirebirdc                 S   rZ   r   r[   r\   r   r   r   r_   ·   r`   r   é   r   Ú	interbase)r   ÚAssertionErrorÚgroupÚtuple)r   rW   Úmr   r   r   rU   «   s   ÿÿ""z)FBDialect_kinterbasdb._parse_version_infoc                 C   sB   t || jj| jjfƒrt|ƒ}d|v pd|v pd|v pd|v S dS )Nz*Unable to complete network request to hostzInvalid connection statezInvalid cursor statezconnection shutdownF)r   r4   ÚOperationalErrorÚProgrammingErrorr   )r   ÚerS   r#   Úmsgr   r   r   Úis_disconnect¹   s   ÿÿþüz#FBDialect_kinterbasdb.is_disconnect)r(   r   TFr
   )r   r   r   Údriverr.   Úsupports_sane_multi_rowcountr   Úexecution_ctx_clsÚsupports_native_decimalr   Úupdate_copyr   ÚcolspecsÚsqltypesÚNumericr   ÚFloatr   r*   Úclassmethodr4   r9   r>   rA   rR   rX   rU   ro   Ú__classcell__r   r   r0   r   r&   O   s4    þþ
û

r&   )Ú__doc__r   Úrer   Úbaser   r   Ú r   rv   r   Úobjectr	   rw   r   rx   r   r   r&   r   r   r   r   r   Ú<module>   s    y