本文整理汇总了Python中south.db.db.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forwards
def forwards(self, orm):
# Adding model 'Recruit'
db.create_table('hr_recruit', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
('recruiter', self.gf('django.db.models.fields.related.ForeignKey')(related_name='recruiter', to=orm['auth.User'])),
))
db.send_create_signal('hr', ['Recruit'])
# Adding M2M table for field reference on 'Recruit'
db.create_table('hr_recruit_reference', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('recruit', models.ForeignKey(orm['hr.recruit'], null=False)),
('user', models.ForeignKey(orm['auth.user'], null=False))
))
db.create_unique('hr_recruit_reference', ['recruit_id', 'user_id'])
# Changing field 'TitleCompoDiff.id'
if 'postgres' in db.backend_name.lower():
db.execute("ALTER TABLE hr_titlecompodiff ALTER COLUMN id TYPE integer;")
else:
db.alter_column('hr_titlecompodiff', 'id', self.gf('django.db.models.fields.AutoField')(primary_key=True))
# Changing field 'TitleMemberDiff.id'
if 'postgres' in db.backend_name.lower():
db.execute("ALTER TABLE hr_titlememberdiff ALTER COLUMN id TYPE integer;")
else:
db.alter_column('hr_titlememberdiff', 'id', self.gf('django.db.models.fields.AutoField')(primary_key=True))
开发者ID:Betriebsrat,项目名称:ecm,代码行数:28,代码来源:0011_auto__add_recruit__chg_field_titlecompodiff_id__chg_field_titlememberd.py
示例2: forwards
def forwards(self, orm):
for link in orm['djotero.zoterolink'].objects.all():
db.execute(
u'UPDATE main_document '
'SET zotero_data = %s, zotero_link_id = %s '
'WHERE id = %s;',
params=[link.zotero_data, link.id, link.doc_id])
示例3: forwards
def forwards(self, orm):
if connection.vendor == 'sqlite':
return True
# Convert Configuration model to UTF-8
db.execute("ALTER TABLE seo_configuration "
"CONVERT TO CHARACTER SET utf8 "
"COLLATE utf8_general_ci")
示例4: forwards
def forwards(self, orm):
db.execute("""
CREATE FUNCTION set_fault_simplegeom(target_fault_id integer) RETURNS VOID AS $$
DECLARE
sections_united geometry;
BEGIN
SELECT
ST_Union(fault_section_view.geom)
FROM
gem.fault_section_view
JOIN
gem.observations_faultsection_fault
ON (fault_section_view.id = observations_faultsection_fault.faultsection_id)
WHERE
observations_faultsection_fault.fault_id = target_fault_id
INTO
sections_united;
UPDATE
gem.observations_fault
SET
simple_geom = ST_Multi(ST_LongestLine(sections_united, sections_united))
WHERE
id = target_fault_id;
END;
$$ LANGUAGE plpgsql VOLATILE STRICT;
""")
示例5: forwards
def forwards(self, orm):
# Adding field 'BrandProposal.status'
db.add_column(u'brand_proposal', 'status',
self.gf('django.db.models.fields.NullBooleanField')(null=True, db_column=u'STATUS', blank=True),
keep_default=False)
db.execute("TRUNCATE TABLE brand_proposal CASCADE;")
db.execute("TRUNCATE TABLE brand_proposal_review;")
示例6: test_datetime_default
def test_datetime_default(self):
"""
Test that defaults are created correctly for datetime columns
"""
end_of_world = datetime.datetime(2012, 12, 21, 0, 0, 1)
try:
from django.utils import timezone
except ImportError:
pass
else:
from django.conf import settings
if getattr(settings, 'USE_TZ', False):
end_of_world = end_of_world.replace(tzinfo=timezone.utc)
db.create_table("test_datetime_def", [
('col0', models.IntegerField(null=True)),
('col1', models.DateTimeField(default=end_of_world)),
('col2', models.DateTimeField(null=True)),
])
db.alter_column("test_datetime_def", "col2", models.DateTimeField(default=end_of_world))
db.add_column("test_datetime_def", "col3", models.DateTimeField(default=end_of_world))
db.execute("insert into test_datetime_def (col0) values (null)")
ends = db.execute("select col1,col2,col3 from test_datetime_def")[0]
self.failUnlessEqual(len(ends), 3)
for e in ends:
self.failUnlessEqual(e, end_of_world)
示例7: test_change_foreign_key_target
def test_change_foreign_key_target(self):
# Tables for FK to target
User = db.mock_model(model_name='User', db_table='auth_user', db_tablespace='', pk_field_name='id', pk_field_type=models.AutoField, pk_field_args=[], pk_field_kwargs={})
db.create_table("test_fk_changed_target", [
('eggs', models.IntegerField(primary_key=True)),
])
Egg = db.mock_model(model_name='Egg', db_table='test_fk_changed_target', db_tablespace='', pk_field_name='eggs', pk_field_type=models.AutoField, pk_field_args=[], pk_field_kwargs={})
# Table with a foreign key to the wrong table
db.create_table("test_fk_changing", [
('egg', models.ForeignKey(User, null=True)),
])
db.execute_deferred_sql()
# Change foreign key pointing
db.alter_column("test_fk_changing", "egg_id", models.ForeignKey(Egg, null=True))
db.execute_deferred_sql()
# Test that it is pointing at the right table now
try:
non_user_id = db.execute("SELECT MAX(id) FROM auth_user")[0][0] + 1
except (TypeError, IndexError):
# Got a "None" or no records, treat as 0
non_user_id = 17
db.execute("INSERT INTO test_fk_changed_target (eggs) VALUES (%s)", [non_user_id])
db.execute("INSERT INTO test_fk_changing (egg_id) VALUES (%s)", [non_user_id])
db.commit_transaction()
db.start_transaction() # The test framework expects tests to end in transaction
示例8: forwards
def forwards(self, orm):
try:
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
except AttributeError:
bucket_name = 'media.demozoo.org'
try:
bucket_format = settings.AWS_BOTO_CALLING_FORMAT
except AttributeError:
bucket_format = 'VHostCallingFormat'
if bucket_format == 'VHostCallingFormat':
url_prefix = "http://%s/" % bucket_name
else:
url_prefix = "http://%s.s3.amazonaws.com/" % bucket_name
# Adding field 'Platform.photo_url'
db.add_column(u'platforms_platform', 'photo_url',
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
keep_default=False)
# Adding field 'Platform.thumbnail_url'
db.add_column(u'platforms_platform', 'thumbnail_url',
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
keep_default=False)
db.execute("UPDATE platforms_platform SET photo_url = %s || photo WHERE photo IS NOT NULL", [url_prefix])
db.execute("UPDATE platforms_platform SET thumbnail_url = %s || thumbnail WHERE thumbnail IS NOT NULL", [url_prefix])
示例9: forwards
def forwards(self, orm):
db.start_transaction()
# Argh. The DB dump has a lot of crap we don't care about at all.
# So, use South's fake ORM dictionary to figure out how to create those columns.
db.add_column('gis_neighborhoods', 'stacked', orm['bmabr.neighborhood:stacked'])
db.add_column('gis_neighborhoods', 'annoline1', orm['bmabr.neighborhood:annoline1']),
db.add_column('gis_neighborhoods', 'annoline2', orm['bmabr.neighborhood:annoline2']),
db.add_column('gis_neighborhoods', 'annoline3', orm['bmabr.neighborhood:annoline3']),
db.add_column('gis_neighborhoods', 'annoangle', orm['bmabr.neighborhood:annoangle']),
db.commit_transaction()
# Now load the data.
db.start_transaction()
HERE = os.path.abspath(os.path.dirname(__file__))
sql_path = os.path.abspath(
os.path.join(HERE, '..', '..', 'sql', 'gis_neighborhoods.sql'))
db.execute_many(open(sql_path).read())
db.execute("UPDATE gis_neighborhoods SET state = 'NY'")
db.commit_transaction()
# Now clean up the crap we don't want.
db.start_transaction()
db.delete_column('gis_neighborhoods', 'stacked')
db.delete_column('gis_neighborhoods', 'annoangle')
db.delete_column('gis_neighborhoods', 'annoline1')
db.delete_column('gis_neighborhoods', 'annoline2')
db.delete_column('gis_neighborhoods', 'annoline3')
db.commit_transaction()
示例10: backwards
def backwards(self, orm):
""" Custom migration to remove 'has_image' field from Posting table.
"""
db.execute("""
DROP INDEX shared_posting_has_image;
ALTER TABLE shared_posting DROP COLUMN has_image;
""")
示例11: forwards
def forwards(self, orm):
""" Custom migration to add 'has_image' field to Posting table.
"""
db.execute("""
ALTER TABLE shared_posting ADD COLUMN has_image boolean NOT NULL DEFAULT FALSE;
CREATE INDEX shared_posting_has_image ON shared_posting USING btree(has_image);
""")
示例12: forwards
def forwards(self, orm):
# Changing field 'Asset.deprecation_rate'
db.alter_column('ralph_assets_asset', 'deprecation_rate', self.gf('django.db.models.fields.DecimalField')(max_digits=5, decimal_places=2))
# Adding field 'AssetModel.category'
db.add_column('ralph_assets_assetmodel', 'category',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['ralph_assets.AssetCategory'], null=True, blank=True),
keep_default=False)
# Adding field 'AssetModel.power_consumption'
db.add_column('ralph_assets_assetmodel', 'power_consumption',
self.gf('django.db.models.fields.IntegerField')(default=0, blank=True),
keep_default=False)
# Adding field 'AssetModel.height_of_device'
db.add_column('ralph_assets_assetmodel', 'height_of_device',
self.gf('django.db.models.fields.IntegerField')(default=0, blank=True),
keep_default=False)
# Migrate categories from assets to assets models
for asset in Asset.objects.values_list(
'category_id', 'model_id').filter():
db.execute(
"UPDATE ralph_assets_assetmodel SET category_id = %s "
"WHERE id = %s",
asset)
开发者ID:ar4s,项目名称:ralph_assets,代码行数:26,代码来源:0008_auto__add_field_assetmodel_category__add_field_assetmodel_power_consum.py
示例13: forwards
def forwards(self, orm):
cursor1 = connection.cursor()
cursor1.execute("UPDATE archives_archive_collectivities as t1 INNER JOIN archives_archive AS t2 ON t1.`archive_id` = t2.`id_archiprod` SET t1.`archive_id` = t2.`id`")
cursor2 = connection.cursor()
cursor2.execute("UPDATE archives_archive_tags as t1 INNER JOIN archives_archive AS t2 ON t1.`archive_id` = t2.`id_archiprod` SET t1.`archive_id` = t2.`id`")
cursor3 = connection.cursor()
cursor3.execute("UPDATE archives_archiveparticipant as t1 INNER JOIN archives_archive AS t2 ON t1.`archive_id` = t2.`id_archiprod` SET t1.`archive_id` = t2.`id`")
cursor4 = connection.cursor()
cursor4.execute("UPDATE archives_contract as t1 INNER JOIN archives_archive AS t2 ON t1.`archive_id` = t2.`id_archiprod` SET t1.`archive_id` = t2.`id`")
cursor5 = connection.cursor()
cursor5.execute("UPDATE archives_media as t1 INNER JOIN archives_archive AS t2 ON t1.`archive_id` = t2.`id_archiprod` SET t1.`archive_id` = t2.`id`")
cursor6 = connection.cursor()
cursor6.execute("UPDATE archives_archive SET time=NULL WHERE time=''")
cursor7 = connection.cursor()
cursor7.execute("UPDATE archives_archive SET time=NULL WHERE time=':'")
#fix ACANTHES MIGRATION ARCHIVES 0018
db.execute('ALTER TABLE archives_archive CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci')
db.execute('ALTER TABLE archives_media CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci')
transaction.commit_unless_managed()
示例14: forwards
def forwards(self, orm):
# Changing field 'Sand.dirt'
db.alter_column('lab_sand', 'dirt', self.gf('django.db.models.fields.TextField')(null=True))
# Changing field 'Sand.module_size'
db.alter_column('lab_sand', 'module_size', self.gf('django.db.models.fields.FloatField')(null=True))
# Changing field 'Sand.particle_size'
db.alter_column('lab_sand', 'particle_size', self.gf('django.db.models.fields.FloatField')(null=True))
# Changing field 'Bar.humidity_transporter'
db.alter_column('lab_bar', 'humidity_transporter', self.gf('django.db.models.fields.FloatField')(null=True))
# Changing field 'Clay.inclusion'
db.alter_column('lab_clay', 'inclusion', self.gf('django.db.models.fields.FloatField')(null=True))
# Changing field 'Clay.humidity'
db.execute('ALTER TABLE "lab_clay" ALTER "humidity" SET DATA TYPE numeric(10,2) USING humidity::numeric(10,2);')
db.alter_column('lab_clay', 'humidity', self.gf('django.db.models.fields.FloatField')())
# Changing field 'Clay.sand'
db.alter_column('lab_clay', 'sand', self.gf('django.db.models.fields.FloatField')(null=True))
# Changing field 'Clay.dust'
db.alter_column('lab_clay', 'dust', self.gf('django.db.models.fields.FloatField')(null=True))
开发者ID:wd5,项目名称:1-bkz,代码行数:26,代码来源:0004_auto__chg_field_sand_dirt__chg_field_sand_module_size__chg_field_sand_.py
示例15: seed
def seed(self):
#get sql file
seed_file = open(os.path.join(SETTINGS.PROJECT_ROOT, '..', 'citi_digits','migrations') + "/stats_fixture.sql")
for line in seed_file.readlines():
#strip off semicolon
insertLine = line[0:len(line)-1]
db.execute(insertLine)