80 lines
2.5 KiB
Diff
80 lines
2.5 KiB
Diff
|
From ae51371ebb87f8f4038b0ab3ed5a5402be7610d4 Mon Sep 17 00:00:00 2001
|
||
|
From: StSav012 <stsav012@gmail.com>
|
||
|
Date: Fri, 27 Oct 2023 14:37:26 +0300
|
||
|
Subject: [PATCH] Restore `QSqlDatabase.exec` deprecated in 6.6
|
||
|
|
||
|
---
|
||
|
qtpy/QtSql.py | 49 ++++++++++++++++++++++++++++++++++++-------------
|
||
|
1 file changed, 36 insertions(+), 13 deletions(-)
|
||
|
|
||
|
diff --git a/qtpy/QtSql.py b/qtpy/QtSql.py
|
||
|
index 76a63760..d8e0f2d9 100644
|
||
|
--- a/qtpy/QtSql.py
|
||
|
+++ b/qtpy/QtSql.py
|
||
|
@@ -6,29 +6,52 @@
|
||
|
# -----------------------------------------------------------------------------
|
||
|
|
||
|
"""Provides QtSql classes and functions."""
|
||
|
+from functools import partialmethod
|
||
|
|
||
|
-from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6
|
||
|
+from packaging.version import parse
|
||
|
+
|
||
|
+from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QT_VERSION
|
||
|
|
||
|
if PYQT5:
|
||
|
from PyQt5.QtSql import *
|
||
|
elif PYQT6:
|
||
|
from PyQt6.QtSql import *
|
||
|
|
||
|
- QSqlDatabase.exec_ = lambda self, *args, **kwargs: self.exec(
|
||
|
- *args,
|
||
|
- **kwargs,
|
||
|
- )
|
||
|
- QSqlQuery.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
|
||
|
- QSqlResult.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
|
||
|
+ if parse(QT_VERSION) >= parse("6.6"):
|
||
|
+ # `QSqlDatabase.exec` is deprecated since 6.6
|
||
|
+
|
||
|
+ def database_exec(db, query):
|
||
|
+ q = QSqlQuery(db)
|
||
|
+ q.exec(query)
|
||
|
+ return q
|
||
|
+
|
||
|
+ QSqlDatabase.exec = partialmethod(database_exec)
|
||
|
+ del database_exec
|
||
|
+
|
||
|
+ QSqlDatabase.exec_ = partialmethod(QSqlDatabase.exec)
|
||
|
+ QSqlQuery.exec_ = partialmethod(QSqlQuery.exec)
|
||
|
+ QSqlResult.exec_ = partialmethod(QSqlResult.exec)
|
||
|
elif PYSIDE6:
|
||
|
from PySide6.QtSql import *
|
||
|
|
||
|
+ if parse(QT_VERSION) >= parse("6.6"):
|
||
|
+ # `QSqlDatabase.exec` is deprecated since 6.6
|
||
|
+
|
||
|
+ def database_exec(db, query):
|
||
|
+ q = QSqlQuery(db)
|
||
|
+ q.exec(query)
|
||
|
+ return q
|
||
|
+
|
||
|
+ QSqlDatabase.exec = partialmethod(database_exec)
|
||
|
+ del database_exec
|
||
|
+
|
||
|
# Map DeprecationWarning methods
|
||
|
- QSqlDatabase.exec_ = lambda self, *args, **kwargs: self.exec(
|
||
|
- *args,
|
||
|
- **kwargs,
|
||
|
- )
|
||
|
- QSqlQuery.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
|
||
|
- QSqlResult.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs)
|
||
|
+ QSqlDatabase.exec_ = partialmethod(QSqlDatabase.exec)
|
||
|
+ QSqlQuery.exec_ = partialmethod(QSqlQuery.exec)
|
||
|
+ QSqlResult.exec_ = partialmethod(QSqlResult.exec)
|
||
|
elif PYSIDE2:
|
||
|
from PySide2.QtSql import *
|
||
|
+
|
||
|
+del PYQT5, PYQT6, PYSIDE2, PYSIDE6, QT_VERSION
|
||
|
+del parse
|
||
|
+del partialmethod
|