本文整理汇总了Python中django.db.backends.utils.strip_quotes方法的典型用法代码示例。如果您正苦于以下问题:Python utils.strip_quotes方法的具体用法?Python utils.strip_quotes怎么用?Python utils.strip_quotes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.backends.utils
的用法示例。
在下文中一共展示了utils.strip_quotes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _alter_column_type_sql
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def _alter_column_type_sql(self, model, old_field, new_field, new_type):
self.sql_alter_column_type = 'ALTER COLUMN %(column)s TYPE %(type)s'
# Cast when data type changed.
if self._field_data_type(old_field) != self._field_data_type(new_field):
self.sql_alter_column_type += ' USING %(column)s::%(type)s'
# Make ALTER TYPE with SERIAL make sense.
# table = strip_quotes(model._meta.db_table)
serial_fields_map = {'bigserial': 'bigint', 'serial': 'integer', 'smallserial': 'smallint'}
if new_type.lower() in serial_fields_map:
column = strip_quotes(new_field.column)
return (
(
self.sql_alter_column_type % {
"column": self.quote_name(column),
"type": serial_fields_map[new_type.lower()],
},
[],
),
# The PostgreSQL backend manages the column sequence here but
# this isn't applicable on CockroachDB because unique_rowid()
# is used instead of sequences.
[],
)
else:
return BaseDatabaseSchemaEditor._alter_column_type_sql(self, model, old_field, new_field, new_type)
示例2: last_insert_id
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
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]
示例3: sequence_reset_by_name_sql
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
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
示例4: sequence_reset_sql
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def sequence_reset_sql(self, style, model_list):
from django.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
示例5: _get_no_autofield_sequence_name
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
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()
示例6: _get_m2m_db_table
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def _get_m2m_db_table(self, opts):
"""
Function that can be curried to provide the m2m table name for this
relation.
"""
if self.remote_field.through is not None:
return self.remote_field.through._meta.db_table
elif self.db_table:
return self.db_table
else:
m2m_table_name = '%s_%s' % (utils.strip_quotes(opts.db_table), self.name)
return utils.truncate_name(m2m_table_name, connection.ops.max_name_length())
示例7: _database_exists
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
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
示例8: _create_index_name
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def _create_index_name(self, model, column_names, suffix=""):
"""
Generates a unique name for an index/unique constraint.
The name is divided into 3 parts: the table name, the column names,
and a unique digest and suffix.
"""
table_name = strip_quotes(model._meta.db_table)
hash_data = [table_name] + list(column_names)
hash_suffix_part = '%s%s' % (self._digest(*hash_data), suffix)
max_length = self.connection.ops.max_name_length() or 200
# If everything fits into max_length, use that name.
index_name = '%s_%s_%s' % (table_name, '_'.join(column_names), hash_suffix_part)
if len(index_name) <= max_length:
return index_name
# Shorten a long suffix.
if len(hash_suffix_part) > max_length / 3:
hash_suffix_part = hash_suffix_part[:max_length // 3]
other_length = (max_length - len(hash_suffix_part)) // 2 - 1
index_name = '%s_%s_%s' % (
table_name[:other_length],
'_'.join(column_names)[:other_length],
hash_suffix_part,
)
# Prepend D if needed to prevent the name from starting with an
# underscore or a number (not permitted on Oracle).
if index_name[0] == "_" or index_name[0].isdigit():
index_name = "D%s" % index_name[:-1]
return index_name
示例9: _get_sequence_name
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def _get_sequence_name(self, table):
name_length = self.max_name_length() - 3
return '%s_SQ' % truncate_name(strip_quotes(table), name_length).upper()
示例10: _get_trigger_name
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import strip_quotes [as 别名]
def _get_trigger_name(self, table):
name_length = self.max_name_length() - 3
return '%s_TR' % truncate_name(strip_quotes(table), name_length).upper()