Skip to content

Commit

Permalink
fix parseDDL bug with escaped quote (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
duc-cnzj committed Apr 24, 2022
1 parent 3ad599a commit 0a99da5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ddlmod.go
Expand Up @@ -32,15 +32,19 @@ func parseDDL(strs ...string) (*ddl, error) {
if sections := tableRegexp.FindStringSubmatch(str); len(sections) > 0 {
var (
ddlBody = sections[2]
ddlBodyRunes = []rune(ddlBody)
bracketLevel int
quote rune
buf string
)

result.head = sections[1]

for idx, c := range []rune(ddlBody) {
var next rune = 0
for idx := 0; idx < len(ddlBodyRunes); idx++ {
var (
next rune = 0
c = ddlBodyRunes[idx]
)
if idx+1 < len(ddlBody) {
next = []rune(ddlBody)[idx+1]
}
Expand Down
5 changes: 5 additions & 0 deletions ddlmod_test.go
Expand Up @@ -180,6 +180,11 @@ func TestGetColumns(t *testing.T) {
ddl: "CREATE TABLE Persons (ID int NOT NULL,LastName varchar(255) NOT NULL,FirstName varchar(255),Age int,CHECK (Age>=18),CHECK (FirstName!='John'))",
columns: []string{"`ID`", "`LastName`", "`FirstName`", "`Age`"},
},
{
name: "with_escaped_quote",
ddl: "CREATE TABLE Persons (ID int NOT NULL,LastName varchar(255) NOT NULL DEFAULT \"\",FirstName varchar(255))",
columns: []string{"`ID`", "`LastName`", "`FirstName`"},
},
}

for _, p := range params {
Expand Down

0 comments on commit 0a99da5

Please sign in to comment.