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.
- mssql_python/__init__.py +307 -0
- mssql_python/auth.py +222 -0
- mssql_python/connection.py +1493 -0
- mssql_python/connection_string_builder.py +113 -0
- mssql_python/connection_string_parser.py +381 -0
- mssql_python/constants.py +509 -0
- mssql_python/cursor.py +2601 -0
- mssql_python/db_connection.py +53 -0
- mssql_python/ddbc_bindings.cp314-amd64.pyd +0 -0
- mssql_python/ddbc_bindings.py +137 -0
- mssql_python/exceptions.py +574 -0
- mssql_python/helpers.py +357 -0
- mssql_python/libs/LICENSING +19 -0
- mssql_python/libs/linux/alpine/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/alpine/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/alpine/arm64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/alpine/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/alpine/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/alpine/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/alpine/x86_64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/alpine/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/debian_ubuntu/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/debian_ubuntu/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/debian_ubuntu/arm64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/debian_ubuntu/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/debian_ubuntu/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/debian_ubuntu/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/debian_ubuntu/x86_64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/debian_ubuntu/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/rhel/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/rhel/arm64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/rhel/arm64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/rhel/arm64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/rhel/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/linux/rhel/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/rhel/x86_64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/rhel/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/linux/suse/x86_64/lib/libmsodbcsql-18.5.so.1.1 +0 -0
- mssql_python/libs/linux/suse/x86_64/lib/libodbcinst.so.2 +0 -0
- mssql_python/libs/linux/suse/x86_64/share/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/macos/arm64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/macos/arm64/lib/libltdl.7.dylib +0 -0
- mssql_python/libs/macos/arm64/lib/libmsodbcsql.18.dylib +0 -0
- mssql_python/libs/macos/arm64/lib/libodbc.2.dylib +0 -0
- mssql_python/libs/macos/arm64/lib/libodbcinst.2.dylib +0 -0
- mssql_python/libs/macos/arm64/share/doc/msodbcsql18/LICENSE.txt +101 -0
- mssql_python/libs/macos/arm64/share/doc/msodbcsql18/RELEASE_NOTES +465 -0
- mssql_python/libs/macos/arm64/share/msodbcsql18/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/macos/x86_64/lib/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/macos/x86_64/lib/libltdl.7.dylib +0 -0
- mssql_python/libs/macos/x86_64/lib/libmsodbcsql.18.dylib +0 -0
- mssql_python/libs/macos/x86_64/lib/libodbc.2.dylib +0 -0
- mssql_python/libs/macos/x86_64/lib/libodbcinst.2.dylib +0 -0
- mssql_python/libs/macos/x86_64/share/doc/msodbcsql18/LICENSE.txt +101 -0
- mssql_python/libs/macos/x86_64/share/doc/msodbcsql18/RELEASE_NOTES +465 -0
- mssql_python/libs/macos/x86_64/share/msodbcsql18/resources/en_US/msodbcsqlr18.rll +0 -0
- mssql_python/libs/windows/x64/1033/msodbcsqlr18.rll +0 -0
- mssql_python/libs/windows/x64/MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt +76 -0
- mssql_python/libs/windows/x64/MICROSOFT_VISUAL_STUDIO_LICENSE.txt +54 -0
- mssql_python/libs/windows/x64/msodbcdiag18.dll +0 -0
- mssql_python/libs/windows/x64/msodbcsql18.dll +0 -0
- mssql_python/libs/windows/x64/mssql-auth.dll +0 -0
- mssql_python/logging.py +610 -0
- mssql_python/mssql_python.pyi +375 -0
- mssql_python/msvcp140.dll +0 -0
- mssql_python/pooling.py +125 -0
- mssql_python/row.py +194 -0
- mssql_python/type.py +143 -0
- mssql_python-1.0.0.dist-info/METADATA +76 -0
- mssql_python-1.0.0.dist-info/RECORD +73 -0
- mssql_python-1.0.0.dist-info/WHEEL +5 -0
- mssql_python-1.0.0.dist-info/licenses/LICENSE +47 -0
- mssql_python-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
Licensed under the MIT license.
|
|
4
|
+
Type stubs for mssql_python package - based on actual public API
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List, Optional, Union, Tuple, Sequence, Callable, Iterator
|
|
8
|
+
import datetime
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
# GLOBALS - DB-API 2.0 Required Module Globals
|
|
12
|
+
# https://www.python.org/dev/peps/pep-0249/#module-interface
|
|
13
|
+
apilevel: str # "2.0"
|
|
14
|
+
paramstyle: str # "qmark"
|
|
15
|
+
threadsafety: int # 1
|
|
16
|
+
|
|
17
|
+
# Module Settings - Properties that can be get/set at module level
|
|
18
|
+
lowercase: bool # Controls column name case behavior
|
|
19
|
+
native_uuid: bool # Controls UUID type handling
|
|
20
|
+
|
|
21
|
+
# Settings Class
|
|
22
|
+
class Settings:
|
|
23
|
+
lowercase: bool
|
|
24
|
+
decimal_separator: str
|
|
25
|
+
native_uuid: bool
|
|
26
|
+
def __init__(self) -> None: ...
|
|
27
|
+
|
|
28
|
+
# Module-level Configuration Functions
|
|
29
|
+
def get_settings() -> Settings: ...
|
|
30
|
+
def setDecimalSeparator(separator: str) -> None: ...
|
|
31
|
+
def getDecimalSeparator() -> str: ...
|
|
32
|
+
def pooling(
|
|
33
|
+
max_size: int = 100, idle_timeout: int = 600, enabled: bool = True
|
|
34
|
+
) -> None: ...
|
|
35
|
+
def get_info_constants() -> Dict[str, int]: ...
|
|
36
|
+
|
|
37
|
+
# Logging Functions
|
|
38
|
+
def setup_logging(mode: str = "file", log_level: int = logging.DEBUG) -> None: ...
|
|
39
|
+
def get_logger() -> Optional[logging.Logger]: ...
|
|
40
|
+
|
|
41
|
+
# DB-API 2.0 Type Objects
|
|
42
|
+
# https://www.python.org/dev/peps/pep-0249/#type-objects
|
|
43
|
+
class STRING:
|
|
44
|
+
"""Type object for string-based database columns (e.g. CHAR, VARCHAR)."""
|
|
45
|
+
|
|
46
|
+
...
|
|
47
|
+
|
|
48
|
+
class BINARY:
|
|
49
|
+
"""Type object for binary database columns (e.g. BINARY, VARBINARY)."""
|
|
50
|
+
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
class NUMBER:
|
|
54
|
+
"""Type object for numeric database columns (e.g. INT, DECIMAL)."""
|
|
55
|
+
|
|
56
|
+
...
|
|
57
|
+
|
|
58
|
+
class DATETIME:
|
|
59
|
+
"""Type object for date/time database columns (e.g. DATE, TIMESTAMP)."""
|
|
60
|
+
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
class ROWID:
|
|
64
|
+
"""Type object for row identifier columns."""
|
|
65
|
+
|
|
66
|
+
...
|
|
67
|
+
|
|
68
|
+
# DB-API 2.0 Type Constructors
|
|
69
|
+
# https://www.python.org/dev/peps/pep-0249/#type-constructors
|
|
70
|
+
def Date(year: int, month: int, day: int) -> datetime.date: ...
|
|
71
|
+
def Time(hour: int, minute: int, second: int) -> datetime.time: ...
|
|
72
|
+
def Timestamp(
|
|
73
|
+
year: int,
|
|
74
|
+
month: int,
|
|
75
|
+
day: int,
|
|
76
|
+
hour: int,
|
|
77
|
+
minute: int,
|
|
78
|
+
second: int,
|
|
79
|
+
microsecond: int,
|
|
80
|
+
) -> datetime.datetime: ...
|
|
81
|
+
def DateFromTicks(ticks: int) -> datetime.date: ...
|
|
82
|
+
def TimeFromTicks(ticks: int) -> datetime.time: ...
|
|
83
|
+
def TimestampFromTicks(ticks: int) -> datetime.datetime: ...
|
|
84
|
+
def Binary(value: Union[str, bytes, bytearray]) -> bytes: ...
|
|
85
|
+
|
|
86
|
+
# DB-API 2.0 Exception Hierarchy
|
|
87
|
+
# https://www.python.org/dev/peps/pep-0249/#exceptions
|
|
88
|
+
class Warning(Exception):
|
|
89
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
90
|
+
driver_error: str
|
|
91
|
+
ddbc_error: str
|
|
92
|
+
message: str
|
|
93
|
+
|
|
94
|
+
class Error(Exception):
|
|
95
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
96
|
+
driver_error: str
|
|
97
|
+
ddbc_error: str
|
|
98
|
+
message: str
|
|
99
|
+
|
|
100
|
+
class InterfaceError(Error):
|
|
101
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
102
|
+
|
|
103
|
+
class DatabaseError(Error):
|
|
104
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
105
|
+
|
|
106
|
+
class DataError(DatabaseError):
|
|
107
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
108
|
+
|
|
109
|
+
class OperationalError(DatabaseError):
|
|
110
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
111
|
+
|
|
112
|
+
class IntegrityError(DatabaseError):
|
|
113
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
114
|
+
|
|
115
|
+
class InternalError(DatabaseError):
|
|
116
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
117
|
+
|
|
118
|
+
class ProgrammingError(DatabaseError):
|
|
119
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
120
|
+
|
|
121
|
+
class NotSupportedError(DatabaseError):
|
|
122
|
+
def __init__(self, driver_error: str, ddbc_error: str) -> None: ...
|
|
123
|
+
|
|
124
|
+
# Row Object
|
|
125
|
+
class Row:
|
|
126
|
+
"""
|
|
127
|
+
Represents a database result row.
|
|
128
|
+
|
|
129
|
+
Supports both index-based and name-based column access.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
def __init__(
|
|
133
|
+
self,
|
|
134
|
+
cursor: "Cursor",
|
|
135
|
+
description: List[
|
|
136
|
+
Tuple[
|
|
137
|
+
str,
|
|
138
|
+
Any,
|
|
139
|
+
Optional[int],
|
|
140
|
+
Optional[int],
|
|
141
|
+
Optional[int],
|
|
142
|
+
Optional[int],
|
|
143
|
+
Optional[bool],
|
|
144
|
+
]
|
|
145
|
+
],
|
|
146
|
+
values: List[Any],
|
|
147
|
+
column_map: Optional[Dict[str, int]] = None,
|
|
148
|
+
settings_snapshot: Optional[Dict[str, Any]] = None,
|
|
149
|
+
) -> None: ...
|
|
150
|
+
def __getitem__(self, index: int) -> Any: ...
|
|
151
|
+
def __getattr__(self, name: str) -> Any: ...
|
|
152
|
+
def __eq__(self, other: Any) -> bool: ...
|
|
153
|
+
def __len__(self) -> int: ...
|
|
154
|
+
def __iter__(self) -> Iterator[Any]: ...
|
|
155
|
+
def __str__(self) -> str: ...
|
|
156
|
+
def __repr__(self) -> str: ...
|
|
157
|
+
|
|
158
|
+
# DB-API 2.0 Cursor Object
|
|
159
|
+
# https://www.python.org/dev/peps/pep-0249/#cursor-objects
|
|
160
|
+
class Cursor:
|
|
161
|
+
"""
|
|
162
|
+
Database cursor for executing SQL operations and fetching results.
|
|
163
|
+
|
|
164
|
+
This class should not be instantiated directly. Use Connection.cursor() instead.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
# DB-API 2.0 Required Attributes
|
|
168
|
+
description: Optional[
|
|
169
|
+
List[
|
|
170
|
+
Tuple[
|
|
171
|
+
str,
|
|
172
|
+
Any,
|
|
173
|
+
Optional[int],
|
|
174
|
+
Optional[int],
|
|
175
|
+
Optional[int],
|
|
176
|
+
Optional[int],
|
|
177
|
+
Optional[bool],
|
|
178
|
+
]
|
|
179
|
+
]
|
|
180
|
+
]
|
|
181
|
+
rowcount: int
|
|
182
|
+
arraysize: int
|
|
183
|
+
|
|
184
|
+
# Extension Attributes
|
|
185
|
+
closed: bool
|
|
186
|
+
messages: List[str]
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def rownumber(self) -> int: ...
|
|
190
|
+
@property
|
|
191
|
+
def connection(self) -> "Connection": ...
|
|
192
|
+
def __init__(self, connection: "Connection", timeout: int = 0) -> None: ...
|
|
193
|
+
|
|
194
|
+
# DB-API 2.0 Required Methods
|
|
195
|
+
def callproc(
|
|
196
|
+
self, procname: str, parameters: Optional[Sequence[Any]] = None
|
|
197
|
+
) -> Optional[Sequence[Any]]: ...
|
|
198
|
+
def close(self) -> None: ...
|
|
199
|
+
def execute(
|
|
200
|
+
self,
|
|
201
|
+
operation: str,
|
|
202
|
+
*parameters: Any,
|
|
203
|
+
use_prepare: bool = True,
|
|
204
|
+
reset_cursor: bool = True,
|
|
205
|
+
) -> "Cursor": ...
|
|
206
|
+
def executemany(
|
|
207
|
+
self, operation: str, seq_of_parameters: List[Sequence[Any]]
|
|
208
|
+
) -> None: ...
|
|
209
|
+
def fetchone(self) -> Optional[Row]: ...
|
|
210
|
+
def fetchmany(self, size: Optional[int] = None) -> List[Row]: ...
|
|
211
|
+
def fetchall(self) -> List[Row]: ...
|
|
212
|
+
def nextset(self) -> Optional[bool]: ...
|
|
213
|
+
def setinputsizes(self, sizes: List[Union[int, Tuple[Any, ...]]]) -> None: ...
|
|
214
|
+
def setoutputsize(self, size: int, column: Optional[int] = None) -> None: ...
|
|
215
|
+
|
|
216
|
+
# DB-API 2.0 Connection Object
|
|
217
|
+
# https://www.python.org/dev/peps/pep-0249/#connection-objects
|
|
218
|
+
class Connection:
|
|
219
|
+
"""
|
|
220
|
+
Database connection object.
|
|
221
|
+
|
|
222
|
+
This class should not be instantiated directly. Use the connect() function instead.
|
|
223
|
+
"""
|
|
224
|
+
|
|
225
|
+
# DB-API 2.0 Exception Attributes
|
|
226
|
+
Warning: type[Warning]
|
|
227
|
+
Error: type[Error]
|
|
228
|
+
InterfaceError: type[InterfaceError]
|
|
229
|
+
DatabaseError: type[DatabaseError]
|
|
230
|
+
DataError: type[DataError]
|
|
231
|
+
OperationalError: type[OperationalError]
|
|
232
|
+
IntegrityError: type[IntegrityError]
|
|
233
|
+
InternalError: type[InternalError]
|
|
234
|
+
ProgrammingError: type[ProgrammingError]
|
|
235
|
+
NotSupportedError: type[NotSupportedError]
|
|
236
|
+
|
|
237
|
+
# Connection Properties
|
|
238
|
+
@property
|
|
239
|
+
def timeout(self) -> int: ...
|
|
240
|
+
@timeout.setter
|
|
241
|
+
def timeout(self, value: int) -> None: ...
|
|
242
|
+
@property
|
|
243
|
+
def autocommit(self) -> bool: ...
|
|
244
|
+
@autocommit.setter
|
|
245
|
+
def autocommit(self, value: bool) -> None: ...
|
|
246
|
+
@property
|
|
247
|
+
def searchescape(self) -> str: ...
|
|
248
|
+
def __init__(
|
|
249
|
+
self,
|
|
250
|
+
connection_str: str = "",
|
|
251
|
+
autocommit: bool = False,
|
|
252
|
+
attrs_before: Optional[Dict[int, Union[int, str, bytes]]] = None,
|
|
253
|
+
timeout: int = 0,
|
|
254
|
+
**kwargs: Any,
|
|
255
|
+
) -> None: ...
|
|
256
|
+
|
|
257
|
+
# DB-API 2.0 Required Methods
|
|
258
|
+
def cursor(self) -> Cursor: ...
|
|
259
|
+
def commit(self) -> None: ...
|
|
260
|
+
def rollback(self) -> None: ...
|
|
261
|
+
def close(self) -> None: ...
|
|
262
|
+
|
|
263
|
+
# Extension Methods
|
|
264
|
+
def setautocommit(self, value: bool = False) -> None: ...
|
|
265
|
+
def setencoding(
|
|
266
|
+
self, encoding: Optional[str] = None, ctype: Optional[int] = None
|
|
267
|
+
) -> None: ...
|
|
268
|
+
def getencoding(self) -> Dict[str, Union[str, int]]: ...
|
|
269
|
+
def setdecoding(
|
|
270
|
+
self, sqltype: int, encoding: Optional[str] = None, ctype: Optional[int] = None
|
|
271
|
+
) -> None: ...
|
|
272
|
+
def getdecoding(self, sqltype: int) -> Dict[str, Union[str, int]]: ...
|
|
273
|
+
def set_attr(
|
|
274
|
+
self, attribute: int, value: Union[int, str, bytes, bytearray]
|
|
275
|
+
) -> None: ...
|
|
276
|
+
def add_output_converter(
|
|
277
|
+
self, sqltype: int, func: Callable[[Any], Any]
|
|
278
|
+
) -> None: ...
|
|
279
|
+
def get_output_converter(
|
|
280
|
+
self, sqltype: Union[int, type]
|
|
281
|
+
) -> Optional[Callable[[Any], Any]]: ...
|
|
282
|
+
def remove_output_converter(self, sqltype: Union[int, type]) -> None: ...
|
|
283
|
+
def clear_output_converters(self) -> None: ...
|
|
284
|
+
def execute(self, sql: str, *args: Any) -> Cursor: ...
|
|
285
|
+
def batch_execute(
|
|
286
|
+
self,
|
|
287
|
+
statements: List[str],
|
|
288
|
+
params: Optional[List[Union[None, Any, Tuple[Any, ...], List[Any]]]] = None,
|
|
289
|
+
reuse_cursor: Optional[Cursor] = None,
|
|
290
|
+
auto_close: bool = False,
|
|
291
|
+
) -> Tuple[List[Union[List[Row], int]], Cursor]: ...
|
|
292
|
+
def getinfo(self, info_type: int) -> Union[str, int, bool, None]: ...
|
|
293
|
+
|
|
294
|
+
# Context Manager Support
|
|
295
|
+
def __enter__(self) -> "Connection": ...
|
|
296
|
+
def __exit__(self, *args: Any) -> None: ...
|
|
297
|
+
|
|
298
|
+
# Module Connection Function
|
|
299
|
+
def connect(
|
|
300
|
+
connection_str: str = "",
|
|
301
|
+
autocommit: bool = False,
|
|
302
|
+
attrs_before: Optional[Dict[int, Union[int, str, bytes]]] = None,
|
|
303
|
+
timeout: int = 0,
|
|
304
|
+
**kwargs: Any,
|
|
305
|
+
) -> Connection: ...
|
|
306
|
+
|
|
307
|
+
# SQL Type Constants
|
|
308
|
+
SQL_CHAR: int
|
|
309
|
+
SQL_VARCHAR: int
|
|
310
|
+
SQL_LONGVARCHAR: int
|
|
311
|
+
SQL_WCHAR: int
|
|
312
|
+
SQL_WVARCHAR: int
|
|
313
|
+
SQL_WLONGVARCHAR: int
|
|
314
|
+
SQL_DECIMAL: int
|
|
315
|
+
SQL_NUMERIC: int
|
|
316
|
+
SQL_BIT: int
|
|
317
|
+
SQL_TINYINT: int
|
|
318
|
+
SQL_SMALLINT: int
|
|
319
|
+
SQL_INTEGER: int
|
|
320
|
+
SQL_BIGINT: int
|
|
321
|
+
SQL_REAL: int
|
|
322
|
+
SQL_FLOAT: int
|
|
323
|
+
SQL_DOUBLE: int
|
|
324
|
+
SQL_BINARY: int
|
|
325
|
+
SQL_VARBINARY: int
|
|
326
|
+
SQL_LONGVARBINARY: int
|
|
327
|
+
SQL_DATE: int
|
|
328
|
+
SQL_TIME: int
|
|
329
|
+
SQL_TIMESTAMP: int
|
|
330
|
+
SQL_WMETADATA: int
|
|
331
|
+
|
|
332
|
+
# Connection Attribute Constants
|
|
333
|
+
SQL_ATTR_ACCESS_MODE: int
|
|
334
|
+
SQL_ATTR_CONNECTION_TIMEOUT: int
|
|
335
|
+
SQL_ATTR_CURRENT_CATALOG: int
|
|
336
|
+
SQL_ATTR_LOGIN_TIMEOUT: int
|
|
337
|
+
SQL_ATTR_PACKET_SIZE: int
|
|
338
|
+
SQL_ATTR_TXN_ISOLATION: int
|
|
339
|
+
|
|
340
|
+
# Transaction Isolation Level Constants
|
|
341
|
+
SQL_TXN_READ_UNCOMMITTED: int
|
|
342
|
+
SQL_TXN_READ_COMMITTED: int
|
|
343
|
+
SQL_TXN_REPEATABLE_READ: int
|
|
344
|
+
SQL_TXN_SERIALIZABLE: int
|
|
345
|
+
|
|
346
|
+
# Access Mode Constants
|
|
347
|
+
SQL_MODE_READ_WRITE: int
|
|
348
|
+
SQL_MODE_READ_ONLY: int
|
|
349
|
+
|
|
350
|
+
# GetInfo Constants for Connection.getinfo()
|
|
351
|
+
SQL_DRIVER_NAME: int
|
|
352
|
+
SQL_DRIVER_VER: int
|
|
353
|
+
SQL_DRIVER_ODBC_VER: int
|
|
354
|
+
SQL_DATA_SOURCE_NAME: int
|
|
355
|
+
SQL_DATABASE_NAME: int
|
|
356
|
+
SQL_SERVER_NAME: int
|
|
357
|
+
SQL_USER_NAME: int
|
|
358
|
+
SQL_SQL_CONFORMANCE: int
|
|
359
|
+
SQL_KEYWORDS: int
|
|
360
|
+
SQL_IDENTIFIER_QUOTE_CHAR: int
|
|
361
|
+
SQL_SEARCH_PATTERN_ESCAPE: int
|
|
362
|
+
SQL_CATALOG_TERM: int
|
|
363
|
+
SQL_SCHEMA_TERM: int
|
|
364
|
+
SQL_TABLE_TERM: int
|
|
365
|
+
SQL_PROCEDURE_TERM: int
|
|
366
|
+
SQL_TXN_CAPABLE: int
|
|
367
|
+
SQL_DEFAULT_TXN_ISOLATION: int
|
|
368
|
+
SQL_NUMERIC_FUNCTIONS: int
|
|
369
|
+
SQL_STRING_FUNCTIONS: int
|
|
370
|
+
SQL_DATETIME_FUNCTIONS: int
|
|
371
|
+
SQL_MAX_COLUMN_NAME_LEN: int
|
|
372
|
+
SQL_MAX_TABLE_NAME_LEN: int
|
|
373
|
+
SQL_MAX_SCHEMA_NAME_LEN: int
|
|
374
|
+
SQL_MAX_CATALOG_NAME_LEN: int
|
|
375
|
+
SQL_MAX_IDENTIFIER_LEN: int
|
|
Binary file
|
mssql_python/pooling.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
Licensed under the MIT license.
|
|
4
|
+
This module provides connection pooling functionality for the mssql_python package.
|
|
5
|
+
"""
|
|
6
|
+
import atexit
|
|
7
|
+
import threading
|
|
8
|
+
from typing import Dict
|
|
9
|
+
|
|
10
|
+
from mssql_python import ddbc_bindings
|
|
11
|
+
from mssql_python.logging import logger
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PoolingManager:
|
|
15
|
+
"""
|
|
16
|
+
Manages connection pooling for the mssql_python package.
|
|
17
|
+
|
|
18
|
+
This class provides thread-safe connection pooling functionality using the
|
|
19
|
+
underlying DDBC bindings. It follows a singleton pattern with class-level
|
|
20
|
+
state management.
|
|
21
|
+
"""
|
|
22
|
+
_enabled: bool = False
|
|
23
|
+
_initialized: bool = False
|
|
24
|
+
_pools_closed: bool = False # Track if pools have been closed
|
|
25
|
+
_lock: threading.Lock = threading.Lock()
|
|
26
|
+
_config: Dict[str, int] = {"max_size": 100, "idle_timeout": 600}
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def enable(cls, max_size: int = 100, idle_timeout: int = 600) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Enable connection pooling with specified parameters.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
max_size: Maximum number of connections in the pool (default: 100)
|
|
35
|
+
idle_timeout: Timeout in seconds for idle connections (default: 600)
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
ValueError: If parameters are invalid (max_size <= 0 or idle_timeout < 0)
|
|
39
|
+
"""
|
|
40
|
+
logger.debug('PoolingManager.enable: Attempting to enable pooling - max_size=%d, idle_timeout=%d', max_size, idle_timeout)
|
|
41
|
+
with cls._lock:
|
|
42
|
+
if cls._enabled:
|
|
43
|
+
logger.debug('PoolingManager.enable: Pooling already enabled, skipping')
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
if max_size <= 0 or idle_timeout < 0:
|
|
47
|
+
logger.error('PoolingManager.enable: Invalid parameters - max_size=%d, idle_timeout=%d', max_size, idle_timeout)
|
|
48
|
+
raise ValueError("Invalid pooling parameters")
|
|
49
|
+
|
|
50
|
+
logger.info('PoolingManager.enable: Enabling connection pooling - max_size=%d, idle_timeout=%d seconds', max_size, idle_timeout)
|
|
51
|
+
ddbc_bindings.enable_pooling(max_size, idle_timeout)
|
|
52
|
+
cls._config["max_size"] = max_size
|
|
53
|
+
cls._config["idle_timeout"] = idle_timeout
|
|
54
|
+
cls._enabled = True
|
|
55
|
+
cls._initialized = True
|
|
56
|
+
logger.info('PoolingManager.enable: Connection pooling enabled successfully')
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def disable(cls) -> None:
|
|
60
|
+
"""
|
|
61
|
+
Disable connection pooling and clean up resources.
|
|
62
|
+
|
|
63
|
+
This method safely disables pooling and closes existing connections.
|
|
64
|
+
It can be called multiple times safely.
|
|
65
|
+
"""
|
|
66
|
+
logger.debug('PoolingManager.disable: Attempting to disable pooling')
|
|
67
|
+
with cls._lock:
|
|
68
|
+
if (
|
|
69
|
+
cls._enabled and not cls._pools_closed
|
|
70
|
+
): # Only cleanup if enabled and not already closed
|
|
71
|
+
logger.info('PoolingManager.disable: Closing connection pools')
|
|
72
|
+
ddbc_bindings.close_pooling()
|
|
73
|
+
logger.info('PoolingManager.disable: Connection pools closed successfully')
|
|
74
|
+
else:
|
|
75
|
+
logger.debug('PoolingManager.disable: Pooling already disabled or closed')
|
|
76
|
+
cls._pools_closed = True
|
|
77
|
+
cls._enabled = False
|
|
78
|
+
cls._initialized = True
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def is_enabled(cls) -> bool:
|
|
82
|
+
"""
|
|
83
|
+
Check if connection pooling is currently enabled.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
bool: True if pooling is enabled, False otherwise
|
|
87
|
+
"""
|
|
88
|
+
return cls._enabled
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def is_initialized(cls) -> bool:
|
|
92
|
+
"""
|
|
93
|
+
Check if the pooling manager has been initialized.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
bool: True if initialized (either enabled or disabled), False otherwise
|
|
97
|
+
"""
|
|
98
|
+
return cls._initialized
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def _reset_for_testing(cls) -> None:
|
|
102
|
+
"""Reset pooling state - for testing purposes only"""
|
|
103
|
+
with cls._lock:
|
|
104
|
+
cls._enabled = False
|
|
105
|
+
cls._initialized = False
|
|
106
|
+
cls._pools_closed = False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@atexit.register
|
|
110
|
+
def shutdown_pooling():
|
|
111
|
+
"""
|
|
112
|
+
Shutdown pooling during application exit.
|
|
113
|
+
|
|
114
|
+
This function is registered with atexit to ensure proper cleanup of
|
|
115
|
+
connection pools when the application terminates.
|
|
116
|
+
"""
|
|
117
|
+
logger.debug('shutdown_pooling: atexit cleanup triggered')
|
|
118
|
+
with PoolingManager._lock:
|
|
119
|
+
if PoolingManager._enabled and not PoolingManager._pools_closed:
|
|
120
|
+
logger.info('shutdown_pooling: Closing connection pools during application exit')
|
|
121
|
+
ddbc_bindings.close_pooling()
|
|
122
|
+
PoolingManager._pools_closed = True
|
|
123
|
+
logger.info('shutdown_pooling: Connection pools closed successfully')
|
|
124
|
+
else:
|
|
125
|
+
logger.debug('shutdown_pooling: No active pools to close')
|
mssql_python/row.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
Licensed under the MIT license.
|
|
4
|
+
This module contains the Row class, which represents a single row of data
|
|
5
|
+
from a cursor fetch operation.
|
|
6
|
+
"""
|
|
7
|
+
import decimal
|
|
8
|
+
from typing import Any
|
|
9
|
+
from mssql_python.helpers import get_settings
|
|
10
|
+
from mssql_python.logging import logger
|
|
11
|
+
|
|
12
|
+
class Row:
|
|
13
|
+
"""
|
|
14
|
+
A row of data from a cursor fetch operation. Provides both tuple-like indexing
|
|
15
|
+
and attribute access to column values.
|
|
16
|
+
|
|
17
|
+
Column attribute access behavior depends on the global 'lowercase' setting:
|
|
18
|
+
- When enabled: Case-insensitive attribute access
|
|
19
|
+
- When disabled (default): Case-sensitive attribute access matching original column names
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
row = cursor.fetchone()
|
|
23
|
+
print(row[0]) # Access by index
|
|
24
|
+
print(row.column_name) # Access by column name (case sensitivity varies)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, values, column_map, cursor=None, converter_map=None):
|
|
28
|
+
"""
|
|
29
|
+
Initialize a Row object with values and pre-built column map.
|
|
30
|
+
Args:
|
|
31
|
+
values: List of values for this row
|
|
32
|
+
column_map: Pre-built column name to index mapping (shared across rows)
|
|
33
|
+
cursor: Optional cursor reference (for backward compatibility and lowercase access)
|
|
34
|
+
converter_map: Pre-computed converter map (shared across rows for performance)
|
|
35
|
+
"""
|
|
36
|
+
# Apply output converters if available using pre-computed converter map
|
|
37
|
+
if converter_map:
|
|
38
|
+
self._values = self._apply_output_converters_optimized(values, converter_map)
|
|
39
|
+
elif cursor and hasattr(cursor.connection, '_output_converters') and cursor.connection._output_converters:
|
|
40
|
+
# Fallback to original method for backward compatibility
|
|
41
|
+
self._values = self._apply_output_converters(values, cursor)
|
|
42
|
+
else:
|
|
43
|
+
self._values = values
|
|
44
|
+
|
|
45
|
+
self._column_map = column_map
|
|
46
|
+
self._cursor = cursor
|
|
47
|
+
|
|
48
|
+
def _apply_output_converters(self, values, cursor):
|
|
49
|
+
"""
|
|
50
|
+
Apply output converters to raw values.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
values: Raw values from the database
|
|
54
|
+
cursor: Cursor object with connection and description
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
List of converted values
|
|
58
|
+
"""
|
|
59
|
+
if not cursor.description:
|
|
60
|
+
return values
|
|
61
|
+
|
|
62
|
+
converted_values = list(values)
|
|
63
|
+
|
|
64
|
+
for i, (value, desc) in enumerate(zip(values, cursor.description)):
|
|
65
|
+
if desc is None or value is None:
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
# Get SQL type from description
|
|
69
|
+
sql_type = desc[1] # type_code is at index 1 in description tuple
|
|
70
|
+
|
|
71
|
+
# Try to get a converter for this type
|
|
72
|
+
converter = cursor.connection.get_output_converter(sql_type)
|
|
73
|
+
|
|
74
|
+
# If no converter found for the SQL type but the value is a string or bytes,
|
|
75
|
+
# try the WVARCHAR converter as a fallback
|
|
76
|
+
if converter is None and isinstance(value, (str, bytes)):
|
|
77
|
+
from mssql_python.constants import ConstantsDDBC
|
|
78
|
+
converter = cursor.connection.get_output_converter(ConstantsDDBC.SQL_WVARCHAR.value)
|
|
79
|
+
|
|
80
|
+
# If we found a converter, apply it
|
|
81
|
+
if converter:
|
|
82
|
+
try:
|
|
83
|
+
# If value is already a Python type (str, int, etc.),
|
|
84
|
+
# we need to convert it to bytes for our converters
|
|
85
|
+
if isinstance(value, str):
|
|
86
|
+
# Encode as UTF-16LE for string values (SQL_WVARCHAR format)
|
|
87
|
+
value_bytes = value.encode("utf-16-le")
|
|
88
|
+
converted_values[i] = converter(value_bytes)
|
|
89
|
+
else:
|
|
90
|
+
converted_values[i] = converter(value)
|
|
91
|
+
except Exception:
|
|
92
|
+
logger.debug('Exception occurred in output converter', exc_info=True)
|
|
93
|
+
# If conversion fails, keep the original value
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
return converted_values
|
|
97
|
+
|
|
98
|
+
def _apply_output_converters_optimized(self, values, converter_map):
|
|
99
|
+
"""
|
|
100
|
+
Apply output converters using pre-computed converter map for optimal performance.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
values: Raw values from the database
|
|
104
|
+
converter_map: Pre-computed list of converters (one per column, None if no converter)
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
List of converted values
|
|
108
|
+
"""
|
|
109
|
+
converted_values = list(values)
|
|
110
|
+
|
|
111
|
+
for i, (value, converter) in enumerate(zip(values, converter_map)):
|
|
112
|
+
if converter and value is not None:
|
|
113
|
+
try:
|
|
114
|
+
if isinstance(value, str):
|
|
115
|
+
value_bytes = value.encode('utf-16-le')
|
|
116
|
+
converted_values[i] = converter(value_bytes)
|
|
117
|
+
else:
|
|
118
|
+
converted_values[i] = converter(value)
|
|
119
|
+
except Exception:
|
|
120
|
+
pass
|
|
121
|
+
|
|
122
|
+
return converted_values
|
|
123
|
+
|
|
124
|
+
def __getitem__(self, index: int) -> Any:
|
|
125
|
+
"""Allow accessing by numeric index: row[0]"""
|
|
126
|
+
return self._values[index]
|
|
127
|
+
|
|
128
|
+
def __getattr__(self, name: str) -> Any:
|
|
129
|
+
"""
|
|
130
|
+
Allow accessing by column name as attribute: row.column_name
|
|
131
|
+
|
|
132
|
+
Note: Case sensitivity depends on the global 'lowercase' setting:
|
|
133
|
+
- When lowercase=True: Column names are stored in lowercase, enabling
|
|
134
|
+
case-insensitive attribute access (e.g., row.NAME, row.name, row.Name all work).
|
|
135
|
+
- When lowercase=False (default): Column names preserve original casing,
|
|
136
|
+
requiring exact case matching for attribute access.
|
|
137
|
+
"""
|
|
138
|
+
# Handle lowercase attribute access - if lowercase is enabled,
|
|
139
|
+
# try to match attribute names case-insensitively
|
|
140
|
+
if name in self._column_map:
|
|
141
|
+
return self._values[self._column_map[name]]
|
|
142
|
+
|
|
143
|
+
# If lowercase is enabled on the cursor, try case-insensitive lookup
|
|
144
|
+
if hasattr(self._cursor, 'lowercase') and self._cursor.lowercase:
|
|
145
|
+
name_lower = name.lower()
|
|
146
|
+
for col_name in self._column_map:
|
|
147
|
+
if col_name.lower() == name_lower:
|
|
148
|
+
return self._values[self._column_map[col_name]]
|
|
149
|
+
|
|
150
|
+
raise AttributeError(f"Row has no attribute '{name}'")
|
|
151
|
+
|
|
152
|
+
def __eq__(self, other: Any) -> bool:
|
|
153
|
+
"""
|
|
154
|
+
Support comparison with lists for test compatibility.
|
|
155
|
+
This is the key change needed to fix the tests.
|
|
156
|
+
"""
|
|
157
|
+
if isinstance(other, list):
|
|
158
|
+
return self._values == other
|
|
159
|
+
if isinstance(other, Row):
|
|
160
|
+
return self._values == other._values
|
|
161
|
+
return super().__eq__(other)
|
|
162
|
+
|
|
163
|
+
def __len__(self) -> int:
|
|
164
|
+
"""Return the number of values in the row"""
|
|
165
|
+
return len(self._values)
|
|
166
|
+
|
|
167
|
+
def __iter__(self) -> Any:
|
|
168
|
+
"""Allow iteration through values"""
|
|
169
|
+
return iter(self._values)
|
|
170
|
+
|
|
171
|
+
def __str__(self) -> str:
|
|
172
|
+
"""Return string representation of the row"""
|
|
173
|
+
# Local import to avoid circular dependency
|
|
174
|
+
from mssql_python import getDecimalSeparator
|
|
175
|
+
parts = []
|
|
176
|
+
for value in self:
|
|
177
|
+
if isinstance(value, decimal.Decimal):
|
|
178
|
+
# Apply custom decimal separator for display
|
|
179
|
+
sep = getDecimalSeparator()
|
|
180
|
+
if sep != "." and value is not None:
|
|
181
|
+
s = str(value)
|
|
182
|
+
if "." in s:
|
|
183
|
+
s = s.replace(".", sep)
|
|
184
|
+
parts.append(s)
|
|
185
|
+
else:
|
|
186
|
+
parts.append(str(value))
|
|
187
|
+
else:
|
|
188
|
+
parts.append(repr(value))
|
|
189
|
+
|
|
190
|
+
return "(" + ", ".join(parts) + ")"
|
|
191
|
+
|
|
192
|
+
def __repr__(self) -> str:
|
|
193
|
+
"""Return a detailed string representation for debugging"""
|
|
194
|
+
return repr(tuple(self._values))
|