
    z<i+                        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	 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 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 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 ddlmZ  ej6                  d      d        Z e
j6                  d      d        Z e	j6                  d      d        Zd Z ej6                  d      d        Z  ej6                  d      d        Z! ej6                  d      d        Z" ej6                  d      d         Z#d+d!Z$ ej6                  d      d"        Z%d# Z& ej6                  d      d$        Z' ej6                  d      d%        Z( ej6                  d      d&        Z) ej6                  d      d'        Z* ej6                  d      d(        Z+ ej6                  d      d)        Z, ej6                  d      d*        Z-y),    N   )create_engine)exc)inspect)url)configure_follower)	create_db)#drop_all_schema_objects_post_tables)"drop_all_schema_objects_pre_tables)drop_db)follower_url_from_main)generate_driver_url)is_preferred_driver)log)post_configure_engine)post_configure_testing_engine)run_reap_dbs) set_default_schema_on_connection) stop_test_class_outside_fixtures)temp_table_keyword_args)update_db_opts)warn_test_suiteoraclec                     | j                         }| j                  |d|      }|dv r|j                  ddg      }n|j                  ddg      }	 |j	                          |S # t
        j                  $ r Y y w xY w)N+)
drivername)oracledboracledb_async)retry_count5)retry_delay2r   r!   )get_backend_namesetupdate_query_pairsdifference_update_queryget_dialectr   NoSuchModuleError)r   driver	query_strbackendnew_urls        i/home/www/utuvibe.miabetepe.com/venv/lib/python3.12/site-packages/sqlalchemy/dialects/oracle/provision.py_oracle_generate_driver_urlr.   "   s     ""$Ggg%v.  G // ,,!#78
 11M*
     s   A& &A<;A<c                    |j                         5 }|j                  d|z         |j                  d|z         |j                  d|z         |j                  d|       |j                  d|z         |j                  d|z         |j                  d|z         |j                  d|z         |j                  d	|z         |j                  d
|z         d d d        y # 1 sw Y   y xY w)Nzcreate user %s identified by xez#create user %s_ts1 identified by xez#create user %s_ts2 identified by xezgrant dba to z grant unlimited tablespace to %sz$grant unlimited tablespace to %s_ts1z$grant unlimited tablespace to %s_ts2zgrant create table to %szgrant create table to %s_ts1zgrant create table to %s_ts2)beginexec_driver_sqlcfgengidentconns       r-   _oracle_create_dbr7   C   s    
 
 E>FGBUJKBUJK%9:?%GHCeKLCeKL7%?@;eCD;eCDE E Es   C	C##C,c                 ,    d|z  | _         d|z  | _        y N%s_ts1%s_ts2)test_schematest_schema_2)configr5   s     r-   _oracle_configure_followerr?   V   s    !E)F#e+F    c                     	 | j                  d|z         t        j                  d|       y# t        j                  $ r }t        j
                  d|       Y d }~yd }~ww xY w)Nzdrop user %s cascadezReaped db: %sTzcouldn't drop db: %sF)r1   r   infor   DatabaseErrorwarning)r6   dbnameerrs      r-   _ora_drop_ignorerG   \   sT    3f<=&) *C0s   *- A  AA c                 F    t        |       t        || j                         y N)_purge_recyclebinr<   r3   r4   s     r-   '_ora_drop_all_schema_objects_pre_tablesrL   f   s    cc3??+r@   c           	         |j                         5 }|j                  j                  |d d d       D ]  }|j                  d|d            |j                  j                  || j                  d d       D ]&  }|j                  d| j                   d|d           ( t        |      j                         D ]  }|j                  d|         	 d d d        y # 1 sw Y   y xY w)Nzdrop synonym synonym_name.zdrop table )r0   dialect_get_synonymsr1   r<   r   get_temp_table_names)r3   r4   r6   syn	tmp_tables        r-   (_ora_drop_all_schema_objects_post_tablesrU   l   s    	 <<<--dD$E 	HC  =^1D0E!FG	H <<--#//4
 	C   0#n2E1FG	 !;;= 	<I  ;yk!:;	<< < <s   B>CC"c                     |j                         5 }t        ||       t        |d|z         t        |d|z         d d d        y # 1 sw Y   y xY wr9   )r0   rG   r2   s       r-   _oracle_drop_dbrW   }   sL    	 1 	u%x%/0x%/01 1 1s   +AAc                     	 t        |       y # t        j                  $ r }t        j                  d|       Y d }~y d }~ww xY w)Nz#purge recyclebin command failed: %s)rJ   r   rC   r   rD   )r>   dbclsrF   s       r-   %_ora_stop_test_class_outside_fixturesr[      s:    @" @93??@s    A<Ac                 4   | j                         5 }||j                  d       n_|j                  dd|j                  j                  |      i      j	                         D ]!  \  }}}|j                  d| d| d| d       # d d d        y # 1 sw Y   y xY w)Nzpurge recyclebinzWselect owner, object_name,type from dba_recyclebin where owner=:schema and type='TABLE'schemazpurge  z."")r0   r1   rP   denormalize_nameall)r4   r]   r6   ownerobject_nametype_s         r-   rJ   rJ      s    	 O>   !34 .2-A-AF4<<88@A. ce	O){E
 $$veWAeWB{m1%MNOO O Os   A4BBc                 f    |j                   j                  dk(  xr |j                   j                   S )ztestablish oracledb as the preferred driver to use for tests, even
    though cx_Oracle is still the "default" driverr   )rP   r)   is_async)r3   engines     r-   _oracle_is_preferred_driverrh      s+    
 >>  J.Nv~~7N7N3NNr@   c                 v   | j                   dk(  sJ d }d }t        d      D ]   }	  | j                  j                  |i |c S  |t        d      |y # | j                  j                  | j                  j
                  f$ r5}|} ||      r%t        d       t        j                  d       Y d }~ d }~ww xY w)N	cx_oraclec                 :    dt        |       v xs dt        |       v S )NzDPY-6005z	ORA-12516)str)rF   s    r-   _is_couldnt_connectz0_connect_with_retry.<locals>._is_couldnt_connect   s    SX%@C)@@r@      zOracle database reconnecting...   z"connect failed after five attempts)
