ó
ø¢TQc           @   s^   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d Z d Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   BaseDatabaseCreation(   t   inputt   test_t   Im_a_lumberjackt   DatabaseCreationc           B   sZ  e  Z i d  d 6d d 6d d 6d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d  d 6d d 6d d 6d d 6d d 6d  d 6d d 6d d 6d d 6d  d  6d! d" 6d
 d# 6d d$ 6Z d% „  Z d& e d' „ Z d& d( „ Z d) „  Z d* „  Z d+ „  Z	 d, „  Z
 d- „  Z d. „  Z d/ „  Z d0 „  Z d1 „  Z d2 „  Z d3 „  Z d4 „  Z d5 „  Z d6 „  Z d7 „  Z RS(8   s
   NUMBER(11)t	   AutoFields(   NUMBER(1) CHECK (%(qn_column)s IN (0,1))t   BooleanFields   NVARCHAR2(%(max_length)s)t	   CharFields   VARCHAR2(%(max_length)s)t   CommaSeparatedIntegerFieldt   DATEt	   DateFieldt	   TIMESTAMPt   DateTimeFields*   NUMBER(%(max_digits)s, %(decimal_places)s)t   DecimalFieldt	   FileFieldt   FilePathFields   DOUBLE PRECISIONt
   FloatFieldt   IntegerFields
   NUMBER(19)t   BigIntegerFields   VARCHAR2(15)t   IPAddressFields   VARCHAR2(39)t   GenericIPAddressFieldsE   NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))t   NullBooleanFieldt   OneToOneFields%   NUMBER(11) CHECK (%(qn_column)s >= 0)t   PositiveIntegerFieldt   PositiveSmallIntegerFieldt	   SlugFieldt   SmallIntegerFieldt   NCLOBt	   TextFieldt	   TimeFieldt   URLFieldc         C   s   t  t |  ƒ j | ƒ d  S(   N(   t   superR   t   __init__(   t   selft
   connection(    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR    ,   s    i   c         C   s   |  j  ƒ  } |  j ƒ  } |  j ƒ  } |  j ƒ  } |  j ƒ  } i | d 6| d 6| d 6| d 6| d 6} |  j j ƒ  }	 |  j ƒ  rƒy |  j |	 | | ƒ Wqƒt	 k
 r}
 t
 j j d |
 ƒ | sÖ t d | ƒ } n  | sè | d k rjyH | d	 k r	d
 |  j j GHn  |  j |	 | | ƒ |  j |	 | | ƒ Wq|t	 k
 rf}
 t
 j j d |
 ƒ t
 j d ƒ q|Xq€d GHt
 j d	 ƒ qƒXn  |  j ƒ  r°| d	 k r£d GHn  y |  j |	 | | ƒ Wq°t	 k
 r¬}
 t
 j j d |
 ƒ | sùt d | ƒ } n  | s| d k r—yR | d	 k r"d GHn  |  j |	 | | ƒ | d	 k rId GHn  |  j |	 | | ƒ Wq©t	 k
 r“}
 t
 j j d |
 ƒ t
 j d ƒ q©Xq­d GHt
 j d	 ƒ q°Xn  |  j j d |  j j d <|  j j d |  j j d <| |  j j d <|  j j d <| |  j j d <|  j j d S(   Nt   dbnamet   usert   passwordt   tblspacet   tblspace_temps,   Got an error creating the test database: %s
s^   It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: t   yesi   s$   Destroying old test database '%s'...s.   Got an error recreating the test database: %s
i   s   Tests cancelled.s   Creating test user...s(   Got an error creating the test user: %s
sZ   It appears the test user, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: s   Destroying old test user...s*   Got an error recreating the test user: %s
t   USERt
   SAVED_USERt   PASSWORDt   SAVED_PASSWORDt	   TEST_USERt   NAME(   t   _test_database_namet   _test_database_usert   _test_database_passwdt   _test_database_tblspacet   _test_database_tblspace_tmpR"   t   cursort   _test_database_createt   _execute_test_db_creationt	   Exceptiont   syst   stderrt   writeR   t   aliast   _execute_test_db_destructiont   exitt   _test_user_createt   _create_test_usert   _destroy_test_usert   settings_dict(   R!   t	   verbosityt   autoclobbert	   TEST_NAMER-   t   TEST_PASSWDt   TEST_TBLSPACEt   TEST_TBLSPACE_TMPt
   parametersR4   t   et   confirm(    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   _create_test_db/   sr    
c   
      C   s2  |  j  ƒ  } |  j ƒ  } |  j ƒ  } |  j ƒ  } |  j ƒ  } |  j j d |  j j d <|  j j d |  j j d <i | d 6| d 6| d 6| d 6| d	 6} |  j j ƒ  }	 t j	 d
 ƒ |  j
 ƒ  rë | d
 k rÕ d GHn  |  j |	 | | ƒ n  |  j ƒ  r!| d
 k rd GHn  |  j |	 | | ƒ n  |  j j ƒ  d S(   s¥   
        Destroy a test database, prompting the user for confirmation if the
        database already exists. Returns the name of the test database created.
        R*   R)   R,   R+   R#   R$   R%   R&   R'   i   s   Destroying test user...s"   Destroying test database tables...N(   R/   R0   R1   R2   R3   R"   RA   R4   t   timet   sleepR>   R@   R5   R<   t   close(
   R!   t   test_database_nameRB   RD   R-   RE   RF   RG   RH   R4   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   _destroy_test_dbr   s0    
