o
    [h%                     @   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   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/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)Z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"   Z	statement
parameterscontextr   r   r   
do_executes   s   z FBDialect_kinterbasdb.do_executec                 C      | | j d S r
   )rollbackr,   r   Zdbapi_connectionr   r   r   do_rollbackx      z!FBDialect_kinterbasdb.do_rollbackc                 C   r8   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+   )Ztranslate_connect_argsr!   updatequeryr   Zcoerce_kw_typeintpopr*   r+   r3   getattrinit)r   urloptsr*   r+   rC   r   r   r   create_connect_args~   s&   

z)FBDialect_kinterbasdb.create_connect_argsc                 C   s   |j }|j}| |S )zGet 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.
        )
connectionZserver_version_parse_version_info)r   rN   Z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   rG   .0xr   r   r   
<listcomp>       z=FBDialect_kinterbasdb._parse_version_info.<locals>.<listcomp>         Zfirebirdc                 S   rS   r   rT   rU   r   r   r   rX      rY   r      r   Z	interbase)r   AssertionErrorgrouptuple)r   rP   mr   r   r   rO      s   ""z)FBDialect_kinterbasdb._parse_version_infoc                 C   sJ   t || jj| jjfr#t|}d|v p"d|v p"d|v p"d|v p"d|v S dS )Nz$Error writing data to the connectionz*Unable to complete network request to hostzInvalid connection statezInvalid cursor statezconnection shutdownF)r   r3   ZOperationalErrorZProgrammingErrorr   )r   erN   r"   msgr   r   r   is_disconnect   s   z#FBDialect_kinterbasdb.is_disconnect)r'   r   TFr
   )r   r   r   Zdriverr-   Zsupports_sane_multi_rowcountr   Zexecution_ctx_clsZsupports_native_decimalr   Zupdate_copyr   ZcolspecssqltypesNumericr   Floatr   r)   classmethodr3   r7   r;   r>   rM   rQ   rO   rd   __classcell__r   r   r/   r   r%   O   s4    


r%   )__doc__r   rer   baser   r    r   re   r   objectr	   rf   r   rg   r   r   r%   r   r   r   r   r   <module>   s    z