当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseManager.to_sql方法代码示例

本文整理汇总了Python中trac.db.api.DatabaseManager.to_sql方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.to_sql方法的具体用法?Python DatabaseManager.to_sql怎么用?Python DatabaseManager.to_sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.db.api.DatabaseManager的用法示例。


在下文中一共展示了DatabaseManager.to_sql方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_upgrade

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, ver, cursor):
    """Add two more subscription db tables for a better normalized schema."""

    connector = DatabaseManager(env).get_connector()[0]
    for table in schema:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)
开发者ID:aroth-arsoft,项目名称:trac-announcer,代码行数:9,代码来源:db3.py

示例2: do_upgrade

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, ver, cursor):
    """Add an auto-increment primary key to `node_change` table and indices
    (repos, rev, path) and (repos, path, rev) (#3676).
    """
    db_connector, _ = DatabaseManager(env)._get_connector()
    table = Table('node_change', key='id')[
        Column('id', auto_increment=True),
        Column('repos', type='int'),
        Column('rev', key_size=40),
        Column('path', key_size=255),
        Column('node_type', size=1),
        Column('change_type', size=1),
        Column('base_path'),
        Column('base_rev'),
        Index(['repos', 'rev', 'path']),
        Index(['repos', 'path', 'rev'])]

    with env.db_transaction:
        cursor.execute("""CREATE TEMPORARY TABLE node_change_old AS
                          SELECT * FROM node_change""")
        cursor.execute("DROP TABLE node_change")

        for stmt in db_connector.to_sql(table):
            cursor.execute(stmt)

        cursor.execute("""\
            INSERT INTO node_change
            (repos,rev,path,node_type,change_type,base_path,base_rev)
            SELECT repos,rev,path,node_type,change_type,base_path,base_rev
            FROM node_change_old""")
        cursor.execute("DROP TABLE node_change_old")
开发者ID:pkdevbox,项目名称:trac,代码行数:33,代码来源:db38.py

示例3: do_upgrade

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, ver, cursor):
    """Change `subscription_attribute` db table:

    + 'subscription_attribute.authenticated'
    """
    cursor.execute("""
        CREATE TEMPORARY TABLE subscription_attribute_old
            AS SELECT * FROM subscription_attribute
    """)
    cursor.execute("DROP TABLE subscription_attribute")

    connector = DatabaseManager(env).get_connector()[0]
    for table in schema:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)
    cursor.execute("""
        INSERT INTO subscription_attribute
               (sid,authenticated,class,realm,target)
        SELECT o.sid,s.authenticated,o.class,o.realm,o.target
          FROM subscription_attribute_old AS o
          LEFT JOIN session AS s
               ON o.sid=s.sid
    """)
    cursor.execute("DROP TABLE subscription_attribute_old")

    # DEVEL: Think that an old 'subscriptions' db table may still exist here.
    cursor.execute("DROP TABLE IF EXISTS subscriptions")
开发者ID:aroth-arsoft,项目名称:trac-announcer,代码行数:29,代码来源:db5.py

示例4: upgrade_environment

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def upgrade_environment(self, db):
     db_connector, _ = DatabaseManager(self.env).get_connector() 
     cursor = db.cursor()
     dbver = self.get_db_version()
     if dbver == 0:
         self.env.log.info("Initialize %s database schema to version %s",
                      PLUGIN_NAME, PLUGIN_VERSION)
         for table in SCHEMA:
             for stmt in db_connector.to_sql(table):
                 cursor.execute(stmt)
         cursor.execute("""
             INSERT INTO system (name, value)
             VALUES (%s, %s)
             """, (PLUGIN_NAME, PLUGIN_VERSION))
     else:
         while dbver != PLUGIN_VERSION:
             dbver = dbver + 1
             self.env.log.info("Upgrade %s database schema to version %s",
                      PLUGIN_NAME, dbver)
             modulename = 'db%i' % dbver
             upgrades = __import__('cards.upgrades', globals(), locals(), [modulename])
             script = getattr(upgrades, modulename)
             script.do_upgrade(self.env, dbver, cursor)
         cursor.execute("""
             UPDATE system
             SET value=%s
             WHERE name=%s
             """, (PLUGIN_VERSION, PLUGIN_NAME))
开发者ID:folpindo,项目名称:psuter-cards-plugin,代码行数:30,代码来源:core.py

示例5: upgrade_environment

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def upgrade_environment(self, db):
     self.log.debug("Upgrading schema for svnhooks plugin")
     db_backend, _ = DatabaseManager(self.env).get_connector()
     cursor = db.cursor()
     for table in SVNHooksModel.svnhooks_schema:
         for stmt in db_backend.to_sql(table):
             self.log.debug(stmt)
             cursor.execute(stmt)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-svnhooks,代码行数:10,代码来源:api.py

示例6: environment_created

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def environment_created(self):
     db_connector, _ = DatabaseManager(self.env).get_connector()
     with self.env.db_transaction as db:
         cursor = db.cursor()
         for table in SCHEMA:
             for stmt in db_connector.to_sql(table): 
                 cursor.execute(stmt) 
         cursor.execute(""" 
             INSERT INTO system (name, value) 
             VALUES (%s, %s) 
             """, (PLUGIN_NAME, PLUGIN_VERSION)) 
