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


Python DatabaseManager._get_connector方法代码示例

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


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

示例1: test_db_table

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
def test_db_table():
    # Create a EnvironmentStub
    env = EnvironmentStub()
    
    # Create a test table
    table = Table('test', key=['id'])[
        Column('id', type='integer'),
        Column(Key.NAME, type='text')
    ]
    # Get The Databse Manager
    dbm = DatabaseManager(env)
    # Get the Connector Object for the current DB schema
    connector, args = dbm._get_connector()
    # Ask the connector to generate the proper DDL for the table
    ddl_gen = connector.to_sql(table)
    # Get a DB Connection from the pool, create a cursor and the table
    conn = dbm.get_connection()
    try:
        cursor = conn.cursor()
        for statement in ddl_gen:
            print "Table: %s\n%s" % (table.name, statement)
            cursor.execute(statement)
        conn.commit()
        print "Successfully Created Table %s" % table.name
    except Exception, e:
        conn.rollback()
        print "[ERROR]: Unable to Create Table %s, an error occurred: %s" % \
                      (table.name, str(e))
开发者ID:djangsters,项目名称:agilo,代码行数:30,代码来源:breaking_env.py

示例2: create_table

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
def create_table(env, table, conn=None):
    """
    Creates a the given table in the given environment. The Table
    has to be of type trac.db.Table, and the Environment a 
    trac.env.Environment.
    """
    assert isinstance(env, Environment), \
        "[DB]: env should be an instance of trac.env.Environment, got %s" % type(env)
    assert isinstance(table, Table), \
        "[DB]: table should be an instance of trac.sb.Table, got %s" % type(table)
    # Get The Databse Manager
    dbm = DatabaseManager(env)
    # Get the Connector Object for the current DB schema
    connector, args = dbm._get_connector()
    # Ask the connector to generate the proper DDL for the table
    ddl_gen = connector.to_sql(table)
    # Get a DB Connection from the pool, create a cursor and the table
    conn, handle_ta = get_db_for_write(env, conn)
    try:
        cursor = conn.cursor()
        for statement in ddl_gen:
            debug(env, "[DB]: Table: %s\n%s" % (table.name, statement))
            cursor.execute(statement)
        if handle_ta:
            conn.commit()
        debug(env, "[DB]: Successfully Created Table %s" % table.name)
    except Exception, e:
        if handle_ta:
            conn.rollback()
        error(env, "[DB]: Unable to Create Table %s, an error occurred: %s" % \
                    (table.name, exception_to_unicode(e)))
        raise
开发者ID:djangsters,项目名称:agilo,代码行数:34,代码来源:db.py

示例3: _upgrade_db

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
    def _upgrade_db(self, db):
        """Each schema version should have its own upgrade module, named
        upgrades/dbN.py, where 'N' is the version number (int).
        """
        db_mgr = DatabaseManager(self.env)
        schema_ver = db_default.get_current_schema_version(db)

        cursor = db.cursor()
        # Is this a new installation?
        if not schema_ver:
            # Perform a single-step install: Create plugin schema and
            # insert default data into the database.
            connector = db_mgr._get_connector()[0]
            for table in db_default.schema:
                for stmt in connector.to_sql(table):
                    cursor.execute(stmt)
            for table, cols, vals in db_default.get_data(db):
                cursor.executemany("INSERT INTO %s (%s) VALUES (%s)" % (table,
                                   ','.join(cols),
                                   ','.join(['%s' for c in cols])), vals)
        else:
            # Perform incremental upgrades.
            for i in range(schema_ver + 1, db_default.schema_version + 1):
                (upgrades_module,_) = __name__.split('.',1)
                upgrades_module += '.upgrades'
                name  = 'db%i' % i
                try:
                    upgrades = __import__(upgrades_module, globals(),
                                          locals(), [name])
                    script = getattr(upgrades, name)
                except (AttributeError, ImportError) as e:
                    self.log.info("No upgrade module for version %(num)i (%(version)s.py) in %(module)s" % { 'num':i, 'version':name, 'module':upgrades_module})
                    script = None
                if script:
                    script.do_upgrade(self.env, i, cursor)
        cursor.execute("""
            UPDATE system
               SET value=%i
             WHERE name='%s'
            """ % (db_default.schema_version, db_default.name + '_version'))
        self.log.info("Upgraded %s db schema from version %d to %d"
                      % (db_default.name, schema_ver, db_default.schema_version))
        db.commit()

        custom = self.config['ticket-custom']
        config_dirty = False
        if 'linked_crash' not in custom:
            custom.set('linked_crash', 'text')
            custom.set('linked_crash.label', 'Linked crash')
            config_dirty = True
        if config_dirty:
            self.config.save()
