Qsqlquery: problem with multiple queries at the same time.



  • I wrote some widgets which I instantiate in a main window. Every widget is bound to a database using a class called dbManager, which implements a qtsqldatabse object and some functions to insert into the db tables. The dbManager cass is passed as reference to every widget in order to have a singe database connection. When I'm inserting record into the db (a threaded Class) and I want to browse the tabe content I get this message:

    Unable to free statement: lost synchronization with server: got message type "?", length -33673258

    and the program crash.

    To load data into the db entries browser I use this pattern to update the shown data:

    @ QSqlQuery query;
    query.prepare("SELECT T.content FROM tweet T WHERE T.topic = :topic AND LANGUAGE = :language AND NOT EXISTS (SELECT V.tweet_id FROM voted_tweet V WHERE T.tweet_id = V.tweet_id)");
    query.bindValue(":topic",arg1);
    query.bindValue(":language",ui->langSelector->currentText());
    query.exec();
    queryModelcol->setQuery(query);
    ui->tableView->setModel(queryModelcol);

        //  --- Full Model
        QSqlQuery query2;
        query2.prepare("SELECT * FROM tweet T WHERE T.topic = :topic AND LANGUAGE = :language AND NOT EXISTS (SELECT V.tweet_id FROM voted_tweet V WHERE T.tweet_id = V.tweet_id)");
        query2.bindValue(":topic",arg1);
        query2.bindValue(":language",ui->langSelector->currentText());
        query2.exec();
        queryModelrow->setQuery(query2);@
    

    In the DB manager cass records are inserted in the folowing way:

    @QSqlQuery query;
    query.prepare("INSERT INTO TWITTER_USER (user_id, name, language, img)"
    "VALUES (:user_id, :name, :language, :img)");

    query.bindValue(":user_id", data.at(0).toUtf8().constData());
    query.bindValue(":name", data.at(1).toUtf8().constData());
    query.bindValue(":language", data.at(2).toUtf8().constData());
    query.bindValue(":img", data.at(3).toUtf8().constData());
    if (query.exec() )
        return true;
    else
        return false;@
    

    I'm using PostgreSql with the psql driver on Windows. I tryed to set transactions for every query execution and also to use a single query object with .finish() function, but the result is Always the same.
    Do you have suggestions to find a way to solve the error?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.