o
    =aO                     @   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 )aO  
.. dialect:: firebird+kinterbasdb
    :name: kinterbasdb
    :dbapi: kinterbasdb
    :connectstring: firebird+kinterbasdb://user:password@host:port/path/to/db[?key=value&key=value...]
    :url: https://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::

    https://sourceforge.net/projects/kinterbasdb

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

    https://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   ^/var/www/html/gps/gps/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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kinterbasdbTF   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   dbapip   s   zFBDialect_kinterbasdb.dbapiNc                 C   s   | ||pg  d S r
   )execute)r   r#   	statement
parameterscontextr   r   r   
do_executet   s   z FBDialect_kinterbasdb.do_executec                 C      | | j d S r
   )rollbackr-   r   dbapi_connectionr   r   r   do_rollbacky      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 )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.
        )
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   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   r4   OperationalErrorProgrammingErrorr   )r   erS   r#   msgr   r   r   is_disconnect   s   z#FBDialect_kinterbasdb.is_disconnect)r(   r   TFr
   )r   r   r   driversupports_statement_cacher.   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   s6    


r&   )__doc__r   rer   baser   r    r   rw   r   objectr	   rx   r   ry   r   r   r&   r   r   r   r   r   <module>   s    {