server/schemahooks.py
changeset 2618 ff9b0d5bd884
parent 2617 89c62b855f2e
child 2624 c0b5b189190e
equal deleted inserted replaced
2617:89c62b855f2e 2618:ff9b0d5bd884
    49     """add necessary column and index for an inlined relation"""
    49     """add necessary column and index for an inlined relation"""
    50     table = SQL_PREFIX + etype
    50     table = SQL_PREFIX + etype
    51     column = SQL_PREFIX + rtype
    51     column = SQL_PREFIX + rtype
    52     try:
    52     try:
    53         session.system_sql(str('ALTER TABLE %s ADD COLUMN %s integer'
    53         session.system_sql(str('ALTER TABLE %s ADD COLUMN %s integer'
    54                                % (table, column)))
    54                                % (table, column)), rollback_on_failure=False)
    55         session.info('added column %s to table %s', column, table)
    55         session.info('added column %s to table %s', column, table)
    56     except:
    56     except:
    57         # silent exception here, if this error has not been raised because the
    57         # silent exception here, if this error has not been raised because the
    58         # column already exists, index creation will fail anyway
    58         # column already exists, index creation will fail anyway
    59         session.exception('error while adding column %s to table %s',
    59         session.exception('error while adding column %s to table %s',
   126         session, table, column = self.session, self.table, self.column
   126         session, table, column = self.session, self.table, self.column
   127         # drop index if any
   127         # drop index if any
   128         session.pool.source('system').drop_index(session, table, column)
   128         session.pool.source('system').drop_index(session, table, column)
   129         try:
   129         try:
   130             session.system_sql('ALTER TABLE %s DROP COLUMN %s'
   130             session.system_sql('ALTER TABLE %s DROP COLUMN %s'
   131                                % (table, column))
   131                                % (table, column), rollback_on_failure=False)
   132             self.info('dropped column %s from table %s', column, table)
   132             self.info('dropped column %s from table %s', column, table)
   133         except Exception, ex:
   133         except Exception, ex:
   134             # not supported by sqlite for instance
   134             # not supported by sqlite for instance
   135             self.error('error while altering table %s: %s', table, ex)
   135             self.error('error while altering table %s: %s', table, ex)
   136 
   136 
   408         # allow unicode queries
   408         # allow unicode queries
   409         table = SQL_PREFIX + subj
   409         table = SQL_PREFIX + subj
   410         column = SQL_PREFIX + rtype
   410         column = SQL_PREFIX + rtype
   411         try:
   411         try:
   412             session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s'
   412             session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s'
   413                                    % (table, column, attrtype)))
   413                                    % (table, column, attrtype)),
       
   414                                rollback_on_failure=False)
   414             self.info('added column %s to table %s', table, column)
   415             self.info('added column %s to table %s', table, column)
   415         except Exception, ex:
   416         except Exception, ex:
   416             # the column probably already exists. this occurs when
   417             # the column probably already exists. this occurs when
   417             # the entity's type has just been added or if the column
   418             # the entity's type has just been added or if the column
   418             # has not been previously dropped
   419             # has not been previously dropped
   720             card = rtype.rproperty(subjtype, objtype, 'cardinality')
   721             card = rtype.rproperty(subjtype, objtype, 'cardinality')
   721             coltype = type_from_constraints(adbh, objtype, [self._cstr],
   722             coltype = type_from_constraints(adbh, objtype, [self._cstr],
   722                                             creating=False)
   723                                             creating=False)
   723             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
   724             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
   724             try:
   725             try:
   725                 session.system_sql(sql)
   726                 session.system_sql(sql, rollback_on_failure=False)
   726                 self.info('altered column %s of table %s: now VARCHAR(%s)',
   727                 self.info('altered column %s of table %s: now VARCHAR(%s)',
   727                           column, table, self._cstr.max)
   728                           column, table, self._cstr.max)
   728             except Exception, ex:
   729             except Exception, ex:
   729                 # not supported by sqlite for instance
   730                 # not supported by sqlite for instance
   730                 self.error('error while altering table %s: %s', table, ex)
   731                 self.error('error while altering table %s: %s', table, ex)
   759         column = SQL_PREFIX + str(self.rtype)
   760         column = SQL_PREFIX + str(self.rtype)
   760         # alter the physical schema on size/unique constraint changes
   761         # alter the physical schema on size/unique constraint changes
   761         if cstrtype == 'SizeConstraint':
   762         if cstrtype == 'SizeConstraint':
   762             try:
   763             try:
   763                 self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
   764                 self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
   764                                         % (table, column))
   765                                         % (table, column),
       
   766                                         rollback_on_failure=False)
   765                 self.info('altered column %s of table %s: now TEXT',
   767                 self.info('altered column %s of table %s: now TEXT',
   766                           column, table)
   768                           column, table)
   767             except Exception, ex:
   769             except Exception, ex:
   768                 # not supported by sqlite for instance
   770                 # not supported by sqlite for instance
   769                 self.error('error while altering table %s: %s', table, ex)
   771                 self.error('error while altering table %s: %s', table, ex)