diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-02-05 11:57:36 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-02-05 11:57:36 +0100 |
commit | 0db8ab796321e9f31c3bddab8830a34fa0ec7020 (patch) | |
tree | 2115802dd92c3fa7f69a3f977c6f33aa3022dc60 | |
parent | dd2673fca5afefaefd7fe0d05ce390e096297c8d (diff) | |
download | logilab-common-0db8ab796321e9f31c3bddab8830a34fa0ec7020.tar.gz |
new sql_rename_col method on db helpers
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | adbh.py | 12 |
2 files changed, 13 insertions, 0 deletions
@@ -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 @@ -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' |