1212import net .sf .jsqlparser .parser .ASTNodeAccessImpl ;
1313import net .sf .jsqlparser .statement .create .table .ColDataType ;
1414
15+ import java .util .Objects ;
16+
1517public class TranscodingFunction extends ASTNodeAccessImpl implements Expression {
18+ private String keyword = "CONVERT" ;
1619 private boolean isTranscodeStyle = true ;
1720 private ColDataType colDataType ;
1821 private Expression expression ;
1922 private String transcodingName ;
2023
24+ public TranscodingFunction (String keyword , Expression expression , String transcodingName ) {
25+ this .keyword = Objects .requireNonNullElse (keyword , "CONVERT" ).toUpperCase ();
26+ this .expression = expression ;
27+ this .transcodingName = transcodingName ;
28+ }
29+
2130 public TranscodingFunction (Expression expression , String transcodingName ) {
2231 this .expression = expression ;
2332 this .transcodingName = transcodingName ;
2433 }
2534
35+ public TranscodingFunction (String keyword , ColDataType colDataType , Expression expression ,
36+ String transcodingName ) {
37+ this .keyword = Objects .requireNonNullElse (keyword , "CONVERT" ).toUpperCase ();
38+ this .colDataType = colDataType ;
39+ this .expression = expression ;
40+ this .transcodingName = transcodingName ;
41+ this .isTranscodeStyle = false ;
42+ }
43+
2644 public TranscodingFunction (ColDataType colDataType , Expression expression ,
2745 String transcodingName ) {
2846 this .colDataType = colDataType ;
@@ -35,6 +53,15 @@ public TranscodingFunction() {
3553 this (null , null );
3654 }
3755
56+ public String getKeyword () {
57+ return keyword ;
58+ }
59+
60+ public TranscodingFunction setKeyword (String keyword ) {
61+ this .keyword = Objects .requireNonNullElse (keyword , "CONVERT" ).toUpperCase ();
62+ return this ;
63+ }
64+
3865 public Expression getExpression () {
3966 return expression ;
4067 }
@@ -87,14 +114,16 @@ public <T, S> T accept(ExpressionVisitor<T> expressionVisitor, S context) {
87114 public StringBuilder appendTo (StringBuilder builder ) {
88115 if (isTranscodeStyle ) {
89116 return builder
90- .append ("CONVERT( " )
117+ .append (keyword )
118+ .append ("( " )
91119 .append (expression )
92120 .append (" USING " )
93121 .append (transcodingName )
94122 .append (" )" );
95123 } else {
96124 return builder
97- .append ("CONVERT( " )
125+ .append (keyword )
126+ .append ("( " )
98127 .append (colDataType )
99128 .append (", " )
100129 .append (expression )
0 commit comments