in core/lib/sqlparse/diff.py [0:0]
def _gen_tbl_attr_sql(self):
"""
Generate the table attribute section for ALTER TABLE statement
"""
segments = []
for attr in self.attrs_to_check:
tbl_option_old = getattr(self.left, attr)
tbl_option_new = getattr(self.right, attr)
if not is_equal(tbl_option_old, tbl_option_new):
# when tbl_option_new is None, do "alter table xxx attr=None" won't work
if attr == "comment" and tbl_option_new is None:
segments.append("{}={}".format(attr, "''"))
elif attr == "row_format" and tbl_option_new is None:
segments.append("{}={}".format(attr, "default"))
elif attr == "partition" and self.ignore_partition is False:
self.generate_table_partition_operations(tbl_option_new, segments)
else:
segments.append("{}={}".format(attr, tbl_option_new))
# populate alter types data
if attr == "row_format":
self.add_alter_type(TableAlterType.CHANGE_ROW_FORMAT)
elif attr == "key_block_size":
self.add_alter_type(TableAlterType.CHANGE_TABLE_KEY_BLOCK_SIZE)
elif attr == "charset":
self.add_alter_type(TableAlterType.CHANGE_TABLE_CHARSET)
elif attr == "collate":
self.add_alter_type(TableAlterType.CHANGE_TABLE_COLLATE)
elif attr == "comment":
self.add_alter_type(TableAlterType.CHANGE_TABLE_COMMENT)
elif attr == "engine":
self.add_alter_type(TableAlterType.CHANGE_ENGINE)
# we don't want to alter auto_increment value in db, just record the alter type
if not is_equal(self.left.auto_increment, self.right.auto_increment):
self.add_alter_type(TableAlterType.CHANGE_AUTO_INC_VAL)
return segments