spraff
spraff

Reputation: 33395

Am I hitting artificial QSqlDatabase limits?

I have a function which has been working well for ages, which begins

QSqlDatabase
DBUtil :: basic_open (const QString & path)
{
    static int connection_num = 0;
    static const QString CONNECTION_NAME = "Connection%1";

    QSqlDatabase db = QSqlDatabase :: addDatabase (
        "QSQLITE",
        CONNECTION_NAME .arg (connection_num++));

    db .setDatabaseName (path);

    if (false == db .open ())
    {
         // error

I am using this to open and read from many small SQLite databases, each ~200k, and when opening the 1013th one it fails with

 out of memory Error opening database

The total application's memory load is ~200M, with gigabytes free on the machine.

It seems like I'm hitting a limit other than sheer memory. Each QSqlDatabase object goes out of loop scope before the next is created, these databases aren't all existing concurrently, and I can't see any connection limits mentioned in the documentation. So I'm confused.

lsof reports about 200 open file handles before this loop starts and about 1,200 when it finishes, so it looks like Qt is keeping the handles open after ~QSqlDatabase, but still, if that's the limit it seems a bit low.

Any idea what's going on? This is on up-to-date Ubuntu.

Upvotes: 2

Views: 147

Answers (1)

RazrFalcon
RazrFalcon

Reputation: 807

First of all - QSqlDatabase is a singleton, so scope doesn't matter.

Try to close connection before opening new one.

Upvotes: 1

Related Questions