[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Error using QSqlDatabase.removeDatabase()
From: Sibylle Koczian <nulla.epistola () web ! de>
Date: 2014-02-16 9:38:09
Message-ID: 53008701.1020902 () web ! de
[Download RAW message or body]
Am 15.02.2014 21:39, schrieb michael h:
>
> The docs for removeDatabase mention the potential issue:
>
> The correct way to do it:
>
> {
> QSqlDatabase db = QSqlDatabase::database("sales");
> QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
> }
> // Both "db" and "query" are destroyed because they are out of scope
> QSqlDatabase::removeDatabase("sales"); // correct
>
> How this relates to python may not be obvious if you are not familiar
> with c++. When I added a "del db" (before the removeDatabase call) so
> that QSqlDatabase is collected/destroyed, the error no longer occurred.
>
Thank you. You're right, I didn't know how to translate the C++ code to
Python. And the PySide documentation isn't helpful in this case:
"Example:
# WRONG
db = QSqlDatabase.database("sales")
query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db)
QSqlDatabase.removeDatabase("sales") # will output a warning
# "db" is now a dangling invalid database connection,
# "query" contains an invalid result set
The correct way to do it:
db = QSqlDatabase.database("sales")
query = QSqlQuery("SELECT NAME, DOB FROM EMPLOYEES", db)
# Both "db" and "query" are destroyed because they are out of scope
QSqlDatabase.removeDatabase("sales") # correct
"
No difference at all, db and query _aren't_ destroyed. Didn't think of
"del", which isn't used very often in Python as far as I can see.
Greetings
Sibylle
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic