mssql-python 1.0.0__cp314-cp314-win_amd64.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 (73) hide show
  1. mssql_python/__init__.py +307 -0
  2. mssql_python/auth.py +222 -0
  3. mssql_python/connection.py +1493 -0
  4. mssql_python/connection_string_builder.py +113 -0
  5. mssql_python/connection_string_parser.py +381 -0
  6. mssql_python/constants.py +509 -0
  7. mssql_python/cursor.py +2601 -0
  8. mssql_python/db_connection.py +53 -0
  9. mssql_python/ddbc_bindings.cp314-amd64.pyd +0 -0
  10. mssql_python/ddbc_bindings.py +137 -0
  11. mssql_python/exceptions.py +574 -0
  12. mssql_python/helpers.py +357 -0
  13. mssql_python/libs/LICENSING +19 -0
  14. mssql_python/libs/linux/alpine/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  15. mssql_python/libs/linux/alpine/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  16. mssql_python/libs/linux/alpine/arm64/lib/libodbcinst.so.2 +0 -0
  17. mssql_python/libs/linux/alpine/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  18. mssql_python/libs/linux/alpine/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  19. mssql_python/libs/linux/alpine/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  20. mssql_python/libs/linux/alpine/x86_64/lib/libodbcinst.so.2 +0 -0
  21. mssql_python/libs/linux/alpine/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  22. mssql_python/libs/linux/debian_ubuntu/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  23. mssql_python/libs/linux/debian_ubuntu/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  24. mssql_python/libs/linux/debian_ubuntu/arm64/lib/libodbcinst.so.2 +0 -0
  25. mssql_python/libs/linux/debian_ubuntu/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  26. mssql_python/libs/linux/debian_ubuntu/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  27. mssql_python/libs/linux/debian_ubuntu/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  28. mssql_python/libs/linux/debian_ubuntu/x86_64/lib/libodbcinst.so.2 +0 -0
  29. mssql_python/libs/linux/debian_ubuntu/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  30. mssql_python/libs/linux/rhel/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  31. mssql_python/libs/linux/rhel/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  32. mssql_python/libs/linux/rhel/arm64/lib/libodbcinst.so.2 +0 -0
  33. mssql_python/libs/linux/rhel/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  34. mssql_python/libs/linux/rhel/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  35. mssql_python/libs/linux/rhel/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  36. mssql_python/libs/linux/rhel/x86_64/lib/libodbcinst.so.2 +0 -0
  37. mssql_python/libs/linux/rhel/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  38. mssql_python/libs/linux/suse/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
  39. mssql_python/libs/linux/suse/x86_64/lib/libodbcinst.so.2 +0 -0
  40. mssql_python/libs/linux/suse/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
  41. mssql_python/libs/macos/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  42. mssql_python/libs/macos/arm64/lib/libltdl.7.dylib +0 -0
  43. mssql_python/libs/macos/arm64/lib/libmsodbcsql.18.dylib +0 -0
  44. mssql_python/libs/macos/arm64/lib/libodbc.2.dylib +0 -0
  45. mssql_python/libs/macos/arm64/lib/libodbcinst.2.dylib +0 -0
  46. mssql_python/libs/macos/arm64/share/doc/msodbcsql18/LICENSE.txt +101 -0
  47. mssql_python/libs/macos/arm64/share/doc/msodbcsql18/RELEASE_NOTES +465 -0
  48. mssql_python/libs/macos/arm64/share/msodbcsql18/resources/en_US/msodbcsqlr18.rll +0 -0
  49. mssql_python/libs/macos/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  50. mssql_python/libs/macos/x86_64/lib/libltdl.7.dylib +0 -0
  51. mssql_python/libs/macos/x86_64/lib/libmsodbcsql.18.dylib +0 -0
  52. mssql_python/libs/macos/x86_64/lib/libodbc.2.dylib +0 -0
  53. mssql_python/libs/macos/x86_64/lib/libodbcinst.2.dylib +0 -0
  54. mssql_python/libs/macos/x86_64/share/doc/msodbcsql18/LICENSE.txt +101 -0
  55. mssql_python/libs/macos/x86_64/share/doc/msodbcsql18/RELEASE_NOTES +465 -0
  56. mssql_python/libs/macos/x86_64/share/msodbcsql18/resources/en_US/msodbcsqlr18.rll +0 -0
  57. mssql_python/libs/windows/x64/1033/msodbcsqlr18.rll +0 -0
  58. mssql_python/libs/windows/x64/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
  59. mssql_python/libs/windows/x64/MICROSOFT_VISUAL_STUDIO_LICENSE.txt +54 -0
  60. mssql_python/libs/windows/x64/msodbcdiag18.dll +0 -0
  61. mssql_python/libs/windows/x64/msodbcsql18.dll +0 -0
  62. mssql_python/libs/windows/x64/mssql-auth.dll +0 -0
  63. mssql_python/logging.py +610 -0
  64. mssql_python/mssql_python.pyi +375 -0
  65. mssql_python/msvcp140.dll +0 -0
  66. mssql_python/pooling.py +125 -0
  67. mssql_python/row.py +194 -0
  68. mssql_python/type.py +143 -0
  69. mssql_python-1.0.0.dist-info/METADATA +76 -0
  70. mssql_python-1.0.0.dist-info/RECORD +73 -0
  71. mssql_python-1.0.0.dist-info/WHEEL +5 -0
  72. mssql_python-1.0.0.dist-info/licenses/LICENSE +47 -0
  73. mssql_python-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,574 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation.
