[Qt-interest] Formatting Boolean values for databases

Andre Somers andre at familiesomers.nl
Sun May 29 13:22:33 CEST 2011


Op 29-5-2011 12:58, Robert Hairgrove schreef:
> 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".
Note that that is only the base implementation. Every concrete driver 
can reimplement this method if needed. I never had any issues storing a 
boolean in an Access database using Qt.

André



More information about the Qt-interest-old mailing list