本文整理匯總了Python中trac.db.api.DatabaseManager.get_connection方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseManager.get_connection方法的具體用法?Python DatabaseManager.get_connection怎麽用?Python DatabaseManager.get_connection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類trac.db.api.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_connection方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: trac_db_transaction
# 需要導入模塊: from trac.db.api import DatabaseManager [as 別名]
# 或者: from trac.db.api.DatabaseManager import get_connection [as 別名]
def trac_db_transaction(env):
"""
Context manager to handle database connection and cursor from trac environment's
read / write connection. This handles automatic commits, rollbacks and connection
closing.
Internally, this uses Trac's connection pool via the Trac DatabaseManager class.
This is because it would appear that to multiproject uses, Trac's with_transaction()
is not sufficient.
For examples of use, see db_transaction()
:param Environment env: The Trac Environment in use.
"""
conn = None
cursor = None
try:
dm = DatabaseManager(env)
conn = dm.get_connection()
except Exception:
env.log.exception("Failed to get database connection from trac database manager")
raise
try:
cursor = conn.cursor()
yield cursor
conn.commit()
except Exception:
env.log.error("Failed to perform transaction to database")
conn.rollback()
raise
finally:
cursor.close()
conn.close()
示例2: trac_db_query
# 需要導入模塊: from trac.db.api import DatabaseManager [as 別名]
# 或者: from trac.db.api.DatabaseManager import get_connection [as 別名]
def trac_db_query(env):
"""
Context manager to handle database connection and cursor from trac environment's
read only connection. This does not attempt to roll back or commit, the connection
is meant only for accessing the data. For examples on use, see db_query().
Internally, this uses Trac's connection pool via the Trac DatabaseManager class
:param Environment env: The Trac environment
"""
conn = None
cursor = None
try:
dm = DatabaseManager(env)
conn = dm.get_connection()
except Exception:
env.log.exception("Failed to get database connection from trac database manager")
raise
try:
# NOTE: Trac's connection does not support alternative cursor types!
cursor = conn.cursor()
yield cursor
except Exception:
env.log.error("Failed to query database")
raise
finally:
cursor.close()
conn.close()
示例3: _utf8_size
# 需要導入模塊: from trac.db.api import DatabaseManager [as 別名]
# 或者: from trac.db.api.DatabaseManager import get_connection [as 別名]
def _utf8_size(self, cnx):
if cnx is None:
connector, args = DatabaseManager(self.env).get_connector()
cnx = connector.get_connection(**args)
charset = cnx.charset
cnx.close()
else:
charset = cnx.charset
return 4 if charset == 'utf8mb4' else 3