本文整理汇总了Python中trac.db.DatabaseManager.get_connector方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.get_connector方法的具体用法?Python DatabaseManager.get_connector怎么用?Python DatabaseManager.get_connector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.db.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_connector方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _upgrade_db
# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import get_connector [as 别名]
def _upgrade_db(self):
"""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()
with self.env.db_transaction as 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):
name = 'db%i' % i
try:
upgrades = __import__('announcer.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)
cursor.execute("""
UPDATE system
SET value=%s
WHERE name='announcer_version'
""", (db_default.schema_version,))
self.log.info("Upgraded TracAnnouncer db schema from version "
"%d to %d", schema_ver, db_default.schema_version)