[migraction] fix cmd_change_attribute_type command (closes #2015073) stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Thu, 13 Oct 2011 11:49:19 +0200
branchstable
changeset 7948 deb596dc343a
parent 7947 64719f6933d4
child 7952 48330faf4cd7
[migraction] fix cmd_change_attribute_type command (closes #2015073) use dbhelper to avoid issuing unsupported SQL
server/migractions.py
--- a/server/migractions.py	Thu Oct 13 10:24:27 2011 +0200
+++ b/server/migractions.py	Thu Oct 13 11:49:19 2011 +0200
@@ -1546,14 +1546,15 @@
         rschema = self.repo.schema.rschema(attr)
         oldtype = rschema.objects(etype)[0]
         rdefeid = rschema.rdef(etype, oldtype).eid
+        allownull = rschema.rdef(etype, oldtype).cardinality[0] != '1'
         sql = ("UPDATE cw_CWAttribute "
                "SET cw_to_entity=(SELECT cw_eid FROM cw_CWEType WHERE cw_name='%s')"
                "WHERE cw_eid=%s") % (newtype, rdefeid)
         self.sqlexec(sql, ask_confirm=False)
         dbhelper = self.repo.system_source.dbhelper
         sqltype = dbhelper.TYPE_MAPPING[newtype]
-        sql = 'ALTER TABLE cw_%s ALTER COLUMN cw_%s TYPE %s' % (etype, attr, sqltype)
-        self.sqlexec(sql, ask_confirm=False)
+        cursor = self.session.cnxset[self.repo.system_source.uri]
+        dbhelper.change_col_type(cursor, 'cw_%s'  % etype, 'cw_%s' % attr, sqltype, allownull)
         if commit:
             self.commit()