mssql-python 0.1.6__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.

Potentially problematic release.


This version of mssql-python might be problematic. Click here for more details.

@@ -0,0 +1,38 @@
1
+ """
2
+ Copyright (c) Microsoft Corporation.
3
+ Licensed under the MIT license.
4
+ This module provides a way to create a new connection object to interact with the database.
5
+ """
6
+ from mssql_python.connection import Connection
7
+
8
+
9
+ def connect(connection_str: str = "", autocommit: bool = True, attrs_before: dict = None, **kwargs) -> Connection:
10
+ """
11
+ Constructor for creating a connection to the database.
12
+
13
+ Args:
14
+ connection_str (str): The connection string to connect to.
15
+ autocommit (bool): If True, causes a commit to be performed after each SQL statement.
16
+ TODO: Add the following parameters to the function signature:
17
+ timeout (int): The timeout for the connection attempt, in seconds.
18
+ readonly (bool): If True, the connection is set to read-only.
19
+ attrs_before (dict): A dictionary of connection attributes to set before connecting.
20
+ Keyword Args:
21
+ **kwargs: Additional key/value pairs for the connection string.
22
+ Below attributes are not implemented in the internal driver:
23
+ - encoding (str): The encoding for the connection string.
24
+ - ansi (bool): If True, indicates the driver does not support Unicode.
25
+
26
+ Returns:
27
+ Connection: A new connection object to interact with the database.
28
+
29
+ Raises:
30
+ DatabaseError: If there is an error while trying to connect to the database.
31
+ InterfaceError: If there is an error related to the database interface.
32
+
33
+ This function provides a way to create a new connection object, which can then
34
+ be used to perform database operations such as executing queries, committing
35
+ transactions, and closing the connection.
36
+ """
37
+ conn = Connection(connection_str, autocommit=autocommit, attrs_before=attrs_before, **kwargs)
38
+ return conn
@@ -0,0 +1,38 @@
1
+ import os
2
+ import importlib.util
3
+ import sys
4
+ import platform
5
+
6
+ # Get current Python version and architecture
7
+ python_version = f"cp{sys.version_info.major}{sys.version_info.minor}"
8
+ if platform.machine().lower() in ('amd64', 'x86_64', 'x64'):
9
+ architecture = "amd64"
10
+ elif platform.machine().lower() in ('arm64', 'aarch64'):
11
+ architecture = "arm64"
12
+ else:
13
+ architecture = platform.machine().lower()
14
+
15
+ # Find the specifically matching PYD file
16
+ module_dir = os.path.dirname(__file__)
17
+ expected_pyd = f"ddbc_bindings.{python_version}-{architecture}.pyd"
18
+ pyd_path = os.path.join(module_dir, expected_pyd)
19
+
20
+ if not os.path.exists(pyd_path):
21
+ # Fallback to searching for any matching PYD if the specific one isn't found
22
+ pyd_files = [f for f in os.listdir(module_dir) if f.startswith('ddbc_bindings.') and f.endswith('.pyd')]
23
+ if not pyd_files:
24
+ raise ImportError(f"No ddbc_bindings PYD module found for {python_version}-{architecture}")
25
+ pyd_path = os.path.join(module_dir, pyd_files[0])
26
+ print(f"Warning: Using fallback PYD file {pyd_files[0]} instead of {expected_pyd}")
27
+
28
+ # Use the original module name 'ddbc_bindings' that the C extension was compiled with
29
+ name = "ddbc_bindings"
30
+ spec = importlib.util.spec_from_file_location(name, pyd_path)
31
+ module = importlib.util.module_from_spec(spec)
32
+ sys.modules[name] = module
33
+ spec.loader.exec_module(module)
34
+
35
+ # Copy all attributes from the loaded module to this module
36
+ for attr in dir(module):
37
+ if not attr.startswith('__'):
38
+ globals()[attr] = getattr(module, attr)