@@ -25,8 +25,8 @@ import (
2525 "log"
2626 "strings"
2727
28- "github.com/xwb1989 /sqlparser/dependency/querypb"
29- "github.com/xwb1989 /sqlparser/dependency/sqltypes"
28+ "github.com/CovenantSQL /sqlparser/dependency/querypb"
29+ "github.com/CovenantSQL /sqlparser/dependency/sqltypes"
3030)
3131
3232// Instructions for creating new types: If a type
@@ -673,6 +673,7 @@ const (
673673 DropStr = "drop"
674674 RenameStr = "rename"
675675 TruncateStr = "truncate"
676+ DropIndexStr = "drop index"
676677 CreateVindexStr = "create vindex"
677678 AddColVindexStr = "add vindex"
678679 DropColVindexStr = "drop vindex"
@@ -696,8 +697,14 @@ func (node *DDL) Format(buf *TrackedBuffer) {
696697 exists = " if exists"
697698 }
698699 buf .Myprintf ("%s table%s %v" , node .Action , exists , node .Table )
700+ case DropIndexStr :
701+ exists := ""
702+ if node .IfExists {
703+ exists = " if exists"
704+ }
705+ buf .Myprintf ("%s%s %v" , node .Action , exists , node .Table )
699706 case RenameStr :
700- buf .Myprintf ("%s table %v to %v" , node .Action , node .Table , node .NewName )
707+ buf .Myprintf ("alter table %v %s to %v" , node .Table , node .Action , node .NewName )
701708 case AlterStr :
702709 if node .PartitionSpec != nil {
703710 buf .Myprintf ("%s table %v %v" , node .Action , node .Table , node .PartitionSpec )
@@ -935,12 +942,6 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
935942 if ct .Zerofill {
936943 opts = append (opts , keywordStrings [ZEROFILL ])
937944 }
938- if ct .Charset != "" {
939- opts = append (opts , keywordStrings [CHARACTER ], keywordStrings [SET ], ct .Charset )
940- }
941- if ct .Collate != "" {
942- opts = append (opts , keywordStrings [COLLATE ], ct .Collate )
943- }
944945 if ct .NotNull {
945946 opts = append (opts , keywordStrings [NOT ], keywordStrings [NULL ])
946947 }
@@ -953,9 +954,6 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
953954 if ct .Autoincrement {
954955 opts = append (opts , keywordStrings [AUTO_INCREMENT ])
955956 }
956- if ct .Comment != nil {
957- opts = append (opts , keywordStrings [COMMENT_KEYWORD ], String (ct .Comment ))
958- }
959957 if ct .KeyOpt == colKeyPrimary {
960958 opts = append (opts , keywordStrings [PRIMARY ], keywordStrings [KEY ])
961959 }
@@ -965,9 +963,6 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
965963 if ct .KeyOpt == colKeyUniqueKey {
966964 opts = append (opts , keywordStrings [UNIQUE ], keywordStrings [KEY ])
967965 }
968- if ct .KeyOpt == colKeySpatialKey {
969- opts = append (opts , keywordStrings [SPATIAL ], keywordStrings [KEY ])
970- }
971966 if ct .KeyOpt == colKey {
972967 opts = append (opts , keywordStrings [KEY ])
973968 }
@@ -1051,10 +1046,6 @@ func (ct *ColumnType) SQLType() querypb.Type {
10511046 return sqltypes .Char
10521047 case keywordStrings [VARCHAR ]:
10531048 return sqltypes .VarChar
1054- case keywordStrings [BINARY ]:
1055- return sqltypes .Binary
1056- case keywordStrings [VARBINARY ]:
1057- return sqltypes .VarBinary
10581049 case keywordStrings [DATE ]:
10591050 return sqltypes .Date
10601051 case keywordStrings [TIME ]:
@@ -1071,30 +1062,8 @@ func (ct *ColumnType) SQLType() querypb.Type {
10711062 return sqltypes .Float64
10721063 case keywordStrings [DECIMAL ]:
10731064 return sqltypes .Decimal
1074- case keywordStrings [BIT ]:
1075- return sqltypes .Bit
1076- case keywordStrings [ENUM ]:
1077- return sqltypes .Enum
10781065 case keywordStrings [SET ]:
10791066 return sqltypes .Set
1080- case keywordStrings [JSON ]:
1081- return sqltypes .TypeJSON
1082- case keywordStrings [GEOMETRY ]:
1083- return sqltypes .Geometry
1084- case keywordStrings [POINT ]:
1085- return sqltypes .Geometry
1086- case keywordStrings [LINESTRING ]:
1087- return sqltypes .Geometry
1088- case keywordStrings [POLYGON ]:
1089- return sqltypes .Geometry
1090- case keywordStrings [GEOMETRYCOLLECTION ]:
1091- return sqltypes .Geometry
1092- case keywordStrings [MULTIPOINT ]:
1093- return sqltypes .Geometry
1094- case keywordStrings [MULTILINESTRING ]:
1095- return sqltypes .Geometry
1096- case keywordStrings [MULTIPOLYGON ]:
1097- return sqltypes .Geometry
10981067 }
10991068 panic ("unimplemented type " + ct .Type )
11001069}
@@ -1805,15 +1774,13 @@ type JoinTableExpr struct {
18051774
18061775// JoinTableExpr.Join
18071776const (
1808- JoinStr = "join"
1809- InnerJoinStr = "inner join"
1810- CrossJoinStr = "cross join"
1811- StraightJoinStr = "straight_join"
1812- LeftJoinStr = "left join"
1813- RightJoinStr = "right join"
1814- NaturalJoinStr = "natural join"
1815- NaturalLeftJoinStr = "natural left join"
1816- NaturalRightJoinStr = "natural right join"
1777+ JoinStr = "join"
1778+ InnerJoinStr = "inner join"
1779+ CrossJoinStr = "cross join"
1780+ StraightJoinStr = "straight_join"
1781+ LeftJoinStr = "left join"
1782+ NaturalJoinStr = "natural join"
1783+ NaturalLeftJoinStr = "natural left join"
18171784)
18181785
18191786// Format formats the node.
@@ -1946,6 +1913,7 @@ func (*ConvertUsingExpr) iExpr() {}
19461913func (* MatchExpr ) iExpr () {}
19471914func (* GroupConcatExpr ) iExpr () {}
19481915func (* Default ) iExpr () {}
1916+ func (* TimeExpr ) iExpr () {}
19491917
19501918// ReplaceExpr finds the from expression from root
19511919// and replaces it with to. If from matches root,
@@ -2105,22 +2073,20 @@ type ComparisonExpr struct {
21052073
21062074// ComparisonExpr.Operator
21072075const (
2108- EqualStr = "="
2109- LessThanStr = "<"
2110- GreaterThanStr = ">"
2111- LessEqualStr = "<="
2112- GreaterEqualStr = ">="
2113- NotEqualStr = "!="
2114- NullSafeEqualStr = "<=>"
2115- NullSafeNotEqualStr = "<>"
2116- InStr = "in"
2117- NotInStr = "not in"
2118- LikeStr = "like"
2119- NotLikeStr = "not like"
2120- RegexpStr = "regexp"
2121- NotRegexpStr = "not regexp"
2122- JSONExtractOp = "->"
2123- JSONUnquoteExtractOp = "->>"
2076+ EqualStr = "="
2077+ LessThanStr = "<"
2078+ GreaterThanStr = ">"
2079+ LessEqualStr = "<="
2080+ GreaterEqualStr = ">="
2081+ NotEqualStr = "!="
2082+ NullSafeEqualStr = "<=>"
2083+ NullSafeNotEqualStr = "<>"
2084+ InStr = "in"
2085+ NotInStr = "not in"
2086+ LikeStr = "like"
2087+ NotLikeStr = "not like"
2088+ RegexpStr = "regexp"
2089+ NotRegexpStr = "not regexp"
21242090)
21252091
21262092// Format formats the node.
@@ -2634,6 +2600,24 @@ func (node *CollateExpr) replace(from, to Expr) bool {
26342600 return replaceExprs (from , to , & node .Expr )
26352601}
26362602
2603+ // TimeExpr represents a time expression.
2604+ type TimeExpr struct {
2605+ Expr ColIdent
2606+ }
2607+
2608+ // Format formats the node.
2609+ func (node * TimeExpr ) Format (buf * TrackedBuffer ) {
2610+ buf .Myprintf (node .Expr .Lowered ())
2611+ }
2612+
2613+ func (node * TimeExpr ) walkSubtree (visit Visit ) error {
2614+ return nil
2615+ }
2616+
2617+ func (node * TimeExpr ) replace (from , to Expr ) bool {
2618+ return false
2619+ }
2620+
26372621// FuncExpr represents a function call.
26382622type FuncExpr struct {
26392623 Qualifier TableIdent
@@ -2816,7 +2800,7 @@ type ConvertExpr struct {
28162800
28172801// Format formats the node.
28182802func (node * ConvertExpr ) Format (buf * TrackedBuffer ) {
2819- buf .Myprintf ("convert (%v, %v)" , node .Expr , node .Type )
2803+ buf .Myprintf ("cast (%v as %v)" , node .Expr , node .Type )
28202804}
28212805
28222806func (node * ConvertExpr ) walkSubtree (visit Visit ) error {
0 commit comments