• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.execute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中south.db.db.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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])
开发者ID:GregePorter,项目名称:editorsnotes,代码行数:7,代码来源:0115_repopulate_zotero_fields.py


示例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")
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:7,代码来源:0014_unicode_configurations.py


示例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;
        """)
开发者ID:gvallarelli,项目名称:oq-ui-api,代码行数:27,代码来源:0003_set_fault_simplegeom_proc.py


示例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;")
开发者ID:Spencerx,项目名称:brand-manager,代码行数:7,代码来源:0025_auto__add_field_brandproposal_status.py


示例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)
开发者ID:15776950506,项目名称:affiliates,代码行数:27,代码来源:db.py


示例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
开发者ID:10sr,项目名称:hue,代码行数:27,代码来源:db.py


示例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])
开发者ID:DannyCork,项目名称:demozoo,代码行数:28,代码来源:0002_add_image_urls.py


示例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()
开发者ID:natea,项目名称:fixcity,代码行数:30,代码来源:0022_populate_hoods.py


示例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;
""")
开发者ID:3taps,项目名称:3taps-data-commons,代码行数:7,代码来源:0006_add_has_image.py


示例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);
        """)
开发者ID:3taps,项目名称:3taps-data-commons,代码行数:7,代码来源:0006_add_has_image.py


示例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()
开发者ID:funkyminh,项目名称:archiprod,代码行数:28,代码来源:0006_alter_table.py


示例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)
开发者ID:NiJeLorg,项目名称:City-Digits,代码行数:7,代码来源:0008_auto__add_neighborhoodstatistics.py


示例16: backwards

    def backwards(self, orm):
        "Write your backwards migration here"

        result = db.execute("SELECT id FROM photos_format")
        for row in result:
            id = row[0]
            # take the first site for every format...
            min_site = db.execute("SELECT MIN(site_id) FROM photos_format_sites WHERE format_id = %s", (id,))[0]

            # ... put it onto the format ...
            db.execute("UPDATE photos_format SET site_id = %s WHERE id = %s", (min_site, id))

            # ... and remove the site from the m2m
            db.execute("DELETE FROM photos_format_sites WHERE format_id = %s AND site_id = %s", (id, site_id))

        # copy all the remaining sites from m2m to format as new rows
        db.execute(
            """
            INSERT INTO
                photos_format 
                (site_id, name, %s)
            SELECT
                pfs.site_id, pf.name, %s
            FROM
                photos_format as pf INNER JOIN photos_format_sites as pfs ON (pfs.format_id = pf.id)
            """
            % (", ".join(FORMAT_FIELDS), ", ".join(map(lambda f: "pf." + f, FORMAT_FIELDS)))
        )

        # DELETE formats with no site
        db.execute("DELETE FROM photos_format WHERE site_id IS NULL")
开发者ID:rajeev,项目名称:ella,代码行数:31,代码来源:0007_migrate_sites_to_m2m.py


示例17: forwards

    def forwards(self, orm):
        
        # Adding field 'User.last_login'
        db.add_column('tomato_user', 'last_login', self.gf('django.db.models.fields.FloatField')(default=1352370115.345284), keep_default=False)

        # Changing field 'User.password_time'
        db.execute("ALTER TABLE tomato_user ALTER password_time TYPE float USING 0.0;")
开发者ID:plaljx,项目名称:ProViNet,代码行数:7,代码来源:0005_auto__add_field_user_last_login__chg_field_user_password_time.py


示例18: forwards

 def forwards(self, orm):
     "Write your forwards methods here."
     sql="drop function  contact_update_message() cascade;"
     try:
         db.execute(sql)
     except DatabaseError:
         transaction.rollback()
开发者ID:JamesMura,项目名称:rapidsms-ureport,代码行数:7,代码来源:0022_remove_conflicting_functions.py


示例19: backwards

 def backwards(self, orm):
     "Write your backwards methods here."
     if db.backend_name == 'mysql':
         table_name = orm['askbot.Thread']._meta.db_table
         if mysql_table_supports_full_text_search(table_name):
             sql = get_drop_index_sql(INDEX_NAME, table_name)
             db.execute(sql)
开发者ID:AndurilLi,项目名称:askbot-devel,代码行数:7,代码来源:0158_add_title_search_indices_for_postgresql_and_mysql.py


示例20: forwards

    def forwards(self, orm):
        "Create archived contacts and associate them to contact records."
        db.execute(CREATE_CONTACTS)
        db.execute(LINK_CONTACTS)

        "Deleting field 'ContactRecord.contact_name'"
        db.delete_column(u'mypartners_contactrecord', 'contact_name')
开发者ID:zeus911,项目名称:MyJobs,代码行数:7,代码来源:0013_link_contact_to_contactrecord.py



注:本文中的south.db.db.execute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.execute_deferred_sql函数代码示例发布时间:2022-05-27
下一篇:
Python db.drop_primary_key函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap