
    &h1                         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y)z;Helper code for Biopython's BioSQL code (for internal use).    NGeneric_dbutils_dbutilsc                   8    e Zd ZdZd Zd Zd Zd	dZd Zd
dZ	y)r   zDefault database utilities.c                      y)z Create a Generic_dbutils object.N )selfs    ]/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/BioSQL/DBUtils.py__init__zGeneric_dbutils.__init__           c                     |dk7  r|S y)zReturn the name of the table.biosequencebioentryr   )r   tables     r	   tnamezGeneric_dbutils.tname   s    M!Lr   c                     | j                  |      }d| d| }|j                  |       |j                         }|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!   sE     

5!E7*UG4s__!ur   Nc                 0    |j                  ||xs d       y)zJust execute an sql command.r   N)r   r   r   r   argss       r	   r   zGeneric_dbutils.execute*   s    sDJB'r   c                 (    |j                  ||       y)zExecute many sql commands.N)executemanyr   r   r   seqs       r	   r    zGeneric_dbutils.executemany.   s    3$r   c                      y)*Set autocommit on the database connection.Nr   r   connys      r	   
autocommitzGeneric_dbutils.autocommit2   r   r   N)   )
__name__
__module____qualname____doc__r
   r   r   r   r    r(   r   r   r	   r   r      s#    %/(%9r   c                   $    e Zd ZdZd ZddZd Zy)Sqlite_dbutilsz%Custom database utilities for SQLite.c                 &    |j                  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                 R    | j                  |      }|j                  ||xs d       y)z_Execute SQL command.

        Replaces %s with ? for variable substitution in sqlite3.
        r   N)r4   r   r   s       r	   r   zSqlite_dbutils.execute>   s&    
 ##C(sDJB'r   c                 J    | j                  |      }|j                  ||       y)zExecute many sql statements.N)r4   r    r!   s       r	   r    zSqlite_dbutils.executemanyF   s"    ##C(3$r   r)   )r+   r,   r-   r.   r4   r   r    r   r   r	   r0   r0   7   s    /&(%r   r0   sqlite3c                       e Zd ZdZd Zy)Mysql_dbutilsz$Custom database utilities for MySQL.c                     t         j                  dk(  rt        j                  | ||      S 	 |j	                         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   sT    77f"**4??	$##%% 	$ ###		$s   < 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y)_PostgreSQL_dbutilsz&Base class for any PostgreSQL adaptor.c                 |    | j                  |      }d| d}|j                  |       |j                         }|d   S )NzSELECT nextval('	_pk_seq')r   r   r   s        r	   next_idz_PostgreSQL_dbutils.next_idf   ?    

5! y1s__!ur   c                 |    | j                  |      }d| d}|j                  |       |j                         }|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   s    0r   rC   c                       e Zd ZdZddZy)Psycopg2_dbutilsz4Custom database utilities for Psycopg2 (PostgreSQL).c                     |r-t         j                  dk(  rd|_        y|j                  d       yt         j                  dk(  rd|_        y|j                  d       y)r$   r;   r*   r   N)r<   r=   r(   set_isolation_levelr%   s      r	   r(   zPsycopg2_dbutils.autocommitx   sG    ww& "#((+ww& "#((+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y)Pgdb_dbutilszBCustom database utilities for Pgdb (aka PyGreSQL, for PostgreSQL).c                     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      s    LAr   rQ   pgdbc                 P    	 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      s-    !$&& !  !s    %%)r.   r<   r   dictstrtype__annotations__r   r0   r9   rC   rJ   rQ   rX   r   r   r	   <module>r]      s    B 	/1$sD*++
, 19 9F%_ %* % $O $" $ / $,* ," ( A& A   !r   