Example #1
0
    def _add_column(my, column, type):

        # if there is no type, then no column is created for widget_config
        if type != "":
            # alter the table
            search_type_obj = SearchType.get(my.search_type)
            db_resource = Project.get_db_resource_by_search_type(
                my.search_type)
            sql = DbContainer.get(db_resource)
            impl = sql.get_database_impl()
            table = search_type_obj.get_table()

            columns = sql.get_columns(table)
            # if the column exists already, skip it
            if column in columns:
                print "skipping: ", column
                raise TacticException(
                    '[%s] already existed in this table [%s]' %
                    (column, table))
                return

            # FIXME: database dependency should be in DatabaseImpl
            if sql.get_database_type() == "MongoDb":
                statement = None

            elif sql.get_database_type() == "MySQL":
                if type == "varchar":
                    type = "varchar(256)"
                statement = 'ALTER TABLE "%s" ADD COLUMN "%s" %s' % \
                    (table, column, type)

            elif sql.get_database_type() == "Oracle":
                statement = 'ALTER TABLE "%s" ADD("%s" %s)' % \
                    (table, column, type)

            elif sql.get_database_type() == 'SQLServer':
                statement = 'ALTER TABLE [%s] ADD "%s" %s' % \
                    (table, column, type)
            else:
                statement = 'ALTER TABLE "%s" ADD COLUMN "%s" %s' % \
                    (table, column, type)

            if statement:
                if not my.nullable:
                    statement = '%s NOT NULL' % statement
                sql.do_update(statement)
                AlterTableUndo.log_add(db_resource, table, column, type)
Example #2
0
    def _add_column(self, column, type):

        # if there is no type, then no column is created for widget_config
        if type != "":
            # alter the table
            search_type_obj = SearchType.get(self.search_type)
            db_resource = Project.get_db_resource_by_search_type(self.search_type)
            sql = DbContainer.get(db_resource)
            impl = sql.get_database_impl()
            table = search_type_obj.get_table()

            columns = sql.get_columns(table)
            # if the column exists already, skip it
            if column in columns:
                print "skipping: ", column
                raise TacticException('[%s] already existed in this table [%s]'%(column, table))
                return

            # FIXME: database dependency should be in DatabaseImpl
            if sql.get_database_type() == "MongoDb":
                statement = None

            elif sql.get_database_type() == "MySQL":
                if type == "varchar":
                    type = "varchar(256)"
                statement = 'ALTER TABLE "%s" ADD COLUMN "%s" %s' % \
                    (table, column, type)

            elif sql.get_database_type() == "Oracle":
                statement = 'ALTER TABLE "%s" ADD("%s" %s)' % \
                    (table, column, type)

            elif sql.get_database_type() == 'SQLServer':
                statement = 'ALTER TABLE [%s] ADD "%s" %s' % \
                    (table, column, type)
            else: 
                statement = 'ALTER TABLE "%s" ADD COLUMN "%s" %s' % \
                    (table, column, type)

            if statement:
                if not self.nullable:
                    statement = '%s NOT NULL' %statement
                sql.do_update(statement)
                AlterTableUndo.log_add(db_resource,table,column,type)