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


Python DatabaseManager.to_sql方法代码示例

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


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

示例1: add_log_table

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def add_log_table(env, db):
    """Add a table for storing the builds logs."""
    from bitten.model import BuildLog, BuildStep
    cursor = db.cursor()

    connector, _ = DatabaseManager(env)._get_connector()
    for table in BuildLog._schema:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)

    cursor.execute("SELECT build,name,log FROM bitten_step "
                   "WHERE log IS NOT NULL")
    for build, step, log in cursor:
        build_log = BuildLog(env, build, step)
        build_log.messages = [(BuildLog.INFO, msg) for msg in log.splitlines()]
        build_log.insert(db)

    cursor.execute("CREATE TEMPORARY TABLE old_step AS SELECT * FROM bitten_step")
    cursor.execute("DROP TABLE bitten_step")
    for table in BuildStep._schema:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)
    cursor.execute("INSERT INTO bitten_step (build,name,description,status,"
                   "started,stopped) SELECT build,name,description,status,"
                   "started,stopped FROM old_step")
开发者ID:blaxter,项目名称:Bitten,代码行数:27,代码来源:upgrades.py

示例2: upgrade_environment

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
    def upgrade_environment(self, db):
        printout("Upgrading SimpleMultiProject database schema")
        cursor = db.cursor()

        db_installed_version = 0
        sqlGetInstalledVersion = """SELECT value FROM system WHERE name = %s"""
        cursor.execute(sqlGetInstalledVersion, [db_version_key])
        for row in cursor:
            db_installed_version = int(row[0])
        printout("SimpleMultiProject database schema version is %s, should be %s" %
                 (db_installed_version, db_version))

        db_connector, _ = DatabaseManager(self.env)._get_connector()

        if db_installed_version < 1:
            # Create tables
            for table in tables:
                for statement in db_connector.to_sql(table):
                    cursor.execute(statement)
                    
            sqlInsertVersion = """INSERT INTO system (name, value) VALUES (%s,%s)"""
            cursor.execute(sqlInsertVersion, [db_version_key, db_version])
            db_installed_version = 1
            
        if db_installed_version < 2:
            # Create tables
            for table in tables_v2:
                for statement in db_connector.to_sql(table):
                    cursor.execute(statement)
                    
            sqlInsertVersion = """UPDATE system SET value=%s WHERE name=%s"""
            cursor.execute(sqlInsertVersion, [db_version, db_version_key])
            db_installed_version = 2

        if db_installed_version < 3:
            # Create tables
            for table in tables_v3:
                for statement in db_connector.to_sql(table):
                    cursor.execute(statement)
                    
            sqlInsertVersion = """UPDATE system SET value=%s WHERE name=%s"""
            cursor.execute(sqlInsertVersion, [db_version, db_version_key])
            db_installed_version = 3

        if db_installed_version < 4:
            # Insert new column
            cursor.execute("""ALTER TABLE smp_project ADD summary varchar(255)""")
            
            sqlInsertVersion = """UPDATE system SET value=%s WHERE name=%s"""
            cursor.execute(sqlInsertVersion, [db_version, db_version_key])
            db_installed_version = 4
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:53,代码来源:environmentSetup.py

