singlestoredb 1.16.1__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.
Files changed (183) hide show
  1. singlestoredb/__init__.py +75 -0
  2. singlestoredb/ai/__init__.py +2 -0
  3. singlestoredb/ai/chat.py +139 -0
  4. singlestoredb/ai/embeddings.py +128 -0
  5. singlestoredb/alchemy/__init__.py +90 -0
  6. singlestoredb/apps/__init__.py +3 -0
  7. singlestoredb/apps/_cloud_functions.py +90 -0
  8. singlestoredb/apps/_config.py +72 -0
  9. singlestoredb/apps/_connection_info.py +18 -0
  10. singlestoredb/apps/_dashboards.py +47 -0
  11. singlestoredb/apps/_process.py +32 -0
  12. singlestoredb/apps/_python_udfs.py +100 -0
  13. singlestoredb/apps/_stdout_supress.py +30 -0
  14. singlestoredb/apps/_uvicorn_util.py +36 -0
  15. singlestoredb/auth.py +245 -0
  16. singlestoredb/config.py +484 -0
  17. singlestoredb/connection.py +1487 -0
  18. singlestoredb/converters.py +950 -0
  19. singlestoredb/docstring/__init__.py +33 -0
  20. singlestoredb/docstring/attrdoc.py +126 -0
  21. singlestoredb/docstring/common.py +230 -0
  22. singlestoredb/docstring/epydoc.py +267 -0
  23. singlestoredb/docstring/google.py +412 -0
  24. singlestoredb/docstring/numpydoc.py +562 -0
  25. singlestoredb/docstring/parser.py +100 -0
  26. singlestoredb/docstring/py.typed +1 -0
  27. singlestoredb/docstring/rest.py +256 -0
  28. singlestoredb/docstring/tests/__init__.py +1 -0
  29. singlestoredb/docstring/tests/_pydoctor.py +21 -0
  30. singlestoredb/docstring/tests/test_epydoc.py +729 -0
  31. singlestoredb/docstring/tests/test_google.py +1007 -0
  32. singlestoredb/docstring/tests/test_numpydoc.py +1100 -0
  33. singlestoredb/docstring/tests/test_parse_from_object.py +109 -0
  34. singlestoredb/docstring/tests/test_parser.py +248 -0
  35. singlestoredb/docstring/tests/test_rest.py +547 -0
  36. singlestoredb/docstring/tests/test_util.py +70 -0
  37. singlestoredb/docstring/util.py +141 -0
  38. singlestoredb/exceptions.py +120 -0
  39. singlestoredb/functions/__init__.py +16 -0
  40. singlestoredb/functions/decorator.py +201 -0
  41. singlestoredb/functions/dtypes.py +1793 -0
  42. singlestoredb/functions/ext/__init__.py +1 -0
  43. singlestoredb/functions/ext/arrow.py +375 -0
  44. singlestoredb/functions/ext/asgi.py +2133 -0
  45. singlestoredb/functions/ext/json.py +420 -0
  46. singlestoredb/functions/ext/mmap.py +413 -0
  47. singlestoredb/functions/ext/rowdat_1.py +724 -0
  48. singlestoredb/functions/ext/timer.py +89 -0
  49. singlestoredb/functions/ext/utils.py +218 -0
  50. singlestoredb/functions/signature.py +1578 -0
  51. singlestoredb/functions/typing/__init__.py +41 -0
  52. singlestoredb/functions/typing/numpy.py +20 -0
  53. singlestoredb/functions/typing/pandas.py +2 -0
  54. singlestoredb/functions/typing/polars.py +2 -0
  55. singlestoredb/functions/typing/pyarrow.py +2 -0
  56. singlestoredb/functions/utils.py +421 -0
  57. singlestoredb/fusion/__init__.py +11 -0
  58. singlestoredb/fusion/graphql.py +213 -0
  59. singlestoredb/fusion/handler.py +916 -0
  60. singlestoredb/fusion/handlers/__init__.py +0 -0
  61. singlestoredb/fusion/handlers/export.py +525 -0
  62. singlestoredb/fusion/handlers/files.py +690 -0
  63. singlestoredb/fusion/handlers/job.py +660 -0
  64. singlestoredb/fusion/handlers/models.py +250 -0
  65. singlestoredb/fusion/handlers/stage.py +502 -0
  66. singlestoredb/fusion/handlers/utils.py +324 -0
  67. singlestoredb/fusion/handlers/workspace.py +956 -0
  68. singlestoredb/fusion/registry.py +249 -0
  69. singlestoredb/fusion/result.py +399 -0
  70. singlestoredb/http/__init__.py +27 -0
  71. singlestoredb/http/connection.py +1267 -0
  72. singlestoredb/magics/__init__.py +34 -0
  73. singlestoredb/magics/run_personal.py +137 -0
  74. singlestoredb/magics/run_shared.py +134 -0
  75. singlestoredb/management/__init__.py +9 -0
  76. singlestoredb/management/billing_usage.py +148 -0
  77. singlestoredb/management/cluster.py +462 -0
  78. singlestoredb/management/export.py +295 -0
  79. singlestoredb/management/files.py +1102 -0
  80. singlestoredb/management/inference_api.py +105 -0
  81. singlestoredb/management/job.py +887 -0
  82. singlestoredb/management/manager.py +373 -0
  83. singlestoredb/management/organization.py +226 -0
  84. singlestoredb/management/region.py +169 -0
  85. singlestoredb/management/utils.py +423 -0
  86. singlestoredb/management/workspace.py +1927 -0
  87. singlestoredb/mysql/__init__.py +177 -0
  88. singlestoredb/mysql/_auth.py +298 -0
  89. singlestoredb/mysql/charset.py +214 -0
  90. singlestoredb/mysql/connection.py +2032 -0
  91. singlestoredb/mysql/constants/CLIENT.py +38 -0
  92. singlestoredb/mysql/constants/COMMAND.py +32 -0
  93. singlestoredb/mysql/constants/CR.py +78 -0
  94. singlestoredb/mysql/constants/ER.py +474 -0
  95. singlestoredb/mysql/constants/EXTENDED_TYPE.py +3 -0
  96. singlestoredb/mysql/constants/FIELD_TYPE.py +48 -0
  97. singlestoredb/mysql/constants/FLAG.py +15 -0
  98. singlestoredb/mysql/constants/SERVER_STATUS.py +10 -0
  99. singlestoredb/mysql/constants/VECTOR_TYPE.py +6 -0
  100. singlestoredb/mysql/constants/__init__.py +0 -0
  101. singlestoredb/mysql/converters.py +271 -0
  102. singlestoredb/mysql/cursors.py +896 -0
  103. singlestoredb/mysql/err.py +92 -0
  104. singlestoredb/mysql/optionfile.py +20 -0
  105. singlestoredb/mysql/protocol.py +450 -0
  106. singlestoredb/mysql/tests/__init__.py +19 -0
  107. singlestoredb/mysql/tests/base.py +126 -0
  108. singlestoredb/mysql/tests/conftest.py +37 -0
  109. singlestoredb/mysql/tests/test_DictCursor.py +132 -0
  110. singlestoredb/mysql/tests/test_SSCursor.py +141 -0
  111. singlestoredb/mysql/tests/test_basic.py +452 -0
  112. singlestoredb/mysql/tests/test_connection.py +851 -0
  113. singlestoredb/mysql/tests/test_converters.py +58 -0
  114. singlestoredb/mysql/tests/test_cursor.py +141 -0
  115. singlestoredb/mysql/tests/test_err.py +16 -0
  116. singlestoredb/mysql/tests/test_issues.py +514 -0
  117. singlestoredb/mysql/tests/test_load_local.py +75 -0
  118. singlestoredb/mysql/tests/test_nextset.py +88 -0
  119. singlestoredb/mysql/tests/test_optionfile.py +27 -0
  120. singlestoredb/mysql/tests/thirdparty/__init__.py +6 -0
  121. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +9 -0
  122. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +323 -0
  123. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +865 -0
  124. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +110 -0
  125. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +224 -0
  126. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +101 -0
  127. singlestoredb/mysql/times.py +23 -0
  128. singlestoredb/notebook/__init__.py +16 -0
  129. singlestoredb/notebook/_objects.py +213 -0
  130. singlestoredb/notebook/_portal.py +352 -0
  131. singlestoredb/py.typed +0 -0
  132. singlestoredb/pytest.py +352 -0
  133. singlestoredb/server/__init__.py +0 -0
  134. singlestoredb/server/docker.py +452 -0
  135. singlestoredb/server/free_tier.py +267 -0
  136. singlestoredb/tests/__init__.py +0 -0
  137. singlestoredb/tests/alltypes.sql +307 -0
  138. singlestoredb/tests/alltypes_no_nulls.sql +208 -0
  139. singlestoredb/tests/empty.sql +0 -0
  140. singlestoredb/tests/ext_funcs/__init__.py +702 -0
  141. singlestoredb/tests/local_infile.csv +3 -0
  142. singlestoredb/tests/test.ipynb +18 -0
  143. singlestoredb/tests/test.sql +680 -0
  144. singlestoredb/tests/test2.ipynb +18 -0
  145. singlestoredb/tests/test2.sql +1 -0
  146. singlestoredb/tests/test_basics.py +1332 -0
  147. singlestoredb/tests/test_config.py +318 -0
  148. singlestoredb/tests/test_connection.py +3103 -0
  149. singlestoredb/tests/test_dbapi.py +27 -0
  150. singlestoredb/tests/test_exceptions.py +45 -0
  151. singlestoredb/tests/test_ext_func.py +1472 -0
  152. singlestoredb/tests/test_ext_func_data.py +1101 -0
  153. singlestoredb/tests/test_fusion.py +1527 -0
  154. singlestoredb/tests/test_http.py +288 -0
  155. singlestoredb/tests/test_management.py +1599 -0
  156. singlestoredb/tests/test_plugin.py +33 -0
  157. singlestoredb/tests/test_results.py +171 -0
  158. singlestoredb/tests/test_types.py +132 -0
  159. singlestoredb/tests/test_udf.py +737 -0
  160. singlestoredb/tests/test_udf_returns.py +459 -0
  161. singlestoredb/tests/test_vectorstore.py +51 -0
  162. singlestoredb/tests/test_xdict.py +333 -0
  163. singlestoredb/tests/utils.py +141 -0
  164. singlestoredb/types.py +373 -0
  165. singlestoredb/utils/__init__.py +0 -0
  166. singlestoredb/utils/config.py +950 -0
  167. singlestoredb/utils/convert_rows.py +69 -0
  168. singlestoredb/utils/debug.py +13 -0
  169. singlestoredb/utils/dtypes.py +205 -0
  170. singlestoredb/utils/events.py +65 -0
  171. singlestoredb/utils/mogrify.py +151 -0
  172. singlestoredb/utils/results.py +585 -0
  173. singlestoredb/utils/xdict.py +425 -0
  174. singlestoredb/vectorstore.py +192 -0
  175. singlestoredb/warnings.py +5 -0
  176. singlestoredb-1.16.1.dist-info/METADATA +165 -0
  177. singlestoredb-1.16.1.dist-info/RECORD +183 -0
  178. singlestoredb-1.16.1.dist-info/WHEEL +5 -0
  179. singlestoredb-1.16.1.dist-info/entry_points.txt +2 -0
  180. singlestoredb-1.16.1.dist-info/licenses/LICENSE +201 -0
  181. singlestoredb-1.16.1.dist-info/top_level.txt +3 -0
  182. sqlx/__init__.py +4 -0
  183. sqlx/magic.py +113 -0
