[Interest] Sqlite "multithreaded" application

Michele Ciampichetti cia.michele at gmail.com
Wed Oct 26 10:07:03 CEST 2011


GoodMorning to everybody.
I've a problem with QSqlite driver: I create an application that use an
SQLite DB by mean of QSqlite Driver. Now. I'd like to makfore it a Network
application, in which some user access the same DB from different instances
of this application on different machines.
I tryed it but, the concurrent access to QSqlite create some mistake.

This use is possible? Which is the best approach for this? I see that
Sqlite3 permit the serialization or multithread approach, how can I activate
this on my driver?

There are other DBMS that create an unique file for a DB (an support View
and Triggers) and can be access by QT?

I attach a peace of my code that create the connection to the db.

#ifndef CONNESSIONE_H

#define CONNESSIONE_H

#endif // CONNESSIONE_H

#include <QSqlDatabase>

#include <QMessageBox>

#include <QPluginLoader>

#include <QSqlDriverPlugin>

static bool createDbConnection(){

    QPluginLoader loader("qsqlite4.dll");

    QObject *plugin = loader.instance();

    if (!plugin)

        return false;

    QSqlDriverPlugin *sqlPlugin  = qobject_cast<QSqlDriverPlugin *>(plugin);

    if (!sqlPlugin ) {

        QMessageBox::warning(0, "SQL plugin", "Loading failed",
QMessageBox::Ok);

        return false;

    }

    QSqlDatabase db = QSqlDatabase::addDatabase(sqlPlugin->create("QSQLITE"));

    //QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE"); //per uso locale

    db.setDatabaseName("X:/FUSERA/RTCoppe/RTCoppe.s3db");

    //QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

    //db.setDatabaseName("CnDBTest");

    if (!db.open()) {

        QMessageBox::critical(0, qApp->tr("Impossibile aprire il
database"), qApp->tr("Errore di connessione al database.\nControllare
la presenza di un file .s3db valido nella cartella del programma"),
QMessageBox::Cancel);

        return false;

    }

    return true;

}


My method use the plugin Approach to port the QSqlite4.dll out of QT path:
the machine in which I install my application haven't got the QT Sdk
installed, and if I use your sugger, I've an error because the usual QT path
for sqldrivers not exist! (Qt/4.7.2/plugins/sqldrivers ecc...)
So I must use the plugin approach to "connect" the Qsqlite4.dll library to
the rest of executable.

Also If I don't use thread, I could have concurrent access to database,
because, the same application is runned by different PC that all connect to
the same database stored in a network device.

Thanks for your time!

Michele
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20111026/5890556a/attachment.html>


More information about the Interest mailing list