示例3: add_log_table

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def add_log_table(env, db):
    """Add a table for storing the builds logs."""
    INFO_LEVEL = 'I'

    cursor = db.cursor()

    build_log_schema_v3 = [
        Table('bitten_log', key='id')[
            Column('id', auto_increment=True), Column('build', type='int'),
            Column('step'), Column('type')
        ],
        Table('bitten_log_message', key=('log', 'line'))[
            Column('log', type='int'), Column('line', type='int'),
            Column('level', size=1), Column('message')
        ]
    ]

    build_step_schema_v3 = [
        Table('bitten_step', key=('build', 'name'))[
            Column('build', type='int'), Column('name'), Column('description'),
            Column('status', size=1), Column('started', type='int'),
            Column('stopped', type='int')
        ]
    ]

    connector, _ = DatabaseManager(env)._get_connector()
    for table in build_log_schema_v3:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)

    update_cursor = db.cursor()
    cursor.execute("SELECT build,name,log FROM bitten_step "
                   "WHERE log IS NOT NULL")
    for build, step, log in cursor:
        update_cursor.execute("INSERT INTO bitten_log (build, step) "
                "VALUES (%s,%s)", (build, step))
        log_id = db.get_last_id(update_cursor, 'bitten_log')
        messages = [(log_id, line, INFO_LEVEL, msg)
            for line, msg in enumerate(log.splitlines())]
        update_cursor.executemany("INSERT INTO bitten_log_message (log, line, level, message) "
            "VALUES (%s, %s, %s, %s)", messages)

    cursor.execute("CREATE TEMPORARY TABLE old_step AS SELECT * FROM bitten_step")
    cursor.execute("DROP TABLE bitten_step")
    for table in build_step_schema_v3:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)
    cursor.execute("INSERT INTO bitten_step (build,name,description,status,"
                   "started,stopped) SELECT build,name,description,status,"
                   "started,stopped FROM old_step")
开发者ID:hefloryd,项目名称:bitten,代码行数:52,代码来源:upgrades.py

示例4: do_upgrade

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.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:lkraav,项目名称:trachacks,代码行数:29,代码来源:db5.py

示例5: setUp

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'bitten.*'])
        self.env.path = tempfile.mkdtemp()

        # Create tables
        db = self.env.get_db_cnx()
        cursor = db.cursor()
        connector, _ = DatabaseManager(self.env)._get_connector()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)

        # Set up permissions
        self.env.config.set('trac', 'permission_store',
                            'DefaultPermissionStore')

        # Hook up a dummy repository
        self.repos = Mock(
            get_node=lambda path, rev=None: Mock(get_history=lambda: [],
                                                 isdir=True),
            normalize_path=lambda path: path,
            sync=lambda: None,
        )
        self.repos.authz = Mock(has_permission=lambda path: True, assert_permission=lambda path: None)
        self.env.get_repository = lambda authname=None: self.repos
开发者ID:blaxter,项目名称:Bitten,代码行数:27,代码来源:web_ui.py

示例6: upgrade_environment

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
 def upgrade_environment(self, db):
     if not type(self).__dict__.get('applySchema', False):
         self.log.debug("""Not updating schema for \"%s\",
                        since applySchema is not defined or is False.
                        """ % type(self).__name__)
         return
     installed = self.get_installed_version(db)
     if installed is None:
         self.log.info(
                 'Installing TracForm plugin schema %s' % db_version)
         db_connector, _ = DatabaseManager(self.env)._get_connector()
         db = self._get_db(db)
         cursor = db.cursor()
         for table in schema:
             for stmt in db_connector.to_sql(table):
                 cursor.execute(stmt)
             self.set_installed_version(db, db_version)
         self.log.info('Installation of %s successful.' % db_version)
         return
     self.log.debug(
         'Upgrading schema for "%s".' % type(self).__name__)
     for version, fn in self.get_schema_functions():
         if version > installed:
             self.log.info(
                 'Upgrading TracForm plugin schema to %s' % version)
             self.log.info('- %s: %s' % (fn.__name__, fn.__doc__))
             db = self._get_db(db)
             cursor = db.cursor()
             fn(self.env, cursor)
             self.set_installed_version(db, version)
             installed = version
             self.log.info('Upgrade to %s successful.' % version)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:tracdb.py

示例7: environment_created

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
    def environment_created(self):
        # Create the required tables
        db = self.env.get_db_cnx()
        connector, _ = DatabaseManager(self.env)._get_connector()
        cursor = db.cursor()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)

        # Insert a global version flag
        cursor.execute("INSERT INTO system (name,value) "
                       "VALUES ('tt_version',%s)", (schema_version,))

        # Create some default templates
        now = int(time.time())
        from default_templates import DEFAULT_TEMPLATES
        for tt_name, tt_value in DEFAULT_TEMPLATES:
            record = [
                now,
                SYSTEM_USER,
                tt_name,
                "description",
                tt_value,
                ]
            TT_Template.insert(self.env, record)
        
        db.commit()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:ttadmin.py

