pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedLocale problem with psqlODBC under Fedora 16
5+ messages / 4 participants
[nested] [flat]
* Locale problem with psqlODBC under Fedora 16
@ 2011-11-06 03:49 Zoltan Boszormenyi <zb@cybertec.at>
2011-11-06 08:11 ` Re: Locale problem with psqlODBC under Fedora 16 Boszormenyi Zoltan <zb@cybertec.at>
2011-11-07 23:53 ` Re: Locale problem with psqlODBC under Fedora 16 Inoue, Hiroshi <inoue@tpf.co.jp>
0 siblings, 2 replies; 5+ messages in thread
From: Zoltan Boszormenyi @ 2011-11-06 03:49 UTC (permalink / raw)
To: pgsql-odbc
Hi,
I just installed Fedora 16 and it has PostgreSQL 9.1.1 and
postgresql-odbc-09.00.0200 (which is psqlODBC).
My problem comes from this code:
SQLBindParameter(hStmt,13,
SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_NUMERIC, 0, 0,
(SQLPOINTER)&co2, sizeof(co2), NULL);
New value of "co2" is 99.47 but as my Hungarian locale uses comma
instead of dot for a decimal separator, this pops up:
ERROR: invalid input syntax for type numeric: "99,47" at character 210
STATEMENT: update al set
megr=1,fpont=1478,csopvez=79,datum='2011-09-05'::date,d1='2011-09-04'::date,t1='21:30:00'::time,d2='2011-09-05'::date,t2='03:00:00'::time,temp=113,n_beepites=1,n_sikeres=1,kutfejnyomas='300',co2='99,47',h2sppm=0,hibajel=E''
where id=2805;
With my previous system when this code was used (PostgreSQL 8.2,
psqlodbc-08.02.xxxx era), the above code worked.
convert.c in psqlODBC hasn't changed much with regard to floating point
handling so it still uses setlocale() to switch to "C" locale and I also
recompiled the SRPM for Fedora 16 and config.h indeed contains
"#define HAVE_LOCALE_H 1" so the relevant code with setlocale() gets
compiled in. Still, something broke the locales where something else than
a decimal-dot is used for decimal separator.
Best regards,
Zoltán Böszörményi
--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Locale problem with psqlODBC under Fedora 16
2011-11-06 03:49 Locale problem with psqlODBC under Fedora 16 Zoltan Boszormenyi <zb@cybertec.at>
@ 2011-11-06 08:11 ` Boszormenyi Zoltan <zb@cybertec.at>
1 sibling, 0 replies; 5+ messages in thread
From: Boszormenyi Zoltan @ 2011-11-06 08:11 UTC (permalink / raw)
To: pgsql-odbc
2011-11-06 04:49 keltezéssel, Zoltan Boszormenyi írta:
> Hi,
>
> I just installed Fedora 16 and it has PostgreSQL 9.1.1 and
> postgresql-odbc-09.00.0200 (which is psqlODBC).
>
> My problem comes from this code:
>
> SQLBindParameter(hStmt,13,
> SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_NUMERIC, 0, 0,
> (SQLPOINTER)&co2, sizeof(co2), NULL);
>
> New value of "co2" is 99.47 but as my Hungarian locale uses comma
> instead of dot for a decimal separator, this pops up:
>
> ERROR: invalid input syntax for type numeric: "99,47" at character 210
> STATEMENT: update al set
> megr=1,fpont=1478,csopvez=79,datum='2011-09-05'::date,d1='2011-09-04'::date,t1='21:30:00'::time,d2='2011-09-05'::date,t2='03:00:00'::time,temp=113,n_beepites=1,n_sikeres=1,kutfejnyomas='300',co2='99,47',h2sppm=0,hibajel=E''
> where id=2805;
>
> With my previous system when this code was used (PostgreSQL 8.2,
> psqlodbc-08.02.xxxx era), the above code worked.
>
> convert.c in psqlODBC hasn't changed much with regard to floating point
> handling so it still uses setlocale() to switch to "C" locale and I also
> recompiled the SRPM for Fedora 16 and config.h indeed contains
> "#define HAVE_LOCALE_H 1" so the relevant code with setlocale() gets
> compiled in. Still, something broke the locales where something else than
> a decimal-dot is used for decimal separator.
Same error after I bootstrapped and compiled psqlodbc-09.00.0310 from CVS.
>
> Best regards,
> Zoltán Böszörményi
>
--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Locale problem with psqlODBC under Fedora 16
2011-11-06 03:49 Locale problem with psqlODBC under Fedora 16 Zoltan Boszormenyi <zb@cybertec.at>
@ 2011-11-07 23:53 ` Inoue, Hiroshi <inoue@tpf.co.jp>
2011-11-09 17:57 ` Re: Locale problem with psqlODBC under Fedora 16 Hiroshi Inoue <inoue@tpf.co.jp>
1 sibling, 1 reply; 5+ messages in thread
From: Inoue, Hiroshi @ 2011-11-07 23:53 UTC (permalink / raw)
To: Zoltan Boszormenyi <zb@cybertec.at>; +Cc: pgsql-odbc
Hi Zoltan,
(2011/11/06 12:49), Zoltan Boszormenyi wrote:
> Hi,
>
> I just installed Fedora 16 and it has PostgreSQL 9.1.1 and
> postgresql-odbc-09.00.0200 (which is psqlODBC).
>
> My problem comes from this code:
>
> SQLBindParameter(hStmt,13,
> SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_NUMERIC, 0, 0,
> (SQLPOINTER)&co2, sizeof(co2), NULL);
>
> New value of "co2" is 99.47 but as my Hungarian locale uses comma
> instead of dot for a decimal separator, this pops up:
>
> ERROR: invalid input syntax for type numeric: "99,47" at character 210
> STATEMENT: update al set
> megr=1,fpont=1478,csopvez=79,datum='2011-09-05'::date,d1='2011-09-04'::date,t1='21:30:00'::time,d2='2011-09-05'::date,t2='03:00:00'::time,temp=113,n_beepites=1,n_sikeres=1,kutfejnyomas='300',co2='99,47',h2sppm=0,hibajel=E''
> where id=2805;
OK I would try to fix it.
Please wait for a day or so.
regards,
Inoue, Hiroshi
> With my previous system when this code was used (PostgreSQL 8.2,
> psqlodbc-08.02.xxxx era), the above code worked.
>
> convert.c in psqlODBC hasn't changed much with regard to floating point
> handling so it still uses setlocale() to switch to "C" locale and I also
> recompiled the SRPM for Fedora 16 and config.h indeed contains
> "#define HAVE_LOCALE_H 1" so the relevant code with setlocale() gets
> compiled in. Still, something broke the locales where something else than
> a decimal-dot is used for decimal separator.
>
> Best regards,
> Zoltán Böszörményi
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Locale problem with psqlODBC under Fedora 16
2011-11-06 03:49 Locale problem with psqlODBC under Fedora 16 Zoltan Boszormenyi <zb@cybertec.at>
2011-11-07 23:53 ` Re: Locale problem with psqlODBC under Fedora 16 Inoue, Hiroshi <inoue@tpf.co.jp>
@ 2011-11-09 17:57 ` Hiroshi Inoue <inoue@tpf.co.jp>
2011-11-10 08:41 ` Re: Locale problem with psqlODBC under Fedora 16 Boszormenyi Zoltan <zb@cybertec.at>
0 siblings, 1 reply; 5+ messages in thread
From: Hiroshi Inoue @ 2011-11-09 17:57 UTC (permalink / raw)
To: Zoltan Boszormenyi <zb@cybertec.at>; +Cc: pgsql-odbc
Hi Zoltan,
(2011/11/08 8:53), Inoue, Hiroshi wrote:
> Hi Zoltan,
>
> (2011/11/06 12:49), Zoltan Boszormenyi wrote:
>> Hi,
>>
>> I just installed Fedora 16 and it has PostgreSQL 9.1.1 and
>> postgresql-odbc-09.00.0200 (which is psqlODBC).
>>
>> My problem comes from this code:
>>
>> SQLBindParameter(hStmt,13,
>> SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_NUMERIC, 0, 0,
>> (SQLPOINTER)&co2, sizeof(co2), NULL);
>>
>> New value of "co2" is 99.47 but as my Hungarian locale uses comma
>> instead of dot for a decimal separator, this pops up:
>>
>> ERROR: invalid input syntax for type numeric: "99,47" at character 210
>> STATEMENT: update al set
>> megr=1,fpont=1478,csopvez=79,datum='2011-09-05'::date,d1='2011-09-04'::date,t1='21:30:00'::time,d2='2011-09-05'::date,t2='03:00:00'::time,temp=113,n_beepites=1,n_sikeres=1,kutfejnyomas='300',co2='99,47',h2sppm=0,hibajel=E''
>>
>> where id=2805;
>
> OK I would try to fix it.
> Please wait for a day or so.
Could you please try the attached patch?
regards,
Inoue, Hiroshi
Attachments:
psqlodbc.patch (text/plain, 6.5K) download
diff --git a/convert.c b/convert.c
index c2dbb72..8b62660 100755
--- a/convert.c
+++ b/convert.c
@@ -20,6 +20,7 @@
#include "convert.h"
#ifdef WIN32
#include <float.h>
+#define HAVE_LOCALE_H
#endif /* WIN32 */
#include <stdio.h>
@@ -602,6 +603,63 @@ interval2istruct(SQLSMALLINT ctype, int precision, const char *str, SQL_INTERVAL
#endif /* ODBCVER */
+#ifdef HAVE_LOCALE_H
+static char *current_locale = NULL;
+static char *current_decimal_point = NULL;
+static void current_numeric_locale()
+{
+ char *loc = setlocale(LC_NUMERIC, NULL);
+ if (NULL == current_locale || 0 != stricmp(loc, current_locale))
+ {
+ struct lconv *lc = localeconv();
+
+ if (NULL != current_locale)
+ free(current_locale);
+ current_locale = strdup(loc);
+ if (NULL != current_decimal_point)
+ free(current_decimal_point);
+ current_decimal_point = strdup(lc->decimal_point);
+ }
+}
+
+static void set_server_decimal_point(char *num)
+{
+ char *str;
+
+ current_numeric_locale();
+ if ('.' == *current_decimal_point)
+ return;
+ for (str = num; '\0' != *str; str++)
+ {
+ if (*str == *current_decimal_point)
+ {
+ *str = '.';
+ break;
+ }
+ }
+}
+
+static void set_client_decimal_point(char *num)
+{
+ char *str;
+
+ current_numeric_locale();
+ if ('.' == *current_decimal_point)
+ return;
+ for (str = num; '\0' != *str; str++)
+ {
+ if (*str == '.')
+ {
+ *str = *current_decimal_point;
+ break;
+ }
+ }
+}
+#else
+static void set_server_decimal_point(char *num) {}
+static void set_client_decimal_point(char *num, BOOL) {}
+#endif /* HAVE_LOCALE_H */
+
/* This is called by SQLFetch() */
int
copy_and_convert_field_bindinfo(StatementClass *stmt, OID field_type, int atttypmod, void *value, int col)
@@ -703,9 +761,6 @@ copy_and_convert_field(StatementClass *stmt,
SQLWCHAR *allocbuf = NULL;
ssize_t wstrlen;
#endif /* WIN_UNICODE_SUPPORT */
-#ifdef HAVE_LOCALE_H
- char *saved_locale;
-#endif /* HAVE_LOCALE_H */
#if (ODBCVER >= 0x0350)
SQLGUID g;
#endif
@@ -1149,6 +1204,15 @@ inolog("2stime fr=%d\n", std_time.fr);
* (i.e, 255 = "FF") */
default:
+ switch (field_type)
+ {
+ case PG_TYPE_FLOAT4:
+ case PG_TYPE_FLOAT8:
+ case PG_TYPE_NUMERIC:
+ set_client_decimal_point(neut_str);
+ break;
+ }
+
if (stmt->current_col < 0)
{
pgdc = &(gdata->fdata);
@@ -1296,37 +1360,6 @@ inolog("2stime fr=%d\n", std_time.fr);
copy_len *= WCLEN;
}
#endif /* UNICODE_SUPPORT */
-#ifdef HAVE_LOCALE_H
- switch (field_type)
- {
- case PG_TYPE_FLOAT4:
- case PG_TYPE_FLOAT8:
- case PG_TYPE_NUMERIC:
- {
- struct lconv *lc;
- char *new_string;
- int i, j;
-
- new_string = malloc(cbValueMax);
- lc = localeconv();
- for (i = 0, j = 0; ptr[i]; i++)
- {
- if (ptr[i] == '.')
- {
- strncpy_null(&new_string[j], lc->decimal_point, cbValueMax - j);
- j += strlen(lc->decimal_point);
- }
- else
- new_string[j++] = ptr[i];
- }
- new_string[j] = '\0';
- strncpy_null(rgbValueBindRow, new_string, copy_len + 1);
- free(new_string);
- already_copied = TRUE;
- break;
- }
- }
-#endif /* HAVE_LOCALE_H */
if (!already_copied)
{
/* Copy the data */
@@ -1498,43 +1531,25 @@ inolog("2stime fr=%d\n", std_time.fr);
break;
case SQL_C_FLOAT:
-#ifdef HAVE_LOCALE_H
- saved_locale = strdup(setlocale(LC_ALL, NULL));
- setlocale(LC_ALL, "C");
-#endif /* HAVE_LOCALE_H */
+ set_client_decimal_point(neut_str);
len = 4;
if (bind_size > 0)
*((SFLOAT *) rgbValueBindRow) = (float) get_double_value(neut_str);
else
*((SFLOAT *) rgbValue + bind_row) = (float) get_double_value(neut_str);
-#ifdef HAVE_LOCALE_H
- setlocale(LC_ALL, saved_locale);
- free(saved_locale);
-#endif /* HAVE_LOCALE_H */
break;
case SQL_C_DOUBLE:
-#ifdef HAVE_LOCALE_H
- saved_locale = strdup(setlocale(LC_ALL, NULL));
- setlocale(LC_ALL, "C");
-#endif /* HAVE_LOCALE_H */
+ set_client_decimal_point(neut_str);
len = 8;
if (bind_size > 0)
*((SDOUBLE *) rgbValueBindRow) = get_double_value(neut_str);
else
*((SDOUBLE *) rgbValue + bind_row) = get_double_value(neut_str);
-#ifdef HAVE_LOCALE_H
- setlocale(LC_ALL, saved_locale);
- free(saved_locale);
-#endif /* HAVE_LOCALE_H */
break;
#if (ODBCVER >= 0x0300)
case SQL_C_NUMERIC:
-#ifdef HAVE_LOCALE_H
- /* strcpy(saved_locale, setlocale(LC_ALL, NULL));
- setlocale(LC_ALL, "C"); not needed currently */
-#endif /* HAVE_LOCALE_H */
{
SQL_NUMERIC_STRUCT *ns;
int i, nlen, bit, hval, tv, dig, sta, olen;
@@ -1607,9 +1622,6 @@ inolog("2stime fr=%d\n", std_time.fr);
if (hval && olen < SQL_MAX_NUMERIC_LEN - 1)
ns->val[olen++] = hval;
}
-#ifdef HAVE_LOCALE_H
- /* setlocale(LC_ALL, saved_locale); */
-#endif /* HAVE_LOCALE_H */
break;
#endif /* ODBCVER */
@@ -4159,7 +4171,10 @@ mylog("C_WCHAR=%s(%d)\n", buffer, used);
#ifdef WIN32
if (_finite(dbv))
#endif /* WIN32 */
- sprintf(param_string, "%.15g", dbv);
+ {
+ sprintf(param_string, "%.15g", dbv);
+ set_server_decimal_point(param_string);
+ }
#ifdef WIN32
else if (_isnan(dbv))
strcpy(param_string, NAN_STRING);
@@ -4175,7 +4190,10 @@ mylog("C_WCHAR=%s(%d)\n", buffer, used);
#ifdef WIN32
if (_finite(flv))
#endif /* WIN32 */
- sprintf(param_string, "%.6g", flv);
+ {
+ sprintf(param_string, "%.6g", flv);
+ set_server_decimal_point(param_string);
+ }
#ifdef WIN32
else if (_isnan(flv))
strcpy(param_string, NAN_STRING);
@@ -4433,6 +4451,14 @@ mylog("buf=%p flag=%d\n", buf, qb->flags);
'1' == param_string[1])
strcpy(param_string, "1");
break;
+ case PG_TYPE_FLOAT4:
+ case PG_TYPE_FLOAT8:
+ case PG_TYPE_NUMERIC:
+ if (NULL != buf)
+ set_server_decimal_point(buf);
+ else
+ set_server_decimal_point(param_string);
+ break;
}
/* it was a SQL_C_CHAR */
if (buf)
@@ -4631,6 +4657,7 @@ mylog("buf=%p flag=%d\n", buf, qb->flags);
case SQL_REAL:
if (buf)
my_strcpy(param_string, sizeof(param_string), buf, used);
+ set_server_decimal_point(param_string);
lastadd = "::float4";
CVT_APPEND_STR(qb, param_string);
break;
@@ -4638,6 +4665,7 @@ mylog("buf=%p flag=%d\n", buf, qb->flags);
case SQL_DOUBLE:
if (buf)
my_strcpy(param_string, sizeof(param_string), buf, used);
+ set_server_decimal_point(param_string);
lastadd = "::float8";
CVT_APPEND_STR(qb, param_string);
break;
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Locale problem with psqlODBC under Fedora 16
2011-11-06 03:49 Locale problem with psqlODBC under Fedora 16 Zoltan Boszormenyi <zb@cybertec.at>
2011-11-07 23:53 ` Re: Locale problem with psqlODBC under Fedora 16 Inoue, Hiroshi <inoue@tpf.co.jp>
2011-11-09 17:57 ` Re: Locale problem with psqlODBC under Fedora 16 Hiroshi Inoue <inoue@tpf.co.jp>
@ 2011-11-10 08:41 ` Boszormenyi Zoltan <zb@cybertec.at>
0 siblings, 0 replies; 5+ messages in thread
From: Boszormenyi Zoltan @ 2011-11-10 08:41 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
Hi,
2011-11-09 18:57 keltezéssel, Hiroshi Inoue írta:
> Hi Zoltan,
>
> (2011/11/08 8:53), Inoue, Hiroshi wrote:
>>
>> OK I would try to fix it.
>> Please wait for a day or so.
>
> Could you please try the attached patch?
>
> regards,
> Inoue, Hiroshi
it seems to work for me, thanks. I patched 09.00.311 and
tested it on the same query.
Best regards,
Zoltán Böszörményi
--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2011-11-10 08:41 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-11-06 03:49 Locale problem with psqlODBC under Fedora 16 Zoltan Boszormenyi <zb@cybertec.at>
2011-11-06 08:11 ` Boszormenyi Zoltan <zb@cybertec.at>
2011-11-07 23:53 ` Inoue, Hiroshi <inoue@tpf.co.jp>
2011-11-09 17:57 ` Hiroshi Inoue <inoue@tpf.co.jp>
2011-11-10 08:41 ` Boszormenyi Zoltan <zb@cybertec.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox