arrowsql 0.1.0__cp310-cp310-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 (45) hide show
  1. arrowsql/__init__.py +653 -0
  2. arrowsql/_rust_auth.py +170 -0
  3. arrowsql/_server_sqlstate.py +11 -0
  4. arrowsql/_utf8_strings.py +78 -0
  5. arrowsql/agent.py +620 -0
  6. arrowsql/aio.py +533 -0
  7. arrowsql/arrow_parallel.py +464 -0
  8. arrowsql/async_query/__init__.py +40 -0
  9. arrowsql/async_query/_connection_context.py +39 -0
  10. arrowsql/async_query/_native.py +24 -0
  11. arrowsql/async_query/async_connection.py +160 -0
  12. arrowsql/async_query/async_cursor.py +225 -0
  13. arrowsql/async_query/async_execute.py +113 -0
  14. arrowsql/async_query/async_fetch.py +153 -0
  15. arrowsql/async_query/exception_translator.py +132 -0
  16. arrowsql/auth.py +913 -0
  17. arrowsql/bulk_parallel.py +385 -0
  18. arrowsql/connection.py +2377 -0
  19. arrowsql/connection_string_builder.py +114 -0
  20. arrowsql/connection_string_parser.py +417 -0
  21. arrowsql/constants.py +701 -0
  22. arrowsql/cursor.py +4516 -0
  23. arrowsql/db_connection.py +98 -0
  24. arrowsql/ddbc_bindings.cp310-win_amd64.pyd +0 -0
  25. arrowsql/ddbc_bindings.pyi +283 -0
  26. arrowsql/decimal_config.py +98 -0
  27. arrowsql/exceptions.py +378 -0
  28. arrowsql/helpers.py +436 -0
  29. arrowsql/logging.py +700 -0
  30. arrowsql/mssql_python.pyi +579 -0
  31. arrowsql/odbc_provider.py +269 -0
  32. arrowsql/parameter_helper.py +442 -0
  33. arrowsql/perf_timer.py +286 -0
  34. arrowsql/pooling.py +147 -0
  35. arrowsql/py.typed +1 -0
  36. arrowsql/row.py +462 -0
  37. arrowsql/type.py +160 -0
  38. arrowsql-0.1.0.dist-info/METADATA +146 -0
  39. arrowsql-0.1.0.dist-info/RECORD +45 -0
  40. arrowsql-0.1.0.dist-info/WHEEL +4 -0
  41. arrowsql-0.1.0.dist-info/entry_points.txt +2 -0
  42. arrowsql-0.1.0.dist-info/licenses/LICENSE +21 -0
  43. arrowsql-0.1.0.dist-info/licenses/LICENSE.upstream-mssql-python +47 -0
  44. arrowsql-0.1.0.dist-info/sboms/ddbc_bindings.cyclonedx.json +5195 -0
  45. mssql_python/__init__.py +39 -0
