o 3a#@sDddlZddlZddlZddlmZddlmZGdddeZdS)N) DatabaseError)BaseDatabaseSchemaEditorcseZdZdZdZdZdZdZdZeZ dZ dZ d Z d Z d Zd d ZfddZfddZd+fdd ZfddZfddZddZddZddZfdd Zfd!d"Zd#d$Zd%d&Zd'd(Zfd)d*ZZS),DatabaseSchemaEditorz3ALTER TABLE %(table)s ADD %(column)s %(definition)szMODIFY %(column)s %(type)szMODIFY %(column)s NULLzMODIFY %(column)s NOT NULLz%MODIFY %(column)s DEFAULT %(default)szMODIFY %(column)s DEFAULT NULLz'MODIFY %(column)s %(type)s%(collation)sz,ALTER TABLE %(table)s DROP COLUMN %(column)szHCONSTRAINT %(name)s REFERENCES %(to_table)s(%(to_column)s)%(deferrable)sz(DROP TABLE %(table)s CASCADE CONSTRAINTSz9CREATE INDEX %(name)s ON %(table)s (%(columns)s)%(extra)scCszt|tjtjtjfrd|St|tr d|ddddSt|tttfr.d| St|t r9|r7dSdSt|S)Nz'%s''z''%z%%10) isinstancedatetimedatetimestrreplacebytes bytearray memoryviewhexboolselfvaluerB/usr/lib/python3/dist-packages/django/db/backends/oracle/schema.py quote_values    z DatabaseSchemaEditor.quote_valuecs6||jj|jr||jj|jt||dSN)_is_identity_column_metadb_tablecolumn_drop_identitysuper remove_field)rmodelfield __class__rrr!%sz!DatabaseSchemaEditor.remove_fieldcs0t||dd|jj|jjidS)NaK DECLARE i INTEGER; BEGIN SELECT COUNT(1) INTO i FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '%(sq_name)s'; IF i = 1 THEN EXECUTE IMMEDIATE 'DROP SEQUENCE "%(sq_name)s"'; END IF; END; /sq_name)r delete_modelexecute connectionops_get_no_autofield_sequence_namerr)rr"r$rrr',s  z!DatabaseSchemaEditor.delete_modelFc sz t||||WdStyn}zVt|}d|vs d|vr(||||n-d|vr>||jj|j|||||nd|vrT|j rT|j |dd||||nWYd}~dSWYd}~dSWYd}~dSd}~ww)Nz ORA-22858z ORA-22859z ORA-30675z ORA-30673T)strict) r alter_fieldrr _alter_field_type_workaroundrrrr primary_key_delete_primary_key)rr" old_field new_fieldr,e descriptionr$rrr-<s$z DatabaseSchemaEditor.alter_fieldcst|}|dv|_||j|_|||||j}||j }t d|r1d|}d}t d|rU|}|dkrDd|}n|dkrMd |}n|d krUd |}| d ||j j||j|f|||t|||d S)a Oracle refuses to change from some type to other type. What we need to do instead is: - Add a nullable version of the desired field with a temporary name. If the new column is an auto field, then the temporary column can't be nullable. - Update the table to transfer values from old to new - Drop old column - Rename the new column and possibly drop the nullable property ) AutoField BigAutoFieldSmallAutoFieldz^N?CLOBz TO_CHAR(%s)VARCHAR2z ^N?VARCHAR2 DateFieldzTO_DATE(%s, 'YYYY-MM-DD') DateTimeFieldz,TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF') TimeFieldzCTO_TIMESTAMP(CONCAT('1900-01-01 ', %s), 'YYYY-MM-DD HH24:MI:SS.FF')zUPDATE %s set %s=%sN)copydeepcopyget_internal_typenull_generate_temp_namer add_field quote_namedb_typer)rematchr(rrr!r r-)rr"r1r2new_temp_field new_valueold_typenew_internal_typer$rrr.Rs0           z1DatabaseSchemaEditor._alter_field_type_workaroundcsVhd}||vr"||vr"||jj|jr"||jj|jt||||S)N>r5r6r7)r>rrrrrr _alter_column_type_sql)rr"r1r2new_typeauto_field_typesr$rrrJs  z+DatabaseSchemaEditor._alter_column_type_sqlcCs2||}|ddkr|ddkr|dd}|S)z Get the properly shortened and uppercased identifier as returned by quote_name() but without the quotes. r")rB)rnamennrrrnormalize_names  z#DatabaseSchemaEditor.normalize_namecCs*tt|dd}||d|S)z@Generate temporary names for workarounds that need temp columns.rON_)rhashupperrR)rfor_namesuffixrrrr@sz(DatabaseSchemaEditor._generate_temp_namecCs ||Sr)rrrrrprepare_defaults z$DatabaseSchemaEditor.prepare_defaultcs:t||}||j}|dur||jjvrdS|S)NF)r _field_should_be_indexedrCr)lower_limited_data_types)rr"r# create_indexrCr$rrrYs  z-DatabaseSchemaEditor._field_should_be_indexedcst||o ||| Sr)r _unique_should_be_added_field_became_primary_key)rr1r2r$rrr]s z,DatabaseSchemaEditor._unique_should_be_addedcCsb|j"}|d||||g|}|r|dndWdS1s*wYdS)Nz SELECT CASE WHEN identity_column = 'YES' THEN 1 ELSE 0 END FROM user_tab_cols WHERE table_name = %s AND column_name = %s rFr)cursorr(rRfetchone)r table_name column_namer`rowrrrrs $z(DatabaseSchemaEditor._is_identity_columncCs$|d||||ddS)Nz5ALTER TABLE %(table)s MODIFY %(column)s DROP IDENTITY)tabler)r(rB)rrbrcrrrrsz#DatabaseSchemaEditor._drop_identitycCsN|j}|d||g|dWdS1s wYdS)Nz] SELECT default_collation FROM user_tables WHERE table_name = %s rr_)rrbr`rrr_get_default_collations   $z+DatabaseSchemaEditor._get_default_collationcs(|dur ||jj}t||||Sr)rfrrr _alter_column_collation_sql)rr"r2rK new_collationr$rrrgsz0DatabaseSchemaEditor._alter_column_collation_sql)F)__name__ __module__ __qualname__sql_create_columnsql_alter_column_typesql_alter_column_nullsql_alter_column_not_nullsql_alter_column_defaultsql_alter_column_no_default sql_alter_column_no_default_nullsql_alter_column_collatesql_delete_columnsql_create_column_inline_fksql_delete_tablesql_create_indexrr!r'r-r.rJrRr@rXrYr]rrrfrg __classcell__rrr$rr s8   .     r)r<r rD django.dbrdjango.db.backends.base.schemarrrrrrs