Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, February 2008
psql driver and locale.


Message 1 in thread

Hi.

There is a problem in psql driver. Double numbers are converted from 
strings using strtod function
which is locale dependent. But values returned from postgresql are 
always in C locale.

In QCoreApplicaion::init() was in version 4.3
#ifdef Q_OS_UNIX
   setlocale(LC_ALL, "");                // use correct char set mapping
   setlocale(LC_NUMERIC, "C");        // make sprintf()/scanf() work
#endif

so the numbers where used as in C locale, but in 4.4 snapshot and tp1 it 
is changed to:
#ifdef Q_OS_UNIX
   setlocale(LC_ALL, "");                // use correct char set mapping
#endif


-- 
 [ signature omitted ] 

Message 2 in thread

On Thursday 21 February 2008 10:07:57 Argo Vessmann wrote:
> Hi.
>
> There is a problem in psql driver. Double numbers are converted from
> strings using strtod function
> which is locale dependent. But values returned from postgresql are
> always in C locale.
>
> In QCoreApplicaion::init() was in version 4.3
> #ifdef Q_OS_UNIX
>    setlocale(LC_ALL, "");                // use correct char set mapping
>    setlocale(LC_NUMERIC, "C");        // make sprintf()/scanf() work
> #endif
>
> so the numbers where used as in C locale, but in 4.4 snapshot and tp1 it
> is changed to:
> #ifdef Q_OS_UNIX
>    setlocale(LC_ALL, "");                // use correct char set mapping
> #endif

Indeed. Can you try the attached patch?


-- 
 [ signature omitted ] 
Connected

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

On Thursday 21 February 2008 10:20:21 Thiago Macieira wrote:
> On Thursday 21 February 2008 10:07:57 Argo Vessmann wrote:
> > Hi.
> >
> > There is a problem in psql driver. Double numbers are converted from
> > strings using strtod function
> > which is locale dependent. But values returned from postgresql are
> > always in C locale.
> >
> > In QCoreApplicaion::init() was in version 4.3
> > #ifdef Q_OS_UNIX
> >    setlocale(LC_ALL, "");                // use correct char set mapping
> >    setlocale(LC_NUMERIC, "C");        // make sprintf()/scanf() work
> > #endif
> >
> > so the numbers where used as in C locale, but in 4.4 snapshot and tp1 it
> > is changed to:
> > #ifdef Q_OS_UNIX
> >    setlocale(LC_ALL, "");                // use correct char set mapping
> > #endif
>
> Indeed. Can you try the attached patch?

Let me put my brown paper bag on...

Here's the correct patch.

-- 
 [ signature omitted ] 
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index 81d9f3a..ba2e60a 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -25,13 +25,11 @@
 #include <qsocketnotifier.h>
 #include <qstringlist.h>
 #include <qmutex.h>
+#include <qlocale.h>

 #include <libpq-fe.h>
 #include <pg_config.h>

-#include <stdlib.h>
-#include <math.h>
-
 // workaround for postgres defining their OIDs in a private header file
 #define QBOOLOID 16
 #define QINT8OID 20
@@ -307,7 +305,7 @@ QVariant QPSQLResult::data(int i)
             }
             return QString::fromAscii(val);
         }
-        return strtod(val, 0);
+        return QLocale::c().toDouble(QString::fromLatin1(val), 0);
     case QVariant::Date:
         if (val[0] == '\0') {
             return QVariant(QDate());

Attachment:

Attachment: signature.asc
Description: This is a digitally signed message part.