c         C   sB   | d k r d | d GHn  d d g } |  j  | | | | ƒ d  S(   Ni   s   _create_test_db(): dbname = %sR#   s˜   CREATE TABLESPACE %(tblspace)s
               DATAFILE '%(tblspace)s.dbf' SIZE 20M
               REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 200M
            s¬   CREATE TEMPORARY TABLESPACE %(tblspace_temp)s
               TEMPFILE '%(tblspace_temp)s.dbf' SIZE 20M
               REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 100M
            (   t   _execute_statements(   R!   R4   RH   RB   t
   statements(    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR6   ”   s
    	c         C   sB   | d k r d | d GHn  d d g } |  j  | | | | ƒ d  S(   Ni   s"   _create_test_user(): username = %sR$   s°   CREATE USER %(user)s
               IDENTIFIED BY %(password)s
               DEFAULT TABLESPACE %(tblspace)s
               TEMPORARY TABLESPACE %(tblspace_temp)s
            s#   GRANT CONNECT, RESOURCE TO %(user)s(   RQ   (   R!   R4   RH   RB   RR   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR?   £   s
    	c         C   sB   | d k r d | d GHn  d d g } |  j  | | | | ƒ d  S(   Ni   s)   _execute_test_db_destruction(): dbname=%sR#   sQ   DROP TABLESPACE %(tblspace)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTSsV   DROP TABLESPACE %(tblspace_temp)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS(   RQ   (   R!   R4   RH   RB   RR   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR<   °   s
    	c         C   sD   | d k r! d | d GHd GHn  d g } |  j  | | | | ƒ d  S(   Ni   s   _destroy_test_user(): user=%sR$   s'   Be patient.  This can take some time...s   DROP USER %(user)s CASCADE(   RQ   (   R!   R4   RH   RB   RR   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR@   ¹   s
    	c         C   sq   xj | D]b } | | } | d k r+ | GHn  y | j  | ƒ Wq t k
 rh } t j j d | ƒ ‚  q Xq Wd  S(   Ni   s   Failed (%s)
(   t   executeR7   R8   R9   R:   (   R!   R4   RR   RH   RB   t   templatet   stmtt   err(    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyRQ   Â   s    
c         C   sS   t  |  j j d } y' |  j j d r: |  j j d } n  Wn t k
 rN n X| S(   NR.   RD   (   t   TEST_DATABASE_PREFIXR"   RA   t   AttributeError(   R!   t   name(    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR/   Í   s    c         C   s   |  j  j j d t ƒ S(   Nt   TEST_CREATE(   R"   RA   t   gett   True(   R!   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR5   Ö   s    c         C   s   |  j  j j d t ƒ S(   Nt   TEST_USER_CREATE(   R"   RA   R[   R\   (   R!   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR>   Ù   s    c         C   sS   t  |  j j d } y' |  j j d r: |  j j d } n  Wn t k
 rN n X| S(   NR)   R-   (   RW   R"   RA   t   KeyError(   R!   RY   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR0   Ü   s    c         C   sE   t  } y' |  j j d r, |  j j d } n  Wn t k
 r@ n X| S(   NRE   (   R+   R"   RA   R^   (   R!   RY   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR1   å   s    c         C   sS   t  |  j j d } y' |  j j d r: |  j j d } n  Wn t k
 rN n X| S(   NR.   RF   (   RW   R"   RA   R^   (   R!   RY   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR2   î   s    c         C   sW   t  |  j j d d } y' |  j j d r> |  j j d } n  Wn t k
 rR n X| S(   NR.   t   _tempRG   (   RW   R"   RA   R^   (   R!   RY   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR3   ÷   s    c         C   s   |  j  j d S(   së   
        We need to return the 'production' DB name to get the test DB creation
        machinery to work. This isn't a great deal in this case because DB
        names as handled by Django haven't real counterparts in Oracle.
        R.   (   R"   RA   (   R!   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   _get_test_db_name   s    c         C   s5   |  j  j } | d | d | d | d |  j ƒ  f S(   Nt   HOSTt   PORTt   ENGINER.   (   R"   RA   R0   (   R!   RA   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   test_db_signature  s    c         C   s   t  |  j j _ d  S(   N(   R\   R"   t
   autocommit(   R!   (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   set_autocommit  s    (   t   __name__t
   __module__t
   data_typesR    t   FalseRK   RP   R6   R?   R<   R@   RQ   R/   R5   R>   R0   R1   R2   R3   R`   Rd   Rf   (    (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyR   	   sT   	
	C"																					
(	   R8   RL   t   django.db.backends.creationR    t   django.utils.six.movesR   RW   R+   R   (    (    (    s;   ../Django//lib/python/django/db/backends/oracle/creation.pyt   <module>   s   