File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed
javacc/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/test/select Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change 2121 */
2222package net .sf .jsqlparser .expression ;
2323
24+ import net .sf .jsqlparser .statement .create .table .ColDataType ;
25+
2426/**
2527 *
2628 * @author tw
2729 */
2830public class CastExpression implements Expression {
2931
3032 private Expression leftExpression ;
31- private String typeName ;
33+ private ColDataType type ;
3234
33- public String getTypeName () {
34- return typeName ;
35+ public ColDataType getType () {
36+ return type ;
3537 }
3638
37- public void setTypeName ( String typeName ) {
38- this .typeName = typeName ;
39+ public void setType ( ColDataType type ) {
40+ this .type = type ;
3941 }
4042
4143 public Expression getLeftExpression () {
@@ -53,6 +55,6 @@ public void accept(ExpressionVisitor expressionVisitor) {
5355
5456 @ Override
5557 public String toString () {
56- return "CAST(" + leftExpression + " AS " + typeName + ")" ;
58+ return "CAST(" + leftExpression + " AS " + type . toString () + ")" ;
5759 }
5860}
Original file line number Diff line number Diff line change @@ -471,7 +471,7 @@ public void visit(CastExpression cast) {
471471 buffer .append ("CAST(" );
472472 buffer .append (cast .getLeftExpression ());
473473 buffer .append (" AS " );
474- buffer .append (cast .getTypeName ());
474+ buffer .append (cast .getType ());
475475 buffer .append (")" );
476476 }
477477
Original file line number Diff line number Diff line change @@ -1565,20 +1565,20 @@ ExtractExpression ExtractExpression() :
15651565CastExpression CastExpression():
15661566{
15671567 CastExpression retval = new CastExpression();
1568- String typeName = null;
1568+ ColDataType type = null;
15691569 Expression expression = null;
15701570}
15711571{
15721572 <K_CAST>
15731573 "("
15741574 expression=SimpleExpression()
15751575 <K_AS>
1576- typeName=RelObjectName ()
1576+ type=ColDataType ()
15771577 ")"
15781578
15791579 {
15801580 retval.setLeftExpression(expression);
1581- retval.setTypeName(typeName );
1581+ retval.setType(type );
15821582 return retval;
15831583 }
15841584}
Original file line number Diff line number Diff line change @@ -589,6 +589,11 @@ public void testCastInCast2() throws JSQLParserException {
589589 String stmt = "SELECT CAST('test' + CAST(assertEqual AS numeric) AS varchar) FROM tabelle1" ;
590590 assertSqlCanBeParsedAndDeparsed (stmt );
591591 }
592+
593+ public void testCastTypeProblem () throws JSQLParserException {
594+ String stmt = "SELECT CAST(col1 AS varchar (256)) FROM tabelle1" ;
595+ assertSqlCanBeParsedAndDeparsed (stmt );
596+ }
592597
593598 public void testCaseElseAddition () throws JSQLParserException {
594599 String stmt = "SELECT CASE WHEN 1 + 3 > 20 THEN 0 ELSE 1000 + 1 END AS d FROM dual" ;
You can’t perform that action at this time.
0 commit comments