本文整理汇总了Python中trac.db.DatabaseManager.get_connection方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.get_connection方法的具体用法?Python DatabaseManager.get_connection怎么用?Python DatabaseManager.get_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.db.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_connection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_db_table
# 需要导入模块: from trac.db import DatabaseManager [as 别名]
# 或者: from trac.db.DatabaseManager import get_connection [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))