summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thenault <sylvain.thenault@logilab.fr>2008-09-26 12:40:04 +0200
committerSylvain Thenault <sylvain.thenault@logilab.fr>2008-09-26 12:40:04 +0200
commitef0938b73adafcfadb3b4e4de085c38b5dd1f08c (patch)
treeae341704d518264c8e7061d4fb5889ccee5de694
parentf759476a662d95de52724d4492886f8926c58d97 (diff)
downloadlogilab-common-ef0938b73adafcfadb3b4e4de085c38b5dd1f08c.tar.gz
be consistent: drop unique index using alter table, so create it using alter table
-rw-r--r--adbh.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/adbh.py b/adbh.py
index 872a29e..828d870 100644
--- a/adbh.py
+++ b/adbh.py
@@ -209,10 +209,17 @@ INSERT INTO %s VALUES (0);''' % (seq_name, seq_name)
def sql_create_index(self, table, column, unique=False):
idx = self._index_name(table, column, unique)
if unique:
- return 'CREATE UNIQUE INDEX %s ON %s(%s);' % (idx, table, column)
+ return 'ALTER TABLE %s ADD UNIQUE(%s)' % (table, column)
else:
return 'CREATE INDEX %s ON %s(%s);' % (idx, table, column)
-
+
+ def sql_drop_index(self, table, column, unique=False):
+ idx = self._index_name(table, column, unique)
+ if unique:
+ return 'ALTER TABLE %s DROP CONSTRAINT %s' % (table, idx)
+ else:
+ return 'DROP INDEX %s' % idx
+
def sql_drop_sequence(self, seq_name):
return 'DROP TABLE %s;' % seq_name
@@ -256,11 +263,7 @@ INSERT INTO %s VALUES (0);''' % (seq_name, seq_name)
def drop_index(self, cursor, table, column, unique=False):
if self.index_exists(cursor, table, column, unique):
- idx = self._index_name(table, column, unique)
- if unique:
- cursor.execute('ALTER TABLE %s DROP CONSTRAINT %s' % (table, idx))
- else:
- cursor.execute('DROP INDEX %s' % idx)
+ cursor.execute(self.sql_drop_index(table, column, unique))
def index_exists(self, cursor, table, column, unique=False):
idx = self._index_name(table, column, unique)