
    Xf1                        U d Z ddlZi Zeeed         f         ed<    G d d          Z G d de          Zeed<    G d	 d
e          Z	e	ed<    G d de          Z
 G d de
          Zeed<    G d de
          Zeed<   d ZdS )z;Helper code for Biopython's BioSQL code (for internal use).    NGeneric_dbutils_dbutilsc                   :    e Zd ZdZd Zd Zd Zd
dZd Zdd	Z	dS )r   zDefault database utilities.c                     dS )z Create a Generic_dbutils object.N )selfs    .lib/python3.11/site-packages/BioSQL/DBUtils.py__init__zGeneric_dbutils.__init__             c                     |dk    r|S dS )zReturn the name of the table.biosequencebioentryr   )r   tables     r	   tnamezGeneric_dbutils.tname   s    M!!L:r   c                     |                      |          }d| d| }|                    |           |                                }|d         S )$Return the last used id for a table.zselect max(z
_id) from r   r   executefetchoner   cursorr   sqlrvs        r	   last_idzGeneric_dbutils.last_id!   sT     

5!!4E44U44s__!ur   Nc                 6    |                     ||pd           dS )zJust execute an sql command.r   N)r   r   r   r   argss       r	   r   zGeneric_dbutils.execute*   s     sDJB'''''r   c                 2    |                     ||           dS )zExecute many sql commands.N)executemanyr   r   r   seqs       r	   r    zGeneric_dbutils.executemany.   s    3$$$$$r      c                     dS )*Set autocommit on the database connection.Nr   r   connys      r	   
autocommitzGeneric_dbutils.autocommit2   r   r   N)r#   )
__name__
__module____qualname____doc__r
   r   r   r   r    r)   r   r   r	   r   r      s~        %%/ / /    ( ( ( (% % %9 9 9 9 9 9r   c                   &    e Zd ZdZd ZddZd ZdS )Sqlite_dbutilsz%Custom database utilities for SQLite.c                 .    |                     dd          S )z6Format the argument placeholders for sqlite (PRIVATE).z%s?)replace)r   r   s     r	   _sub_placeholderzSqlite_dbutils._sub_placeholder:   s    {{4%%%r   Nc                 `    |                      |          }|                    ||pd           dS )z_Execute SQL command.

        Replaces %s with ? for variable substitution in sqlite3.
        r   N)r4   r   r   s       r	   r   zSqlite_dbutils.execute>   s5    
 ##C((sDJB'''''r   c                 \    |                      |          }|                    ||           dS )zExecute many sql statements.N)r4   r    r!   s       r	   r    zSqlite_dbutils.executemanyF   s1    ##C((3$$$$$r   r*   )r+   r,   r-   r.   r4   r   r    r   r   r	   r0   r0   7   sL        //& & &( ( ( (% % % % %r   r0   sqlite3c                       e Zd ZdZd ZdS )Mysql_dbutilsz$Custom database utilities for MySQL.c                     t           j        dk    rt                              | ||          S 	 |                                S # t
          $ r
 |j        cY S w xY w)r   java)osnamer   r   	insert_idAttributeError	lastrowid)r   r   r   s      r	   r   zMysql_dbutils.last_idR   sj    7f"**4???	$##%%% 	$ 	$ 	$ ####		$s   A AAN)r+   r,   r-   r.   r   r   r   r	   r9   r9   O   s)        ..$ $ $ $ $r   r9   MySQLdbc                       e Zd ZdZd Zd ZdS )_PostgreSQL_dbutilsz&Base class for any PostgreSQL adaptor.c                     |                      |          }d| d}|                    |           |                                }|d         S )NzSELECT nextval('	_pk_seq')r   r   r   s        r	   next_idz_PostgreSQL_dbutils.next_idf   M    

5!!1111s__!ur   c                     |                      |          }d| d}|                    |           |                                }|d         S )NzSELECT currval('rE   r   r   r   s        r	   r   z_PostgreSQL_dbutils.last_idm   rG   r   N)r+   r,   r-   r.   rF   r   r   r   r	   rC   rC   c   s8        00      r   rC   c                       e Zd ZdZddZdS )Psycopg2_dbutilsz4Custom database utilities for Psycopg2 (PostgreSQL).Tc                     |r0t           j        dk    r	d|_        dS |                    d           dS t           j        dk    r	d|_        dS |                    d           dS )r%   r;   r#   r   N)r<   r=   r)   set_isolation_levelr&   s      r	   r)   zPsycopg2_dbutils.autocommitx   sn     		,w&  "#((+++++w&  "#((+++++r   NTr+   r,   r-   r.   r)   r   r   r	   rJ   rJ   u   s.        >>, , , , , ,r   rJ   psycopg2c                       e Zd ZdZddZdS )Pgdb_dbutilszBCustom database utilities for Pgdb (aka PyGreSQL, for PostgreSQL).Tc                      t          d          )zESet autocommit on the database connection. Currently not implemented.zpgdb does not support this!)NotImplementedErrorr&   s      r	   r)   zPgdb_dbutils.autocommit   s    !"?@@@r   NrM   rN   r   r   r	   rQ   rQ      s4        LLA A A A A Ar   rQ   pgdbc                 h    	 t          |                      S # t          $ r t                      cY S w xY w)z:Return the correct dbutils object for the database driver.)r   KeyErrorr   )module_names    r	   get_dbutilsrX      sE    !$&&& ! ! !     !s    11)r.   r<   r   dictstrtype__annotations__r   r0   r9   rC   rJ   rQ   rX   r   r   r	   <module>r]      s   B A A 				/1$sD*++
, 1 1 19 9 9 9 9 9 9 9F% % % % %_ % % %* % $ $ $ $ $O $ $ $" $     /   $, , , , ,* , , ," ( A A A A A& A A A   ! ! ! ! !r   