示例8: do_upgrade

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, ver, cursor):
    """Add new table for tag change records."""

    connector = DatabaseManager(env)._get_connector()[0]
    for table in schema:
        for stmt in connector.to_sql(table):
            cursor.execute(stmt)
开发者ID:t-kenji,项目名称:trac-tags-plugin,代码行数:9,代码来源:db4.py

示例9: setUp

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'bitten.notify.*',
                                           'bitten.tests.notify.*'])

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        connector, _ = DatabaseManager(self.env)._get_connector()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)
        db.commit()

        # Hook up a dummy repository
        self.repos = Mock(
                    get_changeset=lambda rev: Mock(author='author', rev=rev),
                    normalize_rev=lambda rev: rev)
        self.env.get_repository = lambda authname=None: self.repos # 0.11
        try: # 0.12+
            from trac.core import Component, implements
            from trac.versioncontrol.api import IRepositoryConnector, \
                                                IRepositoryProvider
            class DummyRepos(Component):
                implements(IRepositoryConnector, IRepositoryProvider)
                def get_supported_types(self):
                    yield ('dummy', 9)
                def get_repository(this, repos_type, repos_dir, params):
                    return self.repos # Note: 'this' vs 'self' usage
                def get_repositories(self):
                    yield ('', {'dir': 'dummy_dir', 'type': 'dummy'})
            self.dummy = DummyRepos
        except ImportError:
            self.dummy = None # not supported, will use get_repository()
开发者ID:hefloryd,项目名称:bitten,代码行数:34,代码来源:notify.py

示例10: setUp

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'bitten.*'])
        self.env.path = tempfile.mkdtemp()

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        connector, _ = DatabaseManager(self.env)._get_connector()
        for table in schema:
            for stmt in connector.to_sql(table):
                cursor.execute(stmt)

        self.config = BuildConfig(self.env, name='test', path='somepath')
        self.config.insert(db=db)
        self.platform = TargetPlatform(self.env, config='test', name='Foo')
        self.platform.insert(db=db)
        db.commit()

        # Hook up a dummy repository
        self.repos = Mock()
        self.env.get_repository = lambda authname=None: self.repos # 0.11
        try: # 0.12+
            from trac.core import Component, implements
            from trac.versioncontrol.api import IRepositoryConnector, \
                                                IRepositoryProvider
            class DummyRepos(Component):
                implements(IRepositoryConnector, IRepositoryProvider)
                def get_supported_types(self):
                    yield ('dummy', 9)
                def get_repository(this, repos_type, repos_dir, params):
                    return self.repos # Note: 'this' vs 'self' usage
                def get_repositories(self):
                    yield ('', {'dir': 'dummy_dir', 'type': 'dummy'})
            self.dummy = DummyRepos
        except ImportError:
            self.dummy = None # not supported, will use get_repository()
开发者ID:hefloryd,项目名称:bitten,代码行数:37,代码来源:queue.py

示例11: do_upgrade

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, cursor):
    db_connector, _ = DatabaseManager(env)._get_connector()

    # Backup old topic table
    cursor.execute("CREATE TEMPORARY TABLE topic_old AS "
                   "SELECT * "
                   "FROM topic")
    cursor.execute("DROP TABLE topic")

    # Create tables.
    for table in tables:
        for statement in db_connector.to_sql(table):
            cursor.execute(statement)

    # Add two columns that uses constraints.
    # TODO: No other way how to do it.
    cursor.execute("ALTER TABLE topic ADD COLUMN status INT DEFAULT 0 NOT NULL")
    cursor.execute("ALTER TABLE topic ADD COLUMN priority INT DEFAULT 0 NOT NULL")

    # Copy old topics.
    cursor.execute("INSERT INTO topic "
                   "(id, forum, time, author, subscribers, subject, body, "
                     "status, priority) "
                   "SELECT id, forum, time, author, subscribers, subject, "
                     "body, 0, 0 "
                   "FROM topic_old")
    cursor.execute("DROP TABLE topic_old")

    # Set database schema version.
    cursor.execute("UPDATE system "
                   "SET value = '5' "
                   "WHERE name = 'discussion_version'")
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:db5.py

