Returning query on SQLite db from python function
-
I built a python class which binds all functions of a SQLite3 db using QSqlDatabase, QSqlQuery from PyQt5. I would need to return from the 'read' method of this class a query object resulting from QSQlQuery.exec method but I'm not able to get it.
Do you have any idea how to do it ? Thanks
-
I built a python class which binds all functions of a SQLite3 db using QSqlDatabase, QSqlQuery from PyQt5. I would need to return from the 'read' method of this class a query object resulting from QSQlQuery.exec method but I'm not able to get it.
Do you have any idea how to do it ? Thanks
@Achab61 What is the problem?
QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) VALUES (?, ?, ?)"); query.addBindValue(1001); query.addBindValue("Bart"); query.addBindValue("Simpson"); query.exec(); return query; -
It works, thanks. Just another, maybe, stupid question: in the same class there are also methods to update db (insert, update, delete). Which is the best way to returning the result of such methods to the program issuing the method ? In other words, I would need to return (e.g.) the result of the "insert" method of the class. Which is the correct way of doing it ?
-
It works, thanks. Just another, maybe, stupid question: in the same class there are also methods to update db (insert, update, delete). Which is the best way to returning the result of such methods to the program issuing the method ? In other words, I would need to return (e.g.) the result of the "insert" method of the class. Which is the correct way of doing it ?
@Achab61 said in Returning query on SQLite db from python function:
result of the "insert" method
What would it be in your case? Success/Failure?
-
Hi,
The exec method returns a Boolean value to indicate the success or failure of the call.