@@ -726,8 +726,9 @@ func TestInsertComments(t *testing.T) {
726726 }
727727}
728728
729- func TestEmptySpecialComments (t * testing.T ) {
730- for _ , input := range []string {"select /*!*/ 1" , "select /*!1234*/ 1" } {
729+ func TestFloatColumnPrecision (t * testing.T ) {
730+ for _ , typ := range []string {"float" , "double" , "real" } {
731+ input := "create table t (a " + typ + "(24) default current_timestamp)"
731732 queries , statements , err := ParseMultiple (NewStringTokenizer (input ))
732733 if err != nil {
733734 t .Errorf ("ParseMultiple(%q): %v" , input , err )
@@ -737,8 +738,48 @@ func TestEmptySpecialComments(t *testing.T) {
737738 t .Errorf ("ParseMultiple(%q): unexpected result %v, %v" , input , queries , statements )
738739 continue
739740 }
740- if got := String (statements [0 ]); got != "select 1" {
741- t .Errorf ("ParseMultiple(%q) = %q, want select 1" , input , got )
741+ ddl := statements [0 ].(* DDL )
742+ if ddl .TableSpec == nil || len (ddl .TableSpec .Columns ) != 1 {
743+ t .Errorf ("ParseMultiple(%q): missing column specification" , input )
744+ continue
745+ }
746+ column := ddl .TableSpec .Columns [0 ].Type
747+ if column .Type != typ || column .Length == nil || string (column .Length .Val ) != "24" || column .Scale != nil {
748+ t .Errorf ("ParseMultiple(%q): unexpected column type %+v" , input , column )
749+ }
750+ foundDefault := false
751+ Walk (func (node SQLNode ) (bool , error ) {
752+ if value , ok := node .(* SQLVal ); ok && value .Type == ValArg && bytes .EqualFold (value .Val , []byte ("current_timestamp" )) {
753+ foundDefault = true
754+ }
755+ return true , nil
756+ }, column .Default )
757+ if ! foundDefault {
758+ t .Errorf ("ParseMultiple(%q): missing stateful default" , input )
759+ }
760+ }
761+ }
762+
763+ func TestFloatColumnPrecisionSemicolonDefault (t * testing.T ) {
764+ for _ , typ := range []string {"float" , "double" , "real" } {
765+ input := "create table t (a " + typ + "(24) default 'a;b')"
766+ queries , statements , err := ParseMultiple (NewStringTokenizer (input ))
767+ if err != nil {
768+ t .Errorf ("ParseMultiple(%q): %v" , input , err )
769+ continue
770+ }
771+ if len (queries ) != 1 || queries [0 ] != input || len (statements ) != 1 {
772+ t .Errorf ("ParseMultiple(%q): unexpected result %v, %v" , input , queries , statements )
773+ continue
774+ }
775+ ddl := statements [0 ].(* DDL )
776+ if ddl .TableSpec == nil || len (ddl .TableSpec .Columns ) != 1 {
777+ t .Errorf ("ParseMultiple(%q): missing column specification" , input )
778+ continue
779+ }
780+ value := ddl .TableSpec .Columns [0 ].Type .Default
781+ if value == nil || value .Type != StrVal || string (value .Val ) != "a;b" {
782+ t .Errorf ("ParseMultiple(%q): unexpected default %v" , input , value )
742783 }
743784 }
744785}
@@ -846,6 +887,23 @@ func TestKeywords(t *testing.T) {
846887 }
847888}
848889
890+ func TestEmptySpecialComments (t * testing.T ) {
891+ for _ , input := range []string {"select /*!*/ 1" , "select /*!1234*/ 1" } {
892+ queries , statements , err := ParseMultiple (NewStringTokenizer (input ))
893+ if err != nil {
894+ t .Errorf ("ParseMultiple(%q): %v" , input , err )
895+ continue
896+ }
897+ if len (queries ) != 1 || queries [0 ] != input || len (statements ) != 1 {
898+ t .Errorf ("ParseMultiple(%q): unexpected result %v, %v" , input , queries , statements )
899+ continue
900+ }
901+ if got := String (statements [0 ]); got != "select 1" {
902+ t .Errorf ("ParseMultiple(%q) = %q, want select 1" , input , got )
903+ }
904+ }
905+ }
906+
849907func TestConvert (t * testing.T ) {
850908 validSQL := []struct {
851909 input string
0 commit comments