
TQc           @   s`  d  d l  m Z y d  d l m Z Wn! e k
 rG d  d l m Z n Xd  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 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   i(   t   DatabaseError(   t   _thread(   t   _dummy_thread(   t   contextmanager(   t   settings(   t   DEFAULT_DB_ALIAS(   t   util(   t   TransactionManagementError(   t   cached_property(   t   import_module(   t   six(   t   is_awaret   BaseDatabaseWrapperc           B   sj  e  Z d  Z d% Z d Z e e d  Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ e% d    Z& d   Z' d    Z( d% d!  Z) d"   Z* d#   Z+ d$   Z, RS(&   s+   
    Represents a database connection.
    t   unknownc         C   sd   d  |  _ g  |  _ | |  _ | |  _ d  |  _ g  |  _ d |  _ d  |  _ t	 j
   |  _ | |  _ d  S(   Ni    (   t   Nonet
   connectiont   queriest   settings_dictt   aliast   use_debug_cursort   transaction_statet   savepoint_statet   _dirtyt   threadt	   get_identt   _thread_identt   allow_thread_sharing(   t   selfR   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   __init__   s    								c         C   s   |  j  | j  k S(   N(   R   (   R   t   other(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   __eq__,   s    c         C   s   |  | k S(   N(    (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   __ne__/   s    c         C   s   t  |  j  S(   N(   t   hashR   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   __hash__2   s    c         C   s    |  j  d  k	 r |  j  j   Sd  S(   N(   R   R   t   commit(   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   _commit5   s    c         C   s    |  j  d  k	 r |  j  j   Sd  S(   N(   R   R   t   rollback(   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt	   _rollback9   s    c         C   s   d S(   sq   
        A hook for backend-specific changes required when entering manual
        transaction handling.
        N(    (   R   t   managed(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   _enter_transaction_management=   s    c         C   s   d S(   s   
        A hook for backend-specific changes required when leaving manual
        transaction handling. Will usually be implemented only when
        _enter_transaction_management() is also required.
        N(    (   R   R&   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   _leave_transaction_managementD   s    c         C   s3   |  j  j s d  S|  j   j |  j j |   d  S(   N(   t   featurest   uses_savepointst   cursort   executet   opst   savepoint_create_sql(   R   t   sid(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt
   _savepointL   s    c         C   s3   |  j  j s d  S|  j   j |  j j |   d  S(   N(   R)   R*   R+   R,   R-   t   savepoint_rollback_sql(   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   _savepoint_rollbackQ   s    c         C   s3   |  j  j s d  S|  j   j |  j j |   d  S(   N(   R)   R*   R+   R,   R-   t   savepoint_commit_sql(   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   _savepoint_commitV   s    c         C   s=   |  j  r |  j   t |  _  n  x |  j r8 |  j   q" Wd S(   sb   
        Roll back any ongoing transaction and clean the transaction state
        stack.
        N(   R   R%   t   FalseR   t   leave_transaction_management(   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   abort[   s
    	
c         C   sb   |  j  r# |  j  j |  j  d  n |  j  j t j  |  j d k rQ t |  _ n  |  j |  d S(   s  
        Enters transaction management for a running thread. It must be balanced with
        the appropriate leave_transaction_management call, since the actual state is
        managed as a stack.

        The state and dirty flag are carried over from the surrounding block or
        from the settings, if there is no surrounding block (dirty is always false
        when no current block is running).
        iN(   R   t   appendR   t   TRANSACTIONS_MANAGEDR   R   R5   R'   (   R   R&   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   enter_transaction_managementf   s    
	c         C   sd   |  j  r |  j  d =n t d   |  j |  j    |  j rW |  j   t d   n  t |  _ d S(   s   
        Leaves transaction management for a running thread. A dirty flag is carried
        over to the surrounding block, as a commit will commit all changes, even
        those from outside. (Commits are on connection level.)
        is,   This code isn't under transaction managements<   Transaction managed block ended with pending COMMIT/ROLLBACKN(   R   R   R(   t
   is_managedR   R$   R5   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR6   y   s    			
c         C   sK   |  j  rG |  j t j   k rG t d |  j |  j t j   f   n  d S(   s7  
        Validates that the connection isn't accessed by another thread than the
        one which originally created it, unless the connection was explicitly
        authorized to be shared between threads (via the `allow_thread_sharing`
        property). Raises an exception if the validation fails.
        s   DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias '%s' was created in thread id %s and this is thread id %s.N(   R   R   R   R   R    R   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   validate_thread_sharing   s    
c         C   s   |  j  S(   sj   
        Returns True if the current transaction requires a commit for changes to
        happen.
        (   R   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   is_dirty   s    c         C   s+   |  j  d k	 r t |  _  n t d   d S(   s   
        Sets a dirty flag for the current thread and code streak. This can be used
        to decide in a managed block of code to decide whether there are open
        changes waiting for commit.
        s,   This code isn't under transaction managementN(   R   R   t   TrueR   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt	   set_dirty   s    c         C   s5   |  j  d k	 r t |  _  n t d   |  j   d S(   s   
        Resets a dirty flag for the current thread and code streak. This can be used
        to decide in a managed block of code to decide whether a commit or rollback
        should happen.
        s,   This code isn't under transaction managementN(   R   R   R5   R   t   clean_savepoints(   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt	   set_clean   s    c         C   s   d |  _  d  S(   Ni    (   R   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR@      s    c         C   s   |  j  r |  j  d St j S(   sW   
        Checks whether the transaction manager is in manual or in auto state.
        i(   R   R   R9   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR;      s    	c         C   sV   |  j  } | rF | | d <| rR |  j   rR |  j   |  j   qR n t d   d S(   s	  
        Puts the transaction manager into a manual state: managed transactions have
        to be committed explicitly by the user. If you switch off transaction
        management and there is a pending commit/rollback, the data will be
        commited.
        is,   This code isn't under transaction managementN(   R   R=   R#   RA   R   (   R   t   flagt   top(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR&      s    	

c         C   s;   |  j    |  j   s- |  j   |  j   n
 |  j   d S(   sS   
        Commits changes if the system is not in managed transaction mode.
        N(   R<   R;   R#   R@   R?   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   commit_unless_managed   s
    

c         C   s1   |  j    |  j   s# |  j   n
 |  j   d S(   sV   
        Rolls back changes if the system is not in managed transaction mode.
        N(   R<   R;   R%   R?   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   rollback_unless_managed   s    
c         C   s"   |  j    |  j   |  j   d S(   sC   
        Does the commit itself and resets the dirty flag.
        N(   R<   R#   RA   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR"      s    

c         C   s"   |  j    |  j   |  j   d S(   sS   
        This function does the rollback itself and resets the dirty flag.
        N(   R<   R%   RA   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR$      s    

c         C   sW   t  j   } |  j d 7_ t |  j d d  } d | |  j f } |  j |  | S(   s   
        Creates a savepoint (if supported and required by the backend) inside the
        current transaction. Returns an identifier for the savepoint that will be
        used for the subsequent rollback or commit.
        i   t   -t    s   s%s_x%d(   R   R   R   t   strt   replaceR0   (   R   t   thread_identt   tidR/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt	   savepoint   s    c         C   s'   |  j    |  j r# |  j |  n  d S(   s}   
        Rolls back the most recent savepoint (if one exists). Does nothing if
        savepoints are not supported.
        N(   R<   R   R2   (   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   savepoint_rollback  s    
	c         C   s'   |  j    |  j r# |  j |  n  d S(   sz   
        Commits the most recent savepoint (if one exists). Does nothing if
        savepoints are not supported.
        N(   R<   R   R4   (   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   savepoint_commit  s    
	c         c   s0   |  j    } z	 d  VWd  | r+ |  j   n  Xd  S(   N(   t   disable_constraint_checkingt   enable_constraint_checking(   R   t   disabled(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   constraint_checks_disabled  s
    	c         C   s   d S(   sr   
        Backends can implement as needed to temporarily disable foreign key constraint
        checking.
        N(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRO   &  s    c         C   s   d S(   s`   
        Backends can implement as needed to re-enable foreign key constraint checking.
        N(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRP   -  s    c         C   s   d S(   s   
        Backends can override this method if they can apply constraint checking (e.g. via "SET CONSTRAINTS
        ALL IMMEDIATE"). Should raise an IntegrityError if any invalid foreign key references are encountered.
        N(    (   R   t   table_names(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   check_constraints3  s    c         C   s6   |  j    |  j d  k	 r2 |  j j   d  |  _ n  d  S(   N(   R<   R   R   t   close(   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRU   :  s    
c         C   s_   |  j    |  j s+ |  j d  k rC t j rC |  j |  j    } n t j |  j   |   } | S(   N(	   R<   R   R   R   t   DEBUGt   make_debug_cursort   _cursorR   t   CursorWrapper(   R   R+   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR+   @  s    
	c         C   s   t  j | |   S(   N(   R   t   CursorDebugWrapper(   R   R+   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRW   I  s    N(-   t   __name__t
   __module__t   __doc__R   R-   t   vendorR   R5   R   R   R   R!   R#   R%   R'   R(   R0   R2   R4   R7   R>   R:   R6   R<   R=   R?   RA   R@   R;   R&   RD   RE   R"   R$   RL   RM   RN   R   RR   RO   RP   RT   RU   R+   RW   (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR      sN   																				
													t   BaseDatabaseFeaturesc           B   s  e  Z e Z e Z g  Z e Z e Z e Z	 e Z
 e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z e Z  e Z! e Z" e Z# e Z$ e Z% e Z& e Z' e Z( e Z) d    Z* e+ d    Z, e+ d    Z- RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR     s    c         C   s   z |  j  j   |  j  j t  |  j  j   } | j d  |  j  j   | j d  |  j  j   | j d  | j   \ } | j d  |  j  j   t	 |  j  _
 Wd |  j  j   X| d k S(   s    Confirm support for transactionss"   CREATE TABLE ROLLBACK_TEST (X INT)s(   INSERT INTO ROLLBACK_TEST (X) VALUES (8)s"   SELECT COUNT(X) FROM ROLLBACK_TESTs   DROP TABLE ROLLBACK_TESTNi    (   R   R:   R&   R>   R+   R,   R#   R%   t   fetchoneR5   R   R6   (   R   R+   t   count(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   supports_transactions  s    c         C   sM   d t  f d     Y} y |  j j j |    t SWn t k
 rH t SXd S(   s6   Confirm support for STDDEV and related stats functionst	   StdDevPopc           B   s   e  Z d  Z RS(   t
   STDDEV_POP(   R[   R\   t   sql_function(    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRc     s   N(   t   objectR   R-   t   check_aggregate_supportR>   t   NotImplementedErrorR5   (   R   Rc   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   supports_stddev  s    (.   R[   R\   R5   t   allows_group_by_pkR>   t   needs_datetime_string_castt   empty_fetchmany_valuet   update_can_self_selectt!   interprets_empty_strings_as_nullst#   ignores_nulls_in_unique_constraintst   can_use_chunked_readst   can_return_id_from_insertt   has_bulk_insertt   uses_autocommitR*   t6   can_combine_inserts_with_and_without_auto_increment_pkt   related_fields_match_typet   allow_sliced_subqueriest   has_select_for_updatet   has_select_for_update_nowaitt   supports_select_relatedt#   test_db_allows_multiple_connectionst   supports_unspecified_pkt   supports_forward_referencest&   requires_rollback_on_dirty_transactiont   supports_long_model_namest   has_real_datatypet   supports_subqueries_in_group_byt   supports_bitwise_ort   supports_microsecond_precisiont   supports_regex_backreferencingt!   supports_date_lookup_using_stringt   supports_timezonest-   requires_explicit_null_ordering_when_groupingt   supports_1000_query_parameterst   allows_primary_key_0t   can_defer_constraint_checkst(   supports_mixed_date_datetime_comparisonst   supports_tablespacest   supports_sequence_resett   can_introspect_foreign_keyst   can_distinct_on_fieldsR   R   Rb   Ri   (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR_   M  sR   	t   BaseDatabaseOperationsc           B   s  e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d    Z# d!   Z$ d"   Z% d#   Z& d$   Z' d%   Z( d&   Z) d'   Z* e+ d(  Z, e d)  Z- d*   Z. e. Z/ d+   Z0 d,   Z1 d-   Z2 d.   Z3 d/   Z4 d0   Z5 d1   Z6 d2   Z7 d3   Z8 d4   Z9 d5   Z: RS(6   s   
    This class encapsulates all backend-specific differences, such as the way
    a backend performs ordering or calculates the ID of a recently-inserted
    row.
    s   django.db.models.sql.compilerc         C   s   | |  _  d  |  _ d  S(   N(   R   R   t   _cache(   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR     s    	c         C   s   d S(   s   
        Returns any SQL needed to support auto-incrementing primary keys, or
        None if no SQL is necessary.

        This SQL is executed when a table is created.
        N(   R   (   R   t   tablet   column(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   autoinc_sql  s    c         C   s
   t  |  S(   s   
        Returns the maximum allowed batch size for the backend. The fields
        are the fields going to be inserted in the batch, the objs contains
        all the objects to be inserted.
        (   t   len(   R   t   fieldst   objs(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   bulk_batch_size  s    c         C   s   d S(   s   
        Returns a SQL query that retrieves the first cache key greater than the
        n smallest.

        This is used by the 'db' cache backend to determine where to start
        culling.
        s>   SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   cache_key_culling_sql  s    c         C   s   t     d S(   s   
        Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
        extracts a value from the given date field field_name.
        N(   Rh   (   R   t   lookup_typet
   field_name(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   date_extract_sql  s    c         C   s   t     d S(   sL   
        Implements the date interval functionality for expressions
        N(   Rh   (   R   t   sqlt	   connectort	   timedelta(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   date_interval_sql  s    c         C   s   t     d S(   s   
        Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
        truncates the given date field field_name to a DATE object with only
        the given specificity.
        N(   Rh   (   R   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   date_trunc_sql  s    c         C   s   d S(   s   
        Returns the SQL necessary to cast a datetime value so that it will be
        retrieved as a Python datetime object instead of a string.

        This SQL should include a '%s' in place of the field's name.
        s   %s(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   datetime_cast_sql  s    c         C   s   d S(   s~   
        Returns the SQL necessary to make a constraint "initially deferred"
        during a CREATE TABLE statement.
        RG   (    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   deferrable_sql  s    c         C   s   | r t  d   n d Sd S(   s   
        Returns an SQL DISTINCT clause which removes duplicate rows from the
        result set. If any fields are given, only the given fields are being
        checked for duplicates.
        s<   DISTINCT ON fields is not supported by this database backendt   DISTINCTN(   Rh   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   distinct_sql#  s    c         C   s   d S(   sC   
        Returns the SQL command that drops a foreign key.
        s   DROP CONSTRAINT(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   drop_foreignkey_sql.  s    c         C   s   d S(   s   
        Returns any SQL necessary to drop the sequence for the given table.
        Returns None if no SQL is necessary.
        N(   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   drop_sequence_sql4  s    c         C   s   | j    d S(   s   
        Given a cursor object that has just performed an INSERT...RETURNING
        statement into a table that has an auto-incrementing ID, returns the
        newly created ID.
        i    (   R`   (   R   R+   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   fetch_returned_insert_id;  s    c         C   s   d S(   s
  
        Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary
        to cast it before using it in a WHERE statement. Note that the
        resulting string should contain a '%s' placeholder for the column being
        searched against.
        s   %s(    (   R   t   db_type(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   field_cast_sqlC  s    c         C   s   g  S(   s   
        Returns a list used in the "ORDER BY" clause to force no ordering at
        all. Returning an empty list means that nothing will be included in the
        ordering.
        (    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   force_no_orderingL  s    c         C   s   | r
 d Sd Sd S(   sY   
        Returns the FOR UPDATE SQL clause to lock rows for an update operation.
        s   FOR UPDATE NOWAITs
   FOR UPDATEN(    (   R   t   nowait(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   for_update_sqlT  s    c         C   s   t  d   d S(   s   
        Returns the SQL WHERE clause to use in order to perform a full-text
        search of the given field_name. Note that the resulting string should
        contain a '%s' placeholder for the value being searched against.
        s=   Full-text search is not implemented for this database backendN(   Rh   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   fulltext_search_sql]  s    c   	         s   d d l  m     f d   } t | t t f  r\ t g  | D] } | |  ^ q>  } n= t g  | j   D]$ \ } } | |  | |  f ^ ql  }   |  | S(   s  
        Returns a string of the query last executed by the given cursor, with
        placeholders replaced with actual values.

        `sql` is the raw query containing placeholders, and `params` is the
        sequence of parameters. These are used by default, but this method
        exists for database backends to provide a better implementation
        according to their own quoting schemes.
        i(   t
   force_textc            s     |  d t  d d S(   Nt   strings_onlyt   errorsRI   (   R>   (   t   s(   R   (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   <lambda>r  s    (   t   django.utils.encodingR   t
   isinstancet   listt   tuplet   dictt   items(	   R   R+   R   t   paramst
   to_unicodet   valt   u_paramst   kt   v(    (   R   s4   ../Django//lib/python/django/db/backends/__init__.pyt   last_executed_querye  s    
(=c         C   s   | j  S(   s
  
        Given a cursor object that has just performed an INSERT statement into
        a table that has an auto-incrementing ID, returns the newly created ID.

        This method also receives the table name and the name of the primary-key
        column.
        (   t	   lastrowid(   R   R+   t
   table_namet   pk_name(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   last_insert_idz  s    c         C   s   d S(   s   
        Returns the string to use in a query when performing lookups
        ("contains", "like", etc). The resulting string should contain a '%s'
        placeholder for the column being searched against.
        s   %s(    (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   lookup_cast  s    c         C   s   d S(   s   
        Returns the maximum number of items that can be passed in a single 'IN'
        list condition, or None if the backend does not impose a limit.
        N(   R   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   max_in_list_size  s    c         C   s   d S(   sm   
        Returns the maximum length of table and column names, or None if there
        is no limit.
        N(   R   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   max_name_length  s    c         C   s
   t   d S(   s   
        Returns the value to use for the LIMIT when we are wanting "LIMIT
        infinity". Returns None if the limit clause can be omitted in this case.
        N(   Rh   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   no_limit_value  s    c         C   s   d S(   s   
        Returns the value to use during an INSERT statement to specify that
        the field should use its default value.
        t   DEFAULT(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   pk_default_value  s    c         C   s   | S(   s   
        Returns the value of a CLOB column, for backends that return a locator
        object that requires additional processing.
        (    (   R   t   value(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   process_clob  s    c         C   s   d S(   s  
        For backends that support returning the last insert ID as part
        of an insert query, this method returns the SQL and params to
        append to the INSERT query. The returned fragment should
        contain a format string to hold the appropriate column.
        N(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   return_insert_id  s    c         C   s4   |  j  d k r$ t |  j  |  _  n  t |  j  |  S(   s   
        Returns the SQLCompiler class corresponding to the given name,
        in the namespace corresponding to the `compiler_module` attribute
        on this backend.
        N(   R   R   R	   t   compiler_modulet   getattr(   R   t   compiler_name(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   compiler  s    c         C   s   t     d S(   s   
        Returns a quoted version of the given table, index or column name. Does
        not quote the given name if it's already been quoted.
        N(   Rh   (   R   t   name(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt
   quote_name  s    c         C   s   d S(   sG   
        Returns a SQL expression that returns a random value.
        s   RANDOM()(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   random_function_sql  s    c         C   s
   t   d S(   sn  
        Returns the string to use in a query when performing regular expression
        lookups (using "regex" or "iregex"). The resulting string should
        contain a '%s' placeholder for the column being searched against.

        If the feature is not supported (or part of it is not supported), a
        NotImplementedError exception can be raised.
        N(   Rh   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   regex_lookup  s    	c         C   s
   t   d S(   s   
        Returns the SQL for starting a new savepoint. Only required if the
        "uses_savepoints" feature is True. The "sid" parameter is a string
        for the savepoint id.
        N(   Rh   (   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR.     s    c         C   s
   t   d S(   sE   
        Returns the SQL for committing the given savepoint.
        N(   Rh   (   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR3     s    c         C   s
   t   d S(   sG   
        Returns the SQL for rolling back the given savepoint.
        N(   Rh   (   R   R/   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR1     s    c         C   s   d S(   s   
        Returns the SQL that will set the connection's time zone.

        Returns '' if the backend doesn't support time zones.
        RG   (    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   set_time_zone_sql  s    c         C   s   t     d S(   s  
        Returns a list of SQL statements required to remove all data from
        the given database tables (without actually removing the tables
        themselves).

        The returned value also includes SQL statements required to reset DB
        sequences passed in :param sequences:.

        The `style` argument is a Style object as returned by either
        color_style() or no_style() in django.core.management.color.
        N(   Rh   (   R   t   stylet   tablest	   sequences(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt	   sql_flush  s    c         C   s   g  S(   s  
        Returns a list of the SQL statements required to reset sequences
        passed in :param sequences:.

        The `style` argument is a Style object as returned by either
        color_style() or no_style() in django.core.management.color.
        (    (   R   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   sequence_reset_by_name_sql  s    c         C   s   g  S(   s   
        Returns a list of the SQL statements required to reset sequences for
        the given models.

        The `style` argument is a Style object as returned by either
        color_style() or no_style() in django.core.management.color.
        (    (   R   R   t
   model_list(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   sequence_reset_sql  s    c         C   s   d S(   sL   
        Returns the SQL statement required to start a transaction.
        s   BEGIN;(    (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   start_transaction_sql  s    c         C   s   | s
 d Sd S(   Ns	   ROLLBACK;s   COMMIT;(    (   R   t   success(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   end_transaction_sql  s    c         C   s   d S(   s(  
        Returns the SQL that will be used in a query to define the tablespace.

        Returns '' if the backend doesn't support tablespaces.

        If inline is True, the SQL is appended to a row; otherwise it's appended
        to the entire CREATE TABLE or CREATE INDEX statement.
        RG   (    (   R   t
   tablespacet   inline(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   tablespace_sql#  s    	c         C   s>   d d l  m } | |  j d d  j d d  j d d  S(	   s)   Prepares a value for use in a LIKE query.i(   R   s   \s   \\t   %s   \%t   _s   \_(   R   R   RI   (   R   t   xR   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   prep_for_like_query.  s    c         C   s   | S(   s   
        Certain backends do not accept some values for "serial" fields
        (for example zero in MySQL). This method will raise a ValueError
        if the value is invalid, otherwise returns validated value.
        (    (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   validate_autopk_value7  s    c         C   s   | d k r d St j |  S(   s   
        Transform a date value to an object compatible with what is expected
        by the backend driver for date columns.
        N(   R   R
   t	   text_type(   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   value_to_db_date?  s    c         C   s   | d k r d St j |  S(   s   
        Transform a datetime value to an object compatible with what is expected
        by the backend driver for datetime columns.
        N(   R   R
   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   value_to_db_datetimeH  s    c         C   s8   | d k r d St |  r+ t d   n  t j |  S(   s   
        Transform a time value to an object compatible with what is expected
        by the backend driver for time columns.
        s-   Django does not support timezone-aware times.N(   R   R   t
   ValueErrorR
   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   value_to_db_timeQ  s
    c         C   s#   | d k r d St j | | |  S(   s   
        Transform a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        N(   R   R   t   format_number(   R   R   t
   max_digitst   decimal_places(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   value_to_db_decimal\  s    c         C   s   d } d } | | | | g S(   s   
        Returns a two-elements list with the lower and upper bound to be used
        with a BETWEEN operator to query a field value using a year lookup

        `value` is an int, containing the looked-up year.
        s   %s-01-01 00:00:00s   %s-12-31 23:59:59.999999(    (   R   R   t   firstt   second(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   year_lookup_boundse  s    c         C   s   |  j  |  S(   s  
        Returns a two-elements list with the lower and upper bound to be used
        with a BETWEEN operator to query a DateField value using a year lookup

        `value` is an int, containing the looked-up year.

        By default, it just calls `self.year_lookup_bounds`. Some backends need
        this hook because on their DB date fields can't be compared to values
        which include a time part.
        (   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt!   year_lookup_bounds_for_date_fieldp  s    c         C   sa   | d k r | S| j   } | d k r2 t |  S| r] | j d  sS | d k r] t |  S| S(   s   
        Coerce the value returned by the database backend into a consistent type
        that is compatible with the field type.
        t
   FloatFieldt   IntegerFieldt	   AutoFieldN(   R   t   get_internal_typet   floatt   endswitht   int(   R   R   t   fieldt   internal_type(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   convert_values}  s    

c         C   s   d S(   s1  Check that the backend supports the provided aggregate

        This is used on specific backends to rule out known aggregates
        that are known to have faulty implementations. If the named
        aggregate function has a known problem, the backend should
        raise NotImplementedError.
        N(    (   R   t   aggregate_func(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRg     s    c         C   s   d | } | j  |  S(   s  Combine a list of subexpressions into a single expression, using
        the provided connecting operator. This is required because operators
        can vary between backends (e.g., Oracle with %% and &) and between
        subexpression types (e.g., date expressions)
        s    %s (   t   join(   R   R   t   sub_expressionst   conn(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   combine_expression  s    
c         C   s   | S(   sj   Allow modification of insert parameters. Needed for Oracle Spatial
        backend due to #10888.
        (    (   R   t   placeholdersR   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   modify_insert_params  s    (;   R[   R\   R]   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R5   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R.   R3   R1   R   R   R   R   R   R>   R   R   R   t   prep_for_iexact_queryR   R   R   R   R   R   R   R   Rg   R  R  (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR     sn   					
																	
									
									
	
														
		t   BaseDatabaseIntrospectionc           B   s}   e  Z d  Z i  Z d   Z d   Z d   Z d d  Z d   Z	 e
 d  Z d   Z d   Z d	   Z d
   Z d   Z RS(   sN   
    This class encapsulates all backend-specific introspection utilities
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR     s    c         C   s   |  j  | S(   s  Hook for a database backend to use the cursor description to
        match a Django field type to a database column.

        For Oracle, the column data_type on its own is insufficient to
        distinguish between a FloatField and IntegerField, for example.(   t   data_types_reverse(   R   t	   data_typet   description(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   get_field_type  s    c         C   s   | S(   s   Apply a conversion to the name for the purposes of comparison.

        The default table name converter is for case sensitive comparison.
        (    (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   table_name_converter  s    c         C   s1   | d k r |  j j   } n  t |  j |   S(   s  
        Returns a list of names of all tables that exist in the database.
        The returned table list is sorted by Python's default sorting. We
        do NOT use database's ORDER BY here to avoid subtle differences
        in sorting order between databases.
        N(   R   R   R+   t   sortedt   get_table_list(   R   R+   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyRS     s    c         C   s
   t   d S(   se   
        Returns an unsorted list of names of all tables that exist in the
        database.
        N(   Rh   (   R   R+   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR    s    c   
      C   s  d d l  m } m } t   } x | j   D] } x | j |  D]u } | j j sZ qB n  | j |  j	 j
 |  sx qB n  | j | j j  | j g  | j j D] } | j   ^ q  qB Wq, Wt |  } | r|  j   } g  | D]! }	 |  j |	  | k r |	 ^ q } n  | S(   s   
        Returns a list of all table names that have associated Django models and
        are in INSTALLED_APPS.

        If only_existing is True, the resulting list will only include the tables
        that actually exist in the database.
        i(   t   modelst   router(   t	   django.dbR  R  t   sett   get_appst
   get_modelst   _metaR&   t   allow_syncdbR   R   t   addt   db_tablet   updatet   local_many_to_manyt   m2m_db_tableR   RS   R  (
   R   t   only_existingR  R  R   t   appt   modelt   ft   existing_tablest   t(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   django_table_names  s"    	4
$c         C   s   d d l  m } m } g  } xV | j   D]H } x? | j |  D]. } | j |  j j |  r? | j |  q? q? Wq) Wt	 t
 |  j |   } t g  | D]' } |  j | j j  | k r | ^ q  S(   sL   Returns a set of all models represented by the provided list of table names.i(   R  R  (   R  R  R  R  R  R  R   R   R8   R   t   mapR  R  R  R  (   R   R   R  R  t
   all_modelsR  R  t   m(    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   installed_models  s    c         C   s7  d d l  m } m } | j   } g  } x| D] } x | j |  D] } | j j s] qE n  | j j ro qE n  | j |  j	 j
 |  s qE n  xN | j j D]@ } t | | j  r | j i | j j d 6| j d 6 Pq q WxJ | j j D]< } | j j d k r | j i | j   d 6d d 6 q q WqE Wq/ W| S(   sP   Returns a list of information about all DB sequences for all models in all apps.i(   R  R  R   R   N(   R  R  R  R  R  R  R&   t   swappedR  R   R   t   local_fieldsR   R   R8   R  R   R  t   relt   throughR   R  (   R   R  R  t   appst   sequence_listR  R  R  (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR,    s&    $0c         C   s
   t   d S(   s   
        Backends can override this to return a list of (column_name, referenced_table_name,
        referenced_column_name) for all key columns in given table.
        N(   Rh   (   R   R+   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   get_key_columns  s    c         C   s@   x9 t  j |  j | |   D] } | d d r | d Sq Wd S(   sQ   
        Returns the name of the primary key column for the given table.
        i   t   primary_keyi    N(   R
   t	   iteritemst   get_indexesR   (   R   R+   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   get_primary_key_column  s    "c         C   s
   t   d S(   sX  
        Returns a dictionary of indexed fieldname -> infodict for the given
        table, where each infodict is in the format:
            {'primary_key': boolean representing whether it's the primary key,
             'unique': boolean representing whether it's a unique index}

        Only single-column indexes are introspected.
        N(   Rh   (   R   R+   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR0  %  s    	N(   R[   R\   R]   R  R   R  R  R   RS   R  R5   R"  R&  R,  R-  R1  R0  (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR    s   									t   BaseDatabaseClientc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s^   
    This class encapsulates all backend-specific methods for opening a
    client shell.
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR   :  s    c         C   s   t     d  S(   N(   Rh   (   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   runshell>  s    N(   R[   R\   R]   R   t   executable_nameR   R3  (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR2  1  s   	t   BaseDatabaseValidationc           B   s    e  Z d  Z d   Z d   Z RS(   sH   
    This class encapsualtes all backend-specific model validation.
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR   F  s    c         C   s   d S(   s3   By default, there is no backend-specific validationN(    (   R   R   t   optsR  (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   validate_fieldI  s    (   R[   R\   R]   R   R7  (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyR5  B  s   	N(    t   django.db.utilsR    t   django.utils.six.movesR   R   t   ImportErrorR   t
   contextlibR   t   django.confR   R  R   t   django.db.backendsR   t   django.db.transactionR   t   django.utils.functionalR   t   django.utils.importlibR	   t   django.utilsR
   t   django.utils.timezoneR   Rf   R   R_   R   R  R2  R5  (    (    (    s4   ../Django//lib/python/django/db/backends/__init__.pyt   <module>   s*    ; 