xwb1989 / sqlparser

SQL Parser implemented in Go
Apache License 2.0
1.49k stars 240 forks source link

"SET NAMES utf8;" doesn't work #36

Closed philiplb closed 6 years ago

philiplb commented 6 years ago

Hi, I got another one:

r := strings.NewReader(`SET NAMES utf8;`)

tokens := sqlparser.NewTokenizer(r)
for {
    stmt, err := sqlparser.ParseNext(tokens)
    if err == io.EOF {
        break
    }
    fmt.Println(sqlparser.String(stmt))
    if err != nil {
        fmt.Println(err)
    }
}

This results only in this output:

set

The rest is missing?

bramp commented 6 years ago

Yup, in sql.y:

set_statement:
  SET comment_opt charset_or_character_set charset_value force_eof
  {
    $$ = &Set{Comments: Comments($2), Charset: $4}
  }
...
charset_or_character_set:
  CHARSET
| CHARACTER SET
| NAMES

charset_or_character_set ($3) does not seem to be stored in the sqlparser.Set type. That should be a easy fix.

bramp commented 6 years ago

This has now been fixed.