@@ -0,0 +1,865 @@
1
+ # type: ignore
2
+ """ Python DB API 2.0 driver compliance unit test suite.
3
+
4
+ This software is Public Domain and may be used without restrictions.
5
+
6
+ "Now we have booze and barflies entering the discussion, plus rumours of
7
+ DBAs on drugs... and I won't tell you what flashes through my mind each
8
+ time I read the subject line with 'Anal Compliance' in it. All around
9
+ this is turning out to be a thoroughly unwholesome unit test."
10
+
11
+ -- Ian Bicking
12
+ """
13
+
14
+ __rcs_id__ = '$Id$'
15
+ __version__ = '$Revision$'[11:-2]
16
+ __author__ = 'Stuart Bishop <zen@shangri-la.dropbear.id.au>'
17
+
18
+ import time
19
+ import unittest
20
+
21
+ # $Log$
22
+ # Revision 1.1.2.1 2006/02/25 03:44:32 adustman
23
+ # Generic DB-API unit test module
24
+ #
25
+ # Revision 1.10 2003/10/09 03:14:14 zenzen
26
+ # Add test for DB API 2.0 optional extension, where database exceptions
27
+ # are exposed as attributes on the Connection object.
28
+ #
29
+ # Revision 1.9 2003/08/13 01:16:36 zenzen
30
+ # Minor tweak from Stefan Fleiter
31
+ #
32
+ # Revision 1.8 2003/04/10 00:13:25 zenzen
33
+ # Changes, as per suggestions by M.-A. Lemburg
34
+ # - Add a table prefix, to ensure namespace collisions can always be avoided
35
+ #
36
+ # Revision 1.7 2003/02/26 23:33:37 zenzen
37
+ # Break out DDL into helper functions, as per request by David Rushby
38
+ #
39
+ # Revision 1.6 2003/02/21 03:04:33 zenzen
40
+ # Stuff from Henrik Ekelund:
41
+ # added test_None
42
+ # added test_nextset & hooks
43
+ #
44
+ # Revision 1.5 2003/02/17 22:08:43 zenzen
45
+ # Implement suggestions and code from Henrik Eklund - test that cursor.arraysize
46
+ # defaults to 1 & generic cursor.callproc test added
47
+ #
48
+ # Revision 1.4 2003/02/15 00:16:33 zenzen
49
+ # Changes, as per suggestions and bug reports by M.-A. Lemburg,
50
+ # Matthew T. Kromer, Federico Di Gregorio and Daniel Dittmar
51
+ # - Class renamed
52
+ # - Now a subclass of TestCase, to avoid requiring the driver stub
53
+ # to use multiple inheritance
54
+ # - Reversed the polarity of buggy test in test_description
55
+ # - Test exception heirarchy correctly
56
+ # - self.populate is now self._populate(), so if a driver stub
57
+ # overrides self.ddl1 this change propogates
58
+ # - VARCHAR columns now have a width, which will hopefully make the
59
+ # DDL even more portible (this will be reversed if it causes more problems)
60
+ # - cursor.rowcount being checked after various execute and fetchXXX methods
61
+ # - Check for fetchall and fetchmany returning empty lists after results
62
+ # are exhausted (already checking for empty lists if select retrieved
63
+ # nothing
64
+ # - Fix bugs in test_setoutputsize_basic and test_setinputsizes
65
+ #
66
+
67
+
68
+ class DatabaseAPI20Test(unittest.TestCase):
69
+ """
70
+ Test a database self.driver for DB API 2.0 compatibility.
71
+
72
+ This implementation tests Gadfly, but the TestCase
73
+ is structured so that other self.drivers can subclass this
74
+ test case to ensure compiliance with the DB-API. It is
75
+ expected that this TestCase may be expanded in the future
76
+ if ambiguities or edge conditions are discovered.
77
+
78
+ The 'Optional Extensions' are not yet being tested.
79
+
80
+ self.drivers should subclass this test, overriding setUp, tearDown,
81
+ self.driver, connect_args and connect_kw_args. Class specification
82
+ should be as follows:
83
+
84
+ import dbapi20
85
+ class mytest(dbapi20.DatabaseAPI20Test):
86
+ [...]
87
+
88
+ Don't 'import DatabaseAPI20Test from dbapi20', or you will
89
+ confuse the unit tester - just 'import dbapi20'.
90
+
91
+ """
92
+
93
+ # The self.driver module. This should be the module where the 'connect'
94
+ # method is to be found
95
+ driver = None
96
+ connect_args = () # List of arguments to pass to connect
97
+ connect_kw_args = {} # Keyword arguments for connect
98
+ table_prefix = 'dbapi20test_' # If you need to specify a prefix for tables
99
+
100
+ ddl1 = 'create table %sbooze (name varchar(20))' % table_prefix
101
+ ddl2 = 'create table %sbarflys (name varchar(20))' % table_prefix
102
+ xddl1 = 'drop table %sbooze' % table_prefix
103
+ xddl2 = 'drop table %sbarflys' % table_prefix
104
+
105
+ lowerfunc = 'lower' # Name of stored procedure to convert string->lowercase
106
+
107
+ # Some drivers may need to override these helpers, for example adding
108
+ # a 'commit' after the execute.
109
+ def executeDDL1(self, cursor):
110
+ cursor.execute(self.ddl1)
111
+
112
+ def executeDDL2(self, cursor):
113
+ cursor.execute(self.ddl2)
114
+
115
+ def setUp(self):
116
+ """
117
+ Setup the tests.
118
+
119
+ self.drivers should override this method to perform required setup
120
+ if any is necessary, such as creating the database.
121
+
122
+ """
123
+ pass
124
+
125
+ def tearDown(self):
126
+ """
127
+ Tear down the tests.
128
+
129
+ self.drivers should override this method to perform required cleanup
130
+ if any is necessary, such as deleting the test database.
131
+ The default drops the tables that may be created.
132
+
133
+ """
134
+ con = self._connect()
135
+ try:
136
+ cur = con.cursor()
137
+ for ddl in (self.xddl1, self.xddl2):
138
+ try:
139
+ cur.execute(ddl)
140
+ con.commit()
141
+ except self.driver.Error:
142
+ # Assume table didn't exist. Other tests will check if
143
+ # execute is busted.
144
+ pass
145
+ finally:
146
+ con.close()
147
+
148
+ def _connect(self):
149
+ try:
150
+ return self.driver.connect(*self.connect_args, **self.connect_kw_args)
151
+ except AttributeError:
152
+ self.fail('No connect method found in self.driver module')
153
+
154
+ def test_connect(self):
155
+ con = self._connect()
156
+ con.close()
157
+
158
+ def test_apilevel(self):
159
+ try:
160
+ # Must exist
161
+ apilevel = self.driver.apilevel
162
+ # Must equal 2.0
163
+ self.assertEqual(apilevel, '2.0')
164
+ except AttributeError:
165
+ self.fail("Driver doesn't define apilevel")
166
+
167
+ def test_threadsafety(self):
168
+ try:
169
+ # Must exist
170
+ threadsafety = self.driver.threadsafety
171
+ # Must be a valid value
172
+ self.assertTrue(threadsafety in (0, 1, 2, 3))
173
+ except AttributeError:
174
+ self.fail("Driver doesn't define threadsafety")
175
+
176
+ def test_paramstyle(self):
177
+ try:
178
+ # Must exist
179
+ paramstyle = self.driver.paramstyle
180
+ # Must be a valid value
181
+ self.assertTrue(
182
+ paramstyle in ('qmark', 'numeric', 'named', 'format', 'pyformat'),
183
+ )
184
+ except AttributeError:
185
+ self.fail("Driver doesn't define paramstyle")
186
+
187
+ def test_Exceptions(self):
188
+ # Make sure required exceptions exist, and are in the
189
+ # defined heirarchy.
190
+ self.assertTrue(issubclass(self.driver.Warning, Exception))
191
+ self.assertTrue(issubclass(self.driver.Error, Exception))
192
+ self.assertTrue(issubclass(self.driver.InterfaceError, self.driver.Error))
193
+ self.assertTrue(issubclass(self.driver.DatabaseError, self.driver.Error))
194
+ self.assertTrue(issubclass(self.driver.OperationalError, self.driver.Error))
195
+ self.assertTrue(issubclass(self.driver.IntegrityError, self.driver.Error))
196
+ self.assertTrue(issubclass(self.driver.InternalError, self.driver.Error))
197
+ self.assertTrue(issubclass(self.driver.ProgrammingError, self.driver.Error))
198
+ self.assertTrue(issubclass(self.driver.NotSupportedError, self.driver.Error))
199
+
200
+ def test_ExceptionsAsConnectionAttributes(self):
201
+ # OPTIONAL EXTENSION
202
+ # Test for the optional DB API 2.0 extension, where the exceptions
203
+ # are exposed as attributes on the Connection object
204
+ # I figure this optional extension will be implemented by any
205
+ # driver author who is using this test suite, so it is enabled
206
+ # by default.
207
+ con = self._connect()
208
+ drv = self.driver
209
+ self.assertTrue(con.Warning is drv.Warning)
210
+ self.assertTrue(con.Error is drv.Error)
211
+ self.assertTrue(con.InterfaceError is drv.InterfaceError)
212
+ self.assertTrue(con.DatabaseError is drv.DatabaseError)
213
+ self.assertTrue(con.OperationalError is drv.OperationalError)
214
+ self.assertTrue(con.IntegrityError is drv.IntegrityError)
215
+ self.assertTrue(con.InternalError is drv.InternalError)
216
+ self.assertTrue(con.ProgrammingError is drv.ProgrammingError)
217
+ self.assertTrue(con.NotSupportedError is drv.NotSupportedError)
218
+
219
+ def test_commit(self):
220
+ con = self._connect()
221
+ try:
222
+ # Commit must work, even if it doesn't do anything
223
+ con.commit()
224
+ finally:
225
+ con.close()
226
+
227
+ def test_rollback(self):
228
+ con = self._connect()
229
+ # If rollback is defined, it should either work or throw
230
+ # the documented exception
231
+ if hasattr(con, 'rollback'):
232
+ try:
233
+ con.rollback()
234
+ except self.driver.NotSupportedError:
235
+ pass
236
+
237
+ def test_cursor(self):
238
+ con = self._connect()
239
+ try:
240
+ cur = con.cursor() # noqa: F841
241
+ finally:
242
+ con.close()
243
+
244
+ def test_cursor_isolation(self):
245
+ con = self._connect()
246
+ try:
247
+ # Make sure cursors created from the same connection have
248
+ # the documented transaction isolation level
249
+ cur1 = con.cursor()
250
+ cur2 = con.cursor()
251
+ self.executeDDL1(cur1)
252
+ cur1.execute(
253
+ "insert into %sbooze values ('Victoria Bitter')" % (self.table_prefix),
254
+ )
255
+ cur2.execute('select name from %sbooze' % self.table_prefix)
256
+ booze = cur2.fetchall()
257
+ self.assertEqual(len(booze), 1)
258
+ self.assertEqual(len(booze[0]), 1)
259
+ self.assertEqual(booze[0][0], 'Victoria Bitter')
260
+ finally:
261
+ con.close()
262
+
263
+ def test_description(self):
264
+ con = self._connect()
265
+ try:
266
+ cur = con.cursor()
267
+ self.executeDDL1(cur)
268
+ self.assertEqual(
269
+ cur.description,
270
+ None,
271
+ 'cursor.description should be none after executing a '
272
+ 'statement that can return no rows (such as DDL)',
273
+ )
274
+ cur.execute('select name from %sbooze' % self.table_prefix)
275
+ self.assertEqual(
276
+ len(cur.description), 1, 'cursor.description describes too many columns',
277
+ )
278
+ self.assertEqual(
279
+ len(cur.description[0]),
280
+ 9,
281
+ 'cursor.description[x] tuples must have 7 elements',
282
+ )
283
+ self.assertEqual(
284
+ cur.description[0][0].lower(),
285
+ 'name',
286
+ 'cursor.description[x][0] must return column name',
287
+ )
288
+ self.assertEqual(
289
+ cur.description[0][1],
290
+ self.driver.STRING,
291
+ 'cursor.description[x][1] must return column type. Got %r'
292
+ % cur.description[0][1],
293
+ )
294
+ cur.fetchall()
295
+
296
+ # Make sure self.description gets reset
297
+ self.executeDDL2(cur)
298
+ self.assertEqual(
299
+ cur.description,
300
+ None,
301
+ 'cursor.description not being set to None when executing '
302
+ 'no-result statements (eg. DDL)',
303
+ )
304
+ finally:
305
+ con.close()
306
+
307
+ def test_rowcount(self):
308
+ con = self._connect()
309
+ try:
310
+ cur = con.cursor()
311
+ self.executeDDL1(cur)
312
+ self.assertEqual(
313
+ cur.rowcount,
314
+ -1,
315
+ 'cursor.rowcount should be -1 after executing no-result ' 'statements',
316
+ )
317
+ cur.execute(
318
+ "insert into %sbooze values ('Victoria Bitter')" % (self.table_prefix),
319
+ )
320
+ self.assertTrue(
321
+ cur.rowcount in (-1, 1),
322
+ 'cursor.rowcount should == number or rows inserted, or '
323
+ 'set to -1 after executing an insert statement',
324
+ )
325
+ cur.execute('select name from %sbooze' % self.table_prefix)
326
+ self.assertTrue(
327
+ cur.rowcount in (-1, 1),
328
+ 'cursor.rowcount should == number of rows returned, or '
329
+ 'set to -1 after executing a select statement',
330
+ )
331
+ self.executeDDL2(cur)
332
+ self.assertEqual(
333
+ cur.rowcount,
334
+ -1,
335
+ 'cursor.rowcount not being reset to -1 after executing '
336
+ 'no-result statements',
337
+ )
338
+ finally:
339
+ con.close()
340
+
341
+ lower_func = 'lower'
342
+
343
+ def test_callproc(self):
344
+ con = self._connect()
345
+ try:
346
+ cur = con.cursor()
347
+ if self.lower_func and hasattr(cur, 'callproc'):
348
+ r = cur.callproc(self.lower_func, ('FOO',))
349
+ self.assertEqual(len(r), 1)
350
+ self.assertEqual(r[0], 'FOO')
351
+ r = cur.fetchall()
352
+ self.assertEqual(len(r), 1, 'callproc produced no result set')
353
+ self.assertEqual(len(r[0]), 1, 'callproc produced invalid result set')
354
+ self.assertEqual(r[0][0], 'foo', 'callproc produced invalid results')
355
+ finally:
356
+ con.close()
357
+
358
+ def test_close(self):
359
+ con = self._connect()
360
+ try:
361
+ cur = con.cursor()
362
+ finally:
363
+ con.close()
364
+
365
+ # cursor.execute should raise an Error if called after connection
366
+ # closed
367
+ self.assertRaises(self.driver.Error, self.executeDDL1, cur)
368
+
369
+ # connection.commit should raise an Error if called after connection'
370
+ # closed.'
371
+ self.assertRaises(self.driver.Error, con.commit)
372
+
373
+ # connection.close should raise an Error if called more than once
374
+ self.assertRaises(self.driver.Error, con.close)
375
+
376
+ def test_execute(self):
377
+ con = self._connect()
378
+ try:
379
+ cur = con.cursor()
380
+ self._paraminsert(cur)
381
+ finally:
382
+ con.close()
383
+
384
+ def _paraminsert(self, cur):
385
+ self.executeDDL1(cur)
386
+ cur.execute(
387
+ "insert into %sbooze values ('Victoria Bitter')" % (self.table_prefix),
388
+ )
389
+ self.assertTrue(cur.rowcount in (-1, 1))
390
+
391
+ if self.driver.paramstyle == 'qmark':
392
+ cur.execute(
393
+ 'insert into %sbooze values (?)' % self.table_prefix, ("Cooper's",),
394
+ )
395
+ elif self.driver.paramstyle == 'numeric':
396
+ cur.execute(
397
+ 'insert into %sbooze values (:1)' % self.table_prefix, ("Cooper's",),
398
+ )
399
+ elif self.driver.paramstyle == 'named':
400
+ cur.execute(
401
+ 'insert into %sbooze values (:beer)' % self.table_prefix,
402
+ {'beer': "Cooper's"},
403
+ )
404
+ elif self.driver.paramstyle == 'format':
405
+ cur.execute(
406
+ 'insert into %sbooze values (%%s)' % self.table_prefix, ("Cooper's",),
407
+ )
408
+ elif self.driver.paramstyle == 'pyformat':
409
+ cur.execute(
410
+ 'insert into %sbooze values (%%(beer)s)' % self.table_prefix,
411
+ {'beer': "Cooper's"},
412
+ )
413
+ else:
414
+ self.fail('Invalid paramstyle')
415
+ self.assertTrue(cur.rowcount in (-1, 1))
416
+
417
+ cur.execute('select name from %sbooze' % self.table_prefix)
418
+ res = cur.fetchall()
419
+ self.assertEqual(len(res), 2, 'cursor.fetchall returned too few rows')
420
+ beers = [res[0][0], res[1][0]]
421
+ beers.sort()
422
+ self.assertEqual(
423
+ beers[0],
424
+ "Cooper's",
425
+ 'cursor.fetchall retrieved incorrect data, or data inserted ' 'incorrectly',
426
+ )
427
+ self.assertEqual(
428
+ beers[1],
429
+ 'Victoria Bitter',
430
+ 'cursor.fetchall retrieved incorrect data, or data inserted ' 'incorrectly',
431
+ )
432
+
433
+ def test_executemany(self):
434
+ con = self._connect()
435
+ try:
436
+ cur = con.cursor()
437
+ self.executeDDL1(cur)
438
+ largs = [("Cooper's",), ("Boag's",)]
439
+ margs = [{'beer': "Cooper's"}, {'beer': "Boag's"}]
440
+ if self.driver.paramstyle == 'qmark':
441
+ cur.executemany(
442
+ 'insert into %sbooze values (?)' % self.table_prefix, largs,
443
+ )
444
+ elif self.driver.paramstyle == 'numeric':
445
+ cur.executemany(
446
+ 'insert into %sbooze values (:1)' % self.table_prefix, largs,
447
+ )
448
+ elif self.driver.paramstyle == 'named':
449
+ cur.executemany(
450
+ 'insert into %sbooze values (:beer)' % self.table_prefix, margs,
451
+ )
452
+ elif self.driver.paramstyle == 'format':
453
+ cur.executemany(
454
+ 'insert into %sbooze values (%%s)' % self.table_prefix, largs,
455
+ )
456
+ elif self.driver.paramstyle == 'pyformat':
457
+ cur.executemany(
458
+ 'insert into %sbooze values (%%(beer)s)' % (self.table_prefix),
459
+ margs,
460
+ )
461
+ else:
462
+ self.fail('Unknown paramstyle')
463
+ self.assertTrue(
464
+ cur.rowcount in (-1, 2),
465
+ 'insert using cursor.executemany set cursor.rowcount to '
466
+ 'incorrect value %r' % cur.rowcount,
467
+ )
468
+ cur.execute('select name from %sbooze' % self.table_prefix)
469
+ res = cur.fetchall()
470
+ self.assertEqual(
471
+ len(res), 2, 'cursor.fetchall retrieved incorrect number of rows',
472
+ )
473
+ beers = [res[0][0], res[1][0]]
474
+ beers.sort()
475
+ self.assertEqual(beers[0], "Boag's", 'incorrect data retrieved')
476
+ self.assertEqual(beers[1], "Cooper's", 'incorrect data retrieved')
477
+ finally:
478
+ con.close()
479
+
480
+ def test_fetchone(self):
481
+ con = self._connect()
482
+ try:
483
+ cur = con.cursor()
484
+
485
+ # cursor.fetchone should raise an Error if called before
486
+ # executing a select-type query
487
+ self.assertRaises(self.driver.Error, cur.fetchone)
488
+
489
+ # cursor.fetchone should raise an Error if called after
490
+ # executing a query that cannnot return rows
491
+ self.executeDDL1(cur)
492
+ self.assertRaises(self.driver.Error, cur.fetchone)
493
+
494
+ cur.execute('select name from %sbooze' % self.table_prefix)
495
+ self.assertEqual(
496
+ cur.fetchone(),
497
+ None,
498
+ 'cursor.fetchone should return None if a query retrieves ' 'no rows',
499
+ )
500
+ self.assertTrue(cur.rowcount in (-1, 0))
501
+
502
+ # cursor.fetchone should raise an Error if called after
503
+ # executing a query that cannnot return rows
504
+ cur.execute(
505
+ "insert into %sbooze values ('Victoria Bitter')" % (self.table_prefix),
506
+ )
507
+ self.assertRaises(self.driver.Error, cur.fetchone)
508
+
509
+ cur.execute('select name from %sbooze' % self.table_prefix)
510
+ r = cur.fetchone()
511
+ self.assertEqual(
512
+ len(r), 1, 'cursor.fetchone should have retrieved a single row',
513
+ )
514
+ self.assertEqual(
515
+ r[0], 'Victoria Bitter', 'cursor.fetchone retrieved incorrect data',
516
+ )
517
+ self.assertEqual(
518
+ cur.fetchone(),
519
+ None,
520
+ 'cursor.fetchone should return None if no more rows available',
521
+ )
522
+ self.assertTrue(cur.rowcount in (-1, 1))
523
+ finally:
524
+ con.close()
525
+
526
+ samples = [
527
+ 'Carlton Cold',
528
+ 'Carlton Draft',
529
+ 'Mountain Goat',
530
+ 'Redback',
531
+ 'Victoria Bitter',
532
+ 'XXXX',
533
+ ]
534
+
535
+ def _populate(self):
536
+ """Return a list of sql commands to setup the DB for the fetch
537
+ tests.
538
+ """
539
+ populate = [
540
+ "insert into %sbooze values ('%s')" % (self.table_prefix, s)
541
+ for s in self.samples
542
+ ]
543
+ return populate
544
+
545
+ def test_fetchmany(self):
546
+ con = self._connect()
547
+ try:
548
+ cur = con.cursor()
549
+
550
+ # cursor.fetchmany should raise an Error if called without
551
+ # issuing a query
552
+ self.assertRaises(self.driver.Error, cur.fetchmany, 4)
553
+
554
+ self.executeDDL1(cur)
555
+ for sql in self._populate():
556
+ cur.execute(sql)
557
+
558
+ cur.execute('select name from %sbooze' % self.table_prefix)
559
+ r = cur.fetchmany()
560
+ self.assertEqual(
561
+ len(r),
562
+ 1,
563
+ 'cursor.fetchmany retrieved incorrect number of rows, '
564
+ 'default of arraysize is one.',
565
+ )
566
+ cur.arraysize = 10
567
+ r = cur.fetchmany(3) # Should get 3 rows
568
+ self.assertEqual(
569
+ len(r), 3, 'cursor.fetchmany retrieved incorrect number of rows',
570
+ )
571
+ r = cur.fetchmany(4) # Should get 2 more
572
+ self.assertEqual(
573
+ len(r), 2, 'cursor.fetchmany retrieved incorrect number of rows',
574
+ )
575
+ r = cur.fetchmany(4) # Should be an empty sequence
576
+ self.assertEqual(
577
+ len(r),
578
+ 0,
579
+ 'cursor.fetchmany should return an empty sequence after '
580
+ 'results are exhausted',
581
+ )
582
+ self.assertTrue(cur.rowcount in (-1, 6))
583
+
584
+ # Same as above, using cursor.arraysize
585
+ cur.arraysize = 4
586
+ cur.execute('select name from %sbooze' % self.table_prefix)
587
+ r = cur.fetchmany() # Should get 4 rows
588
+ self.assertEqual(
589
+ len(r), 4, 'cursor.arraysize not being honoured by fetchmany',
590
+ )
591
+ r = cur.fetchmany() # Should get 2 more
592
+ self.assertEqual(len(r), 2)
593
+ r = cur.fetchmany() # Should be an empty sequence
594
+ self.assertEqual(len(r), 0)
595
+ self.assertTrue(cur.rowcount in (-1, 6))
596
+
597
+ cur.arraysize = 6
598
+ cur.execute('select name from %sbooze' % self.table_prefix)
599
+ rows = cur.fetchmany() # Should get all rows
600
+ self.assertTrue(cur.rowcount in (-1, 6))
601
+ self.assertEqual(len(rows), 6)
602
+ self.assertEqual(len(rows), 6)
603
+ rows = [r[0] for r in rows]
604
+ rows.sort()
605
+
606
+ # Make sure we get the right data back out
607
+ for i in range(0, 6):
608
+ self.assertEqual(
609
+ rows[i],
610
+ self.samples[i],
611
+ 'incorrect data retrieved by cursor.fetchmany',
612
+ )
613
+
614
+ rows = cur.fetchmany() # Should return an empty list
615
+ self.assertEqual(
616
+ len(rows),
617
+ 0,
618
+ 'cursor.fetchmany should return an empty sequence if '
619
+ 'called after the whole result set has been fetched',
620
+ )
621
+ self.assertTrue(cur.rowcount in (-1, 6))
622
+
623
+ self.executeDDL2(cur)
624
+ cur.execute('select name from %sbarflys' % self.table_prefix)
625
+ r = cur.fetchmany() # Should get empty sequence
626
+ self.assertEqual(
627
+ len(r),
628
+ 0,
629
+ 'cursor.fetchmany should return an empty sequence if '
630
+ 'query retrieved no rows',
631
+ )
632
+ self.assertTrue(cur.rowcount in (-1, 0))
633
+
634
+ finally:
635
+ con.close()
636
+
637
+ def test_fetchall(self):
638
+ con = self._connect()
639
+ try:
640
+ cur = con.cursor()
641
+ # cursor.fetchall should raise an Error if called
642
+ # without executing a query that may return rows (such
643
+ # as a select)
644
+ self.assertRaises(self.driver.Error, cur.fetchall)
645
+
646
+ self.executeDDL1(cur)
647
+ for sql in self._populate():
648
+ cur.execute(sql)
649
+
650
+ # cursor.fetchall should raise an Error if called
651
+ # after executing a a statement that cannot return rows
652
+ self.assertRaises(self.driver.Error, cur.fetchall)
653
+
654
+ cur.execute('select name from %sbooze' % self.table_prefix)
655
+ rows = cur.fetchall()
656
+ self.assertTrue(cur.rowcount in (-1, len(self.samples)))
657
+ self.assertEqual(
658
+ len(rows),
659
+ len(self.samples),
660
+ 'cursor.fetchall did not retrieve all rows',
661
+ )
662
+ rows = [r[0] for r in rows]
663
+ rows.sort()
664
+ for i in range(0, len(self.samples)):
665
+ self.assertEqual(
666
+ rows[i], self.samples[i], 'cursor.fetchall retrieved incorrect rows',
667
+ )
668
+ rows = cur.fetchall()
669
+ self.assertEqual(
670
+ len(rows),
671
+ 0,
672
+ 'cursor.fetchall should return an empty list if called '
673
+ 'after the whole result set has been fetched',
674
+ )
675
+ self.assertTrue(cur.rowcount in (-1, len(self.samples)))
676
+
677
+ self.executeDDL2(cur)
678
+ cur.execute('select name from %sbarflys' % self.table_prefix)
679
+ rows = cur.fetchall()
680
+ self.assertTrue(cur.rowcount in (-1, 0))
681
+ self.assertEqual(
682
+ len(rows),
683
+ 0,
684
+ 'cursor.fetchall should return an empty list if '
685
+ 'a select query returns no rows',
686
+ )
687
+
688
+ finally:
689
+ con.close()
690
+
691
+ def test_mixedfetch(self):
692
+ con = self._connect()
693
+ try:
694
+ cur = con.cursor()
695
+ self.executeDDL1(cur)
696
+ for sql in self._populate():
697
+ cur.execute(sql)
698
+
699
+ cur.execute('select name from %sbooze order by name' % self.table_prefix)
700
+ rows1 = cur.fetchone()
701
+ rows23 = cur.fetchmany(2)
702
+ rows4 = cur.fetchone()
703
+ rows56 = cur.fetchall()
704
+ self.assertTrue(cur.rowcount in (-1, 6))
705
+ self.assertEqual(
706
+ len(rows23), 2, 'fetchmany returned incorrect number of rows',
707
+ )
708
+ self.assertEqual(
709
+ len(rows56), 2, 'fetchall returned incorrect number of rows',
710
+ )
711
+
712
+ rows = [rows1[0]]
713
+ rows.extend([rows23[0][0], rows23[1][0]])
714
+ rows.append(rows4[0])
715
+ rows.extend([rows56[0][0], rows56[1][0]])
716
+ rows.sort()
717
+ for i in range(0, len(self.samples)):
718
+ self.assertEqual(
719
+ rows[i], self.samples[i], 'incorrect data retrieved or inserted',
720
+ )
721
+ finally:
722
+ con.close()
723
+
724
+ def help_nextset_setUp(self, cur):
725
+ """Should create a procedure called deleteme
726
+ that returns two result sets, first the
727
+ number of rows in booze then "name from booze"
728
+ """
729
+ raise NotImplementedError('Helper not implemented')
730
+ # sql="""
731
+ # create procedure deleteme as
732
+ # begin
733
+ # select count(*) from booze
734
+ # select name from booze
735
+ # end
736
+ # """
737
+ # cur.execute(sql)
738
+
739
+ def help_nextset_tearDown(self, cur):
740
+ 'If cleaning up is needed after nextSetTest'
741
+ raise NotImplementedError('Helper not implemented')
742
+ # cur.execute("drop procedure deleteme")
743
+
744
+ def test_nextset(self):
745
+ con = self._connect()
746
+ try:
747
+ cur = con.cursor()
748
+ if not hasattr(cur, 'nextset'):
749
+ return
750
+
751
+ try:
752
+ self.executeDDL1(cur)
753
+ sql = self._populate()
754
+ for sql in self._populate():
755
+ cur.execute(sql)
756
+
757
+ self.help_nextset_setUp(cur)
758
+
759
+ cur.callproc('deleteme')
760
+ numberofrows = cur.fetchone()
761
+ assert numberofrows[0] == len(self.samples)
762
+ assert cur.nextset()
763
+ names = cur.fetchall()
764
+ assert len(names) == len(self.samples)
765
+ s = cur.nextset() # noqa: F841
766
+ assert s is None, 'No more return sets, should return None'
767
+ finally:
768
+ self.help_nextset_tearDown(cur)
769
+
770
+ finally:
771
+ con.close()
772
+
773
+ def test_arraysize(self):
774
+ # Not much here - rest of the tests for this are in test_fetchmany
775
+ con = self._connect()
776
+ try:
777
+ cur = con.cursor()
778
+ self.assertTrue(
779
+ hasattr(cur, 'arraysize'), 'cursor.arraysize must be defined',
780
+ )
781
+ finally:
782
+ con.close()
783
+
784
+ def test_setinputsizes(self):
785
+ con = self._connect()
786
+ try:
787
+ cur = con.cursor()
788
+ cur.setinputsizes((25,))
789
+ self._paraminsert(cur) # Make sure cursor still works
790
+ finally:
791
+ con.close()
792
+
793
+ def test_setoutputsize_basic(self):
794
+ # Basic test is to make sure setoutputsize doesn't blow up
795
+ con = self._connect()
796
+ try:
797
+ cur = con.cursor()
798
+ cur.setoutputsize(1000)
799
+ cur.setoutputsize(2000, 0)
800
+ self._paraminsert(cur) # Make sure the cursor still works
801
+ finally:
802
+ con.close()
803
+
804
+ def test_setoutputsize(self):
805
+ # Real test for setoutputsize is driver dependant
806
+ raise NotImplementedError('Driver need to override this test')
807
+
808
+ def test_None(self):
809
+ con = self._connect()
810
+ try:
811
+ cur = con.cursor()
812
+ self.executeDDL1(cur)
813
+ cur.execute('insert into %sbooze values (NULL)' % self.table_prefix)
814
+ cur.execute('select name from %sbooze' % self.table_prefix)
815
+ r = cur.fetchall()
816
+ self.assertEqual(len(r), 1)
817
+ self.assertEqual(len(r[0]), 1)
818
+ self.assertEqual(r[0][0], None, 'NULL value not returned as None')
819
+ finally:
820
+ con.close()
821
+
822
+ def test_Date(self):
823
+ self.driver.Date(2002, 12, 25)
824
+ self.driver.DateFromTicks(time.mktime((2002, 12, 25, 0, 0, 0, 0, 0, 0)))
825
+ # Can we assume this? API doesn't specify, but it seems implied
826
+ # self.assertEqual(str(d1), str(d2))
827
+
828
+ def test_Time(self):
829
+ self.driver.Time(13, 45, 30)
830
+ self.driver.TimeFromTicks(time.mktime((2001, 1, 1, 13, 45, 30, 0, 0, 0)))
831
+ # Can we assume this? API doesn't specify, but it seems implied
832
+ # self.assertEqual(str(t1), str(t2))
833
+
834
+ def test_Timestamp(self):
835
+ self.driver.Timestamp(2002, 12, 25, 13, 45, 30)
836
+ self.driver.TimestampFromTicks(
837
+ time.mktime((2002, 12, 25, 13, 45, 30, 0, 0, 0)),
838
+ )
839
+ # Can we assume this? API doesn't specify, but it seems implied
840
+ # self.assertEqual(str(t1), str(t2))
841
+
842
+ def test_Binary(self):
843
+ self.driver.Binary(b'Something')
844
+ self.driver.Binary(b'')
845
+
846
+ def test_STRING(self):
847
+ self.assertTrue(hasattr(self.driver, 'STRING'), 'module.STRING must be defined')
848
+
849
+ def test_BINARY(self):
850
+ self.assertTrue(
851
+ hasattr(self.driver, 'BINARY'), 'module.BINARY must be defined.',
852
+ )
853
+
854
+ def test_NUMBER(self):
855
+ self.assertTrue(
856
+ hasattr(self.driver, 'NUMBER'), 'module.NUMBER must be defined.',
857
+ )
858
+
859
+ def test_DATETIME(self):
860
+ self.assertTrue(
861
+ hasattr(self.driver, 'DATETIME'), 'module.DATETIME must be defined.',
862
+ )
863
+
864
+ def test_ROWID(self):
865
+ self.assertTrue(hasattr(self.driver, 'ROWID'), 'module.ROWID must be defined.')