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


Python DatabaseManager.get_connection方法代码示例

本文整理汇总了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()
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:37,代码来源:db.py

示例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()
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:32,代码来源:db.py

示例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
开发者ID:exocad,项目名称:exotrac,代码行数:11,代码来源:mysql_backend.py


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