[glom/glom-1-14] Allow unique fields with same name in multiple tables.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-14] Allow unique fields with same name in multiple tables.
- Date: Sat, 24 Jul 2010 22:47:41 +0000 (UTC)
commit 17dbb39a2d386e1aafbd7572cb16ab53b15c5c59
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Jul 25 00:46:36 2010 +0200
Allow unique fields with same name in multiple tables.
* glom/libglom/connectionpool_backends/postgres.cc:
change_column(): Prefix the table name to the constraint name when
setting/removing the unique-key constraint, as libgda (or PostgreSQL)
seems to do when creating a field. This prevents a clash when two tables
have the same field name, and both should be unique.
This is nasty code anyway that I would rather have in libgda.
This fixes bug #625192 (fmyhr).
ChangeLog | 12 ++++++++++++
glom/libglom/connectionpool_backends/postgres.cc | 15 ++++++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d3f6df..904e0ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-07-25 Murray Cumming <murrayc murrayc com>
+
+ Allow unique fields with same name in multiple tables.
+
+ * glom/libglom/connectionpool_backends/postgres.cc:
+ change_column(): Prefix the table name to the constraint name when
+ setting/removing the unique-key constraint, as libgda (or PostgreSQL)
+ seems to do when creating a field. This prevents a clash when two tables
+ have the same field name, and both should be unique.
+ This is nasty code anyway that I would rather have in libgda.
+ This fixes bug #625192 (fmyhr).
+
1.14.4:
2010-07-22 Murray Cumming <murrayc murrayc com>
diff --git a/glom/libglom/connectionpool_backends/postgres.cc b/glom/libglom/connectionpool_backends/postgres.cc
index 58cc023..d4f7b3e 100644
--- a/glom/libglom/connectionpool_backends/postgres.cc
+++ b/glom/libglom/connectionpool_backends/postgres.cc
@@ -324,8 +324,11 @@ bool Postgres::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connec
// Remove unique key constraint, because this is already implied in
// the field being primary key.
+ //TODO: This depends on knowledge of the automatically-created
+ //(during SERVER_OPERATION_CREATE_TABLE) constraint name.
+ //TODO: Find out how the table name and field name are escaped/quoted.
if(old_fields[i]->get_unique_key())
- if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + old_fields[i]->get_name() + "_key", error))
+ if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + table_name + "_" + old_fields[i]->get_name() + "_key", error))
break;
}
else
@@ -345,12 +348,18 @@ bool Postgres::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connec
// to do that separately if we already made it a primary key
if(!primary_key_was_set && new_fields[i]->get_unique_key())
{
- if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" ADD CONSTRAINT \"" + old_fields[i]->get_name() + "_key\" UNIQUE (\"" + old_fields[i]->get_name() + "\")", error))
+ //TODO: This depends on knowledge of the automatically-created
+ //(during SERVER_OPERATION_CREATE_TABLE) constraint name.
+ //TODO: Find out how the table name and field name are escaped/quoted.
+ if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" ADD CONSTRAINT \"" + table_name + "_" + old_fields[i]->get_name() + "_key\" UNIQUE (\"" + old_fields[i]->get_name() + "\")", error))
break;
}
else if(!primary_key_was_unset && !new_fields[i]->get_unique_key() && !new_fields[i]->get_primary_key())
{
- if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + old_fields[i]->get_name() + "_key\"", error))
+ //TODO: This depends on knowledge of the automatically-created
+ //(during SERVER_OPERATION_CREATE_TABLE) constraint name.
+ //TODO: Find out how the table name and field name are escaped/quoted.
+ if(!query_execute(connection, "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + table_name + "_" +old_fields[i]->get_name() + "_key\"", error))
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]