database-wrapper-mssql 0.2.27__tar.gz → 0.2.31__tar.gz
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.
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/PKG-INFO +2 -2
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/connector.py +52 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql.egg-info/PKG-INFO +2 -2
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql.egg-info/requires.txt +1 -1
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/pyproject.toml +2 -2
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/README.md +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/__init__.py +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/db_wrapper_mssql.py +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/mssql_introspector.py +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/py.typed +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/type_mapping.py +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql.egg-info/SOURCES.txt +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql.egg-info/dependency_links.txt +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql.egg-info/top_level.txt +0 -0
- {database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: database_wrapper_mssql
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.31
|
|
4
4
|
Summary: database_wrapper for Mssql database
|
|
5
5
|
Author-email: Gints Murans <gm@gm.lv>
|
|
6
6
|
License: GNU General Public License v3.0 (GPL-3.0)
|
|
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
|
|
|
32
32
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
33
|
Requires-Python: >=3.8
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
|
-
Requires-Dist: database_wrapper==0.2.
|
|
35
|
+
Requires-Dist: database_wrapper==0.2.31
|
|
36
36
|
Requires-Dist: pymssql>=2.2.10
|
|
37
37
|
Provides-Extra: dev
|
|
38
38
|
Requires-Dist: pyodbc; extra == "dev"
|
{database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/connector.py
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import stat
|
|
1
3
|
from typing import Any, NotRequired, TypedDict, cast
|
|
2
4
|
|
|
3
5
|
from pymssql import Connection as MssqlConnection
|
|
@@ -48,11 +50,25 @@ class Mssql(DatabaseBackend):
|
|
|
48
50
|
connection: MssqlConnection
|
|
49
51
|
cursor: MssqlTypedDictCursor
|
|
50
52
|
|
|
53
|
+
# FDs created by the connection, used to detect leaks from pymssql/FreeTDS
|
|
54
|
+
_connection_fds: set[int]
|
|
55
|
+
|
|
51
56
|
##################
|
|
52
57
|
### Connection ###
|
|
53
58
|
##################
|
|
54
59
|
|
|
60
|
+
def _snapshot_fds(self) -> set[int]:
|
|
61
|
+
"""Snapshot current open file descriptors (Linux only)."""
|
|
62
|
+
try:
|
|
63
|
+
return set(int(fd) for fd in os.listdir("/proc/self/fd"))
|
|
64
|
+
except OSError:
|
|
65
|
+
return set()
|
|
66
|
+
|
|
55
67
|
def open(self) -> None:
|
|
68
|
+
# Free resources
|
|
69
|
+
if hasattr(self, "connection") and self.connection:
|
|
70
|
+
self.close()
|
|
71
|
+
|
|
56
72
|
self.logger.debug("Connecting to DB")
|
|
57
73
|
|
|
58
74
|
# Set defaults
|
|
@@ -65,6 +81,7 @@ class Mssql(DatabaseBackend):
|
|
|
65
81
|
if "kwargs" not in self.config or not self.config["kwargs"]:
|
|
66
82
|
self.config["kwargs"] = {}
|
|
67
83
|
|
|
84
|
+
fds_before = self._snapshot_fds()
|
|
68
85
|
self.connection = MssqlConnect(
|
|
69
86
|
server=self.config["hostname"],
|
|
70
87
|
user=self.config["username"],
|
|
@@ -77,8 +94,43 @@ class Mssql(DatabaseBackend):
|
|
|
77
94
|
login_timeout=self.connection_timeout,
|
|
78
95
|
**self.config["kwargs"],
|
|
79
96
|
)
|
|
97
|
+
self._connection_fds = self._snapshot_fds() - fds_before
|
|
80
98
|
self.cursor = cast(MssqlTypedDictCursor, self.connection.cursor(as_dict=True))
|
|
81
99
|
|
|
100
|
+
def close(self) -> Any:
|
|
101
|
+
"""Close connections, force-closing any FDs leaked by pymssql/FreeTDS."""
|
|
102
|
+
try:
|
|
103
|
+
if self.cursor:
|
|
104
|
+
self.logger.debug("Closing cursor")
|
|
105
|
+
self.cursor.close()
|
|
106
|
+
except Exception as e:
|
|
107
|
+
self.logger.debug(f"Error while closing cursor: {e}")
|
|
108
|
+
finally:
|
|
109
|
+
self.cursor = None
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
if self.connection:
|
|
113
|
+
self.logger.debug("Closing connection")
|
|
114
|
+
self.connection.close()
|
|
115
|
+
except Exception as e:
|
|
116
|
+
self.logger.debug(f"Error while closing connection: {e}")
|
|
117
|
+
finally:
|
|
118
|
+
self.connection = None
|
|
119
|
+
|
|
120
|
+
# Workaround for pymssql/FreeTDS bug: dbclose() on a dead DBPROCESS
|
|
121
|
+
# doesn't release the wakeup eventfd. Force-close any leaked FDs.
|
|
122
|
+
# See: https://github.com/pymssql/pymssql/issues/1002
|
|
123
|
+
if hasattr(self, "_connection_fds"):
|
|
124
|
+
for fd in self._connection_fds:
|
|
125
|
+
try:
|
|
126
|
+
fd_stat = os.fstat(fd)
|
|
127
|
+
if stat.S_ISSOCK(fd_stat.st_mode) or stat.S_ISFIFO(fd_stat.st_mode):
|
|
128
|
+
os.close(fd)
|
|
129
|
+
self.logger.warning(f"Force-closed leaked FD {fd} from pymssql")
|
|
130
|
+
except OSError:
|
|
131
|
+
pass
|
|
132
|
+
self._connection_fds = set()
|
|
133
|
+
|
|
82
134
|
def ping(self) -> bool:
|
|
83
135
|
try:
|
|
84
136
|
self.cursor.execute("SELECT 1")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: database_wrapper_mssql
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.31
|
|
4
4
|
Summary: database_wrapper for Mssql database
|
|
5
5
|
Author-email: Gints Murans <gm@gm.lv>
|
|
6
6
|
License: GNU General Public License v3.0 (GPL-3.0)
|
|
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
|
|
|
32
32
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
33
|
Requires-Python: >=3.8
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
|
-
Requires-Dist: database_wrapper==0.2.
|
|
35
|
+
Requires-Dist: database_wrapper==0.2.31
|
|
36
36
|
Requires-Dist: pymssql>=2.2.10
|
|
37
37
|
Provides-Extra: dev
|
|
38
38
|
Requires-Dist: pyodbc; extra == "dev"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "database_wrapper_mssql"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.31"
|
|
8
8
|
description = "database_wrapper for Mssql database"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -32,7 +32,7 @@ classifiers = [
|
|
|
32
32
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
33
|
]
|
|
34
34
|
keywords = ["database", "wrapper", "python", "mssql", "sqlserver"]
|
|
35
|
-
dependencies = ["database_wrapper == 0.2.
|
|
35
|
+
dependencies = ["database_wrapper == 0.2.31", "pymssql >= 2.2.10"]
|
|
36
36
|
|
|
37
37
|
[project.urls]
|
|
38
38
|
Homepage = "https://github.com/gintsmurans/py_database_wrapper"
|
|
File without changes
|
{database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{database_wrapper_mssql-0.2.27 → database_wrapper_mssql-0.2.31}/database_wrapper_mssql/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|