You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.2KB

  1. # mysql/cymysql.py
  2. # Copyright (C) 2005-2021 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: http://www.opensource.org/licenses/mit-license.php
  7. r"""
  8. .. dialect:: mysql+cymysql
  9. :name: CyMySQL
  10. :dbapi: cymysql
  11. :connectstring: mysql+cymysql://<username>:<password>@<host>/<dbname>[?<options>]
  12. :url: https://github.com/nakagami/CyMySQL
  13. .. note::
  14. The CyMySQL dialect is **not tested as part of SQLAlchemy's continuous
  15. integration** and may have unresolved issues. The recommended MySQL
  16. dialects are mysqlclient and PyMySQL.
  17. """ # noqa
  18. from .base import BIT
  19. from .base import MySQLDialect
  20. from .mysqldb import MySQLDialect_mysqldb
  21. from ... import util
  22. class _cymysqlBIT(BIT):
  23. def result_processor(self, dialect, coltype):
  24. """Convert MySQL's 64 bit, variable length binary string to a long."""
  25. def process(value):
  26. if value is not None:
  27. v = 0
  28. for i in util.iterbytes(value):
  29. v = v << 8 | i
  30. return v
  31. return value
  32. return process
  33. class MySQLDialect_cymysql(MySQLDialect_mysqldb):
  34. driver = "cymysql"
  35. supports_statement_cache = True
  36. description_encoding = None
  37. supports_sane_rowcount = True
  38. supports_sane_multi_rowcount = False
  39. supports_unicode_statements = True
  40. colspecs = util.update_copy(MySQLDialect.colspecs, {BIT: _cymysqlBIT})
  41. @classmethod
  42. def dbapi(cls):
  43. return __import__("cymysql")
  44. def _detect_charset(self, connection):
  45. return connection.connection.charset
  46. def _extract_error_code(self, exception):
  47. return exception.errno
  48. def is_disconnect(self, e, connection, cursor):
  49. if isinstance(e, self.dbapi.OperationalError):
  50. return self._extract_error_code(e) in (
  51. 2006,
  52. 2013,
  53. 2014,
  54. 2045,
  55. 2055,
  56. )
  57. elif isinstance(e, self.dbapi.InterfaceError):
  58. # if underlying connection is closed,
  59. # this is the error you get
  60. return True
  61. else:
  62. return False
  63. dialect = MySQLDialect_cymysql