arrowsql/__init__.py ADDED
@@ -0,0 +1,653 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation.
3
+ Licensed under the MIT license.
4
+ This module initializes the mssql_python package.
5
+ """
6
+
7
+ import atexit
8
+ import sys
9
+ import threading
10
+ import types
11
+ import weakref
12
+ from typing import Optional
13
+
14
+ # Import settings from helpers module
15
+ from .helpers import Settings, get_settings, _settings, _settings_lock
16
+
17
+ # Driver version
18
+ __version__ = "1.16.0"
19
+
20
+ # Exceptions
21
+ # https://www.python.org/dev/peps/pep-0249/#exceptions
22
+
23
+ # Import necessary modules
24
+ from .exceptions import (
25
+ Warning,
26
+ Error,
27
+ InterfaceError,
28
+ DatabaseError,
29
+ DataError,
30
+ OperationalError,
31
+ IntegrityError,
32
+ InternalError,
33
+ ProgrammingError,
34
+ NotSupportedError,
35
+ ConnectionStringParseError,
36
+ )
37
+
38
+ # Type Objects
39
+ from .type import (
40
+ Date,
41
+ Time,
42
+ Timestamp,
43
+ DateFromTicks,
44
+ TimeFromTicks,
45
+ TimestampFromTicks,
46
+ Binary,
47
+ STRING,
48
+ BINARY,
49
+ NUMBER,
50
+ DATETIME,
51
+ ROWID,
52
+ )
53
+
54
+ # Connection Objects
55
+ from .db_connection import connect, Connection
56
+
57
+ # Token provider protocol (structural type for the token_provider= parameter)
58
+ from .connection import TokenProvider
59
+
60
+ # Connection String Handling
61
+ from .connection_string_parser import _ConnectionStringParser
62
+ from .connection_string_builder import _ConnectionStringBuilder
63
+
64
+ # Cursor Objects
65
+ from .cursor import Cursor
66
+
67
+ # RUST-PORT: partitioned parallel Arrow reads
68
+ from .arrow_parallel import read_arrow, read_arrow_stream
69
+
70
+ # RUST-PORT: parallel Arrow bulk load into a heap
71
+ from .bulk_parallel import write_arrow, write_rows
72
+
73
+ # Row Objects
74
+ from .row import Row, RowMapping
75
+
76
+ # Logging Configuration (Simplified single-level DEBUG system)
77
+ from .logging import logger, setup_logging, driver_logger
78
+
79
+ # Constants
80
+ from .constants import ConstantsDDBC, GetInfoConstants
81
+
82
+ # Pooling
83
+ from .pooling import PoolingManager
84
+
85
+ # ODBC provider selection
86
+ from .odbc_provider import ProviderManager
87
+
88
+
89
+ def get_native_provider_info() -> dict:
90
+ """Return the selected native provider for diagnostics.
91
+
92
+ Reports the provider ``id``, package ``version``, resolved ``driver_path``,
93
+ the ``package`` that ships its native binaries, selection ``source``, and
94
+ whether the choice is ``frozen`` (loaded and no longer changeable).
95
+ """
96
+ return ProviderManager.get_info()
97
+
98
+
99
+ # Global registry for tracking active connections (using weak references)
100
+ _active_connections = weakref.WeakSet()
101
+ _connections_lock = threading.Lock()
102
+
103
+
104
+ def _register_connection(conn):
105
+ """Register a connection for cleanup before shutdown."""
106
+ with _connections_lock:
107
+ _active_connections.add(conn)
108
+
109
+
110
+ def _cleanup_connections():
111
+ """
112
+ Cleanup function called by atexit to close all active connections.
113
+
114
+ This prevents resource leaks during interpreter shutdown by ensuring
115
+ all ODBC handles are freed in the correct order before Python finalizes.
116
+ """
117
+ # Make a copy of the connections to avoid modification during iteration
118
+ with _connections_lock:
119
+ connections_to_close = list(_active_connections)
120
+
121
+ for conn in connections_to_close:
122
+ try:
123
+ # Check if connection is still valid and not closed
124
+ if hasattr(conn, "_closed") and not conn._closed:
125
+ # Close will handle both cursors and the connection
126
+ conn.close()
127
+ except Exception as e:
128
+ # Log errors during shutdown cleanup for debugging
129
+ # We're prioritizing crash prevention over error propagation
130
+ try:
131
+ driver_logger.error(
132
+ f"Error during connection cleanup at shutdown: {type(e).__name__}: {e}"
133
+ )
134
+ except Exception:
135
+ # If logging fails during shutdown, silently ignore
136
+ pass
137
+
138
+
139
+ # Register cleanup function to run before Python exits
140
+ atexit.register(_cleanup_connections)
141
+
142
+ # GLOBALS
143
+ # Read-Only
144
+ apilevel: str = "2.0"
145
+ paramstyle: str = "pyformat"
146
+ threadsafety: int = 1
147
+
148
+ # Create decimal separator control functions bound to our settings
149
+ from .decimal_config import create_decimal_separator_functions
150
+
151
+ setDecimalSeparator, getDecimalSeparator = create_decimal_separator_functions(_settings)
152
+
153
+ # Import module-level constants from constants module
154
+ from .constants import ( # noqa: F401
155
+ # Enum classes
156
+ AuthType,
157
+ SQLTypes,
158
+ # Helper function
159
+ get_info_constants,
160
+ # SQL Type constants (from ConstantsDDBC)
161
+ SQL_CHAR,
162
+ SQL_VARCHAR,
163
+ SQL_LONGVARCHAR,
164
+ SQL_WCHAR,
165
+ SQL_WVARCHAR,
166
+ SQL_WLONGVARCHAR,
167
+ SQL_DECIMAL,
168
+ SQL_NUMERIC,
169
+ SQL_BIT,
170
+ SQL_TINYINT,
171
+ SQL_SMALLINT,
172
+ SQL_INTEGER,
173
+ SQL_BIGINT,
174
+ SQL_REAL,
175
+ SQL_FLOAT,
176
+ SQL_DOUBLE,
177
+ SQL_BINARY,
178
+ SQL_VARBINARY,
179
+ SQL_LONGVARBINARY,
180
+ SQL_DATE,
181
+ SQL_TIME,
182
+ SQL_TIMESTAMP,
183
+ SQL_TYPE_DATE,
184
+ SQL_TYPE_TIME,
185
+ SQL_TYPE_TIMESTAMP,
186
+ SQL_GUID,
187
+ SQL_XML,
188
+ # SQL Server-specific type constants (pyodbc parity)
189
+ SQL_SS_TIME2,
190
+ SQL_SS_XML,
191
+ SQL_SS_VARIANT,
192
+ # Connection attribute constants
193
+ SQL_ATTR_ACCESS_MODE,
194
+ SQL_ATTR_CONNECTION_TIMEOUT,
195
+ SQL_ATTR_CURRENT_CATALOG,
196
+ SQL_ATTR_LOGIN_TIMEOUT,
197
+ SQL_ATTR_PACKET_SIZE,
198
+ SQL_ATTR_TXN_ISOLATION,
199
+ SQL_TXN_ISOLATION_LEVEL,
200
+ # Legacy statement options
201
+ SQL_ROWSET_SIZE,
202
+ SQL_CONCURRENCY,
203
+ SQL_ROW_NUMBER,
204
+ # Transaction isolation levels
205
+ SQL_TXN_READ_UNCOMMITTED,
206
+ SQL_TXN_READ_COMMITTED,
207
+ SQL_TXN_REPEATABLE_READ,
208
+ SQL_TXN_SERIALIZABLE,
209
+ # Access modes
210
+ SQL_MODE_READ_WRITE,
211
+ SQL_MODE_READ_ONLY,
212
+ # Special constants
213
+ SQL_WMETADATA,
214
+ # GetInfoConstants (all exported as module-level constants)
215
+ SQL_DRIVER_NAME,
216
+ SQL_DRIVER_VER,
217
+ SQL_DRIVER_ODBC_VER,
218
+ SQL_DRIVER_HLIB,
219
+ SQL_DRIVER_HENV,
220
+ SQL_DRIVER_HDBC,
221
+ SQL_DATA_SOURCE_NAME,
222
+ SQL_DATABASE_NAME,
223
+ SQL_SERVER_NAME,
224
+ SQL_USER_NAME,
225
+ SQL_SQL_CONFORMANCE,
226
+ SQL_KEYWORDS,
227
+ SQL_IDENTIFIER_CASE,
228
+ SQL_IDENTIFIER_QUOTE_CHAR,
229
+ SQL_SPECIAL_CHARACTERS,
230
+ SQL_SUBQUERIES,
231
+ SQL_EXPRESSIONS_IN_ORDERBY,
232
+ SQL_CORRELATION_NAME,
233
+ SQL_SEARCH_PATTERN_ESCAPE,
234
+ SQL_CATALOG_TERM,
235
+ SQL_CATALOG_NAME_SEPARATOR,
236
+ SQL_SCHEMA_TERM,
237
+ SQL_TABLE_TERM,
238
+ SQL_PROCEDURES,
239
+ SQL_ACCESSIBLE_TABLES,
240
+ SQL_ACCESSIBLE_PROCEDURES,
241
+ SQL_CATALOG_NAME,
242
+ SQL_CATALOG_USAGE,
243
+ SQL_SCHEMA_USAGE,
244
+ SQL_COLUMN_ALIAS,
245
+ SQL_DESCRIBE_PARAMETER,
246
+ SQL_TXN_CAPABLE,
247
+ SQL_TXN_ISOLATION_OPTION,
248
+ SQL_DEFAULT_TXN_ISOLATION,
249
+ SQL_MULTIPLE_ACTIVE_TXN,
250
+ SQL_NUMERIC_FUNCTIONS,
251
+ SQL_STRING_FUNCTIONS,
252
+ SQL_DATETIME_FUNCTIONS,
253
+ SQL_TIMEDATE_FUNCTIONS,
254
+ SQL_SYSTEM_FUNCTIONS,
255
+ SQL_CONVERT_FUNCTIONS,
256
+ SQL_LIKE_ESCAPE_CLAUSE,
257
+ SQL_MAX_COLUMN_NAME_LEN,
258
+ SQL_MAX_TABLE_NAME_LEN,
259
+ SQL_MAX_SCHEMA_NAME_LEN,
260
+ SQL_MAX_CATALOG_NAME_LEN,
261
+ SQL_MAX_IDENTIFIER_LEN,
262
+ SQL_MAX_STATEMENT_LEN,
263
+ SQL_MAX_CHAR_LITERAL_LEN,
264
+ SQL_MAX_BINARY_LITERAL_LEN,
265
+ SQL_MAX_COLUMNS_IN_TABLE,
266
+ SQL_MAX_COLUMNS_IN_SELECT,
267
+ SQL_MAX_COLUMNS_IN_GROUP_BY,
268
+ SQL_MAX_COLUMNS_IN_ORDER_BY,
269
+ SQL_MAX_COLUMNS_IN_INDEX,
270
+ SQL_MAX_TABLES_IN_SELECT,
271
+ SQL_MAX_CONCURRENT_ACTIVITIES,
272
+ SQL_MAX_DRIVER_CONNECTIONS,
273
+ SQL_MAX_ROW_SIZE,
274
+ SQL_MAX_USER_NAME_LEN,
275
+ SQL_ACTIVE_CONNECTIONS,
276
+ SQL_ACTIVE_STATEMENTS,
277
+ SQL_DATA_SOURCE_READ_ONLY,
278
+ SQL_NEED_LONG_DATA_LEN,
279
+ SQL_GETDATA_EXTENSIONS,
280
+ SQL_CURSOR_COMMIT_BEHAVIOR,
281
+ SQL_CURSOR_ROLLBACK_BEHAVIOR,
282
+ SQL_CURSOR_SENSITIVITY,
283
+ SQL_BOOKMARK_PERSISTENCE,
284
+ SQL_DYNAMIC_CURSOR_ATTRIBUTES1,
285
+ SQL_DYNAMIC_CURSOR_ATTRIBUTES2,
286
+ SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1,
287
+ SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2,
288
+ SQL_STATIC_CURSOR_ATTRIBUTES1,
289
+ SQL_STATIC_CURSOR_ATTRIBUTES2,
290
+ SQL_KEYSET_CURSOR_ATTRIBUTES1,
291
+ SQL_KEYSET_CURSOR_ATTRIBUTES2,
292
+ SQL_SCROLL_OPTIONS,
293
+ SQL_SCROLL_CONCURRENCY,
294
+ SQL_FETCH_DIRECTION,
295
+ SQL_STATIC_SENSITIVITY,
296
+ SQL_BATCH_SUPPORT,
297
+ SQL_BATCH_ROW_COUNT,
298
+ SQL_PARAM_ARRAY_ROW_COUNTS,
299
+ SQL_PARAM_ARRAY_SELECTS,
300
+ SQL_PROCEDURE_TERM,
301
+ SQL_POSITIONED_STATEMENTS,
302
+ SQL_GROUP_BY,
303
+ SQL_OJ_CAPABILITIES,
304
+ SQL_ORDER_BY_COLUMNS_IN_SELECT,
305
+ SQL_OUTER_JOINS,
306
+ SQL_QUOTED_IDENTIFIER_CASE,
307
+ SQL_CONCAT_NULL_BEHAVIOR,
308
+ SQL_NULL_COLLATION,
309
+ SQL_ALTER_TABLE,
310
+ SQL_UNION,
311
+ SQL_DDL_INDEX,
312
+ SQL_MULT_RESULT_SETS,
313
+ SQL_OWNER_USAGE,
314
+ SQL_QUALIFIER_USAGE,
315
+ SQL_TIMEDATE_ADD_INTERVALS,
316
+ SQL_TIMEDATE_DIFF_INTERVALS,
317
+ # SQLGetInfo return values (not information types)
318
+ SQL_IC_UPPER,
319
+ SQL_IC_LOWER,
320
+ SQL_IC_SENSITIVE,
321
+ SQL_IC_MIXED,
322
+ SQL_SC_SQL92_ENTRY,
323
+ SQL_SC_FIPS127_2_TRANSITIONAL,
324
+ SQL_SC_SQL92_INTERMEDIATE,
325
+ SQL_SC_SQL92_FULL,
326
+ # Deprecated legacy values, not SQL conformance flags
327
+ SQL_SQL92_ENTRY_SQL,
328
+ SQL_SQL92_INTERMEDIATE_SQL,
329
+ SQL_SQL92_FULL_SQL,
330
+ )
331
+
332
+ __all__ = [
333
+ # Exception classes
334
+ "Warning",
335
+ "Error",
336
+ "InterfaceError",
337
+ "DatabaseError",
338
+ "DataError",
339
+ "OperationalError",
340
+ "IntegrityError",
341
+ "InternalError",
342
+ "ProgrammingError",
343
+ "NotSupportedError",
344
+ "ConnectionStringParseError",
345
+ # Type objects and functions
346
+ "Date",
347
+ "Time",
348
+ "Timestamp",
349
+ "DateFromTicks",
350
+ "TimeFromTicks",
351
+ "TimestampFromTicks",
352
+ "Binary",
353
+ "STRING",
354
+ "BINARY",
355
+ "NUMBER",
356
+ "DATETIME",
357
+ "ROWID",
358
+ # Connection and cursor classes
359
+ "connect",
360
+ "write_arrow",
361
+ "write_rows",
362
+ "Connection",
363
+ "TokenProvider",
364
+ "Cursor",
365
+ "Row",
366
+ "RowMapping",
367
+ # Settings
368
+ "Settings",
369
+ "get_settings",
370
+ # Logging
371
+ "logger",
372
+ "setup_logging",
373
+ "driver_logger",
374
+ # Decimal functions
375
+ "setDecimalSeparator",
376
+ "getDecimalSeparator",
377
+ # Pooling
378
+ "pooling",
379
+ "PoolingManager",
380
+ # Constants - Enum classes
381
+ "AuthType",
382
+ "SQLTypes",
383
+ "get_info_constants",
384
+ # SQL Type constants
385
+ "SQL_CHAR",
386
+ "SQL_VARCHAR",
387
+ "SQL_LONGVARCHAR",
388
+ "SQL_WCHAR",
389
+ "SQL_WVARCHAR",
390
+ "SQL_WLONGVARCHAR",
391
+ "SQL_DECIMAL",
392
+ "SQL_NUMERIC",
393
+ "SQL_BIT",
394
+ "SQL_TINYINT",
395
+ "SQL_SMALLINT",
396
+ "SQL_INTEGER",
397
+ "SQL_BIGINT",
398
+ "SQL_REAL",
399
+ "SQL_FLOAT",
400
+ "SQL_DOUBLE",
401
+ "SQL_BINARY",
402
+ "SQL_VARBINARY",
403
+ "SQL_LONGVARBINARY",
404
+ "SQL_DATE",
405
+ "SQL_TIME",
406
+ "SQL_TIMESTAMP",
407
+ "SQL_TYPE_DATE",
408
+ "SQL_TYPE_TIME",
409
+ "SQL_TYPE_TIMESTAMP",
410
+ "SQL_GUID",
411
+ "SQL_XML",
412
+ # SQL Server-specific type constants (pyodbc parity)
413
+ "SQL_SS_TIME2",
414
+ "SQL_SS_XML",
415
+ "SQL_SS_VARIANT",
416
+ # Connection attribute constants
417
+ "SQL_ATTR_ACCESS_MODE",
418
+ "SQL_ATTR_CONNECTION_TIMEOUT",
419
+ "SQL_ATTR_CURRENT_CATALOG",
420
+ "SQL_ATTR_LOGIN_TIMEOUT",
421
+ "SQL_ATTR_PACKET_SIZE",
422
+ "SQL_ATTR_TXN_ISOLATION",
423
+ "SQL_TXN_ISOLATION_LEVEL",
424
+ # Legacy statement options
425
+ "SQL_ROWSET_SIZE",
426
+ "SQL_CONCURRENCY",
427
+ "SQL_ROW_NUMBER",
428
+ # Transaction isolation levels
429
+ "SQL_TXN_READ_UNCOMMITTED",
430
+ "SQL_TXN_READ_COMMITTED",
431
+ "SQL_TXN_REPEATABLE_READ",
432
+ "SQL_TXN_SERIALIZABLE",
433
+ # Access modes
434
+ "SQL_MODE_READ_WRITE",
435
+ "SQL_MODE_READ_ONLY",
436
+ # Special constants
437
+ "SQL_WMETADATA",
438
+ # GetInfo constants
439
+ "SQL_DRIVER_NAME",
440
+ "SQL_DRIVER_VER",
441
+ "SQL_DRIVER_ODBC_VER",
442
+ "SQL_DRIVER_HLIB",
443
+ "SQL_DRIVER_HENV",
444
+ "SQL_DRIVER_HDBC",
445
+ "SQL_DATA_SOURCE_NAME",
446
+ "SQL_DATABASE_NAME",
447
+ "SQL_SERVER_NAME",
448
+ "SQL_USER_NAME",
449
+ "SQL_SQL_CONFORMANCE",
450
+ "SQL_KEYWORDS",
451
+ "SQL_IDENTIFIER_CASE",
452
+ "SQL_IDENTIFIER_QUOTE_CHAR",
453
+ "SQL_SPECIAL_CHARACTERS",
454
+ "SQL_SUBQUERIES",
455
+ "SQL_EXPRESSIONS_IN_ORDERBY",
456
+ "SQL_CORRELATION_NAME",
457
+ "SQL_SEARCH_PATTERN_ESCAPE",
458
+ "SQL_CATALOG_TERM",
459
+ "SQL_CATALOG_NAME_SEPARATOR",
460
+ "SQL_SCHEMA_TERM",
461
+ "SQL_TABLE_TERM",
462
+ "SQL_PROCEDURES",
463
+ "SQL_ACCESSIBLE_TABLES",
464
+ "SQL_ACCESSIBLE_PROCEDURES",
465
+ "SQL_CATALOG_NAME",
466
+ "SQL_CATALOG_USAGE",
467
+ "SQL_SCHEMA_USAGE",
468
+ "SQL_COLUMN_ALIAS",
469
+ "SQL_DESCRIBE_PARAMETER",
470
+ "SQL_TXN_CAPABLE",
471
+ "SQL_TXN_ISOLATION_OPTION",
472
+ "SQL_DEFAULT_TXN_ISOLATION",
473
+ "SQL_MULTIPLE_ACTIVE_TXN",
474
+ "SQL_NUMERIC_FUNCTIONS",
475
+ "SQL_STRING_FUNCTIONS",
476
+ "SQL_DATETIME_FUNCTIONS",
477
+ "SQL_TIMEDATE_FUNCTIONS",
478
+ "SQL_SYSTEM_FUNCTIONS",
479
+ "SQL_CONVERT_FUNCTIONS",
480
+ "SQL_LIKE_ESCAPE_CLAUSE",
481
+ "SQL_MAX_COLUMN_NAME_LEN",
482
+ "SQL_MAX_TABLE_NAME_LEN",
483
+ "SQL_MAX_SCHEMA_NAME_LEN",
484
+ "SQL_MAX_CATALOG_NAME_LEN",
485
+ "SQL_MAX_IDENTIFIER_LEN",
486
+ "SQL_MAX_STATEMENT_LEN",
487
+ "SQL_MAX_CHAR_LITERAL_LEN",
488
+ "SQL_MAX_BINARY_LITERAL_LEN",
489
+ "SQL_MAX_COLUMNS_IN_TABLE",
490
+ "SQL_MAX_COLUMNS_IN_SELECT",
491
+ "SQL_MAX_COLUMNS_IN_GROUP_BY",
492
+ "SQL_MAX_COLUMNS_IN_ORDER_BY",
493
+ "SQL_MAX_COLUMNS_IN_INDEX",
494
+ "SQL_MAX_TABLES_IN_SELECT",
495
+ "SQL_MAX_CONCURRENT_ACTIVITIES",
496
+ "SQL_MAX_DRIVER_CONNECTIONS",
497
+ "SQL_MAX_ROW_SIZE",
498
+ "SQL_MAX_USER_NAME_LEN",
499
+ "SQL_ACTIVE_CONNECTIONS",
500
+ "SQL_ACTIVE_STATEMENTS",
501
+ "SQL_DATA_SOURCE_READ_ONLY",
502
+ "SQL_NEED_LONG_DATA_LEN",
503
+ "SQL_GETDATA_EXTENSIONS",
504
+ "SQL_CURSOR_COMMIT_BEHAVIOR",
505
+ "SQL_CURSOR_ROLLBACK_BEHAVIOR",
506
+ "SQL_CURSOR_SENSITIVITY",
507
+ "SQL_BOOKMARK_PERSISTENCE",
508
+ "SQL_DYNAMIC_CURSOR_ATTRIBUTES1",
509
+ "SQL_DYNAMIC_CURSOR_ATTRIBUTES2",
510
+ "SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1",
511
+ "SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2",
512
+ "SQL_STATIC_CURSOR_ATTRIBUTES1",
513
+ "SQL_STATIC_CURSOR_ATTRIBUTES2",
514
+ "SQL_KEYSET_CURSOR_ATTRIBUTES1",
515
+ "SQL_KEYSET_CURSOR_ATTRIBUTES2",
516
+ "SQL_SCROLL_OPTIONS",
517
+ "SQL_SCROLL_CONCURRENCY",
518
+ "SQL_FETCH_DIRECTION",
519
+ "SQL_STATIC_SENSITIVITY",
520
+ "SQL_BATCH_SUPPORT",
521
+ "SQL_BATCH_ROW_COUNT",
522
+ "SQL_PARAM_ARRAY_ROW_COUNTS",
523
+ "SQL_PARAM_ARRAY_SELECTS",
524
+ "SQL_PROCEDURE_TERM",
525
+ "SQL_POSITIONED_STATEMENTS",
526
+ "SQL_GROUP_BY",
527
+ "SQL_OJ_CAPABILITIES",
528
+ "SQL_ORDER_BY_COLUMNS_IN_SELECT",
529
+ "SQL_OUTER_JOINS",
530
+ "SQL_QUOTED_IDENTIFIER_CASE",
531
+ "SQL_CONCAT_NULL_BEHAVIOR",
532
+ "SQL_NULL_COLLATION",
533
+ "SQL_ALTER_TABLE",
534
+ "SQL_UNION",
535
+ "SQL_DDL_INDEX",
536
+ "SQL_MULT_RESULT_SETS",
537
+ "SQL_OWNER_USAGE",
538
+ "SQL_QUALIFIER_USAGE",
539
+ "SQL_TIMEDATE_ADD_INTERVALS",
540
+ "SQL_TIMEDATE_DIFF_INTERVALS",
541
+ # SQLGetInfo return values (not information types)
542
+ "SQL_IC_UPPER",
543
+ "SQL_IC_LOWER",
544
+ "SQL_IC_SENSITIVE",
545
+ "SQL_IC_MIXED",
546
+ "SQL_SC_SQL92_ENTRY",
547
+ "SQL_SC_FIPS127_2_TRANSITIONAL",
548
+ "SQL_SC_SQL92_INTERMEDIATE",
549
+ "SQL_SC_SQL92_FULL",
550
+ # Deprecated legacy values, not SQL conformance flags
551
+ "SQL_SQL92_ENTRY_SQL",
552
+ "SQL_SQL92_INTERMEDIATE_SQL",
553
+ "SQL_SQL92_FULL_SQL",
554
+ # API level globals
555
+ "apilevel",
556
+ "paramstyle",
557
+ "threadsafety",
558
+ # Module properties
559
+ "lowercase",
560
+ "native_uuid",
561
+ "native_provider",
562
+ # Native provider diagnostics
563
+ "get_native_provider_info",
564
+ ]
565
+
566
+
567
+ def pooling(max_size: int = 100, idle_timeout: int = 600, enabled: bool = True) -> None:
568
+ """
569
+ Enable connection pooling with the specified parameters.
570
+ By default:
571
+ - If not explicitly called, pooling will be auto-enabled with default values.
572
+
573
+ Args:
574
+ max_size (int): Maximum number of connections in the pool.
575
+ idle_timeout (int): Time in seconds before idle connections are closed.
576
+ enabled (bool): Whether to enable or disable pooling.
577
+
578
+ Returns:
579
+ None
580
+ """
581
+ if not enabled:
582
+ PoolingManager.disable()
583
+ else:
584
+ PoolingManager.enable(max_size, idle_timeout)
585
+
586
+
587
+ # Create a custom module class that uses properties instead of __setattr__
588
+ class _MSSQLModule(types.ModuleType):
589
+ @property
590
+ def lowercase(self) -> bool:
591
+ """Get the lowercase setting."""
592
+ return _settings.lowercase
593
+
594
+ @lowercase.setter
595
+ def lowercase(self, value: bool) -> None:
596
+ """Set the lowercase setting."""
597
+ if not isinstance(value, bool):
598
+ raise ValueError("lowercase must be a boolean value")
599
+ with _settings_lock:
600
+ _settings.lowercase = value
601
+
602
+ @property
603
+ def native_uuid(self) -> bool:
604
+ """Get the native_uuid setting.
605
+
606
+ Controls whether UNIQUEIDENTIFIER columns return uuid.UUID objects (True)
607
+ or str (False). Default is True.
608
+ Set to False to return str for pyodbc-compatible migration.
609
+ """
610
+ return _settings.native_uuid
611
+
612
+ @native_uuid.setter
613
+ def native_uuid(self, value: bool) -> None:
614
+ """Set the native_uuid setting."""
615
+ if not isinstance(value, bool):
616
+ raise ValueError("native_uuid must be a boolean value")
617
+ with _settings_lock:
618
+ _settings.native_uuid = value
619
+
620
+ @property
621
+ def native_provider(self) -> str:
622
+ """Get the native ODBC provider that will be (or was) loaded.
623
+
624
+ Honored only when set before the first connection; a later change is
625
+ ignored with a warning. The ``MSSQL_PYTHON_NATIVE_PROVIDER`` environment
626
+ variable takes precedence over this property.
627
+ """
628
+ return ProviderManager.effective()
629
+
630
+ @native_provider.setter
631
+ def native_provider(self, value: Optional[str]) -> None:
632
+ """Set the native ODBC provider selection (or None to clear)."""
633
+ ProviderManager.set_property(value)
634
+
635
+
636
+ # Replace the current module with our custom module class
637
+ old_module: types.ModuleType = sys.modules[__name__]
638
+ new_module: _MSSQLModule = _MSSQLModule(__name__)
639
+
640
+ # Copy all existing attributes to the new module
641
+ for attr_name in dir(old_module):
642
+ if attr_name != "__class__":
643
+ try:
644
+ setattr(new_module, attr_name, getattr(old_module, attr_name))
645
+ except AttributeError:
646
+ pass
647
+
648
+ # Replace the module in sys.modules
649
+ sys.modules[__name__] = new_module
650
+
651
+ # Initialize property values
652
+ lowercase: bool = _settings.lowercase
653
+ native_uuid: bool = _settings.native_uuid