Skip to content

Commit

Permalink
Restore QSqlDatabase.exec deprecated in 6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
StSav012 committed Oct 27, 2023
1 parent b3b222a commit ae51371
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions qtpy/QtSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ae51371

Please sign in to comment.