Question

I want to get the current states of sqlite pragma using Qt's QSqlQuery. But I do not get a result for some values from the program but from sqlite console. Qt version 5.2.1, Sqlite version 3.8.4.3, Windows 7, Ubuntu 12.4 LTS

Output:
application_id = "0"
auto_vacuum = "0"
automatic_index = "1"
busy_timeout = "5000"
cache_size = "2000"
cache_spill = [NoResult]
case_sensitive_like = [NoResult]

void MySqliteInfo::PrintState(QString state)
{
    printf("%s = ", state.toStdString().c_str());
    QSqlQuery query(*m_db);
    query.prepare(QString("PRAGMA %1").arg(state));
    query.exec();

    if(0 == query.size()) {
        printf("%s returns nothing\n", state.toStdString().c_str());
    }
    else {
        if(query.next()) {
            QVariant value = query.value(0);
            if(value.canConvert(QMetaType::QString)) {
                printf("\"%s\"\n", value.toString().toStdString().c_str());
            }
            else {
                printf("[UnknownDataType]\n");
            }
        }
        else {
            printf("[NoResult]\n");
        }
    }
    query.finish();
}

PrintState("application_id");
PrintState("auto_vacuum");
PrintState("automatic_index");
PrintState("busy_timeout");
PrintState("cache_size");
PrintState("cache_spill");
PrintState("case_sensitive_like");
Was it helpful?

Solution

The SQLite version that you are actually using in your Qt program does not yet implement PRAGMA cache_spill.

SQLite just ignores any PRAGMA it does not recognize.

As documented, PRAGMA case_sensitive_like does not allow reading the current value.

OTHER TIPS

First of all, the query.size() test ist useless, since it returns -1 for every value. query.size() can only be used with SELECT queries.

Now [NoResult] can have two different meanings:

  1. A pragma value does not exist
  2. A pragma value is Not Set

In an example database created from another program, I observe the first case for cache_spill and the second case for case_sensitive_like. You might want to check the values using sqliteman on Ubuntu.

I found the solution tt least for cache_spill: The used sqlite3.exe supports pragma cache_spill but not the sqlite version comes with Qt 5.2. (3.7.17).
Qt 5.3 comes with Sqlite 3.8.4.3 - the git repro says this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top