def show_create_table(instance, db, table, standardize=True):
""" Get a standardized CREATE TABLE statement
Args:
instance - a hostAddr object
db - the MySQL database to run against
table - the table on the db database to run against
standardize - Remove AUTO_INCREMENT=$NUM and similar
Returns:
A string of the CREATE TABLE statement
"""
conn = connect_mysql(instance)
cursor = conn.cursor()
try:
cursor.execute('SHOW CREATE TABLE `{db}`.`{table}`'.format(
table=table, db=db))
ret = cursor.fetchone()['Create Table']
if standardize is True:
ret = re.sub('AUTO_INCREMENT=[0-9]+ ', '', ret)
except MySQLdb.ProgrammingError as detail:
(error_code, msg) = detail.args
if error_code != MYSQL_ERROR_NO_SUCH_TABLE:
raise
ret = ''
return ret
评论列表
文章目录