I need to write a multithreaded application doing database queries.
At this time I have chosen the following architecture:
// wrapper class that provides programmer with an abstracted functions such as "connect" and "login"
{
// provides programmer with multithreaded connect in "void run ()"
DatabaseQuery
(DatabaseObject
*,
QString query
);
// provides programmer with multithreaded database query in "void run ()"
}
DatabaseTools : public QObject
// wrapper class that provides programmer with an abstracted functions such as "connect" and "login"
{
DatabaseObject : public QThread, public QSqlDatabase
// provides programmer with multithreaded connect in "void run ()"
DatabaseQuery : public QThread, QSqlQuery
DatabaseQuery (DatabaseObject*, QString query);
// provides programmer with multithreaded database query in "void run ()"
}
To copy to clipboard, switch view to plain text mode
When I use connect method of DatabaseTools (opens database connection with multithreaded QSqlDatabase::open in DatabaseObject::run()) everything works great, but when I try to do some multithreaded queries, QSqlQuery's exec() method returns false with a simple query. There is also a problem with last error (displays nothing).
I have read that there are some peculiarities with Qt Sql Module and threads.
Can you advise me a good achitecture of multithreaded database queries?
Added after 8 minutes:
I've been struck with a perfect idea, I can write multithreaded sql qeuries with a database sdk, that means that I can use database sdk in Qt classes. But I have to write another module if I change database from MySQL to PostgreSql, for example.
At the same moment, could you suggest a good architecture in the post above?
Bookmarks