def sequence_reset_sql(self, style, model_list):
     from server.db import models
     output = []
     query = self._sequence_reset_sql
     for model in model_list:
         for f in model._meta.local_fields:
             if isinstance(f, models.AutoField):
                 no_autofield_sequence_name = self._get_no_autofield_sequence_name(model._meta.db_table)
                 table = self.quote_name(model._meta.db_table)
                 column = self.quote_name(f.column)
                 output.append(query % {
                     'no_autofield_sequence_name': no_autofield_sequence_name,
                     'table': table,
                     'column': column,
                     'table_name': strip_quotes(table),
                     'column_name': strip_quotes(column),
                 })
                 # Only one AutoField is allowed per model, so don't
                 # continue to loop
                 break
         for f in model._meta.many_to_many:
             if not f.remote_field.through:
                 no_autofield_sequence_name = self._get_no_autofield_sequence_name(f.m2m_db_table())
                 table = self.quote_name(f.m2m_db_table())
                 column = self.quote_name('id')
                 output.append(query % {
                     'no_autofield_sequence_name': no_autofield_sequence_name,
                     'table': table,
                     'column': column,
                     'table_name': strip_quotes(table),
                     'column_name': 'ID',
                 })
     return output
 def sequence_reset_by_name_sql(self, style, sequences):
     sql = []
     for sequence_info in sequences:
         no_autofield_sequence_name = self._get_no_autofield_sequence_name(sequence_info['table'])
         table = self.quote_name(sequence_info['table'])
         column = self.quote_name(sequence_info['column'] or 'id')
         query = self._sequence_reset_sql % {
             'no_autofield_sequence_name': no_autofield_sequence_name,
             'table': table,
             'column': column,
             'table_name': strip_quotes(table),
             'column_name': strip_quotes(column),
         }
         sql.append(query)
     return sql
 def _get_no_autofield_sequence_name(self, table):
     """
     Manually created sequence name to keep backward compatibility for
     AutoFields that aren't Oracle identity columns.
     """
     name_length = self.max_name_length() - 3
     return '%s_SQ' % truncate_name(strip_quotes(table), name_length).upper()
Beispiel #4
0
 def _database_exists(self, cursor, database_name):
     cursor.execute(
         'SELECT 1 FROM pg_catalog.pg_database WHERE datname = %s',
         [strip_quotes(database_name)])
     return cursor.fetchone() is not None
 def last_insert_id(self, cursor, table_name, pk_name):
     sq_name = self._get_sequence_name(cursor, strip_quotes(table_name), pk_name)
     cursor.execute('"%s".currval' % sq_name)
     return cursor.fetchone()[0]