Skip to content

Commit c57eec9

Browse files
authored
Fixed the bug (#23)
- Syntax error occurred when SQL contains partition queries.
1 parent 9fb66f0 commit c57eec9

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

builder/builder.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func willAlterTableCharacterSet(old, new *mysql.Table) string {
6060
alter = append(alter, new.ToConvertCharsetSQL())
6161
old.TableCollation = new.TableCollation
6262
}
63-
return new.ToAlterSQL(alter)
63+
return new.ToAlterSQL(alter, "")
6464
}
6565

6666
func willAlterColumnCharacterSet(old, new *mysql.Table) []string {
@@ -81,7 +81,7 @@ func willAlterColumnCharacterSet(old, new *mysql.Table) []string {
8181
continue
8282
}
8383
oldCols[colName].CollationName = newCol.CollationName
84-
sqls = append(sqls, new.ToAlterSQL([]string{newCol.ToModifyCharsetSQL()}))
84+
sqls = append(sqls, new.ToAlterSQL([]string{newCol.ToModifyCharsetSQL()}, ""))
8585
}
8686
return sqls
8787
}
@@ -100,11 +100,7 @@ func willAlter(old, new *mysql.Table) string {
100100
alter = append(alter, willAddColumn(old, new)...)
101101
alter = append(alter, willAddIndex(old, new)...)
102102
alter = append(alter, willModifyColumn(old, new)...)
103-
sql := willModifyPartition(old, new)
104-
if sql != "" {
105-
alter = append(alter, sql)
106-
}
107-
return new.ToAlterSQL(alter)
103+
return new.ToAlterSQL(alter, willModifyPartition(old, new))
108104
}
109105

110106
func willAddColumn(old, new *mysql.Table) []string {

dialect/mysql/table.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
%s
4040
) engine=%s default charset=%s %s`
4141
dropSQLFmt string = `drop table if exists %s`
42-
alterSQLFmt string = `alter table %s
42+
alterSQLFmt string = `alter table %s %s
4343
%s`
4444
)
4545

@@ -56,11 +56,11 @@ func (m *Table) GetCharset() string {
5656
return seg[0]
5757
}
5858

59-
func (m *Table) ToAlterSQL(sqls []string) string {
59+
func (m *Table) ToAlterSQL(sqls []string, partitionSql string) string {
6060
if len(sqls) <= 0 {
6161
return ""
6262
}
63-
return fmt.Sprintf(alterSQLFmt, m.GetFormatedTableName(), strings.Join(sqls, ",\n "))
63+
return fmt.Sprintf(alterSQLFmt, m.GetFormatedTableName(), strings.Join(sqls, ",\n "), partitionSql)
6464
}
6565

6666
func (m Tables) GetFormatedTableNames() []string {

0 commit comments

Comments
 (0)