[libgda/LIBGDA_5.0] MySQL: handle GdaNumeric type in recordsets (thanks to Carlos Savoretti)



commit 2d95479cb799ce61bf30d927595e0392e19be355
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Jan 6 21:18:52 2012 +0100

    MySQL: handle GdaNumeric type in recordsets (thanks to Carlos Savoretti)

 providers/mysql/gda-mysql-recordset.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-recordset.c b/providers/mysql/gda-mysql-recordset.c
index 4b86109..05828f3 100644
--- a/providers/mysql/gda-mysql-recordset.c
+++ b/providers/mysql/gda-mysql-recordset.c
@@ -331,6 +331,8 @@ _gda_mysql_type_to_gda (G_GNUC_UNUSED MysqlConnectionData *cdata,
 		break;
 	case MYSQL_TYPE_DECIMAL:
 	case MYSQL_TYPE_NEWDECIMAL:
+		gtype = GDA_TYPE_NUMERIC;
+		break;
 	case MYSQL_TYPE_DOUBLE:
 		gtype = G_TYPE_DOUBLE;
 		break;
@@ -652,6 +654,7 @@ gda_mysql_recordset_new (GdaConnection            *cnc,
 		case MYSQL_TYPE_TINY_BLOB:
 		case MYSQL_TYPE_MEDIUM_BLOB:
 		case MYSQL_TYPE_LONG_BLOB:
+		case MYSQL_TYPE_DECIMAL:
 		case MYSQL_TYPE_NEWDECIMAL:
 		case MYSQL_TYPE_BIT:
 			mysql_bind_result[i].buffer = g_malloc0 (field->max_length + 1);
@@ -911,6 +914,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
 		case MYSQL_TYPE_MEDIUM_BLOB:
 		case MYSQL_TYPE_LONG_BLOB:
 		case MYSQL_TYPE_NEWDECIMAL:
+		case MYSQL_TYPE_DECIMAL:
 		case MYSQL_TYPE_BIT: {
 			char *strvalue = NULL;
 			g_memmove (&length, mysql_bind_result[i].length, sizeof(unsigned long));
@@ -936,6 +940,19 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
 				GdaBlob blob = { {(guchar*) strvalue, length}, NULL };
 				gda_value_set_blob (value, &blob);
 			}
+			else if (type == GDA_TYPE_NUMERIC) {
+				setlocale (LC_NUMERIC, "C");
+				if (length > 0) {
+					GdaNumeric *numeric;
+					numeric = gda_numeric_new ();
+					gda_numeric_set_from_string (numeric, strvalue);
+					gda_numeric_set_precision (numeric, 6);
+					gda_numeric_set_width (numeric, length);
+					gda_value_set_numeric (value, numeric);
+					gda_numeric_free (numeric);
+				}
+				setlocale (LC_NUMERIC, gda_numeric_locale);
+			}
 			else if (type == G_TYPE_DOUBLE) {
 				if (length > 0) {
 					setlocale (LC_NUMERIC, "C");



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