[libgda] MySQL: correctly read FLOAT values when returned by a SELECT



commit a18dc9533c25a8fea875fd66a1159ef2c8ea2503
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed May 5 21:01:33 2010 +0200

    MySQL: correctly read FLOAT values when returned by a SELECT

 providers/mysql/gda-mysql-recordset.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-recordset.c b/providers/mysql/gda-mysql-recordset.c
index 627f816..e4f6921 100644
--- a/providers/mysql/gda-mysql-recordset.c
+++ b/providers/mysql/gda-mysql-recordset.c
@@ -632,6 +632,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 		int intvalue = 0;
 		long long longlongvalue = 0;
 		double doublevalue = 0.0;
+		float floatvalue = 0.;
 		MYSQL_TIME timevalue = { 0 };
 		my_bool is_null = FALSE;
 		unsigned long length;
@@ -732,15 +733,24 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 			}
 
 			break;
-		case MYSQL_TYPE_FLOAT:
+		case MYSQL_TYPE_FLOAT: {
+			g_memmove (&floatvalue, mysql_bind_result[i].buffer, sizeof(float));
+			
+			if (type == G_TYPE_FLOAT)
+				g_value_set_float (value, (float) floatvalue);
+			else {
+				gda_row_invalidate_value (row, value);
+				g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
+					     GDA_SERVER_PROVIDER_DATA_ERROR,
+					     _("Type %s not mapped for value %f"),
+					     g_type_name (type), doublevalue);
+			}			
+			break;
+		}
 		case MYSQL_TYPE_DOUBLE: {
-			char *current_locale;
 			g_memmove (&doublevalue, mysql_bind_result[i].buffer, sizeof(double));
 			
-			current_locale = setlocale (LC_NUMERIC, "C");
-			if (type == G_TYPE_FLOAT)
-				g_value_set_float (value, (float) doublevalue);
-			else if (type == G_TYPE_DOUBLE)
+			if (type == G_TYPE_DOUBLE)
 				g_value_set_double (value, doublevalue);
 			else {
 				gda_row_invalidate_value (row, value);
@@ -749,8 +759,6 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 					     _("Type %s not mapped for value %f"),
 					     g_type_name (type), doublevalue);
 			}
-			setlocale (LC_NUMERIC, current_locale);
-			
 			break;
 		}
 		case MYSQL_TYPE_STRING:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]