def delete(my, log=False): column = my.get_value("name") search_type = my.get_value("search_type") search_type_obj = SearchType.get(search_type) table = search_type_obj.get_table() database = search_type_obj.get_database() # remove it from the table if log: AlterTableUndo.log_drop(database, table, column) sql = DbContainer.get(database) try: from pyasm.search.sql import Sql if Sql.get_database_type() == 'SQLServer': statement = 'ALTER TABLE [%s] DROP "%s" %s' % \ (table, column) else: statement = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table, column) sql.do_update(statement) except SqlException, e: print("WARNING: %s" % e)
def delete(my,log=False): column = my.get_value("name") search_type = my.get_value("search_type") search_type_obj = SearchType.get(search_type) table = search_type_obj.get_table() database = search_type_obj.get_database() # remove it from the table if log: AlterTableUndo.log_drop(database, table, column) sql = DbContainer.get(database) try: from pyasm.search.sql import Sql if Sql.get_database_type() == 'SQLServer': statement = 'ALTER TABLE [%s] DROP "%s" %s' % \ (table, column) else: statement = 'ALTER TABLE "%s" DROP COLUMN "%s"' % (table, column) sql.do_update(statement) except SqlException, e: print("WARNING: %s" % e )
def execute(my): search_type_obj = SearchType.get(my.search_type) database = search_type_obj.get_database() table = search_type_obj.get_table() alter = AlterTable(my.search_type) alter.drop(my.attr_name) # log it first before committing AlterTableUndo.log_drop(database,table, my.attr_name) alter.commit()
def execute(self): search_type_obj = SearchType.get(self.search_type) database = search_type_obj.get_database() table = search_type_obj.get_table() alter = AlterTable(self.search_type) alter.drop(self.attr_name) # log it first before committing AlterTableUndo.log_drop(database,table, self.attr_name) alter.commit()
def execute(my): search_type_obj = SearchType.get(my.search_type) database = search_type_obj.get_database() table = search_type_obj.get_table() alter = AlterTable(my.search_type) #TODO: check the varchar length and put it in alter.modify(my.attr_name, my.data_type, not_null=not my.nullable) # log it first before committing to get the corrent from and to data type AlterTableUndo.log_modify(database,table, my.attr_name, \ my.data_type, not my.nullable) alter.commit()
def execute(self): search_type_obj = SearchType.get(self.search_type) database = search_type_obj.get_database() table = search_type_obj.get_table() alter = AlterTable(self.search_type) #TODO: check the varchar length and put it in alter.modify(self.attr_name, self.data_type, not_null=not self.nullable) # log it first before committing to get the corrent from and to data type AlterTableUndo.log_modify(database,table, self.attr_name, \ self.data_type, not self.nullable) alter.commit()
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)
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)