[glom/mysql2] MySQL: Use MySQL syntax to change columns
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/mysql2] MySQL: Use MySQL syntax to change columns
- Date: Thu, 10 Jan 2013 22:57:57 +0000 (UTC)
commit fc79a2d8ff819b88087cd9983e312684c5ed6976
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jan 10 23:30:51 2013 +0100
MySQL: Use MySQL syntax to change columns
glom/libglom/connectionpool_backends/mysql.cc | 12 +++++++-----
tests/test_selfhosting_new_then_change_columns.cc | 7 -------
2 files changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/glom/libglom/connectionpool_backends/mysql.cc b/glom/libglom/connectionpool_backends/mysql.cc
index 50c2e60..49b69ef 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]