Path: blob/main/singlestoredb/mysql/__init__.py
469 views
"""1PyMySQL: A pure-Python MySQL client library.23Copyright (c) 2010-2016 PyMySQL contributors45Permission is hereby granted, free of charge, to any person obtaining a copy6of this software and associated documentation files (the "Software"), to deal7in the Software without restriction, including without limitation the rights8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9copies of the Software, and to permit persons to whom the Software is10furnished to do so, subject to the following conditions:1112The above copyright notice and this permission notice shall be included in13all copies or substantial portions of the Software.1415THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21THE SOFTWARE.22"""23import sys24from typing import Any25from typing import FrozenSet2627from .constants import FIELD_TYPE28from .err import DatabaseError29from .err import DataError30from .err import Error31from .err import IntegrityError32from .err import InterfaceError33from .err import InternalError34from .err import MySQLError35from .err import NotSupportedError36from .err import OperationalError37from .err import ProgrammingError38from .err import Warning39from .times import Date40from .times import DateFromTicks41from .times import Time42from .times import TimeFromTicks43from .times import Timestamp44from .times import TimestampFromTicks454647threadsafety = 148apilevel = '2.0'49paramstyle = 'pyformat'5051from . import connection # noqa: E402525354class DBAPISet(FrozenSet[Any]):5556def __ne__(self, other: Any) -> bool:57if isinstance(other, set):58return frozenset.__ne__(self, other)59else:60return other not in self6162def __eq__(self, other: Any) -> bool:63if isinstance(other, frozenset):64return frozenset.__eq__(self, other)65else:66return other in self6768def __hash__(self) -> int:69return frozenset.__hash__(self)707172STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING])73BINARY = DBAPISet(74[75FIELD_TYPE.BLOB,76FIELD_TYPE.LONG_BLOB,77FIELD_TYPE.MEDIUM_BLOB,78FIELD_TYPE.TINY_BLOB,79],80)81NUMBER = DBAPISet(82[83FIELD_TYPE.DECIMAL,84FIELD_TYPE.DOUBLE,85FIELD_TYPE.FLOAT,86FIELD_TYPE.INT24,87FIELD_TYPE.LONG,88FIELD_TYPE.LONGLONG,89FIELD_TYPE.TINY,90FIELD_TYPE.YEAR,91],92)93DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])94TIME = DBAPISet([FIELD_TYPE.TIME])95TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])96DATETIME = TIMESTAMP97ROWID = DBAPISet()9899100def Binary(x: Any) -> bytes:101"""Return x as a binary type."""102return bytes(x)103104105Connect = connect = Connection = connection.Connection # type: ignore106107108def get_client_info() -> str: # for MySQLdb compatibility109from .. import __version__110return __version__111112113# we include a doctored version_info here for MySQLdb compatibility114version_info = (1, 4, 0, 'final', 0)115116NULL = 'NULL'117118__version__ = get_client_info()119120121def thread_safe() -> bool:122return True # match MySQLdb.thread_safe()123124125def install_as_MySQLdb() -> None:126"""127After this function is called, any application that imports MySQLdb or128_mysql will unwittingly actually use pymysql.129"""130sys.modules['MySQLdb'] = sys.modules['_mysql'] = sys.modules['pymysql']131132133__all__ = [134'BINARY',135'Binary',136'Connect',137'Connection',138'DATE',139'Date',140'Time',141'Timestamp',142'DateFromTicks',143'TimeFromTicks',144'TimestampFromTicks',145'DataError',146'DatabaseError',147'Error',148'FIELD_TYPE',149'IntegrityError',150'InterfaceError',151'InternalError',152'MySQLError',153'NULL',154'NUMBER',155'NotSupportedError',156'DBAPISet',157'OperationalError',158'ProgrammingError',159'ROWID',160'STRING',161'TIME',162'TIMESTAMP',163'Warning',164'apilevel',165'connect',166'connection',167'constants',168'converters',169'cursors',170'get_client_info',171'paramstyle',172'threadsafety',173'version_info',174'install_as_MySQLdb',175'__version__',176]177178179