开发者ID:folpindo,项目名称:psuter-cards-plugin,代码行数:13,代码来源:core.py

示例7: create_table

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def create_table(env):
    '''
    Constructor, see trac/db/postgres_backend.py:95 (method init_db)
    '''
    conn, dummyArgs = DatabaseManager(env).get_connector()
    db = env.get_read_db()
    cursor = db.cursor()

    for stmt in conn.to_sql(XMAIL_TABLE):
        if db.schema:
            stmt = re.sub(r'CREATE TABLE ','CREATE TABLE "' 
                          + db.schema + '".', stmt) 
        env.log.info( "result of execution: %s" % cursor.execute(stmt) )
    db.commit()
    db.close()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:17,代码来源:XMailFilterObject.py

示例8: upgrade_environment

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def upgrade_environment(self, db):
     self.log.debug("Upgrading schema for disclaimer plugin")
     db_backend, _ = DatabaseManager(self.env).get_connector()
     cursor = db.cursor()
     for table in DisclaimerModel.disclaimer_schema:
         for stmt in db_backend.to_sql(table):
             self.log.debug(stmt)
             cursor.execute(stmt)
     cursor.execute("select count(*) from disclaimer")
     entries = cursor.fetchone()[0]
     if entries == 0:
         DisclaimerModel(self.env).insert(self.c_name,
                                          self.c_text,
                                          'system',
                                          db=db)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-disclaimer,代码行数:17,代码来源:web_ui.py

示例9: do_upgrade

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, ver, cursor):
    """Migrate old `subscriptions` db table.

    Changes to other tables:
    'subscription.priority' type=(default == char) --> 'int'
    'subscription_attribute.name --> 'subscription_attribute.realm'
    'subscription_attribute.value --> 'subscription_attribute.target'
    """
    with env.db_transaction as db:
        cursor = db.cursor()
        cursor.execute("""
            CREATE TEMPORARY TABLE subscription_old
                AS SELECT * FROM subscription
        """)
        cursor.execute("DROP TABLE subscription")
        cursor.execute("""
            CREATE TEMPORARY TABLE subscription_attribute_old
                AS SELECT * FROM subscription_attribute
        """)
        cursor.execute("DROP TABLE subscription_attribute")

        connector = DatabaseManager(env).get_connector()[0]
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        # Convert priority values to integer.
        cursor.execute("""
            INSERT INTO subscription
                   (time,changetime,class,sid,authenticated,
                    distributor,format,priority,adverb)
            SELECT o.time,o.changetime,o.class,o.sid,o.authenticated,
                   o.distributor,o.format,%s,o.adverb
              FROM subscription_old AS o
            """ % db.cast('o.priority', 'int'))
        cursor.execute("DROP TABLE subscription_old")

        # Copy table on column name change.
        cursor.execute("""
            INSERT INTO subscription_attribute
                   (sid,class,realm,target)
            SELECT o.sid,o.class,o.name,o.value
              FROM subscription_attribute_old AS o
        """)
        cursor.execute("DROP TABLE subscription_attribute_old")

        # DEVEL: Migrate old subscription db table data.
        cursor.execute("DROP TABLE IF EXISTS subscriptions")
开发者ID:aroth-arsoft,项目名称:trac-announcer,代码行数:49,代码来源:db4.py

示例10: create_table

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def create_table(self):
     '''
     Constructor, see trac/postgres_backend.py:95 (method init_db)
     '''
     conn, dummyArgs = DatabaseManager(self.env).get_connector()
     try:
         with self.env.db_transaction as db:
             for stmt in conn.to_sql(BUDGETING_TABLE):
                 if db.schema:
                     stmt = re.sub(r'CREATE TABLE ', 'CREATE TABLE "'
                                   + db.schema + '".', stmt)
                 stmt = re.sub(r'(?i)bigint', 'NUMERIC(10,2)', stmt)
                 stmt += ";"
                 self.log.info("[INIT table] executing sql: %s" % stmt)
                 db(stmt)
                 self.log.info("[INIT table] successfully created table %s"
                                % BUDGETING_TABLE.name)
     except Exception, e:
         self.log.error("[INIT table] Error executing SQL Statement \n %s" % e)
开发者ID:lkraav,项目名称:trachacks,代码行数:21,代码来源:ticketbudgeting.py

示例11: to_sql

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
def to_sql(env, table):
    """ Convenience function to get the to_sql for the active connector."""
    dc = DatabaseManager(env)._get_connector()[0]
    return dc.to_sql(table)
开发者ID:Kras4ooo,项目名称:trac-code-comments-plugin,代码行数:6,代码来源:db.py

示例12: _create_table

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import to_sql [as 别名]
 def _create_table(self, cursor, table):
     db_manager, _ = DatabaseManager(self.env)._get_connector()
     for sql in db_manager.to_sql(table):
         cursor.execute(sql)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-vcsfavorite,代码行数:6,代码来源:model.py


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