From: Andrea Zagli Date: Sun, 8 Sep 2019 09:36:47 +0000 (+0200) Subject: Added GdaEx::double_to_sql. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=8311356dbf4211bffeed43796f9227044d5774cc;p=libgdaex Added GdaEx::double_to_sql. --- diff --git a/.gitignore b/.gitignore index 9aa7ae2..99cef6d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ po/libgdaex.pot *.bak intltool* libgdaex*tar* +tests/doubletosql tests/test_prefix* tests/query_editor tests/*.gdaexxml diff --git a/src/gdaex.c b/src/gdaex.c index 7bf4281..3463659 100644 --- a/src/gdaex.c +++ b/src/gdaex.c @@ -28,6 +28,8 @@ #include #include +#include + #include #include @@ -3893,6 +3895,22 @@ GdaDataModel return dm; } +gchar +*gdaex_double_to_sql (gdouble number) +{ + gchar *ret; + + char *cur = g_strdup (setlocale (LC_NUMERIC, NULL)); + setlocale (LC_NUMERIC, "C"); + + ret = g_strdup_printf ("%f", number); + + setlocale (LC_NUMERIC, cur); + g_free (cur); + + return ret; +} + /* PRIVATE */ static void gdaex_create_connection_parser (GdaEx *gdaex) diff --git a/src/gdaex.h b/src/gdaex.h index 43a31c5..9bcb3ff 100644 --- a/src/gdaex.h +++ b/src/gdaex.h @@ -1,7 +1,7 @@ /* * gdaex.h * - * Copyright (C) 2005-2018 Andrea Zagli + * Copyright (C) 2005-2019 Andrea Zagli * * This file is part of libgdaex. * @@ -315,6 +315,8 @@ gboolean gdaex_meta_store_update (GdaEx *gdaex, GdaMetaContext *mcontext); GdaDataModel *gdaex_meta_store_get_tables (GdaEx *gdaex, gboolean update_meta_store); GdaDataModel *gdaex_meta_store_get_table_fields (GdaEx *gdaex, const gchar *table_name, gboolean update_meta_store); +gchar *gdaex_double_to_sql (gdouble number); + G_END_DECLS diff --git a/tests/Makefile.am b/tests/Makefile.am index 4634e12..28f2b22 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,7 +5,9 @@ AM_CPPFLAGS = $(GDAEX_CFLAGS) \ -I$(top_srcdir)/src \ -DTESTSDIR="\"@abs_builddir@\"" -noinst_PROGRAMS = fill_liststore \ +noinst_PROGRAMS = \ + doubletosql \ + fill_liststore \ getsqlfromhashtable \ metastore \ query_editor \ diff --git a/tests/doubletosql.c b/tests/doubletosql.c new file mode 100644 index 0000000..089e688 --- /dev/null +++ b/tests/doubletosql.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 Andrea Zagli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include + +int +main (int argc, char **argv) +{ + gdouble number; + + number = zak_utils_unformat_money ("123.456,78"); + + g_message ("%f", number); + + g_message ("%s", gdaex_double_to_sql (number)); + + return 0; +}