Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore QSqlDatabase.exec deprecated in 6.6 #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading