QSqlQuery memory leak when INSERT



  • I use postgres DB to log some actions in my system. I use QSqlQuery to make inserts. But when I run my program till the long period of time I see that my program eats lot of RAM. I use 32-bit OS Windows, but the same situation is on Linux.



  • Hi,
    Before complaining, post your code, there might be a memory leak in your code! Qt is properly tested, but off course bugs might exist.



  • Here the method wich I call every time when need to write some data to DB. m_query is a mebber of class. @void LogRunnable::dbInsert(const sxProperties & cmd, const QVariant & parent, int type) {

    QSqlDatabase db = QSqlDatabase::database(sxDB::connection::connectionName);
    if (db.isOpen() == false) {
    printToConsole("Database is not opened...");
    if (false == checkDb(db)) {
    return;
    }
    }
    int nextCommandId = getNextIdList();

    // adding command to db
    QString newQueryStr;
    const QString dateTime = QDateTime::currentDateTime().toString(TimeTemplate::dateTime);
    if (0 != parent) {
    newQueryStr = QString("insert into %1( %2, %3, %4, %5, ) values (%6, '%7','%8', '%9', ''); ")
    .arg(sxDB::table::cmd_list)
    .arg(sxDB::cmd_list::CMD_ID)
    .arg(sxDB::cmd_list::CMD_TIME)
    .arg(sxDB::cmd_list::CMD_TYPE)
    .arg(sxDB::cmd_list::CMD_PARENT)
    .arg(nextCommandId)
    .arg(dateTime)
    .arg(type)
    .arg(parent.toString())
    .arg(sxDB::cmd_list::CMD_COMMAND)
    .arg(cmd.collectCommand());
    }
    else {
    newQueryStr = QString("insert into %1( %2, %3, %4,%8) values (%5, '%6','%7','%9'); ")
    .arg(sxDB::table::cmd_list)
    .arg(sxDB::cmd_list::CMD_ID)
    .arg(sxDB::cmd_list::CMD_TIME)
    .arg(sxDB::cmd_list::CMD_TYPE)
    .arg(nextCommandId)
    .arg(dateTime)
    .arg(type)
    .arg(sxDB::cmd_list::CMD_COMMAND)
    .arg(cmd.collectCommand());
    }

    db.transaction();
    if (false == m_query.exec(newQueryStr)) {
    printToConsole("Failed to insert argument to argument list: " + db.lastError().text());
    }
    db.commit();
    m_query.finish();
    m_query.clear();
    }@


Log in to reply
 

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