开发者ID:aroth-arsoft,项目名称:trac-crashdump,代码行数:54,代码来源:api.py

示例4: get_db_type

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
def get_db_type(env):
    """Returns the DB type for the given trac Environment"""
    assert isinstance(env, Environment), \
        "env should be an instance of trac.Environment, got %s" % str(env)
    # Get The Databse Manager
    dbm = DatabaseManager(env)
    # Get the Connector Object for the current DB schema
    connector, args = dbm._get_connector()
    
    # Since trac r8582 get_supported_schemes is now a generator so we need to 
    # unroll it first (also to stay compatible with trac < 0.11.6)
    supported_schemes = [i for i in connector.get_supported_schemes()]
    db_type, trans = supported_schemes[0]
    return db_type
开发者ID:djangsters,项目名称:agilo,代码行数:16,代码来源:db.py

示例5: upgrade_environment

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
    def upgrade_environment(self, db):
        """Each schema version should have its own upgrade module, named
        upgrades/dbN.py, where 'N' is the version number (int).
        """
        db_mgr = DatabaseManager(self.env)
        schema_ver = self.get_schema_version(db)

        cursor = db.cursor()
        # Is this a new installation?
        if not schema_ver:
            # Perform a single-step install: Create plugin schema and
            # insert default data into the database.
            connector = db_mgr._get_connector()[0]
            for table in self.schema:
                for stmt in connector.to_sql(table):
                    self.env.log.debug(stmt)
                    cursor.execute(stmt)
            for table, cols, vals in self.db_data:
                cursor.executemany("INSERT INTO %s (%s) VALUES (%s)"
                                   % (table, ','.join(cols),
                                      ','.join(['%s' for c in cols])), vals)
        elif schema_ver < self.schema_version:
            # Perform incremental upgrades.
            for i in range(schema_ver + 1, self.schema_version + 1):
                name  = 'db%i' % i
                try:
                    upgrades = __import__('tracvote.upgrades', globals(),
                                          locals(), [name])
                    script = getattr(upgrades, name)
                except AttributeError:
                    raise TracError("No upgrade module for version "
                                    "%(num)i (%(version)s.py)",
                                    num=i, version=name)
                script.do_upgrade(self.env, i, cursor)
        else:
            # Obsolete call handled gracefully.
            return
        cursor.execute("""
            UPDATE system
               SET value=%s
             WHERE name='vote_version'
            """, (self.schema_version,))
        self.log.info("Upgraded VotePlugin db schema from version %d to %d"
                      % (schema_ver, self.schema_version))
        db.commit()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:47,代码来源:__init__.py

示例6: run_upgrade_scripts

# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import _get_connector [as 别名]
 def run_upgrade_scripts(self, cursor, current_db_version):
     dbm = DatabaseManager(self.env)
     connector, args = dbm._get_connector()
     upgrade_was_successful = True
     expected_db_version = self.get_expected_db_version()
     for i in xrange(current_db_version + 1, expected_db_version + 1):
         name  = 'db%i' % i
         filename = '%s.py' % name
         try:
             pkg_name = self.get_package_name()
             upgrades = __import__(pkg_name, globals(), locals(), [name])
             script = getattr(upgrades, name)
         except AttributeError:
             msg = _('No upgrade module for version %(num)i (%(filename)s)')
             raise TracError(msg, num=i, filename=filename)
         upgrade_was_successful = script.do_upgrade(self.env, i, cursor, connector)
         if not upgrade_was_successful:
             msg = _('Upgrade script %s did not complete successfully')
             self.env.log.error(msg % filename)
             break
     return upgrade_was_successful
开发者ID:djangsters,项目名称:agilo,代码行数:23,代码来源:plugin_env_setup.py


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