singlestoredb 0.4.0__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of singlestoredb might be problematic. Click here for more details.

Files changed (120) hide show
  1. singlestoredb/__init__.py +33 -1
  2. singlestoredb/alchemy/__init__.py +90 -0
  3. singlestoredb/auth.py +5 -1
  4. singlestoredb/config.py +116 -14
  5. singlestoredb/connection.py +483 -516
  6. singlestoredb/converters.py +238 -135
  7. singlestoredb/exceptions.py +30 -2
  8. singlestoredb/functions/__init__.py +1 -0
  9. singlestoredb/functions/decorator.py +142 -0
  10. singlestoredb/functions/dtypes.py +1639 -0
  11. singlestoredb/functions/ext/__init__.py +2 -0
  12. singlestoredb/functions/ext/arrow.py +375 -0
  13. singlestoredb/functions/ext/asgi.py +661 -0
  14. singlestoredb/functions/ext/json.py +427 -0
  15. singlestoredb/functions/ext/mmap.py +306 -0
  16. singlestoredb/functions/ext/rowdat_1.py +744 -0
  17. singlestoredb/functions/signature.py +673 -0
  18. singlestoredb/fusion/__init__.py +11 -0
  19. singlestoredb/fusion/graphql.py +213 -0
  20. singlestoredb/fusion/handler.py +621 -0
  21. singlestoredb/fusion/handlers/stage.py +257 -0
  22. singlestoredb/fusion/handlers/utils.py +162 -0
  23. singlestoredb/fusion/handlers/workspace.py +412 -0
  24. singlestoredb/fusion/registry.py +164 -0
  25. singlestoredb/fusion/result.py +399 -0
  26. singlestoredb/http/__init__.py +27 -0
  27. singlestoredb/{http.py → http/connection.py} +555 -154
  28. singlestoredb/management/__init__.py +3 -0
  29. singlestoredb/management/billing_usage.py +148 -0
  30. singlestoredb/management/cluster.py +14 -6
  31. singlestoredb/management/manager.py +100 -38
  32. singlestoredb/management/organization.py +188 -0
  33. singlestoredb/management/region.py +5 -5
  34. singlestoredb/management/utils.py +281 -2
  35. singlestoredb/management/workspace.py +1344 -49
  36. singlestoredb/{clients/pymysqlsv → mysql}/__init__.py +16 -21
  37. singlestoredb/{clients/pymysqlsv → mysql}/_auth.py +39 -8
  38. singlestoredb/{clients/pymysqlsv → mysql}/charset.py +26 -23
  39. singlestoredb/{clients/pymysqlsv/connections.py → mysql/connection.py} +532 -165
  40. singlestoredb/{clients/pymysqlsv → mysql}/constants/CLIENT.py +0 -1
  41. singlestoredb/{clients/pymysqlsv → mysql}/constants/COMMAND.py +0 -1
  42. singlestoredb/{clients/pymysqlsv → mysql}/constants/CR.py +0 -2
  43. singlestoredb/{clients/pymysqlsv → mysql}/constants/ER.py +0 -1
  44. singlestoredb/{clients/pymysqlsv → mysql}/constants/FIELD_TYPE.py +1 -1
  45. singlestoredb/{clients/pymysqlsv → mysql}/constants/FLAG.py +0 -1
  46. singlestoredb/{clients/pymysqlsv → mysql}/constants/SERVER_STATUS.py +0 -1
  47. singlestoredb/mysql/converters.py +271 -0
  48. singlestoredb/{clients/pymysqlsv → mysql}/cursors.py +228 -112
  49. singlestoredb/mysql/err.py +92 -0
  50. singlestoredb/{clients/pymysqlsv → mysql}/optionfile.py +5 -4
  51. singlestoredb/{clients/pymysqlsv → mysql}/protocol.py +49 -20
  52. singlestoredb/mysql/tests/__init__.py +19 -0
  53. singlestoredb/{clients/pymysqlsv → mysql}/tests/base.py +32 -12
  54. singlestoredb/mysql/tests/conftest.py +37 -0
  55. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_DictCursor.py +11 -7
  56. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_SSCursor.py +17 -12
  57. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_basic.py +32 -24
  58. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_connection.py +130 -119
  59. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_converters.py +9 -7
  60. singlestoredb/mysql/tests/test_cursor.py +141 -0
  61. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_err.py +3 -2
  62. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_issues.py +35 -27
  63. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_load_local.py +13 -11
  64. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_nextset.py +7 -3
  65. singlestoredb/{clients/pymysqlsv → mysql}/tests/test_optionfile.py +2 -1
  66. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/__init__.py +1 -1
  67. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +9 -0
  68. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/test_MySQLdb/capabilities.py +19 -17
  69. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/test_MySQLdb/dbapi20.py +31 -22
  70. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +3 -4
  71. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +24 -20
  72. singlestoredb/{clients/pymysqlsv → mysql}/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +4 -4
  73. singlestoredb/{clients/pymysqlsv → mysql}/times.py +3 -4
  74. singlestoredb/pytest.py +283 -0
  75. singlestoredb/tests/empty.sql +0 -0
  76. singlestoredb/tests/ext_funcs/__init__.py +385 -0
  77. singlestoredb/tests/test.sql +210 -0
  78. singlestoredb/tests/test2.sql +1 -0
  79. singlestoredb/tests/test_basics.py +482 -115
  80. singlestoredb/tests/test_config.py +13 -13
  81. singlestoredb/tests/test_connection.py +241 -305
  82. singlestoredb/tests/test_dbapi.py +27 -0
  83. singlestoredb/tests/test_ext_func.py +1193 -0
  84. singlestoredb/tests/test_ext_func_data.py +1101 -0
  85. singlestoredb/tests/test_fusion.py +465 -0
  86. singlestoredb/tests/test_http.py +32 -26
  87. singlestoredb/tests/test_management.py +588 -8
  88. singlestoredb/tests/test_plugin.py +33 -0
  89. singlestoredb/tests/test_results.py +11 -12
  90. singlestoredb/tests/test_udf.py +687 -0
  91. singlestoredb/tests/utils.py +3 -2
  92. singlestoredb/utils/config.py +58 -0
  93. singlestoredb/utils/debug.py +13 -0
  94. singlestoredb/utils/mogrify.py +151 -0
  95. singlestoredb/utils/results.py +4 -1
  96. singlestoredb-1.0.4.dist-info/METADATA +139 -0
  97. singlestoredb-1.0.4.dist-info/RECORD +112 -0
  98. {singlestoredb-0.4.0.dist-info → singlestoredb-1.0.4.dist-info}/WHEEL +1 -1
  99. singlestoredb-1.0.4.dist-info/entry_points.txt +2 -0
  100. singlestoredb/clients/pymysqlsv/converters.py +0 -365
  101. singlestoredb/clients/pymysqlsv/err.py +0 -144
  102. singlestoredb/clients/pymysqlsv/tests/__init__.py +0 -19
  103. singlestoredb/clients/pymysqlsv/tests/test_cursor.py +0 -133
  104. singlestoredb/clients/pymysqlsv/tests/thirdparty/test_MySQLdb/__init__.py +0 -9
  105. singlestoredb/drivers/__init__.py +0 -45
  106. singlestoredb/drivers/base.py +0 -198
  107. singlestoredb/drivers/cymysql.py +0 -38
  108. singlestoredb/drivers/http.py +0 -47
  109. singlestoredb/drivers/mariadb.py +0 -40
  110. singlestoredb/drivers/mysqlconnector.py +0 -49
  111. singlestoredb/drivers/mysqldb.py +0 -60
  112. singlestoredb/drivers/pymysql.py +0 -37
  113. singlestoredb/drivers/pymysqlsv.py +0 -35
  114. singlestoredb/drivers/pyodbc.py +0 -65
  115. singlestoredb-0.4.0.dist-info/METADATA +0 -111
  116. singlestoredb-0.4.0.dist-info/RECORD +0 -86
  117. /singlestoredb/{clients → fusion/handlers}/__init__.py +0 -0
  118. /singlestoredb/{clients/pymysqlsv → mysql}/constants/__init__.py +0 -0
  119. {singlestoredb-0.4.0.dist-info → singlestoredb-1.0.4.dist-info}/LICENSE +0 -0
  120. {singlestoredb-0.4.0.dist-info → singlestoredb-1.0.4.dist-info}/top_level.txt +0 -0
