a
    [f                     @   sh   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZmZ G dd deZdS )	    )settings)caches)BaseDatabaseCache)BaseCommandCommandError)DEFAULT_DB_ALIASDatabaseErrorconnectionsmodelsroutertransactionc                   @   s,   e Zd ZdZg Zdd Zdd Zdd ZdS )	Commandz7Creates the tables needed to use the SQL cache backend.c                 C   s6   |j ddddd |j dtdd |j d	d
dd d S )NargsZ
table_name*zNOptional table names. Otherwise, settings.CACHES is used to find cache tables.)metavarnargshelpz
--databasezgNominates a database onto which the cache tables will be installed. Defaults to the "default" database.)defaultr   z	--dry-run
store_truezADoes not create the table, just prints the SQL that would be run.)actionr   )add_argumentr   )selfparser r   C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\django/core/management/commands/createcachetable.pyadd_arguments   s     	zCommand.add_argumentsc                 O   sj   |d }|d | _ |d }|r8|D ]}| ||| q"n.tjD ]&}t| }t|tr>| ||j| q>d S )Ndatabase	verbositydry_run)r   create_tabler   ZCACHESr   
isinstancer   _table)r   Z
tablenamesoptionsdbr   	tablenameZcache_aliascacher   r   r   handle*   s    


zCommand.handlec                 C   s  t |i }t||jsd S t| }||j v rP| jdkrL| j	d|  d S t
jdddddt
jddt
jd	dd
f}g }g }|jj}	|D ]}
|	|
j|
j|dd|
jsdnd g}|
jr|d n|
jr|d |
jr|
jrdnd}|d||	d||
jf |	||	|
jf  |d| qd|	| g}t|D ]2\}}|d||t|d k rldndf  qF|d d|}|r| j	| |D ]}| j	| qd S tj||jjd | l}z|| W n6 t y } zt!d||f W Y d }~n
d }~0 0 |D ]}|| q$W d    n1 sL0    Y  W d    n1 sl0    Y  | jdkr| j	d|  d S )Nr   z Cache table '%s' already exists.	cache_key   T)name
max_lengthuniqueprimary_keyvalue)r)   expires)r)   db_index)
connectionz%sNULLzNOT  zPRIMARY KEYZUNIQUEzUNIQUE zCREATE %sINDEX %s ON %s (%s);z%s_%s zCREATE TABLE %s (z    %s%s   ,z);
)usingZ	savepointz9Cache table '%s' could not be created.
The error was: %s.zCache table '%s' created.)"r   r   Zallow_migrate_modelZcache_model_classr	   ZintrospectionZtable_namesr   stdoutwriter
   Z	CharFieldZ	TextFieldZDateTimeFieldopsZ
quote_namer)   Zdb_typenullr,   appendr+   r/   join	enumeratelenr   ZatomicfeaturesZcan_rollback_ddlcursorexecuter   r   )r   r   r$   r   r%   r0   fieldsZtable_outputZindex_outputqnfZfield_outputr+   Zfull_statementilineZ	statementZcurser   r   r   r   8   s    




	 


NzCommand.create_tableN)__name__
__module____qualname__r   Zrequires_system_checksr   r&   r   r   r   r   r   r      s
   r   N)Zdjango.confr   Zdjango.core.cacher   Zdjango.core.cache.backends.dbr   Zdjango.core.management.baser   r   Z	django.dbr   r   r	   r
   r   r   r   r   r   r   r   <module>   s
    