示例12: do_upgrade

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def do_upgrade(env, cursor):
    db_connector, _ = DatabaseManager(env)._get_connector()

    # Backup old forum table.
    cursor.execute("CREATE TEMPORARY TABLE forum_old AS "
                   "SELECT * "
                   "FROM forum")
    cursor.execute("DROP TABLE forum")

    # Create tables.
    for table in tables:
        for statement in db_connector.to_sql(table):
            cursor.execute(statement)

    # Copy old forums.
    cursor.execute("INSERT INTO forum "
                   "(id, name, time, moderators, subject, description) "
                   "SELECT id, name, time, moderators, subject, description "
                   "FROM forum_old")
    cursor.execute("DROP TABLE forum_old")

    # Set database schema version.
    cursor.execute("UPDATE system "
                   "SET value = '2' "
                   "WHERE name = 'discussion_version'")
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:27,代码来源:db2.py

示例13: do_upgrade

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
def do_upgrade(env):
    """ Upgrade the database schema so that it is compatible with version 1 
    of the plugin. 

    :param env: the current Trac environment

    """
    db_connector, _ = DatabaseManager(env)._get_connector()
    db = env.get_db_cnx()
    cursor = db.cursor()

    # add 'ticket_split' table to the schema
    split_ticket_table = Table('ticket_split', key=('ticket', 'split_to'))[
                             Column('ticket', type='int'),
                             Column('split_to', type='int'),
                             Column('split_at', type='int')
                         ]

    for statement in db_connector.to_sql(split_ticket_table):
        cursor.execute(statement)
    
    # update stored schema version for the plugin
    sql = ("INSERT INTO system(name, value) "
           "VALUES ('splitticket_plugin_version', '1')")

    cursor.execute(sql)
开发者ID:trac-hacks,项目名称:trac-split-ticket,代码行数:28,代码来源:db1.py

示例14: upgrade_environment

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
 def upgrade_environment(self, db):
     self.log.debug("Upgrading schema for bi history plugin")
     
     cursor = db.cursor()
     db_connector, _ = DatabaseManager(self.env).get_connector()
     
     found_version = self._check_schema_version(db)
     if not found_version:
         # Create tables
         self.environment_created()
     elif found_version == 2:
         # We've not released anywhere yet, so this seems more practical 
         # than writing a database-agnostic way to convert the isclosed column
         cursor.execute("DROP table ticket_bi_historical")
         for table in self.schema:
             for statement in db_connector.to_sql(table):
                 cursor.execute(statement)
         cursor.execute("UPDATE system SET value = %s WHERE name = 'bi_history_schema'", 
                        (str(self._schema_version),))
     elif found_version == 3:
         cursor.execute("CREATE INDEX ticket_bi_historical_isclosed "
                        "ON ticket_bi_historical (isclosed)")
         cursor.execute("CREATE INDEX ticket_bi_historical_id "
                        "ON ticket_bi_historical (id)")
         cursor.execute("CREATE INDEX ticket_bi_historical_milestone "
                        "ON ticket_bi_historical (milestone)")
         cursor.execute("UPDATE system SET value = %s "
                        "WHERE name = 'bi_history_schema'", 
                        (str(self._schema_version),))
     elif found_version == 4:
         if self.env.config.get('trac', 'database').startswith('postgres'):
             cursor.execute("ALTER TABLE ticket_bi_historical ALTER COLUMN _snapshottime SET NOT NULL")            
         cursor.execute("UPDATE system SET value = %s "
                        "WHERE name = 'bi_history_schema'", 
                        (str(self._schema_version),))
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-kettle,代码行数:37,代码来源:history.py

示例15: _initialize_db

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import to_sql [as 别名]
 def _initialize_db(self, db):
     # pylint: disable=protected-access
     self.log.debug("creating initial db schema for %s.", PLUGIN_NAME)
     db_connector, dummy = DatabaseManager(self.env)._get_connector()
     for table in db_default.SCHEMA:
         for statement in db_connector.to_sql(table):
             db(statement)
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:9,代码来源:api.py


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