@@ -1,365 +0,0 @@
1
- # type: ignore
2
- import datetime
3
- import re
4
- import time
5
- from decimal import Decimal
6
-
7
- from .constants import FIELD_TYPE
8
- from .err import ProgrammingError
9
-
10
-
11
- def escape_item(val, charset, mapping=None):
12
- if mapping is None:
13
- mapping = encoders
14
- encoder = mapping.get(type(val))
15
-
16
- # Fallback to default when no encoder found
17
- if not encoder:
18
- try:
19
- encoder = mapping[str]
20
- except KeyError:
21
- raise TypeError('no default type converter defined')
22
-
23
- if encoder in (escape_dict, escape_sequence):
24
- val = encoder(val, charset, mapping)
25
- else:
26
- val = encoder(val, mapping)
27
- return val
28
-
29
-
30
- def escape_dict(val, charset, mapping=None):
31
- n = {}
32
- for k, v in val.items():
33
- quoted = escape_item(v, charset, mapping)
34
- n[k] = quoted
35
- return n
36
-
37
-
38
- def escape_sequence(val, charset, mapping=None):
39
- n = []
40
- for item in val:
41
- quoted = escape_item(item, charset, mapping)
42
- n.append(quoted)
43
- return '(' + ','.join(n) + ')'
44
-
45
-
46
- def escape_set(val, charset, mapping=None):
47
- return ','.join([escape_item(x, charset, mapping) for x in val])
48
-
49
-
50
- def escape_bool(value, mapping=None):
51
- return str(int(value))
52
-
53
-
54
- def escape_int(value, mapping=None):
55
- return str(value)
56
-
57
-
58
- def escape_float(value, mapping=None):
59
- s = repr(value)
60
- if s in ('inf', 'nan'):
61
- raise ProgrammingError('%s can not be used with MySQL' % s)
62
- if 'e' not in s:
63
- s += 'e0'
64
- return s
65
-
66
-
67
- _escape_table = [chr(x) for x in range(128)]
68
- _escape_table[0] = '\\0'
69
- _escape_table[ord('\\')] = '\\\\'
70
- _escape_table[ord('\n')] = '\\n'
71
- _escape_table[ord('\r')] = '\\r'
72
- _escape_table[ord('\032')] = '\\Z'
73
- _escape_table[ord('"')] = '\\"'
74
- _escape_table[ord("'")] = "\\'"
75
-
76
-
77
- def escape_string(value, mapping=None):
78
- """escapes *value* without adding quote.
79
-
80
- Value should be unicode
81
- """
82
- return value.translate(_escape_table)
83
-
84
-
85
- def escape_bytes_prefixed(value, mapping=None):
86
- return "_binary'%s'" % value.decode('ascii', 'surrogateescape').translate(
87
- _escape_table,
88
- )
89
-
90
-
91
- def escape_bytes(value, mapping=None):
92
- return "'%s'" % value.decode('ascii', 'surrogateescape').translate(_escape_table)
93
-
94
-
95
- def escape_str(value, mapping=None):
96
- return "'%s'" % escape_string(str(value), mapping)
97
-
98
-
99
- def escape_None(value, mapping=None):
100
- return 'NULL'
101
-
102
-
103
- def escape_timedelta(obj, mapping=None):
104
- seconds = int(obj.seconds) % 60
105
- minutes = int(obj.seconds // 60) % 60
106
- hours = int(obj.seconds // 3600) % 24 + int(obj.days) * 24
107
- if obj.microseconds:
108
- fmt = "'{0:02d}:{1:02d}:{2:02d}.{3:06d}'"
109
- else:
110
- fmt = "'{0:02d}:{1:02d}:{2:02d}'"
111
- return fmt.format(hours, minutes, seconds, obj.microseconds)
112
-
113
-
114
- def escape_time(obj, mapping=None):
115
- if obj.microsecond:
116
- fmt = "'{0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
117
- else:
118
- fmt = "'{0.hour:02}:{0.minute:02}:{0.second:02}'"
119
- return fmt.format(obj)
120
-
121
-
122
- def escape_datetime(obj, mapping=None):
123
- if obj.microsecond:
124
- fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
125
- else:
126
- fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}'"
127
- return fmt.format(obj)
128
-
129
-
130
- def escape_date(obj, mapping=None):
131
- fmt = "'{0.year:04}-{0.month:02}-{0.day:02}'"
132
- return fmt.format(obj)
133
-
134
-
135
- def escape_struct_time(obj, mapping=None):
136
- return escape_datetime(datetime.datetime(*obj[:6]))
137
-
138
-
139
- def Decimal2Literal(o, d):
140
- return format(o, 'f')
141
-
142
-
143
- def _convert_second_fraction(s):
144
- if not s:
145
- return 0
146
- # Pad zeros to ensure the fraction length in microseconds
147
- s = s.ljust(6, '0')
148
- return int(s[:6])
149
-
150
-
151
- DATETIME_RE = re.compile(
152
- r'(\d{1,4})-(\d{1,2})-(\d{1,2})[T ](\d{1,2}):(\d{1,2}):(\d{1,2})(?:.(\d{1,6}))?',
153
- )
154
-
155
-
156
- def convert_datetime(obj):
157
- """Returns a DATETIME or TIMESTAMP column value as a datetime object:
158
-
159
- >>> convert_datetime('2007-02-25 23:06:20')
160
- datetime.datetime(2007, 2, 25, 23, 6, 20)
161
- >>> convert_datetime('2007-02-25T23:06:20')
162
- datetime.datetime(2007, 2, 25, 23, 6, 20)
163
-
164
- Illegal values are returned as str:
165
-
166
- >>> convert_datetime('2007-02-31T23:06:20')
167
- '2007-02-31T23:06:20'
168
- >>> convert_datetime('0000-00-00 00:00:00')
169
- '0000-00-00 00:00:00'
170
- """
171
- if isinstance(obj, (bytes, bytearray)):
172
- obj = obj.decode('ascii')
173
-
174
- m = DATETIME_RE.match(obj)
175
- if not m:
176
- return convert_date(obj)
177
-
178
- try:
179
- groups = list(m.groups())
180
- groups[-1] = _convert_second_fraction(groups[-1])
181
- return datetime.datetime(*[int(x) for x in groups])
182
- except ValueError:
183
- return convert_date(obj)
184
-
185
-
186
- TIMEDELTA_RE = re.compile(r'(-)?(\d{1,3}):(\d{1,2}):(\d{1,2})(?:.(\d{1,6}))?')
187
-
188
-
189
- def convert_timedelta(obj):
190
- """Returns a TIME column as a timedelta object:
191
-
192
- >>> convert_timedelta('25:06:17')
193
- datetime.timedelta(days=1, seconds=3977)
194
- >>> convert_timedelta('-25:06:17')
195
- datetime.timedelta(days=-2, seconds=82423)
196
-
197
- Illegal values are returned as string:
198
-
199
- >>> convert_timedelta('random crap')
200
- 'random crap'
201
-
202
- Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
203
- can accept values as (+|-)DD HH:MM:SS. The latter format will not
204
- be parsed correctly by this function.
205
- """
206
- if isinstance(obj, (bytes, bytearray)):
207
- obj = obj.decode('ascii')
208
-
209
- m = TIMEDELTA_RE.match(obj)
210
- if not m:
211
- return obj
212
-
213
- try:
214
- groups = list(m.groups())
215
- groups[-1] = _convert_second_fraction(groups[-1])
216
- negate = -1 if groups[0] else 1
217
- hours, minutes, seconds, microseconds = groups[1:]
218
-
219
- tdelta = (
220
- datetime.timedelta(
221
- hours=int(hours),
222
- minutes=int(minutes),
223
- seconds=int(seconds),
224
- microseconds=int(microseconds),
225
- )
226
- * negate
227
- )
228
- return tdelta
229
- except ValueError:
230
- return obj
231
-
232
-
233
- TIME_RE = re.compile(r'(\d{1,2}):(\d{1,2}):(\d{1,2})(?:.(\d{1,6}))?')
234
-
235
-
236
- def convert_time(obj):
237
- """Returns a TIME column as a time object:
238
-
239
- >>> convert_time('15:06:17')
240
- datetime.time(15, 6, 17)
241
-
242
- Illegal values are returned as str:
243
-
244
- >>> convert_time('-25:06:17')
245
- '-25:06:17'
246
- >>> convert_time('random crap')
247
- 'random crap'
248
-
249
- Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
250
- can accept values as (+|-)DD HH:MM:SS. The latter format will not
251
- be parsed correctly by this function.
252
-
253
- Also note that MySQL's TIME column corresponds more closely to
254
- Python's timedelta and not time. However if you want TIME columns
255
- to be treated as time-of-day and not a time offset, then you can
256
- use set this function as the converter for FIELD_TYPE.TIME.
257
- """
258
- if isinstance(obj, (bytes, bytearray)):
259
- obj = obj.decode('ascii')
260
-
261
- m = TIME_RE.match(obj)
262
- if not m:
263
- return obj
264
-
265
- try:
266
- groups = list(m.groups())
267
- groups[-1] = _convert_second_fraction(groups[-1])
268
- hours, minutes, seconds, microseconds = groups
269
- return datetime.time(
270
- hour=int(hours),
271
- minute=int(minutes),
272
- second=int(seconds),
273
- microsecond=int(microseconds),
274
- )
275
- except ValueError:
276
- return obj
277
-
278
-
279
- def convert_date(obj):
280
- """Returns a DATE column as a date object:
281
-
282
- >>> convert_date('2007-02-26')
283
- datetime.date(2007, 2, 26)
284
-
285
- Illegal values are returned as str:
286
-
287
- >>> convert_date('2007-02-31')
288
- '2007-02-31'
289
- >>> convert_date('0000-00-00')
290
- '0000-00-00'
291
- """
292
- if isinstance(obj, (bytes, bytearray)):
293
- obj = obj.decode('ascii')
294
- try:
295
- return datetime.date(*[int(x) for x in obj.split('-', 2)])
296
- except ValueError:
297
- return obj
298
-
299
-
300
- def through(x):
301
- return x
302
-
303
-
304
- # def convert_bit(b):
305
- # b = "\x00" * (8 - len(b)) + b # pad w/ zeroes
306
- # return struct.unpack(">Q", b)[0]
307
- #
308
- # the snippet above is right, but MySQLdb doesn't process bits,
309
- # so we shouldn't either
310
- convert_bit = through
311
-
312
-
313
- encoders = {
314
- bool: escape_bool,
315
- int: escape_int,
316
- float: escape_float,
317
- str: escape_str,
318
- bytes: escape_bytes,
319
- tuple: escape_sequence,
320
- list: escape_sequence,
321
- set: escape_sequence,
322
- frozenset: escape_sequence,
323
- dict: escape_dict,
324
- type(None): escape_None,
325
- datetime.date: escape_date,
326
- datetime.datetime: escape_datetime,
327
- datetime.timedelta: escape_timedelta,
328
- datetime.time: escape_time,
329
- time.struct_time: escape_struct_time,
330
- Decimal: Decimal2Literal,
331
- }
332
-
333
-
334
- decoders = {
335
- FIELD_TYPE.BIT: convert_bit,
336
- FIELD_TYPE.TINY: int,
337
- FIELD_TYPE.SHORT: int,
338
- FIELD_TYPE.LONG: int,
339
- FIELD_TYPE.FLOAT: float,
340
- FIELD_TYPE.DOUBLE: float,
341
- FIELD_TYPE.LONGLONG: int,
342
- FIELD_TYPE.INT24: int,
343
- FIELD_TYPE.YEAR: int,
344
- FIELD_TYPE.TIMESTAMP: convert_datetime,
345
- FIELD_TYPE.DATETIME: convert_datetime,
346
- FIELD_TYPE.TIME: convert_timedelta,
347
- FIELD_TYPE.DATE: convert_date,
348
- FIELD_TYPE.BLOB: through,
349
- FIELD_TYPE.TINY_BLOB: through,
350
- FIELD_TYPE.MEDIUM_BLOB: through,
351
- FIELD_TYPE.LONG_BLOB: through,
352
- FIELD_TYPE.STRING: through,
353
- FIELD_TYPE.VAR_STRING: through,
354
- FIELD_TYPE.VARCHAR: through,
355
- FIELD_TYPE.DECIMAL: Decimal,
356
- FIELD_TYPE.NEWDECIMAL: Decimal,
357
- }
358
-
359
-
360
- # for MySQLdb compatibility
361
- conversions = encoders.copy()
362
- conversions.update(decoders)
363
- Thing2Literal = escape_str
364
-
365
- # Run doctests with `pytest --doctest-modules pymysql/converters.py`
@@ -1,144 +0,0 @@
1
- # type: ignore
2
- import struct
3
-
4
- from .constants import ER
5
-
6
-
7
- class MySQLError(Exception):
8
- """Exception related to operation with MySQL."""
9
-
10
-
11
- class Warning(Warning, MySQLError):
12
- """Exception raised for important warnings like data truncations
13
- while inserting, etc."""
14
-
15
-
16
- class Error(MySQLError):
17
- """Exception that is the base class of all other error exceptions
18
- (not Warning)."""
19
-
20
-
21
- class InterfaceError(Error):
22
- """Exception raised for errors that are related to the database
23
- interface rather than the database itself."""
24
-
25
-
26
- class DatabaseError(Error):
27
- """Exception raised for errors that are related to the
28
- database."""
29
-
30
-
31
- class DataError(DatabaseError):
32
- """Exception raised for errors that are due to problems with the
33
- processed data like division by zero, numeric value out of range,
34
- etc."""
35
-
36
-
37
- class OperationalError(DatabaseError):
38
- """Exception raised for errors that are related to the database's
39
- operation and not necessarily under the control of the programmer,
40
- e.g. an unexpected disconnect occurs, the data source name is not
41
- found, a transaction could not be processed, a memory allocation
42
- error occurred during processing, etc."""
43
-
44
-
45
- class IntegrityError(DatabaseError):
46
- """Exception raised when the relational integrity of the database
47
- is affected, e.g. a foreign key check fails, duplicate key,
48
- etc."""
49
-
50
-
51
- class InternalError(DatabaseError):
52
- """Exception raised when the database encounters an internal
53
- error, e.g. the cursor is not valid anymore, the transaction is
54
- out of sync, etc."""
55
-
56
-
57
- class ProgrammingError(DatabaseError):
58
- """Exception raised for programming errors, e.g. table not found
59
- or already exists, syntax error in the SQL statement, wrong number
60
- of parameters specified, etc."""
61
-
62
-
63
- class NotSupportedError(DatabaseError):
64
- """Exception raised in case a method or database API was used
65
- which is not supported by the database, e.g. requesting a
66
- .rollback() on a connection that does not support transaction or
67
- has transactions turned off."""
68
-
69
-
70
- error_map = {}
71
-
72
-
73
- def _map_error(exc, *errors):
74
- for error in errors:
75
- error_map[error] = exc
76
-
77
-
78
- _map_error(
79
- ProgrammingError,
80
- ER.DB_CREATE_EXISTS,
81
- ER.SYNTAX_ERROR,
82
- ER.PARSE_ERROR,
83
- ER.NO_SUCH_TABLE,
84
- ER.WRONG_DB_NAME,
85
- ER.WRONG_TABLE_NAME,
86
- ER.FIELD_SPECIFIED_TWICE,
87
- ER.INVALID_GROUP_FUNC_USE,
88
- ER.UNSUPPORTED_EXTENSION,
89
- ER.TABLE_MUST_HAVE_COLUMNS,
90
- ER.CANT_DO_THIS_DURING_AN_TRANSACTION,
91
- ER.WRONG_DB_NAME,
92
- ER.WRONG_COLUMN_NAME,
93
- )
94
- _map_error(
95
- DataError,
96
- ER.WARN_DATA_TRUNCATED,
97
- ER.WARN_NULL_TO_NOTNULL,
98
- ER.WARN_DATA_OUT_OF_RANGE,
99
- ER.NO_DEFAULT,
100
- ER.PRIMARY_CANT_HAVE_NULL,
101
- ER.DATA_TOO_LONG,
102
- ER.DATETIME_FUNCTION_OVERFLOW,
103
- ER.TRUNCATED_WRONG_VALUE_FOR_FIELD,
104
- ER.ILLEGAL_VALUE_FOR_TYPE,
105
- )
106
- _map_error(
107
- IntegrityError,
108
- ER.DUP_ENTRY,
109
- ER.NO_REFERENCED_ROW,
110
- ER.NO_REFERENCED_ROW_2,
111
- ER.ROW_IS_REFERENCED,
112
- ER.ROW_IS_REFERENCED_2,
113
- ER.CANNOT_ADD_FOREIGN,
114
- ER.BAD_NULL_ERROR,
115
- )
116
- _map_error(
117
- NotSupportedError,
118
- ER.WARNING_NOT_COMPLETE_ROLLBACK,
119
- ER.NOT_SUPPORTED_YET,
120
- ER.FEATURE_DISABLED,
121
- ER.UNKNOWN_STORAGE_ENGINE,
122
- )
123
- _map_error(
124
- OperationalError,
125
- ER.DBACCESS_DENIED_ERROR,
126
- ER.ACCESS_DENIED_ERROR,
127
- ER.CON_COUNT_ERROR,
128
- ER.TABLEACCESS_DENIED_ERROR,
129
- ER.COLUMNACCESS_DENIED_ERROR,
130
- ER.CONSTRAINT_FAILED,
131
- ER.LOCK_DEADLOCK,
132
- )
133
-
134
-
135
- del _map_error, ER
136
-
137
-
138
- def raise_mysql_exception(data):
139
- errno = struct.unpack('<h', data[1:3])[0]
140
- errval = data[9:].decode('utf-8', 'replace')
141
- errorclass = error_map.get(errno)
142
- if errorclass is None:
143
- errorclass = InternalError if errno < 1000 else OperationalError
144
- raise errorclass(errno, errval)
@@ -1,19 +0,0 @@
1
- # type: ignore
2
- # Sorted by alphabetical order
3
- from singlestoredb.clients.pymysqlsv.tests.test_basic import *
4
- from singlestoredb.clients.pymysqlsv.tests.test_connection import *
5
- from singlestoredb.clients.pymysqlsv.tests.test_converters import *
6
- from singlestoredb.clients.pymysqlsv.tests.test_cursor import *
7
- from singlestoredb.clients.pymysqlsv.tests.test_DictCursor import *
8
- from singlestoredb.clients.pymysqlsv.tests.test_err import *
9
- from singlestoredb.clients.pymysqlsv.tests.test_issues import *
10
- from singlestoredb.clients.pymysqlsv.tests.test_load_local import *
11
- from singlestoredb.clients.pymysqlsv.tests.test_nextset import *
12
- from singlestoredb.clients.pymysqlsv.tests.test_optionfile import *
13
- from singlestoredb.clients.pymysqlsv.tests.test_SSCursor import *
14
- from singlestoredb.clients.pymysqlsv.tests.thirdparty import *
15
-
16
- if __name__ == '__main__':
17
- import unittest
18
-
19
- unittest.main()
@@ -1,133 +0,0 @@
1
- # type: ignore
2
- import warnings
3
-
4
- import singlestoredb.clients.pymysqlsv as sv
5
- import singlestoredb.clients.pymysqlsv.cursors as cursors
6
- from singlestoredb.clients.pymysqlsv.tests import base
7
-
8
-
9
- class CursorTest(base.PyMySQLTestCase):
10
- def setUp(self):
11
- super(CursorTest, self).setUp()
12
-
13
- conn = self.connect()
14
- self.safe_create_table(
15
- conn,
16
- 'test',
17
- 'create table test (data varchar(10))',
18
- )
19
- cursor = conn.cursor()
20
- cursor.execute(
21
- 'insert into test (data) values '
22
- "('row1'), ('row2'), ('row3'), ('row4'), ('row5')",
23
- )
24
- cursor.close()
25
- self.test_connection = sv.connect(**self.databases[0])
26
- self.addCleanup(self.test_connection.close)
27
-
28
- def test_cleanup_rows_unbuffered(self):
29
- conn = self.test_connection
30
- cursor = conn.cursor(cursors.SSCursor)
31
-
32
- cursor.execute('select * from test as t1, test as t2')
33
- for counter, row in enumerate(cursor):
34
- if counter > 10:
35
- break
36
-
37
- del cursor
38
-
39
- c2 = conn.cursor()
40
-
41
- c2.execute('select 1')
42
- self.assertEqual(c2.fetchone(), (1,))
43
- self.assertIsNone(c2.fetchone())
44
-
45
- def test_cleanup_rows_buffered(self):
46
- conn = self.test_connection
47
- cursor = conn.cursor(cursors.Cursor)
48
-
49
- cursor.execute('select * from test as t1, test as t2')
50
- for counter, row in enumerate(cursor):
51
- if counter > 10:
52
- break
53
-
54
- del cursor
55
-
56
- c2 = conn.cursor()
57
- c2.execute('select 1')
58
-
59
- self.assertEqual(c2.fetchone(), (1,))
60
- self.assertIsNone(c2.fetchone())
61
-
62
- def test_executemany(self):
63
- conn = self.test_connection
64
- cursor = conn.cursor(cursors.Cursor)
65
-
66
- m = cursors.RE_INSERT_VALUES.match(
67
- 'INSERT INTO TEST (ID, NAME) VALUES (%s, %s)',
68
- )
69
- self.assertIsNotNone(m, 'error parse %s')
70
- self.assertEqual(m.group(3), '', 'group 3 not blank, bug in RE_INSERT_VALUES?')
71
-
72
- m = cursors.RE_INSERT_VALUES.match(
73
- 'INSERT INTO TEST (ID, NAME) VALUES (%(id)s, %(name)s)',
74
- )
75
- self.assertIsNotNone(m, 'error parse %(name)s')
76
- self.assertEqual(m.group(3), '', 'group 3 not blank, bug in RE_INSERT_VALUES?')
77
-
78
- m = cursors.RE_INSERT_VALUES.match(
79
- 'INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s)',
80
- )
81
- self.assertIsNotNone(m, 'error parse %(id_name)s')
82
- self.assertEqual(m.group(3), '', 'group 3 not blank, bug in RE_INSERT_VALUES?')
83
-
84
- m = cursors.RE_INSERT_VALUES.match(
85
- 'INSERT INTO TEST (ID, NAME) VALUES (%(id_name)s, %(name)s) ON duplicate update',
86
- )
87
- self.assertIsNotNone(m, 'error parse %(id_name)s')
88
- self.assertEqual(
89
- m.group(3),
90
- ' ON duplicate update',
91
- 'group 3 not ON duplicate update, bug in RE_INSERT_VALUES?',
92
- )
93
-
94
- # https://github.com/PyMySQL/PyMySQL/pull/597
95
- m = cursors.RE_INSERT_VALUES.match(
96
- 'INSERT INTO bloup(foo, bar)VALUES(%s, %s)',
97
- )
98
- assert m is not None
99
-
100
- # cursor._executed must bee "insert into test (data) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)"
101
- # list args
102
- data = range(10)
103
- cursor.executemany('insert into test (data) values (%s)', data)
104
- self.assertTrue(
105
- cursor._executed.endswith(b',(7),(8),(9)'),
106
- 'execute many with %s not in one query',
107
- )
108
-
109
- # dict args
110
- data_dict = [{'data': i} for i in range(10)]
111
- cursor.executemany('insert into test (data) values (%(data)s)', data_dict)
112
- self.assertTrue(
113
- cursor._executed.endswith(b',(7),(8),(9)'),
114
- 'execute many with %(data)s not in one query',
115
- )
116
-
117
- # %% in column set
118
- cursor.execute(
119
- """\
120
- CREATE TABLE percent_test (
121
- `A%` INTEGER,
122
- `B%` INTEGER)""",
123
- )
124
- try:
125
- q = 'INSERT INTO percent_test (`A%%`, `B%%`) VALUES (%s, %s)'
126
- self.assertIsNotNone(cursors.RE_INSERT_VALUES.match(q))
127
- cursor.executemany(q, [(3, 4), (5, 6)])
128
- self.assertTrue(
129
- cursor._executed.endswith(b'(3, 4),(5, 6)'),
130
- 'executemany with %% not in one query',
131
- )
132
- finally:
133
- cursor.execute('DROP TABLE IF EXISTS percent_test')
@@ -1,9 +0,0 @@
1
- # type: ignore
2
- from .test_MySQLdb_capabilities import test_MySQLdb as test_capabilities
3
- from .test_MySQLdb_dbapi20 import test_MySQLdb as test_dbapi2
4
- from .test_MySQLdb_nonstandard import *
5
-
6
- if __name__ == '__main__':
7
- import unittest
8
-
9
- unittest.main()