[Qt-interest] Formatting Boolean values for databases

Robert Hairgrove evorgriahr at hispeed.ch
Sun May 29 12:58:19 CEST 2011


In the Qt source code for the function QSqlDriver::formatValue(), I
noticed that the default behavior is to translate Boolean values to 1
and 0:

        switch (field.type()) {
        case QVariant::Int:
        case QVariant::UInt:
            if (field.value().type() == QVariant::Bool)
                r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0");
            else
                r = field.value().toString();
            break;

I was wondering why the strings "TRUE" and "FALSE" are not returned
instead? This would work with databases which implement Boolean values
differently -- for example, MS-Access uses -1 and 0, but its SQL engine
still understands the literal strings "TRUE" and "FALSE".




More information about the Qt-interest-old mailing list