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


Python _mysql.connection方法代码示例

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


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

示例1: defaulterrorhandler

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
    """

    If cursor is not None, (errorclass, errorvalue) is appended to
    cursor.messages; otherwise it is appended to
    connection.messages. Then errorclass is raised with errorvalue as
    the value.

    You can override this with your own error handler by assigning it
    to the instance.

    """
    error = errorclass, errorvalue
    if cursor:
        cursor.messages.append(error)
    else:
        connection.messages.append(error)
    del cursor
    del connection
    raise errorclass, errorvalue 
开发者ID:yelongyu,项目名称:chihu,代码行数:22,代码来源:connections.py

示例2: set_character_set

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def set_character_set(self, charset):
        """Set the connection character set to charset. The character
        set can only be changed in MySQL-4.1 and newer. If you try
        to change the character set from the current value in an
        older version, NotSupportedError will be raised."""
        if charset == "utf8mb4":
            py_charset = "utf8"
        else:
            py_charset = charset
        if self.character_set_name() != charset:
            try:
                super(Connection, self).set_character_set(charset)
            except AttributeError:
                if self._server_version < (4, 1):
                    raise NotSupportedError("server is too old to set charset")
                self.query('SET NAMES %s' % charset)
                self.store_result()
        self.string_decoder.charset = py_charset
        self.unicode_literal.charset = py_charset 
开发者ID:yelongyu,项目名称:chihu,代码行数:21,代码来源:connections.py

示例3: defaulterrorhandler

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
    """
    If cursor is not None, (errorclass, errorvalue) is appended to
    cursor.messages; otherwise it is appended to
    connection.messages. Then errorclass is raised with errorvalue as
    the value.

    You can override this with your own error handler by assigning it
    to the instance.
    """
    error = errorclass, errorvalue
    if cursor:
        cursor.messages.append(error)
    else:
        connection.messages.append(error)
    del cursor
    del connection
    if isinstance(errorvalue, BaseException):
        raise errorvalue
    if errorclass is not None:
        raise errorclass(errorvalue)
    else:
        raise Exception(errorvalue) 
开发者ID:Hexaflexagon,项目名称:gtao-python-module,代码行数:25,代码来源:connections.py

示例4: set_character_set

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def set_character_set(self, charset):
        """Set the connection character set to charset. The character
        set can only be changed in MySQL-4.1 and newer. If you try
        to change the character set from the current value in an
        older version, NotSupportedError will be raised."""
        if charset == "utf8mb4":
            py_charset = "utf8"
        else:
            py_charset = charset
        if self.character_set_name() != charset:
            try:
                super(Connection, self).set_character_set(charset)
            except AttributeError:
                if self._server_version < (4, 1):
                    raise NotSupportedError("server is too old to set charset")
                self.query('SET NAMES %s' % charset)
                self.store_result()
        self.string_decoder.charset = py_charset
        self.unicode_literal.charset = py_charset
        self.encoding = py_charset 
开发者ID:Hexaflexagon,项目名称:gtao-python-module,代码行数:22,代码来源:connections.py

示例5: autocommit

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def autocommit(self, on):
        on = bool(on)
        if self.get_autocommit() != on:
            _mysql.connection.autocommit(self, on) 
开发者ID:yelongyu,项目名称:chihu,代码行数:6,代码来源:connections.py

示例6: begin

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def begin(self):
        """Explicitly begin a connection. Non-standard.
        DEPRECATED: Will be removed in 1.3.
        Use an SQL BEGIN statement instead."""
        from warnings import warn
        warn("begin() is non-standard and will be removed in 1.3",
             DeprecationWarning, 2)
        self.query("BEGIN") 
开发者ID:yelongyu,项目名称:chihu,代码行数:10,代码来源:connections.py

示例7: set_sql_mode

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def set_sql_mode(self, sql_mode):
        """Set the connection sql_mode. See MySQL documentation for
        legal values."""
        if self._server_version < (4, 1):
            raise NotSupportedError("server is too old to set sql_mode")
        self.query("SET SESSION sql_mode='%s'" % sql_mode)
        self.store_result() 
开发者ID:yelongyu,项目名称:chihu,代码行数:9,代码来源:connections.py

示例8: set_character_set

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def set_character_set(self, charset):
        """Set the connection character set to charset. The character
        set can only be changed in MySQL-4.1 and newer. If you try
        to change the character set from the current value in an
        older version, NotSupportedError will be raised."""
        if self.character_set_name() != charset:
            try:
                super(Connection, self).set_character_set(charset)
            except AttributeError:
                if self._server_version < (4, 1):
                    raise NotSupportedError("server is too old to set charset")
                self.query('SET NAMES %s' % charset)
                self.store_result()
        self.string_decoder.charset = charset
        self.unicode_literal.charset = charset 
开发者ID:syjsu,项目名称:My-Web-Server-Framework-With-Python2.7,代码行数:17,代码来源:connections.py

示例9: query

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def query(self, query):
        # Since _mysql releases GIL while querying, we need immutable buffer.
        if isinstance(query, bytearray):
            query = bytes(query)
        if self.waiter is not None:
            self.send_query(query)
            self.waiter(self.fileno())
            self.read_query_result()
        else:
            _mysql.connection.query(self, query) 
开发者ID:Hexaflexagon,项目名称:gtao-python-module,代码行数:12,代码来源:connections.py

示例10: begin

# 需要导入模块: import _mysql [as 别名]
# 或者: from _mysql import connection [as 别名]
def begin(self):
        """Explicitly begin a connection. Non-standard.
        DEPRECATED: Will be removed in 1.3.
        Use an SQL BEGIN statement instead."""
        from warnings import warn
        warn("begin() is non-standard and will be removed in 1.4",
             DeprecationWarning, 2)
        self.query("BEGIN") 
开发者ID:Hexaflexagon,项目名称:gtao-python-module,代码行数:10,代码来源:connections.py


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