<s> import re <EOL> from django . db . backends import BaseDatabaseOperations <EOL> class DatabaseOperations ( BaseDatabaseOperations ) : <EOL> def __init__ ( self , connection ) : <EOL> super ( DatabaseOperations , self ) . __init__ ( ) <EOL> self . _postgres_version = None <EOL> self . connection = connection <EOL> def _get_postgres_version ( self ) : <EOL> if self . _postgres_version is None : <EOL> from django . db . backends . postgresql . version import get_version <EOL> cursor = self . connection . cursor ( ) <EOL> self . _postgres_version = get_version ( cursor ) <EOL> return self . _postgres_version <EOL> postgres_version = property ( _get_postgres_version ) <EOL> def date_extract_sql ( self , lookup_type , field_name ) : <EOL> if lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % field_name <EOL> else : <EOL> return "<STR_LIT>" % ( lookup_type , field_name ) <EOL> def date_interval_sql ( self , sql , connector , timedelta ) : <EOL> """<STR_LIT>""" <EOL> modifiers = [ ] <EOL> if timedelta . days : <EOL> modifiers . append ( u'<STR_LIT>' % timedelta . days ) <EOL> if timedelta . seconds : <EOL> modifiers . append ( u'<STR_LIT>' % timedelta . seconds ) <EOL> if timedelta . microseconds : <EOL> modifiers . append ( u'<STR_LIT>' % timedelta . microseconds ) <EOL> mods = u'<STR_LIT:U+0020>' . join ( modifiers ) <EOL> conn = u'<STR_LIT>' % connector <EOL> return u'<STR_LIT>' % conn . join ( [ sql , u'<STR_LIT>' % mods ] ) <EOL> def date_trunc_sql ( self , lookup_type , field_name ) : <EOL> return "<STR_LIT>" % ( lookup_type , field_name ) <EOL> def deferrable_sql ( self ) : <EOL> return "<STR_LIT>" <EOL> def lookup_cast ( self , lookup_type ) : <EOL> lookup = '<STR_LIT:%s>' <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> lookup = "<STR_LIT>" <EOL> if lookup_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> lookup = '<STR_LIT>' % lookup <EOL> return lookup <EOL> def field_cast_sql ( self , db_type ) : <EOL> if db_type == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT:%s>' <EOL> def last_insert_id ( self , cursor , table_name , pk_name ) : <EOL> cursor . execute ( "<STR_LIT>" % ( <EOL> self . quote_name ( table_name ) , pk_name ) ) <EOL> return cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def no_limit_value ( self ) : <EOL> return None <EOL> def quote_name ( self , name ) : <EOL> if name . startswith ( '<STR_LIT:">' ) and name . endswith ( '<STR_LIT:">' ) : <EOL> return name <EOL> return '<STR_LIT>' % name <EOL> def sql_flush ( self , style , tables , sequences ) : <EOL> if tables : <EOL> if self . postgres_version [ <NUM_LIT:0> : <NUM_LIT:2> ] >= ( <NUM_LIT:8> , <NUM_LIT:1> ) : <EOL> sql = [ '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( '<STR_LIT:U+002CU+0020>' . join ( [ self . quote_name ( table ) for table in tables ] ) ) <EOL> ) ] <EOL> else : <EOL> sql = [ '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( self . quote_name ( table ) ) <EOL> ) for table in tables ] <EOL> for sequence_info in sequences : <EOL> table_name = sequence_info [ '<STR_LIT>' ] <EOL> column_name = sequence_info [ '<STR_LIT>' ] <EOL> if not ( column_name and len ( column_name ) > <NUM_LIT:0> ) : <EOL> column_name = '<STR_LIT:id>' <EOL> sql . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( self . quote_name ( table_name ) ) , <EOL> style . SQL_FIELD ( column_name ) ) <EOL> ) <EOL> return sql <EOL> else : <EOL> return [ ] <EOL> def sequence_reset_sql ( self , style , model_list ) : <EOL> from django . db import models <EOL> output = [ ] <EOL> qn = self . quote_name <EOL> for model in model_list : <EOL> for f in model . _meta . local_fields : <EOL> if isinstance ( f , models . AutoField ) : <EOL> output . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( qn ( model . _meta . db_table ) ) , <EOL> style . SQL_FIELD ( f . column ) , <EOL> style . SQL_FIELD ( qn ( f . column ) ) , <EOL> style . SQL_FIELD ( qn ( f . column ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( qn ( model . _meta . db_table ) ) ) ) <EOL> break <EOL> for f in model . _meta . many_to_many : <EOL> if not f . rel . through : <EOL> output . append ( "<STR_LIT>" % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( qn ( f . m2m_db_table ( ) ) ) , <EOL> style . SQL_FIELD ( '<STR_LIT:id>' ) , <EOL> style . SQL_FIELD ( qn ( '<STR_LIT:id>' ) ) , <EOL> style . SQL_FIELD ( qn ( '<STR_LIT:id>' ) ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_TABLE ( qn ( f . m2m_db_table ( ) ) ) ) ) <EOL> return output <EOL> def savepoint_create_sql ( self , sid ) : <EOL> return "<STR_LIT>" % sid <EOL> def savepoint_commit_sql ( self , sid ) : <EOL> return "<STR_LIT>" % sid <EOL> def savepoint_rollback_sql ( self , sid ) : <EOL> return "<STR_LIT>" % sid <EOL> def prep_for_iexact_query ( self , x ) : <EOL> return x <EOL> def check_aggregate_support ( self , aggregate ) : <EOL> """<STR_LIT>""" <EOL> if aggregate . sql_function in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if self . postgres_version [ <NUM_LIT:0> : <NUM_LIT:2> ] < ( <NUM_LIT:8> , <NUM_LIT:2> ) : <EOL> raise NotImplementedError ( '<STR_LIT>' % aggregate . sql_function ) <EOL> if aggregate . sql_function in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if self . postgres_version [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( <NUM_LIT:8> , <NUM_LIT:2> ) : <EOL> if self . postgres_version [ <NUM_LIT:2> ] is None or self . postgres_version [ <NUM_LIT:2> ] <= <NUM_LIT:4> : <EOL> raise NotImplementedError ( '<STR_LIT>' % aggregate . sql_function ) <EOL> def max_name_length ( self ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT> </s>
