[glom] MySQL: Use double instead of DECIMAL for numeric values.



commit 7cd47f1cc3b363c5eb803a468f52bc45d8dde5b5
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 6 15:01:32 2013 +0100

    MySQL: Use double instead of DECIMAL for numeric values.
    
            * glom/libglom/db_utils.cc: create_table():
    Do not use DECIMAL with no parameters because that means
    0 decimal points, so we lose data when reading values
    back.

 ChangeLog                                        |    9 +++++++++
 glom/libglom/db_utils.cc                         |    7 ++++++-
 tests/test_selfhosting_new_from_example_float.cc |    4 ----
 tests/test_selfhosting_utils.cc                  |    2 +-
 4 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f563ea6..f151a4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2013-01-06  Murray Cumming  <murrayc murrayc com>
 
+        MySQL: Use double instead of DECIMAL for numeric values.
+
+        * glom/libglom/db_utils.cc: create_table():
+	Do not use DECIMAL with no parameters because that means
+	0 decimal points, so we lose data when reading values
+	back.
+
+2013-01-06  Murray Cumming  <murrayc murrayc com>
+
         tests: Add try/catch around all calls of the test functions.
 
         * tests/test_selfhosting_utils.[h|cc]: 
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index 0a768d9..24293df 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1247,9 +1247,11 @@ bool create_table(const sharedptr<const TableInfo>& table_info, const Document::
 
     Glib::ustring field_type = field->get_sql_type();
     if(field_type == "varchar")
-      field_type = "varchar(255)"; //For MySQL.
+      field_type = "varchar(255)"; //For MySQL. //TODO: Avoid this for PostgreSQL
     else if(field_type == "VARBINARY")
       field_type = "blob"; //For MySQL.
+    else if(field_type == "DECIMAL")
+      field_type = "double"; //For MySQL, because DECIMAL with no parameters means no decimal points.
 
     Glib::ustring sql_field_description = escape_sql_id(field->get_name()) + " " + field_type;
 
@@ -1639,6 +1641,9 @@ bool insert_example_data(Document* document, const Glib::ustring& table_name)
     //After this, the Parser will know how many SQL parameters there are in
     //the query, and allow us to set their values.
 
+    //std::cout << G_STRFUNC << ": debug: INSERT query: " << std::endl
+    //  << "    " << Utils::sqlbuilder_get_full_query(builder) << std::endl;
+
     insert_succeeded = query_execute(builder);
     if(!insert_succeeded)
     {
diff --git a/tests/test_selfhosting_new_from_example_float.cc b/tests/test_selfhosting_new_from_example_float.cc
index 30079f0..0a120c4 100644
--- a/tests/test_selfhosting_new_from_example_float.cc
+++ b/tests/test_selfhosting_new_from_example_float.cc
@@ -32,8 +32,6 @@
 
 static bool test(Glom::Document::HostingMode hosting_mode)
 {
-  std::cout << "debug: hosting_mode=" << hosting_mode << std::endl;
-
   Glom::Document document;
   const bool recreated = 
     test_create_and_selfhost_from_example("example_smallbusiness.glom", document, hosting_mode);
@@ -101,8 +99,6 @@ static bool test(Glom::Document::HostingMode hosting_mode)
   }
 
   test_selfhosting_cleanup();
- 
-  std::cout << "debug: end hosting_mode=" << hosting_mode << std::endl;
 
   return true; 
 }
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index 7b3b295..bd629c3 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -578,7 +578,7 @@ bool test_check_numeric_value_type(Glom::Document::HostingMode hosting_mode, con
   } else if( (hosting_mode == Glom::Document::HOSTING_MODE_MYSQL_CENTRAL) ||
     (hosting_mode == Glom::Document::HOSTING_MODE_MYSQL_SELF) )
   {
-    if(gtype == G_TYPE_FLOAT)
+    if(gtype == G_TYPE_DOUBLE)
       return true;
   }
 



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