Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/singlestoredb/mysql/__init__.py
469 views
1
"""
2
PyMySQL: A pure-Python MySQL client library.
3
4
Copyright (c) 2010-2016 PyMySQL contributors
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
THE SOFTWARE.
23
"""
24
import sys
25
from typing import Any
26
from typing import FrozenSet
27
28
from .constants import FIELD_TYPE
29
from .err import DatabaseError
30
from .err import DataError
31
from .err import Error
32
from .err import IntegrityError
33
from .err import InterfaceError
34
from .err import InternalError
35
from .err import MySQLError
36
from .err import NotSupportedError
37
from .err import OperationalError
38
from .err import ProgrammingError
39
from .err import Warning
40
from .times import Date
41
from .times import DateFromTicks
42
from .times import Time
43
from .times import TimeFromTicks
44
from .times import Timestamp
45
from .times import TimestampFromTicks
46
47
48
threadsafety = 1
49
apilevel = '2.0'
50
paramstyle = 'pyformat'
51
52
from . import connection # noqa: E402
53
54
55
class DBAPISet(FrozenSet[Any]):
56
57
def __ne__(self, other: Any) -> bool:
58
if isinstance(other, set):
59
return frozenset.__ne__(self, other)
60
else:
61
return other not in self
62
63
def __eq__(self, other: Any) -> bool:
64
if isinstance(other, frozenset):
65
return frozenset.__eq__(self, other)
66
else:
67
return other in self
68
69
def __hash__(self) -> int:
70
return frozenset.__hash__(self)
71
72
73
STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING])
74
BINARY = DBAPISet(
75
[
76
FIELD_TYPE.BLOB,
77
FIELD_TYPE.LONG_BLOB,
78
FIELD_TYPE.MEDIUM_BLOB,
79
FIELD_TYPE.TINY_BLOB,
80
],
81
)
82
NUMBER = DBAPISet(
83
[
84
FIELD_TYPE.DECIMAL,
85
FIELD_TYPE.DOUBLE,
86
FIELD_TYPE.FLOAT,
87
FIELD_TYPE.INT24,
88
FIELD_TYPE.LONG,
89
FIELD_TYPE.LONGLONG,
90
FIELD_TYPE.TINY,
91
FIELD_TYPE.YEAR,
92
],
93
)
94
DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])
95
TIME = DBAPISet([FIELD_TYPE.TIME])
96
TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
97
DATETIME = TIMESTAMP
98
ROWID = DBAPISet()
99
100
101
def Binary(x: Any) -> bytes:
102
"""Return x as a binary type."""
103
return bytes(x)
104
105
106
Connect = connect = Connection = connection.Connection # type: ignore
107
108
109
def get_client_info() -> str: # for MySQLdb compatibility
110
from .. import __version__
111
return __version__
112
113
114
# we include a doctored version_info here for MySQLdb compatibility
115
version_info = (1, 4, 0, 'final', 0)
116
117
NULL = 'NULL'
118
119
__version__ = get_client_info()
120
121
122
def thread_safe() -> bool:
123
return True # match MySQLdb.thread_safe()
124
125
126
def install_as_MySQLdb() -> None:
127
"""
128
After this function is called, any application that imports MySQLdb or
129
_mysql will unwittingly actually use pymysql.
130
"""
131
sys.modules['MySQLdb'] = sys.modules['_mysql'] = sys.modules['pymysql']
132
133
134
__all__ = [
135
'BINARY',
136
'Binary',
137
'Connect',
138
'Connection',
139
'DATE',
140
'Date',
141
'Time',
142
'Timestamp',
143
'DateFromTicks',
144
'TimeFromTicks',
145
'TimestampFromTicks',
146
'DataError',
147
'DatabaseError',
148
'Error',
149
'FIELD_TYPE',
150
'IntegrityError',
151
'InterfaceError',
152
'InternalError',
153
'MySQLError',
154
'NULL',
155
'NUMBER',
156
'NotSupportedError',
157
'DBAPISet',
158
'OperationalError',
159
'ProgrammingError',
160
'ROWID',
161
'STRING',
162
'TIME',
163
'TIMESTAMP',
164
'Warning',
165
'apilevel',
166
'connect',
167
'connection',
168
'constants',
169
'converters',
170
'cursors',
171
'get_client_info',
172
'paramstyle',
173
'threadsafety',
174
'version_info',
175
'install_as_MySQLdb',
176
'__version__',
177
]
178
179