Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/pymysql.py: 50%
38 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1# mysql/pymysql.py
2# Copyright (C) 2005-2022 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
8r"""
10.. dialect:: mysql+pymysql
11 :name: PyMySQL
12 :dbapi: pymysql
13 :connectstring: mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
14 :url: https://pymysql.readthedocs.io/
16Unicode
17-------
19Please see :ref:`mysql_unicode` for current recommendations on unicode
20handling.
22.. _pymysql_ssl:
24SSL Connections
25------------------
27The PyMySQL DBAPI accepts the same SSL arguments as that of MySQLdb,
28described at :ref:`mysqldb_ssl`. See that section for examples.
31MySQL-Python Compatibility
32--------------------------
34The pymysql DBAPI is a pure Python port of the MySQL-python (MySQLdb) driver,
35and targets 100% compatibility. Most behavioral notes for MySQL-python apply
36to the pymysql driver as well.
38""" # noqa
40from .mysqldb import MySQLDialect_mysqldb
41from ...util import langhelpers
42from ...util import py3k
45class MySQLDialect_pymysql(MySQLDialect_mysqldb):
46 driver = "pymysql"
47 supports_statement_cache = True
49 description_encoding = None
51 # generally, these two values should be both True
52 # or both False. PyMySQL unicode tests pass all the way back
53 # to 0.4 either way. See [ticket:3337]
54 supports_unicode_statements = True
55 supports_unicode_binds = True
57 @langhelpers.memoized_property
58 def supports_server_side_cursors(self):
59 try:
60 cursors = __import__("pymysql.cursors").cursors
61 self._sscursor = cursors.SSCursor
62 return True
63 except (ImportError, AttributeError):
64 return False
66 @classmethod
67 def dbapi(cls):
68 return __import__("pymysql")
70 def create_connect_args(self, url, _translate_args=None):
71 if _translate_args is None:
72 _translate_args = dict(username="user")
73 return super(MySQLDialect_pymysql, self).create_connect_args(
74 url, _translate_args=_translate_args
75 )
77 def is_disconnect(self, e, connection, cursor):
78 if super(MySQLDialect_pymysql, self).is_disconnect(
79 e, connection, cursor
80 ):
81 return True
82 elif isinstance(e, self.dbapi.Error):
83 str_e = str(e).lower()
84 return (
85 "already closed" in str_e or "connection was killed" in str_e
86 )
87 else:
88 return False
90 if py3k:
92 def _extract_error_code(self, exception):
93 if isinstance(exception.args[0], Exception):
94 exception = exception.args[0]
95 return exception.args[0]
98dialect = MySQLDialect_pymysql