3
+ Licensed under the MIT license.
4
+ This module contains custom exception classes for the mssql_python package.
5
+ These classes are used to raise exceptions when an error occurs while executing a query.
6
+ """
7
+
8
+ from typing import Optional
9
+ from mssql_python.logging import logger
10
+ import builtins
11
+
12
+
13
+ class ConnectionStringParseError(builtins.Exception):
14
+ """
15
+ Exception raised when connection string parsing fails.
16
+
17
+ This exception is raised when the connection string parser encounters
18
+ syntax errors, unknown keywords, duplicate keywords, or other validation
19
+ failures. It collects all errors and reports them together.
20
+ """
21
+
22
+ def __init__(self, errors: list) -> None:
23
+ """
24
+ Initialize the error with a list of validation errors.
25
+
26
+ Args:
27
+ errors: List of error messages describing what went wrong
28
+ """
29
+ self.errors = errors
30
+ message = "Connection string parsing failed:\n " + "\n ".join(errors)
31
+ super().__init__(message)
32
+
33
+
34
+ class Exception(builtins.Exception):
35
+ """
36
+ Base class for all DB API 2.0 exceptions.
37
+ """
38
+
39
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
40
+ self.driver_error = driver_error
41
+ self.ddbc_error = truncate_error_message(ddbc_error)
42
+ if self.ddbc_error:
43
+ # Both driver and DDBC errors are present
44
+ self.message = (
45
+ f"Driver Error: {self.driver_error}; DDBC Error: {self.ddbc_error}"
46
+ )
47
+ else:
48
+ # Errors raised by the driver itself should not have a DDBC error message
49
+ self.message = f"Driver Error: {self.driver_error}"
50
+ super().__init__(self.message)
51
+
52
+
53
+ class Warning(Exception):
54
+ """
55
+ Exception raised for important warnings like data truncations while inserting, etc.
56
+ """
57
+
58
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
59
+ super().__init__(driver_error, ddbc_error)
60
+
61
+
62
+ class Error(Exception):
63
+ """
64
+ Base class for errors.
65
+ """
66
+
67
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
68
+ super().__init__(driver_error, ddbc_error)
69
+
70
+
71
+ class InterfaceError(Error):
72
+ """
73
+ Exception raised for errors that are related to the database
74
+ interface rather than the database itself.
75
+ """
76
+
77
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
78
+ super().__init__(driver_error, ddbc_error)
79
+
80
+
81
+ class DatabaseError(Error):
82
+ """
83
+ Exception raised for errors that are related to the database.
84
+ """
85
+
86
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
87
+ super().__init__(driver_error, ddbc_error)
88
+
89
+
90
+ class DataError(DatabaseError):
91
+ """
92
+ Exception raised for errors that are due to problems with the
93
+ processed data like division by zero, numeric value out of range, etc.
94
+ """
95
+
96
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
97
+ super().__init__(driver_error, ddbc_error)
98
+
99
+
100
+ class OperationalError(DatabaseError):
101
+ """
102
+ Exception raised for errors that are related to the database's operation
103
+ and not necessarily under the control of the programmer.
104
+ """
105
+
106
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
107
+ super().__init__(driver_error, ddbc_error)
108
+
109
+
110
+ class IntegrityError(DatabaseError):
111
+ """
112
+ Exception raised when the relational integrity of the database is affected,
113
+ e.g., a foreign key check fails.
114
+ """
115
+
116
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
117
+ super().__init__(driver_error, ddbc_error)
118
+
119
+
120
+ class InternalError(DatabaseError):
121
+ """
122
+ Exception raised when the database encounters an internal error,
123
+ e.g., the cursor is not valid anymore, the transaction is out of sync, etc.
124
+ """
125
+
126
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
127
+ super().__init__(driver_error, ddbc_error)
128
+
129
+
130
+ class ProgrammingError(DatabaseError):
131
+ """
132
+ Exception raised for programming errors,
133
+ e.g., table not found or already exists, syntax error in the SQL statement,
134
+ wrong number of parameters specified, etc.
135
+ """
136
+
137
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
138
+ super().__init__(driver_error, ddbc_error)
139
+
140
+
141
+ class NotSupportedError(DatabaseError):
142
+ """
143
+ Exception raised in case a method or database API was used which
144
+ is not supported by the database, e.g., requesting a .rollback()
145
+ on a connection that does not support transaction or has transactions turned off.
146
+ """
147
+
148
+ def __init__(self, driver_error: str, ddbc_error: str) -> None:
149
+ super().__init__(driver_error, ddbc_error)
150
+
151
+
152
+ # Mapping SQLSTATE codes to custom exception classes
153
+ def sqlstate_to_exception(sqlstate: str, ddbc_error: str) -> Optional[Exception]:
154
+ """
155
+ Map an SQLSTATE code to a custom exception class.
156
+ This function maps an SQLSTATE code to a custom exception class based on the code.
157
+ If the code is not found in the mapping, a generic DatabaseError class is returned
158
+ to handle the error.
159
+ Args:
160
+ sqlstate (str): The SQLSTATE code to map to a custom exception class.
161
+ Returns:
162
+ mapping[str, Exception]: A mapping of SQLSTATE codes to custom exception classes.
163
+ """
164
+ mapping = {
165
+ "01000": Warning(
166
+ driver_error="General warning", ddbc_error=ddbc_error
167
+ ), # General warning
168
+ "01001": OperationalError(
169
+ driver_error="Cursor operation conflict", ddbc_error=ddbc_error
170
+ ), # Cursor operation conflict
171
+ "01002": OperationalError(
172
+ driver_error="Disconnect error", ddbc_error=ddbc_error
173
+ ), # Disconnect error
174
+ "01003": DataError(
175
+ driver_error="NULL value eliminated in set function", ddbc_error=ddbc_error
176
+ ), # NULL value eliminated in set function
177
+ "01004": DataError(
178
+ driver_error="String data, right-truncated", ddbc_error=ddbc_error
179
+ ), # String data, right-truncated
180
+ "01006": OperationalError(
181
+ driver_error="Privilege not revoked", ddbc_error=ddbc_error
182
+ ), # Privilege not revoked
183
+ "01007": OperationalError(
184
+ driver_error="Privilege not granted", ddbc_error=ddbc_error
185
+ ), # Privilege not granted
186
+ "01S00": ProgrammingError(
187
+ driver_error="Invalid connection string attribute", ddbc_error=ddbc_error
188
+ ), # Invalid connection string attribute
189
+ "01S01": DataError(
190
+ driver_error="Error in row", ddbc_error=ddbc_error
191
+ ), # Error in row
192
+ "01S02": Warning(
193
+ driver_error="Option value changed", ddbc_error=ddbc_error
194
+ ), # Option value changed
195
+ "01S06": OperationalError(
196
+ driver_error="Attempt to fetch before the result set returned the first rowset",
197
+ ddbc_error=ddbc_error,
198
+ ), # Attempt to fetch before the result set returned the first rowset
199
+ "01S07": DataError(
200
+ driver_error="Fractional truncation", ddbc_error=ddbc_error
201
+ ), # Fractional truncation
202
+ "01S08": OperationalError(
203
+ driver_error="Error saving File DSN", ddbc_error=ddbc_error
204
+ ), # Error saving File DSN
205
+ "01S09": ProgrammingError(
206
+ driver_error="Invalid keyword", ddbc_error=ddbc_error
207
+ ), # Invalid keyword
208
+ "07001": ProgrammingError(
209
+ driver_error="Wrong number of parameters", ddbc_error=ddbc_error
210
+ ), # Wrong number of parameters
211
+ "07002": ProgrammingError(
212
+ driver_error="COUNT field incorrect", ddbc_error=ddbc_error
213
+ ), # COUNT field incorrect
214
+ "07005": ProgrammingError(
215
+ driver_error="Prepared statement not a cursor-specification",
216
+ ddbc_error=ddbc_error,
217
+ ), # Prepared statement not a cursor-specification
218
+ "07006": ProgrammingError(
219
+ driver_error="Restricted data type attribute violation",
220
+ ddbc_error=ddbc_error,
221
+ ), # Restricted data type attribute violation
222
+ "07009": ProgrammingError(
223
+ driver_error="Invalid descriptor index", ddbc_error=ddbc_error
224
+ ), # Invalid descriptor index
225
+ "07S01": ProgrammingError(
226
+ driver_error="Invalid use of default parameter", ddbc_error=ddbc_error
227
+ ), # Invalid use of default parameter
228
+ "08001": OperationalError(
229
+ driver_error="Client unable to establish connection", ddbc_error=ddbc_error
230
+ ), # Client unable to establish connection
231
+ "08002": OperationalError(
232
+ driver_error="Connection name in use", ddbc_error=ddbc_error
233
+ ), # Connection name in use
234
+ "08003": OperationalError(
235
+ driver_error="Connection not open", ddbc_error=ddbc_error
236
+ ), # Connection not open
237
+ "08004": OperationalError(
238
+ driver_error="Server rejected the connection", ddbc_error=ddbc_error
239
+ ), # Server rejected the connection
240
+ "08007": OperationalError(
241
+ driver_error="Connection failure during transaction", ddbc_error=ddbc_error
242
+ ), # Connection failure during transaction
243
+ "08S01": OperationalError(
244
+ driver_error="Communication link failure", ddbc_error=ddbc_error
245
+ ), # Communication link failure
246
+ "21S01": ProgrammingError(
247
+ driver_error="Insert value list does not match column list",
248
+ ddbc_error=ddbc_error,
249
+ ), # Insert value list does not match column list
250
+ "21S02": ProgrammingError(
251
+ driver_error="Degree of derived table does not match column list",
252
+ ddbc_error=ddbc_error,
253
+ ), # Degree of derived table does not match column list
254
+ "22001": DataError(
255
+ driver_error="String data, right-truncated", ddbc_error=ddbc_error
256
+ ), # String data, right-truncated
257
+ "22002": DataError(
258
+ driver_error="Indicator variable required but not supplied",
259
+ ddbc_error=ddbc_error,
260
+ ), # Indicator variable required but not supplied
261
+ "22003": DataError(
262
+ driver_error="Numeric value out of range", ddbc_error=ddbc_error
263
+ ), # Numeric value out of range
264
+ "22007": DataError(
265
+ driver_error="Invalid datetime format", ddbc_error=ddbc_error
266
+ ), # Invalid datetime format
267
+ "22008": DataError(
268
+ driver_error="Datetime field overflow", ddbc_error=ddbc_error
269
+ ), # Datetime field overflow
270
+ "22012": DataError(
271
+ driver_error="Division by zero", ddbc_error=ddbc_error
272
+ ), # Division by zero
273
+ "22015": DataError(
274
+ driver_error="Interval field overflow", ddbc_error=ddbc_error
275
+ ), # Interval field overflow
276
+ "22018": DataError(
277
+ driver_error="Invalid character value for cast specification",
278
+ ddbc_error=ddbc_error,
279
+ ), # Invalid character value for cast specification
280
+ "22019": ProgrammingError(
281
+ driver_error="Invalid escape character", ddbc_error=ddbc_error
282
+ ), # Invalid escape character
283
+ "22025": ProgrammingError(
284
+ driver_error="Invalid escape sequence", ddbc_error=ddbc_error
285
+ ), # Invalid escape sequence
286
+ "22026": DataError(
287
+ driver_error="String data, length mismatch", ddbc_error=ddbc_error
288
+ ), # String data, length mismatch
289
+ "23000": IntegrityError(
290
+ driver_error="Integrity constraint violation", ddbc_error=ddbc_error
291
+ ), # Integrity constraint violation
292
+ "24000": ProgrammingError(
293
+ driver_error="Invalid cursor state", ddbc_error=ddbc_error
294
+ ), # Invalid cursor state
295
+ "25000": OperationalError(
296
+ driver_error="Invalid transaction state", ddbc_error=ddbc_error
297
+ ), # Invalid transaction state
298
+ "25S01": OperationalError(
299
+ driver_error="Transaction state", ddbc_error=ddbc_error
300
+ ), # Transaction state
301
+ "25S02": OperationalError(
302
+ driver_error="Transaction is still active", ddbc_error=ddbc_error
303
+ ), # Transaction is still active
304
+ "25S03": OperationalError(
305
+ driver_error="Transaction is rolled back", ddbc_error=ddbc_error
306
+ ), # Transaction is rolled back
307
+ "28000": OperationalError(
308
+ driver_error="Invalid authorization specification", ddbc_error=ddbc_error
309
+ ), # Invalid authorization specification
310
+ "34000": ProgrammingError(
311
+ driver_error="Invalid cursor name", ddbc_error=ddbc_error
312
+ ), # Invalid cursor name
313
+ "3C000": ProgrammingError(
314
+ driver_error="Duplicate cursor name", ddbc_error=ddbc_error
315
+ ), # Duplicate cursor name
316
+ "3D000": ProgrammingError(
317
+ driver_error="Invalid catalog name", ddbc_error=ddbc_error
318
+ ), # Invalid catalog name
319
+ "3F000": ProgrammingError(
320
+ driver_error="Invalid schema name", ddbc_error=ddbc_error
321
+ ), # Invalid schema name
322
+ "40001": OperationalError(
323
+ driver_error="Serialization failure", ddbc_error=ddbc_error
324
+ ), # Serialization failure
325
+ "40002": IntegrityError(
326
+ driver_error="Integrity constraint violation", ddbc_error=ddbc_error
327
+ ), # Integrity constraint violation
328
+ "40003": OperationalError(
329
+ driver_error="Statement completion unknown", ddbc_error=ddbc_error
330
+ ), # Statement completion unknown
331
+ "42000": ProgrammingError(
332
+ driver_error="Syntax error or access violation", ddbc_error=ddbc_error
333
+ ), # Syntax error or access violation
334
+ "42S01": ProgrammingError(
335
+ driver_error="Base table or view already exists", ddbc_error=ddbc_error
336
+ ), # Base table or view already exists
337
+ "42S02": ProgrammingError(
338
+ driver_error="Base table or view not found", ddbc_error=ddbc_error
339
+ ), # Base table or view not found
340
+ "42S11": ProgrammingError(
341
+ driver_error="Index already exists", ddbc_error=ddbc_error
342
+ ), # Index already exists
343
+ "42S12": ProgrammingError(
344
+ driver_error="Index not found", ddbc_error=ddbc_error
345
+ ), # Index not found
346
+ "42S21": ProgrammingError(
347
+ driver_error="Column already exists", ddbc_error=ddbc_error
348
+ ), # Column already exists
349
+ "42S22": ProgrammingError(
350
+ driver_error="Column not found", ddbc_error=ddbc_error
351
+ ), # Column not found
352
+ "44000": IntegrityError(
353
+ driver_error="WITH CHECK OPTION violation", ddbc_error=ddbc_error
354
+ ), # WITH CHECK OPTION violation
355
+ "HY000": OperationalError(
356
+ driver_error="General error", ddbc_error=ddbc_error
357
+ ), # General error
358
+ "HY001": OperationalError(
359
+ driver_error="Memory allocation error", ddbc_error=ddbc_error
360
+ ), # Memory allocation error
361
+ "HY003": ProgrammingError(
362
+ driver_error="Invalid application buffer type", ddbc_error=ddbc_error
363
+ ), # Invalid application buffer type
364
+ "HY004": ProgrammingError(
365
+ driver_error="Invalid SQL data type", ddbc_error=ddbc_error
366
+ ), # Invalid SQL data type
367
+ "HY007": ProgrammingError(
368
+ driver_error="Associated statement is not prepared", ddbc_error=ddbc_error
369
+ ), # Associated statement is not prepared
370
+ "HY008": OperationalError(
371
+ driver_error="Operation canceled", ddbc_error=ddbc_error
372
+ ), # Operation canceled
373
+ "HY009": ProgrammingError(
374
+ driver_error="Invalid use of null pointer", ddbc_error=ddbc_error
375
+ ), # Invalid use of null pointer
376
+ "HY010": ProgrammingError(
377
+ driver_error="Function sequence error", ddbc_error=ddbc_error
378
+ ), # Function sequence error
379
+ "HY011": ProgrammingError(
380
+ driver_error="Attribute cannot be set now", ddbc_error=ddbc_error
381
+ ), # Attribute cannot be set now
382
+ "HY012": ProgrammingError(
383
+ driver_error="Invalid transaction operation code", ddbc_error=ddbc_error
384
+ ), # Invalid transaction operation code
385
+ "HY013": OperationalError(
386
+ driver_error="Memory management error", ddbc_error=ddbc_error
387
+ ), # Memory management error
388
+ "HY014": OperationalError(
389
+ driver_error="Limit on the number of handles exceeded",
390
+ ddbc_error=ddbc_error,
391
+ ), # Limit on the number of handles exceeded
392
+ "HY015": ProgrammingError(
393
+ driver_error="No cursor name available", ddbc_error=ddbc_error
394
+ ), # No cursor name available
395
+ "HY016": ProgrammingError(
396
+ driver_error="Cannot modify an implementation row descriptor",
397
+ ddbc_error=ddbc_error,
398
+ ), # Cannot modify an implementation row descriptor
399
+ "HY017": ProgrammingError(
400
+ driver_error="Invalid use of an automatically allocated descriptor handle",
401
+ ddbc_error=ddbc_error,
402
+ ), # Invalid use of an automatically allocated descriptor handle
403
+ "HY018": OperationalError(
404
+ driver_error="Server declined cancel request", ddbc_error=ddbc_error
405
+ ), # Server declined cancel request
406
+ "HY019": DataError(
407
+ driver_error="Non-character and non-binary data sent in pieces",
408
+ ddbc_error=ddbc_error,
409
+ ), # Non-character and non-binary data sent in pieces
410
+ "HY020": DataError(
411
+ driver_error="Attempt to concatenate a null value", ddbc_error=ddbc_error
412
+ ), # Attempt to concatenate a null value
413
+ "HY021": ProgrammingError(
414
+ driver_error="Inconsistent descriptor information", ddbc_error=ddbc_error
415
+ ), # Inconsistent descriptor information
416
+ "HY024": ProgrammingError(
417
+ driver_error="Invalid attribute value", ddbc_error=ddbc_error
418
+ ), # Invalid attribute value
419
+ "HY090": ProgrammingError(
420
+ driver_error="Invalid string or buffer length", ddbc_error=ddbc_error
421
+ ), # Invalid string or buffer length
422
+ "HY091": ProgrammingError(
423
+ driver_error="Invalid descriptor field identifier", ddbc_error=ddbc_error
424
+ ), # Invalid descriptor field identifier
425
+ "HY092": ProgrammingError(
426
+ driver_error="Invalid attribute/option identifier", ddbc_error=ddbc_error
427
+ ), # Invalid attribute/option identifier
428
+ "HY095": ProgrammingError(
429
+ driver_error="Function type out of range", ddbc_error=ddbc_error
430
+ ), # Function type out of range
431
+ "HY096": ProgrammingError(
432
+ driver_error="Invalid information type", ddbc_error=ddbc_error
433
+ ), # Invalid information type
434
+ "HY097": ProgrammingError(
435
+ driver_error="Column type out of range", ddbc_error=ddbc_error
436
+ ), # Column type out of range
437
+ "HY098": ProgrammingError(
438
+ driver_error="Scope type out of range", ddbc_error=ddbc_error
439
+ ), # Scope type out of range
440
+ "HY099": ProgrammingError(
441
+ driver_error="Nullable type out of range", ddbc_error=ddbc_error
442
+ ), # Nullable type out of range
443
+ "HY100": ProgrammingError(
444
+ driver_error="Uniqueness option type out of range", ddbc_error=ddbc_error
445
+ ), # Uniqueness option type out of range
446
+ "HY101": ProgrammingError(
447
+ driver_error="Accuracy option type out of range", ddbc_error=ddbc_error
448
+ ), # Accuracy option type out of range
449
+ "HY103": ProgrammingError(
450
+ driver_error="Invalid retrieval code", ddbc_error=ddbc_error
451
+ ), # Invalid retrieval code
452
+ "HY104": ProgrammingError(
453
+ driver_error="Invalid precision or scale value", ddbc_error=ddbc_error
454
+ ), # Invalid precision or scale value
455
+ "HY105": ProgrammingError(
456
+ driver_error="Invalid parameter type", ddbc_error=ddbc_error
457
+ ), # Invalid parameter type
458
+ "HY106": ProgrammingError(
459
+ driver_error="Fetch type out of range", ddbc_error=ddbc_error
460
+ ), # Fetch type out of range
461
+ "HY107": ProgrammingError(
462
+ driver_error="Row value out of range", ddbc_error=ddbc_error
463
+ ), # Row value out of range
464
+ "HY109": ProgrammingError(
465
+ driver_error="Invalid cursor position", ddbc_error=ddbc_error
466
+ ), # Invalid cursor position
467
+ "HY110": ProgrammingError(
468
+ driver_error="Invalid driver completion", ddbc_error=ddbc_error
469
+ ), # Invalid driver completion
470
+ "HY111": ProgrammingError(
471
+ driver_error="Invalid bookmark value", ddbc_error=ddbc_error
472
+ ), # Invalid bookmark value
473
+ "HYC00": NotSupportedError(
474
+ driver_error="Optional feature not implemented", ddbc_error=ddbc_error
475
+ ), # Optional feature not implemented
476
+ "HYT00": OperationalError(
477
+ driver_error="Timeout expired", ddbc_error=ddbc_error
478
+ ), # Timeout expired
479
+ "HYT01": OperationalError(
480
+ driver_error="Connection timeout expired", ddbc_error=ddbc_error
481
+ ), # Connection timeout expired
482
+ "IM001": NotSupportedError(
483
+ driver_error="Driver does not support this function", ddbc_error=ddbc_error
484
+ ), # Driver does not support this function
485
+ "IM002": OperationalError(
486
+ driver_error="Data source name not found and no default driver specified",
487
+ ddbc_error=ddbc_error,
488
+ ), # Data source name not found and no default driver specified
489
+ "IM003": OperationalError(
490
+ driver_error="Specified driver could not be loaded", ddbc_error=ddbc_error
491
+ ), # Specified driver could not be loaded
492
+ "IM004": OperationalError(
493
+ driver_error="Driver's SQLAllocHandle on SQL_HANDLE_ENV failed",
494
+ ddbc_error=ddbc_error,
495
+ ), # Driver's SQLAllocHandle on SQL_HANDLE_ENV failed
496
+ "IM005": OperationalError(
497
+ driver_error="Driver's SQLAllocHandle on SQL_HANDLE_DBC failed",
498
+ ddbc_error=ddbc_error,
499
+ ), # Driver's SQLAllocHandle on SQL_HANDLE_DBC failed
500
+ "IM006": OperationalError(
501
+ driver_error="Driver's SQLSetConnectAttr failed", ddbc_error=ddbc_error
502
+ ), # Driver's SQLSetConnectAttr failed
503
+ "IM007": OperationalError(
504
+ driver_error="No data source or driver specified; dialog prohibited",
505
+ ddbc_error=ddbc_error,
506
+ ), # No data source or driver specified; dialog prohibited
507
+ "IM008": OperationalError(
508
+ driver_error="Dialog failed", ddbc_error=ddbc_error
509
+ ), # Dialog failed
510
+ "IM009": OperationalError(
511
+ driver_error="Unable to load translation DLL", ddbc_error=ddbc_error
512
+ ), # Unable to load translation DLL
513
+ "IM010": OperationalError(
514
+ driver_error="Data source name too long", ddbc_error=ddbc_error
515
+ ), # Data source name too long
516
+ "IM011": OperationalError(
517
+ driver_error="Driver name too long", ddbc_error=ddbc_error
518
+ ), # Driver name too long
519
+ "IM012": OperationalError(
520
+ driver_error="DRIVER keyword syntax error", ddbc_error=ddbc_error
521
+ ), # DRIVER keyword syntax error
522
+ "IM013": OperationalError(
523
+ driver_error="Trace file error", ddbc_error=ddbc_error
524
+ ), # Trace file error
525
+ "IM014": OperationalError(
526
+ driver_error="Invalid name of File DSN", ddbc_error=ddbc_error
527
+ ), # Invalid name of File DSN
528
+ "IM015": OperationalError(
529
+ driver_error="Corrupt file data source", ddbc_error=ddbc_error
530
+ ), # Corrupt file data source
531
+ }
532
+ return mapping.get(sqlstate, None)
533
+
534
+
535
+ def truncate_error_message(error_message: str) -> str:
536
+ """
537
+ - The Driver Error message is the message that is returned by the Internal driver.
538
+ - This section will always be at the start of the message.
539
+ """
540
+ try:
541
+ if not error_message.startswith("[Microsoft]"):
542
+ # The message is not from the driver, so no need to truncate
543
+ return error_message
544
+ string_first = error_message[: error_message.index("]") + 1]
545
+ string_second = error_message[error_message.index("]") + 1 :]
546
+ string_third = string_second[string_second.index("]") + 1 :]
547
+ return string_first + string_third
548
+ except Exception as e:
549
+ logger.warning("Error while truncating error message: %s", e)
550
+ return error_message
551
+
552
+
553
+ def raise_exception(sqlstate: str, ddbc_error: str) -> None:
554
+ """
555
+ Raise a custom exception based on the given SQLSTATE code.
556
+ This function raises a custom exception based on the provided SQLSTATE code.
557
+ If the code is not found in the mapping, a generic DatabaseError is raised.
558
+
559
+ Args:
560
+ sqlstate (str): The SQLSTATE code to map to a custom exception.
561
+ ddbc_error (str): The DDBC error message.
562
+
563
+ Raises:
564
+ DatabaseError: If the SQLSTATE code is not found in the mapping.
565
+ """
566
+ exception_class = sqlstate_to_exception(sqlstate, ddbc_error)
567
+ if exception_class:
568
+ logger.error(f"Raising exception: {exception_class}")
569
+ raise exception_class
570
+ logger.error(f"Unknown SQLSTATE {sqlstate}, raising DatabaseError")
571
+ raise DatabaseError(
572
+ driver_error=f"An error occurred with SQLSTATE code: {sqlstate}",
573
+ ddbc_error=f"{ddbc_error}" if ddbc_error else "Unknown DDBC error",
574
+ )