r)   rangeloaded_dbapiconnectrC   OperationalErrorr   timesleep	Exception)rP   conn_reccargscparamsrm   err__rF   s           r-   _connect_with_retryr|      s    >>[(((A D1X 	/7''//B'BB <=4G    ..  11
 
	 D"3' AB

1
	s   A/B8*B32B33B8c                 r    ddl m} |j                  j                  dk(  r|j	                  |dt
               y y )Nr   eventrj   
do_connect) r   rP   r)   listenr|   )r   rg   optionsscoper   s        r-   %_oracle_post_configure_testing_enginer      s-    ~~+V\+>? ,r@   c                 @    ddl m} |j                  |d      d        }y )Nr   r~   checkinc                 H    	 | j                   }d| _         || _         y #  Y y xY w)Nr   )stmtcachesize)dbapi_connectionconnection_recordscs      r-   r   z._oracle_post_configure_engine.<locals>.checkin   s0     	0!//B
 ./*-/*	s    !)r   r   listens_for)r   rg   follower_identr   r   s        r-   _oracle_post_configure_enginer      s&     
vy)0 *0r@   c                    t        j                  d|        t        |       }|j                         5 }t        j                  ddj	                  |             |j                  d      }|D ch c]  \  }|j                          }}t               }|D ]r  }|j                  d      s|j                  d      r&||v s+|j                  |       d|z  |v r|j                  d|z         d|z  |v s_|j                  d|z         t d	x}	}
t        |d
      D ]  \  }
}t        ||      s|	d
z  }	 t        j                  d|	|
       d d d        y c c}w # 1 sw Y   y xY w)Nzdb reaper connecting to %rzidentifiers in file: %sz, zselect u.username from all_users u where username like 'TEST_%' and not exists (select username from v$session where username=u.username)_ts1_ts2r:   r;   r      z-Dropped %d out of %d stale databases detected)r   rB   r   r0   joinr1   lowerr$   endswithadd	enumeraterG   )r   identsr4   r6   to_reapusername	all_namesto_dropnamedroppedtotals              r-   _reap_oracle_dbsr      s[   HH)3/

C	 
*DIIf,=>&&8

 :AA+8X^^%A	A% 	1D}}V$f(=D!d?i/KK40d?i/KK40	1 %(!4 	OE8h/1	 	;We	
1
 
 B
 
s/   ;E-E8E?3E38E,EEE!c                 R    t        j                  |       } | j                  |d      S )Nxe)r   password)sa_urlmake_urlr$   )r   r5   s     r-   _oracle_follower_url_from_mainr     s#    
//#
C77ED711r@   c                     dgddS )NzGLOBAL TEMPORARYzPRESERVE ROWS)prefixesoracle_on_commit rK   s     r-   _oracle_temp_table_keyword_argsr     s     ((+ r@   c                 l    |j                         }|j                  d|z         |j                          y )Nz#ALTER SESSION SET CURRENT_SCHEMA=%s)cursorexecuteclose)r3   r   schema_namer   s       r-   (_oracle_set_default_schema_on_connectionr     s-     $$&F
NN8;FG
LLNr@   c                 v    |j                   r-t        j                  |       j                         dk(  rd|d<   yyy)zCSet database options (db_opts) for a test database that we created.r   T
thick_modeN)oracledb_thick_moder   r   get_driver_name)db_urldb_optsr   s      r-   _update_db_optsr   "  s<     	##OOF#335C $ D 	$r@   rI   ).rt   r   r   r   r   rg   r   r   testing.provisionr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   testing.warningsr   for_dbr.   r7   r?   rG   rL   rU   rW   r[   rJ   rh   r|   r   r   r   r   r   r   r   r   r@   r-   <module>r      s\       # 3 * D C ( 7 4 4 $ 6 > - A A 8 / / H% &@ (E E$ 8$, %,
 +#**84, 5,
 ,$++H5< 6<  	1 	1 )!((2@ 3@O  H%O &OH2 &%%h/@ 0@ h'0 (0< X
 
@ x(2 )2
  ) * )!((2 3 x % !%r@   