summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-02-05 11:57:36 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-02-05 11:57:36 +0100
commit0db8ab796321e9f31c3bddab8830a34fa0ec7020 (patch)
tree2115802dd92c3fa7f69a3f977c6f33aa3022dc60
parentdd2673fca5afefaefd7fe0d05ce390e096297c8d (diff)
downloadlogilab-common-0db8ab796321e9f31c3bddab8830a34fa0ec7020.tar.gz
new sql_rename_col method on db helpers
-rw-r--r--ChangeLog1
-rw-r--r--adbh.py12
2 files changed, 13 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ab09143..34f3f58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ ChangeLog for logilab.common
- each command returned in backup_commands/restore_commands may now
be list that may be used as argument to subprocess.call, or a string
which will the requires a subshell
+ - new sql_rename_col method
* deprecation: deprecated now takes an optional 'stacklevel' argument, default to 2
* date: some functions to ease python's datetime module usage have been backported
from cubicweb
diff --git a/adbh.py b/adbh.py
index 30b415d..ff7c55b 100644
--- a/adbh.py
+++ b/adbh.py
@@ -225,6 +225,10 @@ INSERT INTO %s VALUES (0);''' % (seq_name, seq_name)
return ('UPDATE %s SET last=last+1;' % seq_name,
'SELECT last FROM %s;' % seq_name)
+ def sql_rename_col(self, table, column, newname, coltype, null_allowed):
+ return 'ALTER TABLE %s RENAME COLUMN %s TO %s' % (
+ table, column, newname)
+
def sql_change_col_type(self, table, column, coltype, null_allowed):
return 'ALTER TABLE %s ALTER COLUMN %s TYPE %s' % (
table, column, coltype)
@@ -532,6 +536,14 @@ class _MyAdvFuncHelper(_GenericAdvFuncHelper):
sql += " CHARACTER SET %(encoding)s"
return sql % locals()
+ def sql_rename_col(self, table, column, newname, coltype, null_allowed):
+ if null_allowed:
+ cmd = 'DEFAULT'
+ else:
+ cmd = 'NOT'
+ return 'ALTER TABLE %s CHANGE %s %s %s %s NULL' % (
+ table, column, newname, coltype, cmd)
+
def sql_change_col_type(self, table, column, coltype, null_allowed):
if null_allowed:
cmd = 'DEFAULT'