# HG changeset patch # User Alexandre Fayolle # Date 1291902951 -3600 # Node ID ec9a5efdc4516399b0f62a4ee4b457b997edf83f # Parent 627a930276058e3c314aa530f39a2f8afb1e3eb4 make rename_table work with MS SQL (needs updated logilab.database) diff -r 627a93027605 -r ec9a5efdc451 hooks/syncschema.py --- a/hooks/syncschema.py Thu Dec 09 14:35:20 2010 +0000 +++ b/hooks/syncschema.py Thu Dec 09 14:55:51 2010 +0100 @@ -282,13 +282,15 @@ self.session.vreg.schema.rename_entity_type(oldname, newname) # we need sql to operate physical changes on the system database sqlexec = self.session.system_sql - sqlexec('ALTER TABLE %s%s RENAME TO %s%s' % (SQL_PREFIX, oldname, - SQL_PREFIX, newname)) + dbhelper= self.session.pool.source('system').dbhelper + sql = dbhelper.sql_rename_table(SQL_PREFIX+oldname, + SQL_PREFIX+newname) + sqlexec(sql) self.info('renamed table %s to %s', oldname, newname) - sqlexec('UPDATE entities SET type=%s WHERE type=%s', - (newname, oldname)) - sqlexec('UPDATE deleted_entities SET type=%s WHERE type=%s', - (newname, oldname)) + sqlexec('UPDATE entities SET type=%(newname)s WHERE type=%(oldname)s', + {'newname': newname, 'oldname': oldname)) + sqlexec('UPDATE deleted_entities SET type=%(newname)s WHERE type=%(oldname)s', + {'newname': newname, 'oldname': oldname)) # XXX transaction records def precommit_event(self): diff -r 627a93027605 -r ec9a5efdc451 server/schemaserial.py --- a/server/schemaserial.py Thu Dec 09 14:35:20 2010 +0000 +++ b/server/schemaserial.py Thu Dec 09 14:55:51 2010 +0100 @@ -126,8 +126,9 @@ sqlexec('UPDATE %(p)sCWEType SET %(p)sname=%%(n)s WHERE %(p)seid=%%(x)s' % {'p': sqlutils.SQL_PREFIX}, {'x': eid, 'n': netype}) if etype.lower() != netype.lower(): - sqlexec('ALTER TABLE %s%s RENAME TO %s%s' % ( - sqlutils.SQL_PREFIX, etype, sqlutils.SQL_PREFIX, netype)) + alter_table_sql = dbhelper.sql_rename_table(sqlutils.SQL_PREFIX+etype, + sqlutils.SQL_PREFIX+netype) + sqlexec(alter_table_sql) sqlexec('UPDATE entities SET type=%(n)s WHERE type=%(x)s', {'x': etype, 'n': netype}) session.commit(False)