[glom/mysql] MySQL:Use MySQL syntax to change columns



commit dc9e67d7666ade4d78aafbfee974804180a20478
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jan 10 23:30:51 2013 +0100

    MySQL:Use MySQL syntax to change columns
    
    	* glom/libglom/connnectionpool_backends/mysql.cc:
    	MYSQL uses:
    	ALTER TABLE tablename CHANGE oldfieldname newfieldname oldfieldtype
    	to rename columns, instead of PostgreSQL's:
    	ALTER TABLE tablename RENAME oldfieldname TO newfieldname

 ChangeLog                                         |   10 ++++++++++
 glom/libglom/connectionpool_backends/mysql.cc     |   12 +++++++-----
 tests/test_selfhosting_new_then_change_columns.cc |    7 -------
 3 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 46c02be..260347a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2013-01-06  Murray Cumming  <murrayc murrayc com>
 
+        MySQL:Use MySQL syntax to change columns
+
+	* glom/libglom/connnectionpool_backends/mysql.cc:
+	MYSQL uses:
+	ALTER TABLE tablename CHANGE oldfieldname newfieldname oldfieldtype
+	to rename columns, instead of PostgreSQL's:
+	ALTER TABLE tablename RENAME oldfieldname TO newfieldname
+
+2013-01-06  Murray Cumming  <murrayc murrayc com>
+
         MySQL: Avoid affecting PostgreSQL field types.
 
         * glom/libglom/db_utils.[h|cc]: create_table():
diff --git a/glom/libglom/connectionpool_backends/mysql.cc b/glom/libglom/connectionpool_backends/mysql.cc
index 50c2e60..6f162d6 100644
--- a/glom/libglom/connectionpool_backends/mysql.cc
+++ b/glom/libglom/connectionpool_backends/mysql.cc
@@ -309,7 +309,8 @@ bool MySQL::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connectio
 
 		    drop_column(connection, table_name, old_fields[i]->get_name());
 
-		    connection->statement_execute_non_select("ALTER TABLE " + DbUtils::escape_sql_id(table_name) + " RENAME COLUMN " + DbUtils::escape_sql_id(TEMP_COLUMN_NAME) + " TO " + DbUtils::escape_sql_id(new_fields[i]->get_name()));
+                    //This part is different compared to PostgreSQL:
+		    connection->statement_execute_non_select("ALTER TABLE " + DbUtils::escape_sql_id(table_name) + " CHANGE " + DbUtils::escape_sql_id(TEMP_COLUMN_NAME) + " " + DbUtils::escape_sql_id(new_fields[i]->get_name()) + " " + new_fields[i]->get_sql_type());
 
 		    // Read primary key constraint
 		    if(new_fields[i]->get_primary_key())
@@ -376,7 +377,8 @@ bool MySQL::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connectio
 
 		    if(old_fields[i]->get_name() != new_fields[i]->get_name())
 		    {
-		      connection->statement_execute_non_select("ALTER TABLE " + DbUtils::escape_sql_id(table_name) + " RENAME COLUMN " + DbUtils::escape_sql_id(old_fields[i]->get_name()) + " TO " + DbUtils::escape_sql_id(new_fields[i]->get_name()));
+                      //This part is different compared to PostgreSQL
+		      connection->statement_execute_non_select("ALTER TABLE " + DbUtils::escape_sql_id(table_name) + " CHANGE " + DbUtils::escape_sql_id(old_fields[i]->get_name()) + " " + DbUtils::escape_sql_id(new_fields[i]->get_name()) + " " + new_fields[i]->get_sql_type());
 		    }
 		  }
 		}
@@ -386,8 +388,8 @@ bool MySQL::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connectio
   }
   catch(const Glib::Error& ex)
   {
-    std::cerr << "Exception: " << ex.what() << std::endl;
-    std::cerr << "Reverting the transaction." << std::endl;
+    std::cerr << G_STRFUNC << "Exception: " << ex.what() << std::endl;
+    std::cerr << "  Reverting the transaction." << std::endl;
     
     try
     {
@@ -395,7 +397,7 @@ bool MySQL::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connectio
     }
     catch(const Glib::Error& ex)
     {
-      std::cerr << "Could not rollback the transaction: Exception: " << ex.what() << std::endl;
+      std::cerr << G_STRFUNC << "Could not rollback the transaction: Exception: " << ex.what() << std::endl;
     }
   }
   
diff --git a/tests/test_selfhosting_new_then_change_columns.cc b/tests/test_selfhosting_new_then_change_columns.cc
index 5bcdb2b..dab0eaf 100644
--- a/tests/test_selfhosting_new_then_change_columns.cc
+++ b/tests/test_selfhosting_new_then_change_columns.cc
@@ -67,13 +67,6 @@ static bool test(Glom::Document::HostingMode hosting_mode)
     return false;
   }
 
-  //TODO_MySQL: Implement column changing.
-  if(hosting_mode == Glom::Document::HOSTING_MODE_MYSQL_SELF)
-  {
-    test_selfhosting_cleanup(false /* do not delete the file. */);
-    return true;
-  }
-
   //Test that change_column() does not fail horribly:
   //TODO: Start with some data that can be converted meaningfully,
   //and check that the result is as expected:



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