glom r1847 - in trunk: . glom/libglom glom/libglom/connectionpool_backends glom/mode_design/fields



Author: arminb
Date: Wed Jan 14 16:51:20 2009
New Revision: 1847
URL: http://svn.gnome.org/viewvc/glom?rev=1847&view=rev

Log:
2009-01-14  Armin Burgmeier  <armin openismus com>

	* glom/libglom/connectionpool_backends/postgres.cc (change_columns):
	When changing column types, only attempt to convert data if
	Field::get_conversion_possible() returns TRUE, otherwise just change
	the column type without trying to convert the data.

	* glom/libglom/connectionpool.cc (change_columns): Added a TODO
	comment about not failing when data could not be converted to the new
	column type.

	* glom/mode_design/fields/box_db_table_definition.cc
	(get_field_definition): Set the glom type explicitely on the result
	field, so that we don't have to guess from the GType.


Modified:
   trunk/ChangeLog
   trunk/glom/libglom/connectionpool.cc
   trunk/glom/libglom/connectionpool_backends/postgres.cc
   trunk/glom/mode_design/fields/box_db_table_definition.cc

Modified: trunk/glom/libglom/connectionpool.cc
==============================================================================
--- trunk/glom/libglom/connectionpool.cc	(original)
+++ trunk/glom/libglom/connectionpool.cc	Wed Jan 14 16:51:20 2009
@@ -421,6 +421,8 @@
 
     const Glib::ustring temp_move_query = "UPDATE " + table_name + " SET " + TEMP_COLUMN_NAME + " = CAST(" + old_fields[i]->get_name() + " AS " + new_fields[i]->get_sql_type() + ")";
     if(!query_execute(connection, temp_move_query, error)) break;
+    // TODO: If this CAST was not successful, then just go on,
+    // dropping the data in the column?
 
     if(!drop_column(connection, table_name, old_fields[i]->get_name(), error)) return false;
 

Modified: trunk/glom/libglom/connectionpool_backends/postgres.cc
==============================================================================
--- trunk/glom/libglom/connectionpool_backends/postgres.cc	(original)
+++ trunk/glom/libglom/connectionpool_backends/postgres.cc	Wed Jan 14 16:51:20 2009
@@ -185,10 +185,7 @@
       const Glib::ustring field_name_old_quoted = "\"" + old_fields[i]->get_name() + "\"";
       const Field::glom_field_type old_field_type = old_fields[i]->get_glom_type();
 
-      // For most conversions that are not possible according to this function,
-      // we get still quite good results when doing them nevertheless, such as
-      // text to date or date to text, so I commented this out.
-//      if(Field::get_conversion_possible(old_fields[i]->get_glom_type(), new_fields[i]->get_glom_type()))
+      if(Field::get_conversion_possible(old_fields[i]->get_glom_type(), new_fields[i]->get_glom_type()))
       {
         //TODO: postgres seems to give an error if the data cannot be converted (for instance if the text is not a numeric digit when converting to numeric) instead of using 0.
         /*
@@ -272,24 +269,10 @@
         if(!query_execute(connection, "UPDATE \"" + table_name + "\" SET \"" + TEMP_COLUMN_NAME + "\" = " + conversion_command, error))
           break;
       }
-#if 0
       else
       {
-        // The conversion is not possible.
-
-        // TODO: What to do here? The old code seems to have changed the type
-        // nevertheless, losing all data in the field.
-        std::cout << "Conversion between " << old_fields[i]->get_sql_type() << " and " << new_fields[i]->get_sql_type() << " not supported, trying direct CAST" << std::endl;
-
-        conversion_command = "CAST(" + field_name_old_quoted + " AS " + new_fields[i]->get_sql_type() + ")";
-        if(!query_execute(connection, "UPDATE \"" + table_name + "\" SET \"" + TEMP_COLUMN_NAME + "\" = " + conversion_command, error))
-	{
-	  // Don't panic if this fails, for now.
-          std::cout << "  ... failed: " << error->what() << std::endl;
-	  error.reset(NULL);
-	}
+        // The conversion is not possible, so drop data in that column
       }
-#endif
 
       if(!drop_column(connection, table_name, old_fields[i]->get_name(), error));
       if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" RENAME COLUMN \"" + TEMP_COLUMN_NAME + "\" TO \"" + new_fields[i]->get_name() + "\"", error)) break;

Modified: trunk/glom/mode_design/fields/box_db_table_definition.cc
==============================================================================
--- trunk/glom/mode_design/fields/box_db_table_definition.cc	(original)
+++ trunk/glom/mode_design/fields/box_db_table_definition.cc	Wed Jan 14 16:51:20 2009
@@ -440,6 +440,7 @@
     fieldInfo->set_g_type(fieldType);
 
     //Put it together:
+    fieldResult->set_glom_type(glom_type);
     fieldResult->set_field_info(fieldInfo);
 
     //TODO: Use the libgda functions above when we make them work:



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