r20177 - gnucash/trunk/src/backend - Change serialization of doubles in the dbi backend to use
John Ralls
jralls at code.gnucash.org
Thu Jan 27 14:38:39 EST 2011
Author: jralls
Date: 2011-01-27 14:38:39 -0500 (Thu, 27 Jan 2011)
New Revision: 20177
Trac: http://svn.gnucash.org/trac/changeset/20177
Modified:
gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
gnucash/trunk/src/backend/sql/gnc-backend-sql.c
Log:
Change serialization of doubles in the dbi backend to use
g_ascii_dtostr() instead of sprintf.
The problem is that sprintf is subject to localization and will output
e.g. 1,25 for one-and-a-quarter in European locales. SQL doesn't support
localization, so will interpret 1,25 as two fields, 1 and 25.
Note also that GUID_ENCODING_LENGTH isn't big enough for a double, so
that's changed to G_ASCII_DTOSTR_BUF_SIZE.
Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2011-01-27 19:22:16 UTC (rev 20176)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2011-01-27 19:38:39 UTC (rev 20177)
@@ -2864,6 +2864,7 @@
guint64 testulonglong = 9223372036854775807LLU, resultulonglong = 0;
gdouble testdouble = 1.7976921348623157E+307, resultdouble = 0.0;
dbi_result result;
+ gchar doublestr[G_ASCII_DTOSTR_BUF_SIZE];
gboolean retval = TRUE;
result = dbi_conn_query( conn, "CREATE TEMPORARY TABLE numtest "
@@ -2875,9 +2876,11 @@
return FALSE;
}
dbi_result_free( result );
+ g_ascii_dtostr( doublestr, sizeof(doublestr), testdouble );
result = dbi_conn_queryf( conn,
- "INSERT INTO numtest VALUES (%lld, %llu, %17e)",
- testlonglong, testulonglong, testdouble );
+ "INSERT INTO numtest VALUES (%" G_GINT64_FORMAT
+ ", %" G_GUINT64_FORMAT ", %s)",
+ testlonglong, testulonglong, doublestr );
if ( result == NULL )
{
PWARN("Test_DBI_Library: Failed to insert test row into table" );
Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2011-01-27 19:22:16 UTC (rev 20176)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c 2011-01-27 19:38:39 UTC (rev 20177)
@@ -707,7 +707,7 @@
QofQueryPredData* pPredData;
gboolean isInverted;
GSList* name;
- gchar val[GUID_ENCODING_LENGTH+1];
+ gchar val[G_ASCII_DTOSTR_BUF_SIZE];
g_return_if_fail( pTerm != NULL );
g_return_if_fail( sql != NULL );
@@ -830,7 +830,7 @@
{
query_double_t pData = (query_double_t)pPredData;
- sprintf( val, "%f", pData->val );
+ g_ascii_dtostr( val, sizeof(val), pData->val );
g_string_append( sql, val );
}
else if ( strcmp( pPredData->type_name, "boolean" ) == 0 )
@@ -2793,7 +2793,10 @@
}
else if ( type == G_TYPE_DOUBLE )
{
- return g_strdup_printf( "%g", g_value_get_double( value ) );
+ gchar doublestr[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr( doublestr, sizeof(doublestr),
+ g_value_get_double( value ));
+ return g_strdup_printf( "%s", doublestr );
}
else if ( g_value_type_transformable( type, G_TYPE_STRING ) )
More information about the gnucash-changes
mailing list