001 002package gudusoft.gsqlparser.scriptWriter; 003 004import gudusoft.gsqlparser.*; 005import gudusoft.gsqlparser.nodes.*; 006import gudusoft.gsqlparser.nodes.functions.TRangeNFunction; 007import gudusoft.gsqlparser.nodes.mssql.TProcedureOption; 008import gudusoft.gsqlparser.nodes.mysql.TGroupConcatParam; 009import gudusoft.gsqlparser.nodes.oracle.TInvokerRightsClause; 010import gudusoft.gsqlparser.nodes.teradata.TDataConversionItem; 011import gudusoft.gsqlparser.nodes.teradata.TRangeNFunctionItem; 012import gudusoft.gsqlparser.stmt.*; 013import gudusoft.gsqlparser.stmt.mssql.*; 014import gudusoft.gsqlparser.stmt.oracle.TPlsqlCreateProcedure; 015import gudusoft.gsqlparser.util.SQLUtil; 016import org.w3c.dom.Element; 017 018import java.lang.reflect.Method; 019 020/** 021 * supported statements: 022 * <ul> 023 * <li>alter table</li> 024 * <li>Create table</li> 025 * <li>Create view</li> 026 * <li>Delete</li> 027 * <li>Insert</li> 028 * <li>Merge</li> 029 * <li>Select</li> 030 * <li>Update</li> 031 * </ul> 032 */ 033 034public class TScriptGeneratorVisitor extends TParseTreeVisitor { 035 036 private TScriptWriter scriptWriter; 037 038 // private EDbVendor dbVendor; 039 040 void acceptToken(TSourceToken st) { 041 scriptWriter.addToken(st); 042 } 043 044 void acceptSymbol(String symbol) { 045 scriptWriter.addSymbol(symbol); 046 } 047 048 void acceptSymbol(String symbol, int tokenCode) { 049 scriptWriter.addSymbol(symbol, tokenCode); 050 } 051 052 void acceptKeyword(String keyword) { 053 scriptWriter.addKeyword(keyword); 054 } 055 056 void acceptKeyword(String keyword, boolean spaceAround) { 057 scriptWriter.addKeyword(keyword, spaceAround); 058 } 059 060 void acceptNewline() { 061 scriptWriter.addNewline(); 062 } 063 064 void acceptSemicolon() { 065 scriptWriter.addSemicolon(); 066 } 067 068 void acceptSpace(int count) { 069 scriptWriter.addSpace(count); 070 } 071 072 void acceptLiteral(String literal) { 073 scriptWriter.addLiteral(literal); 074 } 075 076 void acceptIdentifier(String identifier) { 077 scriptWriter.addIdentifier(identifier); 078 } 079 080 void acceptOracleHint(String identifier) { 081 scriptWriter.acceptOracleHint(identifier); 082 } 083 084 public TScriptGeneratorVisitor(TScriptWriter scriptWriter) { 085 this.scriptWriter = scriptWriter; 086 // this.dbVendor = dbVendor; 087 } 088 089 public void preVisit(TConstant node) { 090 switch (node.getLiteralType()) { 091 case etNumber: 092 acceptToken(node.getValueToken()); 093 break; 094 case etFloat: 095 acceptToken(node.getValueToken()); 096 break; 097 case etString: 098 acceptToken(node.getValueToken()); 099 break; 100 case etTimestamp: 101 acceptKeyword("timestamp"); 102 acceptToken(node.getValueToken()); 103 break; 104 case etDate: 105 acceptKeyword("date"); 106 acceptToken(node.getValueToken()); 107 break; 108 case etInterval: 109 acceptKeyword("interval"); 110 if (node.getSignToken() != null){ 111 acceptToken(node.getSignToken()); 112 } 113 if (node.getIntervalValueTokens().size() > 0){ // databricks 114 for(int i=0;i<node.getIntervalValueTokens().size();i++){ 115 acceptToken(node.getIntervalValueTokens().get(i)); 116 //acceptSpace(1); 117 acceptKeyword(node.getIntervalTypes().get(i).getText()); 118 //acceptSpace(1); 119 } 120 }else{ 121 122 acceptToken(node.getValueToken()); 123 switch (node.getIntervalType()) { 124 case itYear: 125 acceptKeyword("year"); 126 if (node.getLeadingPrecision() != null) { 127 acceptSymbol("("); 128 acceptToken(node.getLeadingPrecision()); 129 acceptSymbol(")"); 130 } 131 break; 132 case itYearToYear: 133 acceptKeyword("year"); 134 if (node.getLeadingPrecision() != null) { 135 acceptSymbol("("); 136 acceptToken(node.getLeadingPrecision()); 137 acceptSymbol(")"); 138 } 139 acceptKeyword("to"); 140 acceptKeyword("year"); 141 break; 142 case itYearToMonth: 143 acceptKeyword("year"); 144 if (node.getLeadingPrecision() != null) { 145 acceptSymbol("("); 146 acceptToken(node.getLeadingPrecision()); 147 acceptSymbol(")"); 148 } 149 acceptKeyword("to"); 150 acceptKeyword("month"); 151 break; 152 case itMonth: 153 acceptKeyword("month"); 154 if (node.getLeadingPrecision() != null) { 155 acceptSymbol("("); 156 acceptToken(node.getLeadingPrecision()); 157 acceptSymbol(")"); 158 } 159 break; 160 case itMonthToMonth: 161 acceptKeyword("month"); 162 if (node.getLeadingPrecision() != null) { 163 acceptSymbol("("); 164 acceptToken(node.getLeadingPrecision()); 165 acceptSymbol(")"); 166 } 167 acceptKeyword("to"); 168 acceptKeyword("month"); 169 break; 170 case itDay: 171 acceptKeyword("day"); 172 if (node.getLeadingPrecision() != null) { 173 acceptSymbol("("); 174 acceptToken(node.getLeadingPrecision()); 175 acceptSymbol(")"); 176 } 177 break; 178 case itDayToDay: 179 acceptKeyword("day"); 180 if (node.getLeadingPrecision() != null) { 181 acceptSymbol("("); 182 acceptToken(node.getLeadingPrecision()); 183 acceptSymbol(")"); 184 } 185 acceptKeyword("to"); 186 acceptKeyword("day"); 187 break; 188 case itDayToHour: 189 acceptKeyword("day"); 190 if (node.getLeadingPrecision() != null) { 191 acceptSymbol("("); 192 acceptToken(node.getLeadingPrecision()); 193 acceptSymbol(")"); 194 } 195 acceptKeyword("to"); 196 acceptKeyword("hour"); 197 break; 198 case itDayToMinute: 199 acceptKeyword("day"); 200 if (node.getLeadingPrecision() != null) { 201 acceptSymbol("("); 202 acceptToken(node.getLeadingPrecision()); 203 acceptSymbol(")"); 204 } 205 acceptKeyword("to"); 206 acceptKeyword("minute"); 207 break; 208 case itDayToSecond: 209 acceptKeyword("day"); 210 if (node.getLeadingPrecision() != null) { 211 acceptSymbol("("); 212 acceptToken(node.getLeadingPrecision()); 213 acceptSymbol(")"); 214 } 215 acceptKeyword("to"); 216 acceptKeyword("second"); 217 if (node.getFractionalSecondsPrecision() != null) { 218 acceptSymbol("("); 219 acceptToken(node.getFractionalSecondsPrecision()); 220 acceptSymbol(")"); 221 } 222 break; 223 case itHour: 224 acceptKeyword("hour"); 225 if (node.getLeadingPrecision() != null) { 226 acceptSymbol("("); 227 acceptToken(node.getLeadingPrecision()); 228 acceptSymbol(")"); 229 } 230 break; 231 case itHourToHour: 232 acceptKeyword("hour"); 233 if (node.getLeadingPrecision() != null) { 234 acceptSymbol("("); 235 acceptToken(node.getLeadingPrecision()); 236 acceptSymbol(")"); 237 } 238 acceptKeyword("to"); 239 acceptKeyword("hour"); 240 break; 241 case itHourToMinute: 242 acceptKeyword("hour"); 243 if (node.getLeadingPrecision() != null) { 244 acceptSymbol("("); 245 acceptToken(node.getLeadingPrecision()); 246 acceptSymbol(")"); 247 } 248 acceptKeyword("to"); 249 acceptKeyword("minute"); 250 break; 251 case itHourToSecond: 252 acceptKeyword("hour"); 253 if (node.getLeadingPrecision() != null) { 254 acceptSymbol("("); 255 acceptToken(node.getLeadingPrecision()); 256 acceptSymbol(")"); 257 } 258 acceptKeyword("to"); 259 acceptKeyword("second"); 260 if (node.getFractionalSecondsPrecision() != null) { 261 acceptSymbol("("); 262 acceptToken(node.getFractionalSecondsPrecision()); 263 acceptSymbol(")"); 264 } 265 break; 266 case itMinute: 267 acceptKeyword("minute"); 268 if (node.getLeadingPrecision() != null) { 269 acceptSymbol("("); 270 acceptToken(node.getLeadingPrecision()); 271 acceptSymbol(")"); 272 } 273 break; 274 case itMinuteToMinute: 275 acceptKeyword("minute"); 276 if (node.getLeadingPrecision() != null) { 277 acceptSymbol("("); 278 acceptToken(node.getLeadingPrecision()); 279 acceptSymbol(")"); 280 } 281 acceptKeyword("to"); 282 acceptKeyword("minute"); 283 break; 284 case itMinuteToSecond: 285 acceptKeyword("minute"); 286 if (node.getLeadingPrecision() != null) { 287 acceptSymbol("("); 288 acceptToken(node.getLeadingPrecision()); 289 acceptSymbol(")"); 290 } 291 acceptKeyword("to"); 292 acceptKeyword("second"); 293 if (node.getFractionalSecondsPrecision() != null) { 294 acceptSymbol("("); 295 acceptToken(node.getFractionalSecondsPrecision()); 296 acceptSymbol(")"); 297 } 298 break; 299 case itSecond: 300 acceptKeyword("second"); 301 if (node.getLeadingPrecision() != null) { 302 acceptSymbol("("); 303 acceptToken(node.getLeadingPrecision()); 304 if (node.getFractionalSecondsPrecision() != null) { 305 acceptSymbol(","); 306 acceptToken(node.getFractionalSecondsPrecision()); 307 } 308 acceptSymbol(")"); 309 } 310 break; 311 } 312 } 313 break; 314 case etBindVar: 315 acceptToken(node.getBind1()); 316 if (node.getIndicator() != null) { 317 acceptToken(node.getIndicator()); 318 } 319 acceptToken(node.getBind2()); 320 break; 321 default: 322 if (node.getStartToken() != null) { 323 visitNodeByToken(node); 324 } else { 325 if (node.getValueToken() != null) { 326 acceptToken(node.getValueToken()); 327 } 328// else if (node.getStringValue() != null) { 329// acceptLiteral(node.getStringValue()); 330// } 331 } 332 333 break; 334 } 335 } 336 337 public void preVisit(TObjectName node) { 338 // acceptIdentifier(node.toString()); 339 if (node.getServerToken() != null) { 340 acceptIdentifier(node.getServerToken().toString()); 341 acceptSymbol("."); 342 } 343 if ((node.getDatabaseToken() != null) && (!node.isImplicitDatabase())) { 344 acceptIdentifier(node.getDatabaseToken().toString()); 345 acceptSymbol("."); 346 } 347 if ((node.getSchemaToken() != null) && (!node.isImplicitSchema())) { 348 acceptIdentifier(node.getSchemaToken().toString()); 349 acceptSymbol("."); 350 } 351 if (node.getObjectToken() != null) { 352 acceptIdentifier(node.getObjectToken().toString()); 353 } 354 if (node.getPartToken() != null) { 355 if (node.getObjectToken() != null) { 356 acceptSymbol("."); 357 } 358 acceptIdentifier(node.getPartToken().toString()); 359 if (node.getPropertyToken() != null) { 360 acceptSymbol("."); 361 acceptIdentifier(node.getPropertyToken().toString()); 362 } 363 } 364 365 if (node.getDblink() != null) { 366 acceptSymbol("@"); 367 node.getDblink().accept(this); 368 } else if (node.getExclamationmark() != null) { 369 acceptSymbol("@"); 370 acceptSymbol("!"); 371 } 372 } 373 374 public void preVisit(TExpressionList node) { 375 for (int i = 0; i < node.size(); i++) { 376 node.getExpression(i).accept(this); 377 if (i != (node.size() - 1)) { 378 acceptSymbol(","); 379 } 380 } 381 } 382 383 384 385 public void preVisit(TRangeNFunction node){ 386 node.getExpr1( ).accept( this ); 387 for(TRangeNFunctionItem item:node.getRangeNFunctionItems()){ 388 item.accept(this); 389 } 390 } 391 392 393 public void preVisit( TFunctionCall node ) 394 { 395 node.getFunctionName( ).accept( this ); 396 if (node.hasParenthesis()){ 397 acceptSymbol( "(" ); 398 } 399 400 switch ( node.getAggregateType( ) ) 401 { 402 case distinct : 403 acceptKeyword( "distinct" ); 404 break; 405 case all : 406 acceptKeyword( "all" ); 407 break; 408 case unique : 409 acceptKeyword( "unique" ); 410 break; 411 } 412 switch ( node.getFunctionType( ) ) 413 { 414 case unknown_t : 415 if ( node.getArgs( ) != null ) 416 { 417 node.getArgs( ).accept( this ); 418 } 419 if (node.getSortClause() != null){ 420 node.getSortClause().accept(this); 421 } 422 break; 423 case udf_t : 424 case case_n_t : 425 case chr_t : 426 if ( node.getArgs( ) != null ) 427 { 428 node.getArgs( ).accept( this ); 429 } 430 if ( node.getWindowDef( ) != null ) 431 { 432 node.getWindowDef( ).accept( this ); 433 } 434 break; 435 case cast_t : 436 if (node.getExpr1() != null) { 437 node.getExpr1().accept(this); 438 acceptKeyword("as"); 439 if (node.getTypename() != null) { 440 node.getTypename().accept(this); 441 } 442 }else{ 443 // mssql use first argument in args instead of using expr1 444 node.getArgs().getExpression(0).accept(this); 445 } 446 447 if (node.getDataConversionItems() != null) { 448 for (TDataConversionItem item : node.getDataConversionItems()) { 449 if (item.getDataType() != null) { 450 item.getDataType().accept(this); 451 } 452 } 453 } 454 break; 455 case convert_t : 456 if ( node.getTypename( ) != null ) 457 { 458 node.getTypename( ).accept( this ); 459 } 460 else 461 { 462 // convert in MySQL have no datatype argument 463 } 464 if ( node.getParameter( ) != null ) 465 { 466 acceptSymbol( "," ); 467 node.getParameter( ).accept( this ); 468 } 469 if ( node.getStyle( ) != null ) 470 { 471 acceptSymbol( "," ); 472 node.getStyle( ).accept( this ); 473 } 474 475 break; 476 case trim_t : 477 if ( node.getTrimArgument( ) != null ) 478 { 479 // node.getTrimArgument().accept(this); 480 TTrimArgument trimArgument = node.getTrimArgument( ); 481 if ( trimArgument.isBoth( ) ) 482 acceptKeyword( "both" ); 483 if ( trimArgument.isTrailing( ) ) 484 acceptKeyword( "trailing" ); 485 if ( trimArgument.isLeading( ) ) 486 acceptKeyword( "leading" ); 487 if ( trimArgument.getTrimCharacter( ) != null ) 488 { 489 trimArgument.getTrimCharacter( ).accept( this ); 490 acceptKeyword( "from" ); 491 } 492 trimArgument.getStringExpression( ).accept( this ); 493 } 494 495 break; 496 case extract_t : 497 if ( node.getArgs( ) != null ) 498 { // extract xml 499 node.getArgs( ).accept( this ); 500 } 501 else 502 { 503 acceptKeyword( node.getExtract_time_token( ).toString( ) ); 504 acceptKeyword( "from" ); 505 // node.getExtract_time_token().toString() 506 507 if ( node.getExpr1( ) != null ) 508 { 509 node.getExpr1( ).accept( this ); 510 } 511 } 512 513 break; 514 case treat_t : 515 node.getExpr1( ).accept( this ); 516 node.getTypename( ).accept( this ); 517 break; 518 case contains_t : 519 if (node.getExpr1() != null){ 520 node.getExpr1( ).accept( this ); 521 acceptSymbol( "," ); 522 node.getExpr2( ).accept( this ); 523 }else{ 524 // databricks 525 if ( node.getArgs( ) != null ) 526 { // extract xml 527 node.getArgs( ).accept( this ); 528 } 529 } 530 break; 531 case freetext_t : 532 node.getExpr1( ).accept( this ); 533 acceptSymbol( "," ); 534 node.getExpr2( ).accept( this ); 535 break; 536 case group_concat_t : 537 node.getGroupConcatParam( ).accept( this ); 538 break; 539 case timestampadd_t : 540 case timestampdiff_t : 541 acceptKeyword(node.getIntervalUnit()); 542 acceptSymbol( "," ); 543 node.getExpr1( ).accept( this ); 544 acceptSymbol("," ); 545 node.getExpr2( ).accept( this ); 546 break; 547// case range_n_t : 548// node.getExpr1( ).accept( this ); 549// for(TRangeNFunctionItem item:node.getRangeNFunctionItems()){ 550// item.accept(this); 551// } 552// break; 553 case position_t : 554 case substring_t : 555 case xmlquery_t : 556 case xmlcast_t : 557 case match_against_t : 558 case adddate_t : 559 case date_add_t : 560 case subdate_t : 561 case date_sub_t : 562 // node.toString(); 563 //break; 564 default : 565 if ( node.getExpr1( ) != null ) 566 { 567 node.getExpr1( ).accept( this ); 568 } 569 if ( node.getExpr2( ) != null ) 570 { 571 acceptSymbol( "," ); 572 node.getExpr2( ).accept( this ); 573 } 574 //add by grq 2023.06.14 issue=I7D618 575 if ( node.getExpr3( ) != null ) 576 { 577 acceptSymbol( "," ); 578 node.getExpr3( ).accept( this ); 579 } 580 //end by grq 581 if ( node.getArgs( ) != null ) 582 { 583 node.getArgs( ).accept( this ); 584 } 585 586 break; 587 } 588 589 if (node.hasParenthesis()){ 590 acceptSymbol( ")" ); 591 } 592 593 if (node.getWithinGroup() != null){ 594 node.getWithinGroup().accept(this); 595 } 596 if ( node.getWindowDef( ) != null ) 597 { 598 node.getWindowDef( ).accept( this ); 599 } 600 } 601 602 603 public void preVisit( TWithinGroup node ){ 604 acceptKeyword( "within" ); 605 acceptKeyword( "group" ); 606 acceptSymbol( "(" ); 607 if ( node.getOrderBy( ) != null ) 608 { 609 node.getOrderBy( ).accept( this ); 610 } 611 acceptSymbol( ")" ); 612 } 613 public void preVisit( TGroupConcatParam node ) 614 { 615 if ( node.isDistinct( ) ) 616 { 617 acceptKeyword( "distinct" ); 618 } 619 node.getExprList( ).accept( this ); 620 if ( node.getOrderBy( ) != null ) 621 { 622 node.getOrderBy( ).accept( this ); 623 } 624 625 if ( node.getSeparatorToken( ) != null ) 626 { 627 acceptKeyword( "separator" ); 628 acceptToken( node.getSeparatorToken( ) ); 629 } 630 631 } 632 633 public void preVisit( TWindowDef node ) 634 { 635 if ( node.getKeepDenseRankClause( ) != null ) 636 { 637 node.getKeepDenseRankClause( ).accept( this ); 638 } 639 if ( node.getWithinGroup( ) != null ) 640 { 641 acceptKeyword( "within" ); 642 acceptKeyword( "group" ); 643 acceptSymbol( "(" ); 644 if ( node.getWithinGroup( ).getOrderBy( ) != null ) 645 { 646 node.getWithinGroup( ).getOrderBy( ).accept( this ); 647 } 648 acceptSymbol( ")" ); 649 } 650 if ( node.isIncludingOverClause( ) ) 651 { 652 acceptKeyword( "over" ); 653 acceptSymbol( "(" ); 654 if ( node.getPartitionClause( ) != null ) 655 { 656 acceptKeyword( "partition" ); 657 acceptKeyword( "by" ); 658 visitExprList( node.getPartitionClause( ).getExpressionList( ) ); 659 } 660 if ( node.getOrderBy( ) != null ) 661 { 662 node.getOrderBy( ).accept( this ); 663 } 664 if ( node.getWindowFrame( ) != null ) 665 { 666 acceptNewline( ); 667 node.getWindowFrame( ).accept( this ); 668 } 669 acceptSymbol( ")" ); 670 } 671 672 if ( node.getName( ) != null ) 673 { 674 preVisit( node.getName( ) ); 675 } 676 } 677 678 public void preVisit( TWindowFrame node ) 679 { 680 if ( node.getLimitRowType( ) == ELimitRowType.Rows ) 681 { 682 acceptKeyword( "rows" ); 683 } 684 else if ( node.getLimitRowType( ) == ELimitRowType.Range ) 685 { 686 acceptKeyword( "range" ); 687 } 688 689 if ( node.getStartBoundary( ) != null && node.getEndBoundary( ) != null ) 690 { 691 acceptKeyword( "between" ); 692 node.getStartBoundary( ).accept( this ); 693 acceptKeyword( "and" ); 694 node.getEndBoundary( ).accept( this ); 695 } 696 else if ( node.getStartBoundary( ) != null ) 697 { 698 node.getStartBoundary( ).accept( this ); 699 } 700 } 701 702 public void preVisit( TWindowFrameBoundary node ) 703 { 704 if ( node.getBoundaryNumber( ) != null ) 705 { 706 node.getBoundaryNumber( ).accept( this ); 707 } 708 709 if ( node.getExclusionClause( ) != null ) 710 { 711 if ( node.getExclusionClause( ).getExcludeType( ) == EWindowExcludeType.currentRow ) 712 { 713 acceptKeyword( "current" ); 714 acceptKeyword( "row" ); 715 } 716 } 717 718 if ( node.getBoundaryType( ) == EBoundaryType.ebtCurrentRow ) 719 { 720 acceptKeyword( "current" ); 721 acceptKeyword( "row" ); 722 } 723 else if ( node.getBoundaryType( ) == EBoundaryType.ebtFollowing ) 724 { 725 acceptKeyword( "following" ); 726 } 727 else if ( node.getBoundaryType( ) == EBoundaryType.ebtPreceding ) 728 { 729 acceptKeyword( "preceding" ); 730 } 731 else if ( node.getBoundaryType( ) == EBoundaryType.ebtUnboundedFollowing ) 732 { 733 acceptKeyword( "unbounded" ); 734 acceptKeyword( "following" ); 735 } 736 else if ( node.getBoundaryType( ) == EBoundaryType.ebtUnboundedPreceding ) 737 { 738 acceptKeyword( "unbounded" ); 739 acceptKeyword( "preceding" ); 740 } 741 } 742 743 public void preVisit( TExpression node ) 744 { 745 746 switch ( node.getExpressionType( ) ) 747 { 748 case simple_object_name_t : 749 node.getObjectOperand( ).accept( this ); 750 if ( node.isOracleOuterJoin( ) ) 751 { 752 // acceptSymbol("("); 753 // acceptSymbol("+"); 754 // acceptSymbol(")"); 755 acceptSymbol( "(+)", TBaseType.outer_join ); 756 } 757 break; 758 case simple_constant_t : 759 node.getConstantOperand( ).accept( this ); 760 break; 761 case function_t : 762 node.getFunctionCall( ).accept( this ); 763 break; 764 case type_constructor_t : 765 acceptKeyword( "new" ); 766 node.getObjectOperand().accept(this); 767 if (node.getExprList() != null){ 768 acceptSymbol("("); 769 node.getExprList().accept(this); 770 acceptSymbol(")"); 771 } 772 break; 773 case cursor_t : 774 acceptKeyword( "cursor" ); 775 node.getSubQuery( ).accept( this ); 776 break; 777 case multiset_t : 778 case subquery_t : 779 node.getSubQuery( ).accept( this ); 780 break; 781 case exists_t : 782 acceptKeyword( "exists" ); 783 if (node.getSubQuery() != null){ 784 node.getSubQuery( ).accept( this ); 785 }else{ 786 // databricks, select exists(array(1,2,3),x -> x % 2 == 0) 787 acceptSymbol("("); 788 node.getLeftOperand().accept(this); 789 acceptSymbol(","); 790 node.getRightOperand().accept(this); 791 acceptSymbol(")"); 792 } 793 break; 794 case assignment_t : 795 node.getLeftOperand( ).accept( this ); 796 if ((node.getOperatorToken( ) != null)&&( node.getOperatorToken( ).toString( ).equals( ":=" ) )) 797 { 798 acceptSymbol( ":=" ); 799 } 800 else 801 { 802 acceptSymbol( "=" ); 803 } 804 node.getRightOperand( ).accept( this ); 805 break; 806 case simple_comparison_t : 807 if ( node.getSubQuery( ) != null ) 808 { 809 node.getExprList( ).accept( this ); 810 scriptWriter.addComparisonOperator( node.getComparisonType( ), node.getOperatorToken( ) ); 811 node.getSubQuery( ).accept( this ); 812 } 813 else 814 { 815 node.getLeftOperand( ).accept( this ); 816 scriptWriter.addComparisonOperator( node.getComparisonType( ), node.getOperatorToken( ) ); 817 node.getRightOperand( ).accept( this ); 818 } 819 break; 820 case group_comparison_t : 821 if ( node.getExprList( ) != null ) 822 { 823 node.getExprList( ).accept( this ); 824 } 825 else 826 { 827 node.getLeftOperand( ).accept( this ); 828 } 829 if (node.getOperatorTokens().isEmpty()){ 830 scriptWriter.addComparisonOperator( node.getComparisonType( ) ); 831 }else{ 832 scriptWriter.addComparisonOperatorByTokens(node.getOperatorTokens()); 833 } 834 835 if ( node.getQuantifierType( ) != EQuantifierType.none ) 836 { 837 switch ( node.getQuantifierType( ) ) 838 { 839 case all : 840 acceptKeyword( "all" ); 841 break; 842 case some : 843 acceptKeyword( "some" ); 844 break; 845 case any : 846 acceptKeyword( "any" ); 847 break; 848 } 849 850 } 851 node.getRightOperand( ).accept( this ); 852 break; 853 case in_t : 854 if ( node.getExprList( ) != null ) 855 { 856 acceptSymbol( "(" ); 857 visitExprList( node.getExprList( ) ); 858 acceptSymbol( ")" ); 859 } 860 else 861 { 862 node.getLeftOperand( ).accept( this ); 863 } 864 865 if ( node.isNotOperator( ) ) 866 acceptKeyword( "not" ); 867 acceptKeyword( "in" ); 868 869 node.getRightOperand( ).accept( this ); 870 break; 871 case collection_constructor_list_t : 872 case collection_constructor_multiset_t : 873 case collection_constructor_set_t : 874 case list_t : 875 if ( node.getExprList( ) != null ) 876 { 877 acceptSymbol( "(" ); 878 visitExprList( node.getExprList( ) ); 879 acceptSymbol( ")" ); 880 } 881 break; 882 case new_structured_type_t : 883 acceptKeyword("new"); 884 for(int i=0;i<node.getExprList().size();i++){ 885 node.getExprList().getExpression(i).accept(this); 886 if (i != (node.getExprList().size() - 1)) { 887 acceptSymbol("."); 888 } 889 } 890 break; 891 case pattern_matching_t : 892 node.getLeftOperand( ).accept( this ); 893 if ( node.isNotOperator( ) ) 894 acceptKeyword( "not" ); 895 if ( node.getOperatorToken( ) != null ) 896 { 897 acceptSpace( 1 ); 898 acceptToken( node.getOperatorToken( ) ); 899 acceptSpace( 1 ); 900 } 901 else 902 { 903 acceptKeyword( "like" ); 904 } 905 906 node.getRightOperand( ).accept( this ); 907 if ( node.getLikeEscapeOperand( ) != null ) 908 { 909 acceptKeyword( "escape" ); 910 node.getLikeEscapeOperand( ).accept( this ); 911 } 912 break; 913 case between_t : 914 node.getBetweenOperand( ).accept( this ); 915 if ( node.isNotOperator( ) ) 916 acceptKeyword( "not" ); 917 acceptKeyword( "between" ); 918 node.getLeftOperand( ).accept( this ); 919 acceptKeyword( "and" ); 920 node.getRightOperand( ).accept( this ); 921 break; 922 case logical_not_t : 923 acceptKeyword( "not" ); 924 node.getRightOperand( ).accept( this ); 925 break; 926 case null_t : 927 node.getLeftOperand( ).accept( this ); 928 acceptKeyword( "is" ); 929 if ( node.isNotOperator( ) ) 930 { 931 acceptKeyword( "not" ); 932 } 933 acceptKeyword( "null" ); 934 break; 935 case parenthesis_t : 936 acceptSymbol( "(" ); 937 node.getLeftOperand( ).accept( this ); 938 acceptSymbol( ")" ); 939 break; 940 case at_local_t : 941 node.getLeftOperand( ).accept( this ); 942 acceptKeyword( "at" ); 943 acceptKeyword( "local" ); 944 break; 945 case teradata_at_t: 946 node.getLeftOperand( ).accept( this ); 947 acceptKeyword( "at" ); 948 node.getRightOperand().accept( this ); 949 break; 950 case day_to_second_t : 951 node.getLeftOperand( ).accept( this ); 952 acceptKeyword( "day" ); 953 if ( node.getLeadingPrecision( ) != null ) 954 { 955 acceptSymbol( "(" ); 956 acceptToken( node.getLeadingPrecision( ) ); 957 acceptSymbol( ")" ); 958 } 959 acceptKeyword( "to" ); 960 acceptKeyword( "second" ); 961 if ( node.getFractionalSecondsPrecision( ) != null ) 962 { 963 acceptSymbol( "(" ); 964 acceptToken( node.getFractionalSecondsPrecision( ) ); 965 acceptSymbol( ")" ); 966 } 967 break; 968 case year_to_month_t : 969 node.getLeftOperand( ).accept( this ); 970 acceptKeyword( "year" ); 971 if ( node.getLeadingPrecision( ) != null ) 972 { 973 acceptSymbol( "(" ); 974 acceptToken( node.getLeadingPrecision( ) ); 975 acceptSymbol( ")" ); 976 } 977 acceptKeyword( "to" ); 978 acceptKeyword( "month" ); 979 break; 980 case floating_point_t : 981 case unary_factorial_t : 982 node.getLeftOperand( ).accept( this ); 983 break; 984 case typecast_t : 985 node.getLeftOperand( ).accept( this ); 986 if (node.dbvendor == EDbVendor.dbvpostgresql){ 987 acceptSymbol("::"); 988 node.getTypeName().accept(this); 989 } 990 break; 991 case is_of_type_t : 992 visitNodeByToken( node ); 993 // node.getLeftOperand().accept(this); 994 // acceptKeyword("is"); 995 // if (node.isNotOperator()) acceptKeyword("not"); 996 // acceptKeyword("of"); 997 break; 998 case unary_plus_t : 999 case unary_minus_t : 1000 case unary_prior_t : 1001 case unary_connect_by_root_t : 1002 case unary_binary_operator_t : 1003 case unary_squareroot_t : 1004 case unary_cuberoot_t : 1005 case unary_factorialprefix_t : 1006 case unary_absolutevalue_t : 1007 case unary_bitwise_not_t : 1008 scriptWriter.addUnaryOperator( node.getExpressionType( ) ); 1009 node.getRightOperand( ).accept( this ); 1010 break; 1011 case power_t : 1012 case range_t : 1013 case concatenate_t : 1014 case period_ldiff_t : 1015 case period_rdiff_t : 1016 case period_p_intersect_t : 1017 case period_p_normalize_t : 1018 case contains_t : 1019 case arithmetic_modulo_t : 1020 case bitwise_exclusive_or_t : 1021 case bitwise_or_t : 1022 case bitwise_and_t : 1023 case bitwise_xor_t : 1024 case exponentiate_t : 1025 case scope_resolution_t : 1026 case member_of_t : 1027 case is_t : 1028 case collate_t : 1029 case left_join_t : 1030 case right_join_t : 1031 case ref_arrow_t : 1032 case left_shift_t : 1033 case right_shift_t : 1034 case bitwise_shift_left_t : 1035 case bitwise_shift_right_t : 1036 case multiset_union_t : 1037 case multiset_union_distinct_t : 1038 case multiset_intersect_t : 1039 case multiset_intersect_distinct_t : 1040 case multiset_except_t : 1041 case multiset_except_distinct_t : 1042 case json_get_text : 1043 case json_get_text_at_path : 1044 case json_get_object : 1045 case json_get_object_at_path : 1046 case json_left_contain : 1047 case json_right_contain : 1048 case json_exist : 1049 case json_any_exist : 1050 case json_all_exist : 1051 case sqlserver_proprietary_column_alias_t : 1052 case submultiset_t : 1053 node.getLeftOperand( ).accept( this ); 1054 String LeftOperand = node.getLeftOperand().toScript(); 1055 long tokenListSize = scriptWriter.getTokenListSize(); 1056 if (!SQLUtil.isEmpty(LeftOperand)) { 1057 scriptWriter.addBinaryOperator(node); 1058 } 1059 node.getRightOperand( ).accept( this ); 1060 String rightOperand = node.getRightOperand().toScript(); 1061 if (SQLUtil.isEmpty(rightOperand)) { 1062 scriptWriter.resetToPosition(tokenListSize); 1063 } 1064 break; 1065 case arithmetic_plus_t : 1066 case arithmetic_minus_t : 1067 case arithmetic_times_t : 1068 case arithmetic_divide_t : 1069 node.getLeftOperand( ).accept( this ); 1070 if (node.getOperatorToken() != null){ 1071 acceptToken(node.getOperatorToken()); 1072 }else{ 1073 switch (node.getExpressionType()){ 1074 case arithmetic_plus_t: 1075 acceptKeyword("+"); 1076 break; 1077 case arithmetic_minus_t: 1078 acceptKeyword("-"); 1079 break; 1080 case arithmetic_times_t: 1081 acceptKeyword("*"); 1082 break; 1083 case arithmetic_divide_t: 1084 acceptKeyword("/"); 1085 break; 1086 } 1087 } 1088 node.getRightOperand( ).accept( this ); 1089 break; 1090 case logical_xor_t : 1091 node.getLeftOperand( ).accept( this ); 1092 acceptKeyword("xor"); 1093 node.getRightOperand( ).accept( this ); 1094 break; 1095 case logical_and_t : 1096 node.getLeftOperand( ).accept( this ); 1097 acceptKeyword("and"); 1098 node.getRightOperand( ).accept( this ); 1099 break; 1100 case logical_or_t : 1101 node.getLeftOperand( ).accept( this ); 1102 acceptKeyword("or"); 1103 node.getRightOperand( ).accept( this ); 1104 break; 1105 case at_time_zone_t : 1106 node.getLeftOperand( ).accept( this ); 1107 acceptKeyword( "at" ); 1108 acceptKeyword( "time" ); 1109 acceptKeyword( "zone" ); 1110 node.getRightOperand( ).accept( this ); 1111 break; 1112 case row_constructor_t : 1113 1114 if ( node.getExprList( ) != null ) 1115 { 1116 node.getExprList( ).accept( this ); 1117 } 1118 break; 1119 case array_constructor_t : 1120 if (node.getStartToken().toString().equalsIgnoreCase("array")){ 1121 acceptKeyword("array"); 1122 } 1123 if ( node.getSubQuery( ) != null ) 1124 { 1125 node.getSubQuery( ).accept( this ); 1126 } 1127 1128 if ( node.getExprList( ) != null ) 1129 { 1130 acceptSymbol("("); 1131 node.getExprList( ).accept( this ); 1132 acceptSymbol(")"); 1133 } 1134 break; 1135 case lambda_t: //databricks 1136 node.getLeftOperand().accept(this); 1137 acceptSymbol("->"); 1138 node.getRightOperand().accept(this); 1139 break; 1140 case case_t : 1141 node.getCaseExpression( ).accept( this ); 1142 break; 1143 case arrayaccess_t : 1144 break; 1145 case interval_t : 1146 break; 1147 case simple_source_token_t : 1148 acceptIdentifier( node.getSourcetokenOperand( ).toString( ) ); 1149 break; 1150 case place_holder_t : 1151 acceptLiteral( node.toString( ) ); 1152 break; 1153 case unknown_t: 1154 if (node.getLeftOperand() != null){ 1155 node.getLeftOperand().accept(this); 1156 } 1157 if (node.getOperatorToken() != null){ 1158 acceptToken(node.getOperatorToken()); 1159 } 1160 if (node.getRightOperand() != null){ 1161 node.getRightOperand().accept(this); 1162 } 1163 break; 1164 //add by grq 2023.06.03 issue=I790G1 1165 case typecast_datatype_t : 1166 acceptSpace(1); 1167 acceptSymbol(node.getStartToken().toString()); 1168 acceptSymbol( "(" ); 1169 if(node.getLeftOperand() != null){ 1170 node.getLeftOperand().accept(this); 1171 } 1172 if(node.getRightOperand() != null){ 1173 node.getRightOperand().accept(this); 1174 } 1175 acceptSymbol( ")" ); 1176 acceptSpace(1); 1177 break; 1178 //end by grq 1179 case implicit_datatype_cast_as_t: 1180 acceptSpace(1); 1181 node.getLeftOperand().accept(this); 1182 acceptSpace(1); 1183 acceptToken(node.getOperatorToken()); 1184 acceptSpace(1); 1185 node.getTypeName().accept(this); 1186 break; 1187 case is_true_t: 1188 acceptSpace(1); 1189 node.getLeftOperand().accept(this); 1190 acceptSpace(1); 1191 acceptKeyword("is"); 1192 if (node.getNotToken() != null){ 1193 acceptKeyword("not"); 1194 } 1195 acceptKeyword("true"); 1196 break; 1197 case is_false_t: 1198 acceptSpace(1); 1199 node.getLeftOperand().accept(this); 1200 acceptSpace(1); 1201 acceptKeyword("is"); 1202 if (node.getNotToken() != null){ 1203 acceptKeyword("not"); 1204 } 1205 acceptKeyword("false"); 1206 break; 1207 case fieldselection_t: 1208 if (node.getStartToken().tokencode == '(' ){ 1209 acceptSymbol("("); 1210 } 1211 node.getLeftOperand().accept(this); 1212 if (node.getStartToken().tokencode == '(' ){ 1213 acceptSymbol(")"); 1214 } 1215 acceptSymbol("."); 1216 node.getFieldName().accept(this); 1217 break; 1218 default : 1219 break; 1220 } 1221 1222 /*** 1223 * SELECT (d).grantee 1224 * In {@link TExpression.setIndirection()} already handles qualified name, which is turned the expression to type of fieldselection_t 1225 * so we don't need to visit indirection for fieldselection_t again here, otherwise it will be duplicated. like this: (d).grantee.grantee 1226 */ 1227 if ((node.getIndirection() != null) && (node.getExpressionType() != EExpressionType.fieldselection_t)) { 1228 node.getIndirection().accept(this); 1229 } 1230 1231 } 1232 1233 1234 public void preVisit( TIndirection node ){ 1235 //node.getIndices().accept(this); 1236 for(int i=0;i<node.getIndices().size();i++){ 1237 node.getIndices().elementAt(i).accept(this); 1238 } 1239 } 1240 1241 /** 1242 * Generates SQL text for TIndices nodes representing array access and qualified name syntax. 1243 * 1244 * <p>This method handles the complete range of indirection patterns found in PostgreSQL 1245 * and other SQL dialects, accurately reconstructing the original SQL syntax from the parse tree. 1246 * 1247 * <h3>Why the isSlice Property Was Introduced</h3> 1248 * <p>The fundamental challenge was distinguishing between two syntactically different but 1249 * semantically similar array access patterns: 1250 * <ul> 1251 * <li><code>array[5]</code> - Single element access (no colon)</li> 1252 * <li><code>array[5:]</code> - Slice from index 5 to end (with colon)</li> 1253 * </ul> 1254 * 1255 * <p>Both patterns have the same internal representation: 1256 * <ul> 1257 * <li>lowerSubscript = expression "5"</li> 1258 * <li>upperSubscript = null</li> 1259 * </ul> 1260 * 1261 * <p>Without the {@code isSlice} property, it was impossible to distinguish between these 1262 * cases during SQL text generation, leading to incorrect output. The {@code isSlice} property 1263 * preserves the original syntax information from the parser, enabling accurate reconstruction. 1264 * 1265 * <h3>Supported Syntax Patterns</h3> 1266 * <table border="1"> 1267 * <tr><th>Original SQL</th><th>Generated Output</th><th>isSlice</th><th>Lower</th><th>Upper</th></tr> 1268 * <tr><td><code>.field</code></td><td><code>.field</code></td><td>N/A</td><td>null</td><td>null</td></tr> 1269 * <tr><td><code>.*</code></td><td><code>.*</code></td><td>N/A</td><td>null</td><td>null</td></tr> 1270 * <tr><td><code>[5]</code></td><td><code>[5]</code></td><td>false</td><td>expr</td><td>null</td></tr> 1271 * <tr><td><code>[2:8]</code></td><td><code>[2:8]</code></td><td>true</td><td>expr</td><td>expr</td></tr> 1272 * <tr><td><code>[:3]</code></td><td><code>[:3]</code></td><td>true</td><td>null</td><td>expr</td></tr> 1273 * <tr><td><code>[5:]</code></td><td><code>[5:]</code></td><td>true</td><td>expr</td><td>null</td></tr> 1274 * <tr><td><code>[:]</code></td><td><code>[:]</code></td><td>true</td><td>null</td><td>null</td></tr> 1275 * </table> 1276 * 1277 * <h3>Implementation Logic</h3> 1278 * <ol> 1279 * <li><strong>Qualified Names</strong>: Check {@code isQualifiedName()}, output dot + attribute name</li> 1280 * <li><strong>Array Access</strong>: Check {@code isArrayAccess()}, output bracket notation</li> 1281 * <li><strong>Slice Detection</strong>: Use {@code isSlice()} to determine colon inclusion</li> 1282 * <li><strong>Bounds Handling</strong>: Output lower/upper subscripts when present</li> 1283 * </ol> 1284 * 1285 * <p>This approach ensures that the generated SQL text exactly matches the original input, 1286 * preserving semantic meaning and syntactic correctness across all supported SQL dialects. 1287 * 1288 * @param node the TIndices node to generate SQL text for 1289 * @see TIndices#isSlice() 1290 * @see TIndices#isArrayAccess() 1291 * @see TIndices#isQualifiedName() 1292 * @see TIndices#getLowerSubscript() 1293 * @see TIndices#getUpperSubscript() 1294 * @see TIndices#getAttributeName() 1295 */ 1296 public void preVisit( TIndices node ){ 1297 if (node.isQualifiedName()) { 1298 // Handle qualified name syntax: .field or .* 1299 acceptSymbol("."); 1300 if (node.getAttributeName() != null) { 1301 node.getAttributeName().accept(this); 1302 } 1303 } else if (node.isArrayAccess()) { 1304 // Handle array access syntax: [expr], [expr:expr], [:expr], [expr:], [:] 1305 acceptSymbol("["); 1306 1307 TExpression lower = node.getLowerSubscript(); 1308 TExpression upper = node.getUpperSubscript(); 1309 1310 // Handle lower bound (start index) 1311 if (lower != null) { 1312 lower.accept(this); 1313 } 1314 1315 // Handle slice notation with colon 1316 if (node.isSlice()) { 1317 acceptSymbol(":"); 1318 1319 // Handle upper bound (end index) 1320 if (upper != null) { 1321 upper.accept(this); 1322 } 1323 } 1324 1325 acceptSymbol("]"); 1326 } 1327 } 1328 1329 public void preVisit( TSelectModifier node ){ 1330 switch (node.getSelectModifier()){ 1331 case HIGH_PRIORITY: 1332 acceptKeyword("HIGH_PRIORITY"); 1333 break; 1334 case STRAIGHT_JOIN: 1335 acceptKeyword("STRAIGHT_JOIN"); 1336 break; 1337 case SQL_SMALL_RESULT: 1338 acceptKeyword("SQL_SMALL_RESULT"); 1339 break; 1340 case SQL_BIG_RESULT: 1341 acceptKeyword("SQL_BIG_RESULT"); 1342 break; 1343 case SQL_BUFFER_RESULT: 1344 acceptKeyword("SQL_BUFFER_RESULT"); 1345 break; 1346 case SQL_NO_CACHE: 1347 acceptKeyword("SQL_NO_CACHE"); 1348 break; 1349 case SQL_CALC_FOUND_ROWS: 1350 acceptKeyword("SQL_CALC_FOUND_ROWS"); 1351 break; 1352 case SQL_CACHE: 1353 acceptKeyword("SQL_CACHE"); 1354 break; 1355 case ALL: 1356 acceptKeyword("ALL"); 1357 break; 1358 case DISTINCT: 1359 acceptKeyword("DISTINCT"); 1360 break; 1361 case DISTINCTROW: 1362 acceptKeyword("DISTINCTROW"); 1363 break; 1364 default: 1365 break; 1366 } 1367 } 1368 1369 public void preVisit( TSelectSqlStatement node ) 1370 { 1371 1372 for ( int i = 0; i < node.getParenthesisCount( ); i++ ) 1373 { 1374 acceptSymbol( "(" ); 1375 } 1376 1377 for ( int i = 0; i < node.getParenthesisCountBeforeOrder( ); i++ ) 1378 { 1379 acceptSymbol( "(" ); 1380 } 1381 1382 if ( node.getCteList( ) != null ) 1383 { 1384 acceptKeyword( "with" ); 1385 visitCTEList( node.getCteList( ) ); 1386 } 1387 1388 if ( node.isCombinedQuery( ) ) 1389 { 1390 1391 acceptNewline( ); 1392 node.getLeftStmt( ).accept( this ); 1393 acceptNewline( ); 1394 acceptKeyword( node.getSetOperatorType( ).toString( ) ); 1395 if ( node.isAll( ) ) 1396 acceptKeyword( "all" ); 1397 acceptNewline( ); 1398 node.getRightStmt( ).accept( this ); 1399 for ( int i = 0; i < node.getParenthesisCountBeforeOrder( ); i++ ) 1400 { 1401 acceptSymbol( ")" ); 1402 } 1403 1404 if ( node.getOrderbyClause( ) != null ) 1405 { 1406 acceptNewline( ); 1407 node.getOrderbyClause( ).accept( this ); 1408 } 1409 1410 if ( node.getLimitClause( ) != null ) 1411 { 1412 node.getLimitClause( ).accept( this ); 1413 } 1414 1415 if ( node.getForUpdateClause( ) != null ) 1416 { 1417 node.getForUpdateClause( ).accept( this ); 1418 } 1419 1420 if ( node.getComputeClause( ) != null ) 1421 { 1422 node.getComputeClause( ).accept( this ); 1423 } 1424 1425 if (node.getOptionClause() != null){ 1426 visitNodeByToken(node.getOptionClause()); 1427 } 1428 1429 for ( int i = 0; i < node.getParenthesisCount( ); i++ ) 1430 { 1431 acceptSymbol( ")" ); 1432 } 1433 1434 return; 1435 } 1436 1437 if ( node.getValueClause( ) != null ) 1438 { 1439 // DB2 values constructor 1440 return; 1441 } 1442 1443 acceptKeyword( "select" ); 1444 if ( node.getSelectDistinct( ) != null ) 1445 { 1446 switch ( node.getSelectDistinct( ).getUniqueRowFilter( ) ) 1447 { 1448 case urfDistinct : 1449 acceptKeyword( "distinct" ); 1450 break; 1451 case urfAll : 1452 acceptKeyword( "all" ); 1453 break; 1454 case urfUnique : 1455 acceptKeyword( "unique" ); 1456 break; 1457 case urfDistinctOn : 1458 acceptKeyword( "distinct" ); 1459 acceptKeyword( "on" ); 1460 break; 1461 } 1462 1463 if (node.getSelectDistinct( ).getExpressionList( ) != null ) 1464 { 1465 acceptSymbol( "(" ); 1466 for ( int i = 0; i < node.getSelectDistinct( ).getExpressionList( ) 1467 .size( ); i++ ) 1468 { 1469 node.getSelectDistinct( ).getExpressionList( ) 1470 .getElement( i ) 1471 .accept( this ); 1472 if ( i != node.getSelectDistinct( ).getExpressionList( ) 1473 .size( ) - 1 ) 1474 { 1475 acceptSymbol( "," ); 1476 } 1477 } 1478 acceptSymbol( ")" ); 1479 } 1480 1481 } 1482 1483 if ( ( node.getOracleHint( ) != null ) ) 1484 { 1485 if ( node.getOracleHint( ).length( ) > 0 ) 1486 acceptOracleHint( node.getOracleHint( ) ); 1487 } 1488 1489 if ( node.getTopClause( ) != null ) 1490 { 1491 node.getTopClause( ).accept( this ); 1492 } 1493 1494 if (node.getSelectModifiers() != null){ 1495 for(int i=0;i<node.getSelectModifiers().size();i++){ 1496 node.getSelectModifiers().get(i).accept(this); 1497 } 1498 } 1499 1500 if ( node.getResultColumnList( ) != null ) 1501 { 1502 acceptNewline( ); 1503 visitResultColumnList( node.getResultColumnList( ) ); 1504 } 1505 else 1506 { 1507 // hive transform clause with no select list 1508 } 1509 1510 if ( node.getIntoClause( ) != null ) 1511 { 1512 acceptNewline( ); 1513 node.getIntoClause( ).accept( this ); 1514 } 1515 1516 if ( node.joins.size( ) > 0 ) 1517 { 1518 acceptNewline( ); 1519 acceptKeyword( "from" ); 1520 visitJoinList( node.joins ); 1521 } 1522 1523 if ( node.getWhereClause( ) != null ) 1524 { 1525 acceptNewline( ); 1526 node.getWhereClause( ).accept( this ); 1527 } 1528 1529 if ( node.getHierarchicalClause( ) != null ) 1530 { 1531 acceptNewline( ); 1532 node.getHierarchicalClause( ).accept( this ); 1533 } 1534 1535 if ( node.getGroupByClause( ) != null ) 1536 { 1537 acceptNewline( ); 1538 node.getGroupByClause( ).accept( this ); 1539 } 1540 1541 if ( node.getQualifyClause( ) != null ) 1542 { 1543 node.getQualifyClause( ).accept( this ); 1544 } 1545 1546 for ( int i = 0; i < node.getParenthesisCountBeforeOrder( ); i++ ) 1547 { 1548 acceptSymbol( ")" ); 1549 } 1550 1551 if ( node.getOrderbyClause( ) != null ) 1552 { 1553 acceptNewline( ); 1554 node.getOrderbyClause( ).accept( this ); 1555 } 1556 1557 if ( node.getLimitClause( ) != null ) 1558 { 1559 node.getLimitClause( ).accept( this ); 1560 } 1561 1562 if ( node.getForUpdateClause( ) != null ) 1563 { 1564 node.getForUpdateClause( ).accept( this ); 1565 } 1566 1567 if ( node.getComputeClause( ) != null ) 1568 { 1569 node.getComputeClause( ).accept( this ); 1570 } 1571 1572 if (node.getOptionClause() != null){ 1573 visitNodeByToken(node.getOptionClause()); 1574 } 1575 1576 if (node.getHintClause() != null){ 1577 visitNodeByToken(node.getHintClause()); 1578 } 1579 1580 for ( int i = 0; i < node.getParenthesisCount( ); i++ ) 1581 { 1582 acceptSymbol( ")" ); 1583 } 1584 1585 } 1586 1587 public void preVisit( TComputeClause computeClause ) 1588 { 1589 for ( int i = 0; i < computeClause.getItems( ).size( ); i++ ) 1590 { 1591 computeClause.getItems( ).getElement( i ).accept( this ); 1592 } 1593 } 1594 1595 public void preVisit( TComputeExpr computeExpr ) 1596 { 1597 switch ( computeExpr.getComputeFunctionType( ) ) 1598 { 1599 case cftNone : 1600 break; 1601 case cftCount : 1602 acceptKeyword( "count" ); 1603 break; 1604 case cftMax : 1605 acceptKeyword( "max" ); 1606 break; 1607 case cftMin : 1608 acceptKeyword( "min" ); 1609 break; 1610 case cftSum : 1611 acceptKeyword( "sum" ); 1612 break; 1613 case cftAvg : 1614 acceptKeyword( "avg" ); 1615 break; 1616 case cftStdev : 1617 acceptKeyword( "stdev" ); 1618 break; 1619 case cftStdevp : 1620 acceptKeyword( "stdevp" ); 1621 break; 1622 case cftVar : 1623 acceptKeyword( "var" ); 1624 break; 1625 case cftVarp : 1626 acceptKeyword( "varp" ); 1627 break; 1628 } 1629 acceptSymbol( "(" ); 1630 computeExpr.getExpr( ).accept( this ); 1631 acceptSymbol( ")" ); 1632 1633 } 1634 1635 public void preVisit( TComputeClauseItem computeClauseItem ) 1636 { 1637 acceptNewline( ); 1638 acceptKeyword( "compute" ); 1639 if ( computeClauseItem.getComputerExprList( ) != null ) 1640 { 1641 for ( int i = 0; i < computeClauseItem.getComputerExprList( ) 1642 .size( ); i++ ) 1643 { 1644 computeClauseItem.getComputerExprList( ) 1645 .getElement( i ) 1646 .accept( this ); 1647 if ( i != computeClauseItem.getComputerExprList( ).size( ) - 1 ) 1648 { 1649 acceptSymbol( "," ); 1650 } 1651 } 1652 } 1653 1654 if ( computeClauseItem.getByExprlist( ) != null ) 1655 { 1656 acceptKeyword( "by" ); 1657 for ( int i = 0; i < computeClauseItem.getByExprlist( ).size( ); i++ ) 1658 { 1659 computeClauseItem.getByExprlist( ) 1660 .getExpression( i ) 1661 .accept( this ); 1662 if ( i != computeClauseItem.getByExprlist( ).size( ) - 1 ) 1663 { 1664 acceptSymbol( "," ); 1665 } 1666 } 1667 } 1668 } 1669 1670 public void preVisit( TCreateViewSqlStatement stmt ) 1671 { 1672 if ( stmt.getCteList( ) != null ) 1673 { 1674 acceptKeyword( "with" ); 1675 visitCTEList( stmt.getCteList( ) ); 1676 } 1677 1678 acceptKeyword( "create" ); 1679 1680 if ( stmt.getStReplace( ) != null ) 1681 { 1682 acceptKeyword( "or" ); 1683 acceptKeyword( "replace" ); 1684 } 1685 1686 if ( stmt.getStForce( ) != null ) 1687 { 1688 if ( stmt.isForce( ) ) 1689 { 1690 acceptKeyword( "force" ); 1691 } 1692 if ( stmt.isNoForce( ) ) 1693 { 1694 acceptKeyword( "noforce" ); 1695 } 1696 } 1697 1698 acceptKeyword( "view" ); 1699 stmt.getViewName( ).accept( this ); 1700 if ( stmt.getViewAliasClause( ) != null ) 1701 { 1702 stmt.getViewAliasClause( ).accept( this ); 1703 } 1704 acceptNewline( ); 1705 acceptKeyword( "as" ); 1706 acceptNewline( ); 1707 1708 if ( stmt.getSubquery( ) != null ) 1709 { 1710 stmt.getSubquery( ).accept( this ); 1711 } 1712 1713 if ( stmt.getRestrictionClause( ) != null ) 1714 { 1715 acceptNewline( ); 1716 preVisit( stmt.getRestrictionClause( ) ); 1717 } 1718 } 1719 1720 public void preVisit( TRestrictionClause clause ) 1721 { 1722 if ( clause.getRestrictionType( ) == ERestrictionType.withCheckOption ) 1723 { 1724 acceptKeyword( "with" ); 1725 acceptKeyword( "check" ); 1726 acceptKeyword( "option" ); 1727 } 1728 else if ( clause.getRestrictionType( ) == ERestrictionType.withReadOnly ) 1729 { 1730 acceptKeyword( "with" ); 1731 acceptKeyword( "read" ); 1732 acceptKeyword( "only" ); 1733 } 1734 else if ( clause.getRestrictionType( ) == ERestrictionType.withLocalCheckOption ) 1735 { 1736 acceptKeyword( "with" ); 1737 acceptKeyword( "local" ); 1738 acceptKeyword( "check" ); 1739 acceptKeyword( "option" ); 1740 } 1741 else if ( clause.getRestrictionType( ) == ERestrictionType.withCascadedCheckOption ) 1742 { 1743 acceptKeyword( "with" ); 1744 acceptKeyword( "cascaded" ); 1745 acceptKeyword( "check" ); 1746 acceptKeyword( "option" ); 1747 } 1748 if ( clause.getConstraintName( ) != null ) 1749 { 1750 clause.getConstraintName( ).accept( this ); 1751 } 1752 } 1753 1754 public void preVisit( TViewAliasClause clause ) 1755 { 1756 acceptSymbol( "(" ); 1757 visitViewAliasItemList( clause.getViewAliasItemList( ) ); 1758 acceptSymbol( ")" ); 1759 } 1760 1761 void visitViewAliasItemList( TViewAliasItemList viewAliasItemList ) 1762 { 1763 for ( int i = 0; i < viewAliasItemList.size( ); i++ ) 1764 { 1765 TViewAliasItem aliasItem = viewAliasItemList.getViewAliasItem( i ); 1766 visitViewAliasItem( aliasItem ); 1767 if ( i != viewAliasItemList.size( ) - 1 ) 1768 acceptSymbol( "," ); 1769 } 1770 } 1771 1772 private void visitViewAliasItem( TViewAliasItem aliasItem ) 1773 { 1774 aliasItem.getAlias( ).accept( this ); 1775 } 1776 1777 public void preVisit( TResultColumn node ) 1778 { 1779 node.getExpr( ).accept( this ); 1780 if (( node.getAliasClause( ) != null )&&(node.getExpr().getExpressionType() != EExpressionType.sqlserver_proprietary_column_alias_t)) 1781 { 1782 acceptSpace( 1 ); 1783 node.getAliasClause( ).accept( this ); 1784 } 1785 } 1786 1787 public void preVisit( TColumnDefinitionList node ) 1788 { 1789 1790 for ( int i = 0; i < node.size( ); i++ ) 1791 { 1792 node.getColumn( i ).accept( this ); 1793 if ( i != node.size( ) - 1 ) 1794 { 1795 acceptSymbol( "," ); 1796 } 1797 } 1798 } 1799 1800 public void preVisit( TObjectNameList node ) 1801 { 1802 1803 for ( int i = 0; i < node.size( ); i++ ) 1804 { 1805 node.getObjectName( i ).accept( this ); 1806 if ( i != node.size( ) - 1 ) 1807 { 1808 acceptSymbol( "," ); 1809 } 1810 } 1811 } 1812 1813 public void preVisit( TConstraintList node ) 1814 { 1815 1816 for ( int i = 0; i < node.size( ); i++ ) 1817 { 1818 node.getConstraint( i ).accept( this ); 1819 if ( i != node.size( ) - 1 ) 1820 { 1821 acceptSymbol( "," ); 1822 } 1823 } 1824 } 1825 1826 public void preVisit( TParameterDeclarationList params ) 1827 { 1828 for ( int i = 0; i < params.size( ); i++ ) 1829 { 1830 TParameterDeclaration param = params.getParameterDeclarationItem( i ); 1831 param.accept( this ); 1832 if ( i != params.size( ) - 1 ) 1833 { 1834 acceptSymbol( "," ); 1835 } 1836 } 1837 } 1838 1839 public void preVisit( TParameterDeclaration param ) 1840 { 1841 if ( param.getParameterName( ) != null ) 1842 { 1843 param.getParameterName( ).accept( this ); 1844 } 1845 if ( param.getDataType( ) != null ) 1846 { 1847 param.getDataType( ).accept( this ); 1848 } 1849 } 1850 1851 public void preVisit( TMssqlCreateFunction function ) 1852 { 1853 acceptKeyword( "create" ); 1854 acceptKeyword( "function" ); 1855 1856 if ( function.getFunctionName( ) != null ) 1857 { 1858 function.getFunctionName( ).accept( this ); 1859 } 1860 1861 if ( function.getParameterDeclarations( ) != null 1862 && function.getParameterDeclarations( ).size( ) > 0 ) 1863 { 1864 acceptSymbol( "(" ); 1865 function.getParameterDeclarations( ).accept( this ); 1866 acceptSymbol( ")" ); 1867 } 1868 1869 if ( function.getReturnDataType( ) != null ) 1870 { 1871 acceptNewline( ); 1872 acceptSpace( 4 ); 1873 acceptKeyword( "returns" ); 1874 function.getReturnDataType( ).accept( this ); 1875 } 1876 1877 acceptNewline( ); 1878 acceptKeyword( "as" ); 1879 acceptNewline( ); 1880 1881 if ( function.getBodyStatements( ) != null ) 1882 { 1883 function.getBodyStatements( ).accept( this ); 1884 } 1885 } 1886 1887 1888 public void preVisit( TDmlEventItem node ){ 1889 switch (node.getDmlType()){ 1890 case sstinsert: 1891 acceptKeyword( "insert" ); 1892 break; 1893 case sstdelete: 1894 acceptKeyword( "delete" ); 1895 break; 1896 case sstupdate: 1897 acceptKeyword( "update" ); 1898 if (node.getColumnList() != null){ 1899 acceptKeyword("of"); 1900 node.getColumnList().accept(this); 1901 } 1902 break; 1903 } 1904 } 1905 1906 public void preVisit( TDdlEventItem node ){ 1907 acceptIdentifier(node.getEventName().toString()); 1908 } 1909 1910 public void preVisit( TSimpleDmlTriggerClause node ){ 1911 acceptNewline( ); 1912 acceptSpace( 4 ); 1913 1914 acceptKeyword( "on" ); 1915 TDmlEventClause dmlEventClause = (TDmlEventClause)node.getEventClause(); 1916 dmlEventClause.getTableName().accept(this); 1917 1918 acceptNewline( ); 1919 switch(node.getActionTime()){ 1920 case tatFor: 1921 acceptKeyword( "for" ); 1922 break; 1923 case tatBefore: 1924 acceptKeyword( "before" ); 1925 break; 1926 case tatAfter: 1927 acceptKeyword( "after" ); 1928 break; 1929 case tatInsteadOf: 1930 acceptKeyword( "instead of" ); 1931 break; 1932 } 1933 1934 for(int i=0;i<dmlEventClause.getEventItems().size();i++){ 1935 dmlEventClause.getEventItems().get(i).accept(this); 1936 if (i != dmlEventClause.getEventItems().size() - 1){ 1937 acceptSymbol( "," ); 1938 } 1939 } 1940 1941 1942 } 1943 1944 public void preVisit( TCreateTriggerStmt trigger ) 1945 { 1946 if ( trigger.isAlterTrigger( ) ) 1947 acceptKeyword( "alter" ); 1948 else 1949 acceptKeyword( "create" ); 1950 acceptKeyword( "trigger" ); 1951 1952 if ( trigger.getTriggerName( ) != null ) 1953 { 1954 trigger.getTriggerName( ).accept( this ); 1955 } 1956 1957 trigger.getTriggeringClause().accept(this); 1958 1959// if ( trigger.getOnTable( ) != null ) 1960// { 1961// acceptNewline( ); 1962// acceptSpace( 4 ); 1963// 1964// acceptKeyword( "on" ); 1965// trigger.getOnTable( ).accept( this ); 1966// } 1967// 1968// acceptNewline( ); 1969// 1970// if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpFor ) 1971// acceptKeyword( "for" ); 1972// if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpTinsteadOf ) 1973// { 1974// acceptKeyword( "instead" ); 1975// acceptKeyword( "of" ); 1976// } 1977// if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpAfter ) 1978// acceptKeyword( "after" ); 1979// if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpBefore ) 1980// acceptKeyword( "before" ); 1981// 1982// if ( trigger.getDmlTypes( ) != null 1983// && trigger.getDmlTypes( ).size( ) > 0 ) 1984// { 1985// EnumSet<ETriggerDmlType> types = trigger.getDmlTypes( ); 1986// for ( Iterator<ETriggerDmlType> iterator = types.iterator( ); iterator.hasNext( ); ) 1987// { 1988// ETriggerDmlType eTriggerDmlType = (ETriggerDmlType) iterator.next( ); 1989// if ( eTriggerDmlType == ETriggerDmlType.tdtInsert ) 1990// { 1991// acceptKeyword( "insert" ); 1992// } 1993// if ( eTriggerDmlType == ETriggerDmlType.tdtUpdate ) 1994// { 1995// acceptKeyword( "update" ); 1996// } 1997// if ( eTriggerDmlType == ETriggerDmlType.tdtDelete ) 1998// { 1999// acceptKeyword( "delete" ); 2000// } 2001// if ( iterator.hasNext( ) ) 2002// { 2003// acceptSymbol( "," ); 2004// } 2005// } 2006// } 2007 2008 acceptNewline( ); 2009 acceptKeyword( "as" ); 2010 acceptNewline( ); 2011 2012 if ( trigger.getBodyStatements( ) != null ) 2013 { 2014 trigger.getBodyStatements( ).accept( this ); 2015 } 2016 } 2017 2018 public void preVisit( TProcedureOption option ) 2019 { 2020 if ( option.getOptionType( ) == EProcedureOptionType.potExecuteAs ) 2021 { 2022 acceptKeyword( "execute" ); 2023 acceptKeyword( "as" ); 2024 acceptKeyword( "caller" ); 2025 } 2026 if ( option.getOptionType( ) == EProcedureOptionType.potCalledOnNullInput ) 2027 { 2028 acceptKeyword( "called" ); 2029 acceptKeyword( "on" ); 2030 acceptKeyword( "null" ); 2031 acceptKeyword( "input" ); 2032 } 2033 if ( option.getOptionType( ) == EProcedureOptionType.potEncryption ) 2034 { 2035 acceptKeyword( "encryption" ); 2036 } 2037 if ( option.getOptionType( ) == EProcedureOptionType.potNativeCompilation ) 2038 { 2039 acceptKeyword( "native" ); 2040 acceptKeyword( "compilation" ); 2041 } 2042 if ( option.getOptionType( ) == EProcedureOptionType.potRecompile ) 2043 { 2044 acceptKeyword( "recompile" ); 2045 } 2046 if ( option.getOptionType( ) == EProcedureOptionType.potReturnsNullOnNullInput ) 2047 { 2048 acceptKeyword( "returns" ); 2049 acceptKeyword( "null" ); 2050 acceptKeyword( "on" ); 2051 acceptKeyword( "null" ); 2052 acceptKeyword( "input" ); 2053 } 2054 if ( option.getOptionType( ) == EProcedureOptionType.potSchemaBinding ) 2055 { 2056 acceptKeyword( "schema" ); 2057 acceptKeyword( "binding" ); 2058 } 2059 } 2060 2061 public void preVisit( TMssqlCreateProcedure procedure ) 2062 { 2063 acceptKeyword( "create" ); 2064 acceptKeyword( "procedure" ); 2065 2066 if ( procedure.getProcedureName( ) != null ) 2067 { 2068 procedure.getProcedureName( ).accept( this ); 2069 } 2070 2071 acceptNewline( ); 2072 acceptSpace( 4 ); 2073 2074 if ( procedure.getParameterDeclarations( ) != null 2075 && procedure.getDeclareStatements( ).size( ) > 0 ) 2076 { 2077 procedure.getParameterDeclarations( ).accept( this ); 2078 } 2079 2080 if ( procedure.getProcedureOptions( ) != null 2081 && procedure.getProcedureOptions( ).size( ) > 0 ) 2082 { 2083 acceptKeyword( "with" ); 2084 2085 for ( int i = 0; i < procedure.getProcedureOptions( ).size( ); i++ ) 2086 { 2087 TProcedureOption option = procedure.getProcedureOptions( ) 2088 .getElement( i ); 2089 option.accept( this ); 2090 if ( i != procedure.getProcedureOptions( ).size( ) - 1 ) 2091 { 2092 acceptSymbol( "," ); 2093 } 2094 } 2095 } 2096 2097 if ( procedure.isForReplication( ) ) 2098 { 2099 acceptKeyword( "for" ); 2100 acceptKeyword( "replication" ); 2101 } 2102 2103 acceptNewline( ); 2104 acceptKeyword( "as" ); 2105 acceptNewline( ); 2106 2107 acceptKeyword( "begin" ); 2108 acceptNewline( ); 2109 2110 if ( procedure.getBodyStatements( ) != null ) 2111 { 2112 procedure.getBodyStatements( ).accept( this ); 2113 } 2114 2115 acceptKeyword( "end" ); 2116 } 2117 2118 public void preVisit( TMssqlFetch stmt ) 2119 { 2120 acceptKeyword( "fetch" ); 2121 acceptKeyword( "from" ); 2122 if ( stmt.getCursorName( ) != null ) 2123 { 2124 stmt.getCursorName( ).accept( this ); 2125 } 2126 acceptKeyword( "into" ); 2127 if ( stmt.getVariableNames( ) != null ) 2128 { 2129 stmt.getVariableNames( ).accept( this ); 2130 } 2131 } 2132 public void preVisit( TMssqlBlock block ) 2133 { 2134 acceptKeyword( "begin" ); 2135 acceptNewline( ); 2136 if ( block.getBodyStatements( ) != null ) 2137 { 2138 block.getBodyStatements( ).accept( this ); 2139 acceptNewline( ); 2140 } 2141 acceptKeyword( "end" ); 2142 } 2143 2144 public void preVisit( TMssqlRollback rollback ) 2145 { 2146 acceptKeyword( "rollback" ); 2147 if ( rollback.getTrans_or_work( ) != null ) 2148 { 2149 acceptToken( rollback.getTrans_or_work( ) ); 2150 } 2151 if ( rollback.getTransactionName( ) != null ) 2152 { 2153 rollback.getTransactionName( ).accept( this ); 2154 } 2155 } 2156 2157 public void preVisit( TMssqlRaiserror raiseError ) 2158 { 2159 acceptKeyword( "raiserror" ); 2160 acceptSymbol( "(" ); 2161 if ( raiseError.getMessageText( ) != null ) 2162 { 2163 raiseError.getMessageText( ).accept( this ); 2164 } 2165 2166 if ( raiseError.getSeverity( ) != null ) 2167 { 2168 acceptSymbol( "," ); 2169 raiseError.getSeverity( ).accept( this ); 2170 } 2171 2172 if ( raiseError.getState( ) != null ) 2173 { 2174 acceptSymbol( "," ); 2175 raiseError.getState( ).accept( this ); 2176 } 2177 2178 if ( raiseError.getArgs( ) != null && raiseError.getArgs( ).size( ) > 0 ) 2179 { 2180 for ( int i = 0; i < raiseError.getArgs( ).size( ); i++ ) 2181 { 2182 acceptSymbol( "," ); 2183 raiseError.getArgs( ).getExpression( i ).accept( this ); 2184 } 2185 } 2186 acceptSymbol( ")" );; 2187 } 2188 2189 public void preVisit( TMssqlPrint stmt ) 2190 { 2191 acceptKeyword( "print" ); 2192 if ( stmt.getMessages( ) != null ) 2193 { 2194 stmt.getMessages( ).accept( this ); 2195 } 2196 } 2197 2198 public void preVisit( TMssqlDeclare stmt ) 2199 { 2200 acceptKeyword( "declare" ); 2201 if ( stmt.getVariables( ) != null ) 2202 { 2203 stmt.getVariables( ).accept( this ); 2204 } 2205 2206 if ( stmt.getCursorName( ) != null ) 2207 { 2208 stmt.getCursorName( ).accept( this ); 2209 acceptKeyword( "cursor" ); 2210 if ( stmt.getSubquery( ) != null ) 2211 { 2212 acceptKeyword( "for" ); 2213 stmt.getSubquery( ).accept( this ); 2214 } 2215 } 2216 } 2217 2218 public void preVisit( TVarDeclStmt stmt ) 2219 { 2220 if ( stmt.getElementName( ) != null ) 2221 { 2222 stmt.getElementName( ).accept( this ); 2223 } 2224 if ( stmt.getDataType( ) != null ) 2225 { 2226 stmt.getDataType( ).accept( this ); 2227 } 2228 if ( stmt.getDefaultValue( ) != null ) 2229 { 2230 if ( stmt.getDeclareType( ) == EDeclareType.variable ) 2231 { 2232 acceptKeyword( "default" ); 2233 stmt.getDefaultValue( ).accept( this ); 2234 } 2235 else if ( stmt.getDeclareType( ) == EDeclareType.constant ) 2236 { 2237 acceptSymbol( ":=" ); 2238 stmt.getDefaultValue( ).accept( this ); 2239 } 2240 } 2241 } 2242 2243 public void preVisit( TMssqlSet stmt ) 2244 { 2245 acceptKeyword( "set" ); 2246 if ( stmt.getVarName( ) != null ) 2247 { 2248 stmt.getVarName( ).accept( this ); 2249 acceptSymbol( "=" ); 2250 } 2251 if ( stmt.getVarExpr( ) != null ) 2252 { 2253 stmt.getVarExpr( ).accept( this ); 2254 } 2255 } 2256 2257 public void preVisit( TMssqlReturn stmt ) 2258 { 2259 acceptKeyword( "return" ); 2260 if ( stmt.getReturnExpr( ) != null ) 2261 { 2262 stmt.getReturnExpr( ).accept( this ); 2263 } 2264 } 2265 2266 public void preVisit( TMssqlLabel stmt ) 2267 { 2268 super.preVisit( stmt ); 2269 } 2270 2271 public void preVisit( TDeclareVariableList variables ) 2272 { 2273 for ( int i = 0; i < variables.size( ); i++ ) 2274 { 2275 variables.getDeclareVariable( i ).accept( this ); 2276 if ( i != variables.size( ) - 1 ) 2277 { 2278 acceptSymbol( "," ); 2279 } 2280 } 2281 } 2282 2283 public void preVisit( TDeclareVariable variable ) 2284 { 2285 if ( variable.getVariableName( ) != null ) 2286 { 2287 variable.getVariableName( ).accept( this ); 2288 } 2289 2290 if ( variable.getDatatype( ) != null ) 2291 { 2292 variable.getDatatype( ).accept( this ); 2293 } 2294 } 2295 2296 public void preVisit( TMssqlExecute stmt ) 2297 { 2298 acceptKeyword( "exec" ); 2299 if ( stmt.getModuleName( ) != null ) 2300 { 2301 stmt.getModuleName( ).accept( this ); 2302 } 2303 if ( stmt.getParameters( ) != null && stmt.getParameters( ).size( ) > 0 ) 2304 { 2305 acceptSpace( 1 ); 2306 stmt.getParameters( ).accept( this ); 2307 } 2308 } 2309 2310 public void preVisit( TMssqlExecuteAs stmt ) 2311 { 2312 acceptKeyword( "execute" ); 2313 acceptKeyword( "as" ); 2314 if ( stmt.getExecuteAsOption( ) != null ) 2315 { 2316 switch ( stmt.getExecuteAsOption( ) ) 2317 { 2318 case eaoCaller : 2319 acceptKeyword( "caller" ); 2320 break; 2321 case eaoLogin : 2322 acceptKeyword( "login" ); 2323 break; 2324 case eaoOwner : 2325 acceptKeyword( "owner" ); 2326 break; 2327 case eaoSelf : 2328 acceptKeyword( "self" ); 2329 break; 2330 case eaoString : 2331 acceptKeyword( "string" ); 2332 break; 2333 case eaoUser : 2334 acceptKeyword( "user" ); 2335 break; 2336 default : 2337 break; 2338 } 2339 } 2340 if ( stmt.getLoginName( ) != null ) 2341 { 2342 stmt.getLoginName( ).accept( this ); 2343 // TScriptGenerator generator = new TScriptGenerator( this.dbVendor 2344 // ); 2345 // generator.createObjectName( stmt.getUserName( ) ).accept( this ); 2346 } 2347 } 2348 2349 public void preVisit( TMssqlRevert stmt ) 2350 { 2351 acceptKeyword( "revert" ); 2352 if ( stmt.getCookie( ) != null ) 2353 { 2354 acceptKeyword( "with" ); 2355 acceptIdentifier( "cookie" ); 2356 acceptSymbol( "=" ); 2357 stmt.getCookie( ).accept( this ); 2358 } 2359 } 2360 2361 public void preVisit( TMssqlStmtStub stmt ) 2362 { 2363 super.preVisit( stmt ); 2364 } 2365 2366 public void preVisit( TExecParameter param ) 2367 { 2368 if ( param.getParameterName( ) != null ) 2369 { 2370 param.getParameterName( ).accept( this ); 2371 } 2372 if ( param.getParameterValue( ) != null ) 2373 { 2374 param.getParameterValue( ).accept( this ); 2375 } 2376 } 2377 2378 public void preVisit( TExecParameterList params ) 2379 { 2380 for ( int i = 0; i < params.size( ); i++ ) 2381 { 2382 params.getExecParameter( i ).accept( this ); 2383 if ( i != params.size( ) - 1 ) 2384 { 2385 acceptSymbol( "," ); 2386 } 2387 } 2388 } 2389 2390 public void preVisit( TAlterTableOption node ) 2391 { 2392 2393 switch ( node.getOptionType( ) ) 2394 { 2395 case AddColumn : 2396 acceptKeyword( "add" ); 2397 if (( node.getColumnDefinitionList( ).size( ) > 1 )&&(TGSqlParser.getCurrentDBVendor() != EDbVendor.dbvmssql)) 2398 acceptSymbol( "(" ); 2399 node.getColumnDefinitionList( ).accept( this ); 2400 if(( node.getColumnDefinitionList( ).size( ) > 1 )&&(TGSqlParser.getCurrentDBVendor() != EDbVendor.dbvmssql)) 2401 acceptSymbol( ")" ); 2402 break; 2403 case AlterColumn : 2404 acceptKeyword( "alter" ); 2405 acceptKeyword( "column" ); 2406 node.getColumnName( ).accept( this ); 2407 break; 2408 case ChangeColumn : 2409 acceptKeyword( "change" ); 2410 node.getColumnName( ).accept( this ); 2411 break; 2412 case DropColumn : 2413 acceptKeyword( "drop" ); 2414 acceptKeyword( "column" ); 2415 if ( node.getColumnNameList( ).size( ) > 1 ) 2416 acceptSymbol( "(" ); 2417 node.getColumnNameList( ).accept( this ); 2418 if ( node.getColumnNameList( ).size( ) > 1 ) 2419 acceptSymbol( ")" ); 2420 2421 break; 2422 case ModifyColumn : 2423 acceptKeyword( "modify" ); 2424 acceptKeyword( "column" ); 2425 if ( node.getColumnDefinitionList( ).size( ) > 1 ) 2426 acceptSymbol( "(" ); 2427 node.getColumnDefinitionList( ).accept( this ); 2428 if ( node.getColumnDefinitionList( ).size( ) > 1 ) 2429 acceptSymbol( ")" ); 2430 break; 2431 case RenameColumn : 2432 acceptKeyword( "rename" ); 2433 acceptKeyword( "column" ); 2434 node.getColumnName( ).accept( this ); 2435 acceptKeyword( "to" ); 2436 node.getNewColumnName( ).accept( this ); 2437 break; 2438 case AddConstraint : 2439 acceptKeyword( "add" ); 2440 node.getConstraintList( ).accept( this ); 2441 break; 2442 default : 2443 } 2444 2445 } 2446 2447 public void preVisit( TAlterTableStatement stmt ) 2448 { 2449 2450 acceptKeyword( "alter" ); 2451 acceptKeyword( "table" ); 2452 stmt.getTableName( ).accept( this ); 2453 acceptNewline( ); 2454 2455 if ( stmt.getAlterTableOptionList( ) != null ) 2456 { 2457 for ( int i = 0; i < stmt.getAlterTableOptionList( ).size( ); i++ ) 2458 { 2459 stmt.getAlterTableOptionList( ) 2460 .getAlterTableOption( i ) 2461 .accept( this ); 2462 if ( i != stmt.getAlterTableOptionList( ).size( ) - 1 ) 2463 { 2464 acceptSymbol( "," ); 2465 acceptNewline( ); 2466 } 2467 } 2468 } 2469 2470 } 2471 2472 public void preVisit( TStatementList stmts ) 2473 { 2474 for ( int i = 0; i < stmts.size( ); i++ ) 2475 { 2476 TCustomSqlStatement stmt = stmts.get( i ); 2477 preVisit( stmt ); 2478 if ( stmts.size( ) > 1 ) 2479 acceptSemicolon( ); 2480 2481 if ( i != stmts.size( ) - 1 ) 2482 { 2483 acceptNewline( ); 2484 } 2485 } 2486 } 2487 2488 protected void preVisit( TCustomSqlStatement stmt ) 2489 { 2490 try 2491 { 2492 Class<?> clazz = stmt.getClass( ); 2493 Method m = this.getClass( ).getMethod( "preVisit", clazz ); 2494 m.setAccessible( true ); 2495 m.invoke( this, stmt ); 2496 } 2497 catch ( Exception e ) 2498 { 2499 throw new UnsupportedOperationException( stmt.sqlstatementtype.name( ), 2500 e ); 2501 } 2502 } 2503 2504 public void preVisit( TElsifStmt elsifStmt ) 2505 { 2506 acceptKeyword( "elsif" ); 2507 if ( elsifStmt.getCondition( ) != null ) 2508 { 2509 elsifStmt.getCondition( ).accept( this ); 2510 } 2511 if ( elsifStmt.getThenStatements( ) != null 2512 && elsifStmt.getThenStatements( ).size( ) > 0 ) 2513 { 2514 acceptKeyword( "then" ); 2515 acceptNewline( ); 2516 acceptSpace( 4 ); 2517 preVisit( elsifStmt.getThenStatements( ) ); 2518 acceptNewline( ); 2519 } 2520 } 2521 2522 public void preVisit( TAssignStmt assignStmt ) 2523 { 2524 assignStmt.getLeft( ).accept( this ); 2525 scriptWriter.addComparisonOperator( EComparisonType.equals ); 2526 assignStmt.getExpression( ).accept( this ); 2527 } 2528 2529 public void preVisit( TIfStmt ifStmt ) 2530 { 2531 acceptKeyword( "if" ); 2532 if ( ifStmt.getCondition( ) != null ) 2533 { 2534 ifStmt.getCondition( ).accept( this ); 2535 } 2536 if ( ifStmt.getThenStatements( ) != null 2537 && ifStmt.getThenStatements( ).size( ) > 0 ) 2538 { 2539 acceptKeyword( "then" ); 2540 acceptNewline( ); 2541 acceptSpace( 4 ); 2542 preVisit( ifStmt.getThenStatements( ) ); 2543 acceptNewline( ); 2544 } 2545 if ( ifStmt.getElseifStatements( ) != null ) 2546 { 2547 preVisit( ifStmt.getElseifStatements( ) ); 2548 } 2549 if ( ifStmt.getElseStatements( ) != null 2550 && ifStmt.getElseStatements( ).size( ) > 0 ) 2551 { 2552 acceptKeyword( "else" ); 2553 preVisit( ifStmt.getElseStatements( ) ); 2554 acceptNewline( ); 2555 } 2556 2557 acceptKeyword( "end" ); 2558 acceptKeyword( "if" ); 2559 acceptNewline( ); 2560 } 2561 2562 public void preVisit( TMssqlIfElse ifElse ) 2563 { 2564 acceptKeyword( "if" ); 2565 if ( ifElse.getCondition( ) != null ) 2566 { 2567 ifElse.getCondition( ).accept( this ); 2568 } 2569 if ( ifElse.getStmt( ) != null ) 2570 { 2571 acceptNewline( ); 2572 acceptSpace( 4 ); 2573 preVisit( ifElse.getStmt( ) ); 2574 } 2575 if ( ifElse.getElseStmt( ) != null ) 2576 { 2577 acceptNewline( ); 2578 acceptSpace( 4 ); 2579 acceptKeyword( "else" ); 2580 acceptNewline( ); 2581 acceptSpace( 4 ); 2582 preVisit( ifElse.getElseStmt( ) ); 2583 } 2584 } 2585 2586 public void preVisit( TAliasClause node ) 2587 { 2588 if ( node.isHasAs( ) ) 2589 { 2590 acceptKeyword( "as" ); 2591 } 2592 node.getAliasName( ).accept( this ); 2593 2594 if ( node.getColumns( ) != null ) 2595 { 2596 acceptSpace( 1 ); 2597 acceptSymbol( "(" ); 2598 visitObjectNameList( node.getColumns( ) ); 2599 acceptSymbol( ")" ); 2600 } 2601 } 2602 2603 2604 public void preVisit( TWhereClause node ) 2605 { 2606 if ( node.getCondition( ) == null ) 2607 return; 2608 acceptKeyword( "where" ); 2609 node.getCondition( ).accept( this ); 2610 } 2611 2612 public void preVisit( TIntoClause node ) 2613 { 2614 if ( node.isBulkCollect( ) ) 2615 { 2616 acceptKeyword( "bulk" ); 2617 acceptKeyword( "collect" ); 2618 } 2619 acceptKeyword( "into" ); 2620 if ( node.getExprList( ) != null ) 2621 { 2622 acceptNewline( ); 2623 node.getExprList( ).accept( this ); 2624 } 2625 else 2626 { 2627 node.getIntoName( ).accept( this ); 2628 } 2629 } 2630 2631 public void preVisit( TTopClause node ) 2632 { 2633 acceptKeyword( "top" ); 2634 node.getExpr( ).accept( this ); 2635 if ( node.isPercent( ) ) 2636 acceptKeyword( "percent" ); 2637 if ( node.isWithties( ) ) 2638 { 2639 acceptKeyword( "with ties" ); 2640 } 2641 } 2642 2643 public void preVisit( TLimitClause node ) 2644 { 2645 acceptNewline( ); 2646 2647 // PostgreSQL writes "LIMIT count OFFSET offset" rather than the 2648 // MySQL-style "LIMIT offset, count". Only rewrite for postgres and 2649 // only when both pieces are present so the rest of the dialects 2650 // (which carry a single value in getOffset()) keep the old behavior. 2651 EDbVendor v = TGSqlParser.getCurrentDBVendor( ); 2652 if ( v == EDbVendor.dbvpostgresql 2653 && node.getOffset( ) != null 2654 && node.getRow_count( ) != null ) 2655 { 2656 acceptKeyword( "limit" ); 2657 node.getRow_count( ).accept( this ); 2658 acceptKeyword( "offset" ); 2659 node.getOffset( ).accept( this ); 2660 return; 2661 } 2662 2663 acceptKeyword( "limit" ); 2664 2665 if ( node.getOffset( ) != null ) 2666 { 2667 node.getOffset( ).accept( this ); 2668 if (node.getRow_count( ) != null){ 2669 acceptSymbol( "," ); 2670 node.getRow_count( ).accept( this ); 2671 } 2672 } 2673 else 2674 { 2675 node.getRow_count( ).accept( this ); 2676 } 2677 } 2678 2679 public void preVisit( TJoin node ) 2680 { 2681 2682 if ( node.getJoinItems( ).size( ) > 0 ) 2683 { 2684 if ( node.getTable( ) != null ) 2685 { 2686 node.setKind( TBaseType.join_source_table ); 2687 } 2688 else if ( node.getJoin( ) != null ) 2689 { 2690 node.setKind( TBaseType.join_source_join ); 2691 } 2692 } 2693 2694 if ( node.isWithParen( ) ) 2695 { 2696 for ( int i = 0; i < node.getNestedParen( ); i++ ) 2697 { 2698 acceptSymbol( "(" ); 2699 } 2700 } 2701 switch ( node.getKind( ) ) 2702 { 2703 case TBaseType.join_source_fake : 2704 node.getTable( ).accept( this ); 2705 break; 2706 case TBaseType.join_source_table : 2707 case TBaseType.join_source_join : 2708 2709 if ( node.getKind( ) == TBaseType.join_source_table ) 2710 { 2711 node.getTable( ).accept( this ); 2712 } 2713 else if ( node.getKind( ) == TBaseType.join_source_join ) 2714 { 2715 // preVisit(node.getJoin()); 2716 node.getJoin( ).accept( this ); 2717 } 2718 2719 for ( int i = 0; i < node.getJoinItems( ).size( ); i++ ) 2720 { 2721 TJoinItem joinItem = node.getJoinItems( ).getJoinItem( i ); 2722 acceptNewline( ); 2723 joinItem.accept( this ); 2724 } 2725 break; 2726 } 2727 if ( node.isWithParen( ) ) 2728 { 2729 for ( int i = 0; i < node.getNestedParen( ); i++ ) 2730 { 2731 acceptSymbol( ")" ); 2732 } 2733 } 2734 2735 if ( node.getAliasClause( ) != null ) 2736 { 2737 acceptSpace( 1 ); 2738 node.getAliasClause( ).accept( this ); 2739 } 2740 } 2741 2742 public void preVisit( TJoinItem joinItem ) 2743 { 2744 2745 switch ( joinItem.getJoinType( ) ) 2746 { 2747 case inner : 2748 acceptKeyword( "inner" ); 2749 acceptKeyword( "join" ); 2750 break; 2751 case join : 2752 acceptKeyword( "join" ); 2753 break; 2754 case left : 2755 acceptKeyword( "left" ); 2756 acceptKeyword( "join" ); 2757 break; 2758 case leftouter : 2759 acceptKeyword( "left" ); 2760 acceptKeyword( "outer" ); 2761 acceptKeyword( "join" ); 2762 break; 2763 case right : 2764 acceptKeyword( "right" ); 2765 acceptKeyword( "join" ); 2766 break; 2767 case rightouter : 2768 acceptKeyword( "right" ); 2769 acceptKeyword( "outer" ); 2770 acceptKeyword( "join" ); 2771 break; 2772 case full : 2773 acceptKeyword( "full" ); 2774 acceptKeyword( "join" ); 2775 break; 2776 case fullouter : 2777 acceptKeyword( "full" ); 2778 acceptKeyword( "outer" ); 2779 acceptKeyword( "join" ); 2780 break; 2781 case cross : 2782 acceptKeyword( "cross" ); 2783 acceptKeyword( "join" ); 2784 break; 2785 case natural : 2786 acceptKeyword( "natural" ); 2787 acceptKeyword( "join" ); 2788 break; 2789 case natural_inner : 2790 acceptKeyword( "natural" ); 2791 acceptKeyword( "inner" ); 2792 acceptKeyword( "join" ); 2793 break; 2794 case crossapply : 2795 acceptKeyword( "cross" ); 2796 acceptKeyword( "apply" ); 2797 break; 2798 case outerapply : 2799 acceptKeyword( "outer" ); 2800 acceptKeyword( "apply" ); 2801 break; 2802 default : 2803 acceptKeyword( "join" ); 2804 break; 2805 } 2806 2807 if ( joinItem.getTable( ) != null ) 2808 { 2809 joinItem.getTable( ).accept( this ); 2810 } 2811 else if ( joinItem.getJoin( ) != null ) 2812 { 2813 joinItem.getJoin( ).accept( this ); 2814 } 2815 2816 if ( joinItem.getOnCondition( ) != null ) 2817 { 2818 acceptKeyword( "on" ); 2819 joinItem.getOnCondition( ).accept( this ); 2820 } 2821 2822 if ( joinItem.getUsingColumns( ) != null ) 2823 { 2824 acceptKeyword( "using" ); 2825 acceptSymbol( "(" ); 2826 visitObjectNameList( joinItem.getUsingColumns( ) ); 2827 acceptSymbol( ")" ); 2828 } 2829 2830 // already implemented in public void preVisit(TJoin node){ 2831 2832 // if (node.getKind() == TBaseType.join_source_table){ 2833 // node.getTable().accept(this); 2834 // }else if (node.getKind() == TBaseType.join_source_join){ 2835 // node.getJoin().accept(this); 2836 // } 2837 2838 // if (node.getTable() != null){ 2839 // node.getTable().accept(this); 2840 // }else if (node.getJoin() != null){ 2841 // node.getJoin().accept(this); 2842 // } 2843 // 2844 // 2845 // if (node.getOnCondition() != null){ 2846 // node.getOnCondition().accept(this); 2847 // } 2848 // 2849 // if (node.getUsingColumns() != null){ 2850 // node.getUsingColumns().accept(this); 2851 // } 2852 } 2853 2854 2855 public void preVisit(TJsonTable node) { 2856 visitNodeByToken(node); 2857 } 2858 2859 public void preVisit( TTable node ) 2860 { 2861 2862 if ( node.getParenthesisCount( ) > 0 ) 2863 { 2864 for ( int i = 0; i < node.getParenthesisCount( ); i++ ) 2865 { 2866 acceptSymbol( "(" ); 2867 } 2868 } 2869 if ( node.getParenthesisAfterAliasCount( ) > 0 ) 2870 { 2871 for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ ) 2872 { 2873 acceptSymbol( "(" ); 2874 } 2875 } 2876 2877 if ( node.isTableKeyword( ) ) 2878 { 2879 acceptKeyword( "table" ); 2880 acceptSymbol( "(" ); 2881 } 2882 2883 if ( node.isOnlyKeyword( ) ) 2884 { 2885 acceptKeyword( "only" ); 2886 acceptSymbol( "(" ); 2887 } 2888 2889 switch ( node.getTableType( ) ) 2890 { 2891 case objectname : 2892 { 2893 node.getTableName( ).accept( this ); 2894 if ( node.getFlashback( ) != null ) 2895 { 2896 acceptNewline( ); 2897 visitNodeByToken( node.getFlashback( ) ); 2898 } 2899 break; 2900 } 2901 case tableExpr : 2902 { 2903 node.getTableExpr( ).accept( this ); 2904 break; 2905 } 2906 case subquery : 2907 { 2908 node.getSubquery( ).accept( this ); 2909 break; 2910 } 2911 case function : 2912 { 2913 node.getFuncCall( ).accept( this ); 2914 break; 2915 } 2916 case pivoted_table : 2917 { 2918 node.getPivotedTable( ).accept( this ); 2919 break; 2920 } 2921 case output_merge : 2922 { 2923 // e_table_reference.setTextContent(node.getOutputMerge().toString()); 2924 break; 2925 } 2926 case containsTable : 2927 { 2928 node.getContainsTable( ).accept( this ); 2929 break; 2930 } 2931 2932 case openrowset : 2933 { 2934 node.getOpenRowSet( ).accept( this ); 2935 break; 2936 } 2937 2938 case openxml : 2939 { 2940 node.getOpenXML( ).accept( this ); 2941 break; 2942 } 2943 2944 case opendatasource : 2945 { 2946 node.getOpenDatasource( ).accept( this ); 2947 break; 2948 } 2949 2950 case openquery : 2951 { 2952 node.getOpenquery( ).accept( this ); 2953 break; 2954 } 2955 case datachangeTable : 2956 { 2957 node.getDatachangeTable( ).accept( this ); 2958 break; 2959 } 2960 case rowList : 2961 { 2962 node.getValueClause( ).accept( this ); 2963 break; 2964 } 2965 case xmltable : 2966 { 2967 node.getXmlTable( ).accept( this ); 2968 break; 2969 } 2970 2971 case informixOuter : 2972 { 2973 node.getOuterClause( ).accept( this ); 2974 break; 2975 } 2976 2977 case table_ref_list : 2978 { 2979 node.getFromTableList( ).accept( this ); 2980 break; 2981 } 2982 case hiveFromQuery : 2983 { 2984 node.getHiveFromQuery( ).accept( this ); 2985 break; 2986 } 2987 case jsonTable : 2988 { 2989 node.getJsonTable( ).accept( this ); 2990 break; 2991 } 2992 2993 default : 2994 // sb.append(node.toString().replace(">",">").replace("<","<")); 2995 break; 2996 2997 } 2998 2999 if ( node.isTableKeyword( ) ) 3000 { 3001 acceptSymbol( ")" ); 3002 } 3003 3004 if ( node.isOnlyKeyword( ) ) 3005 { 3006 acceptSymbol( ")" ); 3007 } 3008 3009 if ( node.getParenthesisCount( ) > 0 ) 3010 { 3011 for ( int i = 0; i < node.getParenthesisCount( ); i++ ) 3012 { 3013 acceptSymbol( ")" ); 3014 } 3015 } 3016 3017 if ( node.getPxGranule( ) != null ) 3018 { 3019 // node.getPxGranule().accept(this); 3020 acceptNewline( ); 3021 visitNodeByToken( node.getPxGranule( ) ); 3022 } 3023 3024 if ( node.getTableSample( ) != null ) 3025 { 3026 // node.getTableSample().accept(this); 3027 acceptNewline( ); 3028 visitNodeByToken( node.getTableSample( ) ); 3029 } 3030 3031 if ( node.getAliasClause( ) != null ) 3032 { 3033 acceptSpace( 1 ); 3034 node.getAliasClause( ).accept( this ); 3035 } 3036 3037 if ( node.getParenthesisAfterAliasCount( ) > 0 ) 3038 { 3039 for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ ) 3040 { 3041 acceptSymbol( ")" ); 3042 } 3043 } 3044 3045 if ( node.getTableHintList( ) != null ) 3046 { 3047 for ( int i = 0; i < node.getTableHintList( ).size( ); i++ ) 3048 { 3049 TTableHint tableHint = node.getTableHintList( ).getElement( i ); 3050 tableHint.accept( this ); 3051 } 3052 } 3053 3054 } 3055 3056 public void preVisit( THierarchical node ) 3057 { 3058 if ( node.getStartWithClause( ) != null ) 3059 { 3060 acceptKeyword( "start" ); 3061 acceptKeyword( "with" ); 3062 node.getStartWithClause( ).accept( this ); 3063 } 3064 3065 for ( int i = 0; i < node.getConnectByList( ).size( ); i++ ) 3066 { 3067 node.getConnectByList( ).getElement( i ).accept( this ); 3068 if ( i != node.getConnectByList( ).size( ) - 1 ) 3069 { 3070 acceptNewline( ); 3071 } 3072 } 3073 3074 } 3075 3076 public void preVisit( TConnectByClause node ) 3077 { 3078 acceptKeyword( "connect" ); 3079 acceptKeyword( "by" ); 3080 if ( node.isNoCycle( ) ) 3081 { 3082 acceptKeyword( "nocycle" ); 3083 } 3084 node.getCondition( ).accept( this ); 3085 } 3086 3087 public void preVisit( TGroupBy node ) 3088 { 3089 if ( node.getItems( ) != null && node.getItems( ).size( ) > 0 ) 3090 { 3091 acceptKeyword( "group" ); 3092 acceptKeyword( "by" ); 3093 for ( int i = 0; i < node.getItems( ).size( ); i++ ) 3094 { 3095 node.getItems( ).getElement( i ).accept( this ); 3096 if ( i != node.getItems( ).size( ) - 1 ) 3097 acceptSymbol( "," ); 3098 } 3099 3100 if (node.isRollupModifier()){ 3101 acceptKeyword("with"); 3102 acceptKeyword("rollup"); 3103 } 3104 3105 if (node.isCubeModifier()){ 3106 acceptKeyword("with"); 3107 acceptKeyword("cube"); 3108 } 3109 } 3110 if ( node.getHavingClause( ) != null ) 3111 { 3112 acceptKeyword( "having" ); 3113 node.getHavingClause( ).accept( this ); 3114 } 3115 } 3116 3117 public void preVisit( TGroupByItem node ) 3118 { 3119 3120 if ( node.getExpr( ) != null ) 3121 { 3122 node.getExpr( ).accept( this ); 3123 } 3124 else if ( node.getGroupingSet( ) != null ) 3125 { 3126 node.getGroupingSet( ).accept( this ); 3127 } 3128 else if ( node.getRollupCube( ) != null ) 3129 { 3130 node.getRollupCube( ).accept( this ); 3131 } 3132 3133 } 3134 3135 public void preVisit( TOrderBy node ) 3136 { 3137 if ( node.getItems( ).size( ) == 0 ) 3138 return; 3139 3140 acceptKeyword( "order" ); 3141 if ( node.isSiblings( ) ) 3142 acceptKeyword( "siblings" ); 3143 acceptKeyword( "by" ); 3144 for ( int i = 0; i < node.getItems( ).size( ); i++ ) 3145 { 3146 node.getItems( ).getOrderByItem( i ).accept( this ); 3147 if ( i != node.getItems( ).size( ) - 1 ) 3148 acceptSymbol( "," ); 3149 } 3150 3151 } 3152 3153 public void preVisit( TOrderByItem node ) 3154 { 3155 if ( node.getSortKey( ) != null ) 3156 { 3157 node.getSortKey( ).accept( this ); 3158 } 3159 if ( node.getSortOrder( ) == ESortType.asc ) 3160 { 3161 acceptKeyword( "asc" ); 3162 } 3163 else if ( node.getSortOrder( ) == ESortType.desc ) 3164 { 3165 acceptKeyword( "desc" ); 3166 } 3167 3168 if (node.getNullOrder() == ENullOrder.nullsFirst){ 3169 acceptKeyword( "nulls" ); 3170 acceptKeyword( "first" ); 3171 }else if (node.getNullOrder() == ENullOrder.nullsLast){ 3172 acceptKeyword( "nulls" ); 3173 acceptKeyword( "last" ); 3174 } 3175 // e_order_by_item.setAttribute("sort_order",node.getSortOrder().toString()); 3176 } 3177 3178 public void preVisit( TCTE node ) 3179 { 3180 if (node.isRecursive()){ 3181 acceptKeyword( "recursive" ); 3182 } 3183 3184 node.getTableName( ).accept( this ); 3185 3186 if ( node.getColumnList( ) != null ) 3187 { 3188 acceptSymbol( "(" ); 3189 for ( int i = 0; i < node.getColumnList( ).size( ); i++ ) 3190 { 3191 node.getColumnList( ).getObjectName( i ).accept( this ); 3192 if ( i != node.getColumnList( ).size( ) - 1 ) 3193 acceptSymbol( "," ); 3194 } 3195 acceptSymbol( ")" ); 3196 3197 } 3198 3199 acceptKeyword( "as" ); 3200 acceptNewline( ); 3201 3202 if (node.dbvendor == EDbVendor.dbvpostgresql){ 3203 acceptSymbol( "(" ); 3204 } 3205 3206 if ( node.getSubquery( ) != null ) 3207 { 3208 node.getSubquery( ).accept( this ); 3209 } 3210 else if ( node.getUpdateStmt( ) != null ) 3211 { 3212 node.getUpdateStmt( ).accept( this ); 3213 } 3214 else if ( node.getInsertStmt( ) != null ) 3215 { 3216 node.getInsertStmt( ).accept( this ); 3217 } 3218 else if ( node.getDeleteStmt( ) != null ) 3219 { 3220 node.getDeleteStmt( ).accept( this ); 3221 } 3222 3223 if (node.dbvendor == EDbVendor.dbvpostgresql) { 3224 acceptSymbol(")"); 3225 } 3226 3227 3228 } 3229 3230 public void preVisit( TPivotInClause node ) 3231 { 3232 acceptKeyword( "in" ); 3233 if ( node.getItems( ) != null ) 3234 { 3235 acceptSymbol( "(" ); 3236 visitResultColumnList( node.getItems( ) ); 3237 acceptSymbol( ")" ); 3238 } 3239 if ( node.getSubQuery( ) != null ) 3240 node.getSubQuery( ).accept( this ); 3241 3242 } 3243 3244 public void preVisit( TPivotedTable node ) 3245 { 3246 TPivotClause pivotClause; 3247 3248 for ( int i = 0; i < node.getPivotClauseList( ).size( ); i++ ) 3249 { 3250 3251 if ( i == 0 ) 3252 { 3253 node.getTableSource( ).accept( this ); 3254 } 3255 else 3256 { 3257 } 3258 3259 pivotClause = node.getPivotClauseList( ).getElement( i ); 3260 if ( pivotClause.getAliasClause( ) != null ) 3261 { 3262 pivotClause.getAliasClause( ).accept( this ); 3263 } 3264 pivotClause.accept( this ); 3265 3266 } 3267 3268 } 3269 3270 public void preVisit( TPivotClause node ) 3271 { 3272 if ( node.getType( ) == TPivotClause.pivot ) 3273 { 3274 acceptKeyword( "pivot" ); 3275 acceptSymbol( "(" ); 3276 if ( node.getAggregation_function( ) != null ) 3277 { 3278 node.getAggregation_function( ).accept( this ); 3279 } 3280 else if ( node.getAggregation_function_list( ) != null ) 3281 { 3282 if ( node.getAggregation_function_list( ).size( ) > 1 ) 3283 acceptSymbol( "(" ); 3284 for ( int i = 0; i < node.getAggregation_function_list( ) 3285 .size( ); i++ ) 3286 { 3287 node.getAggregation_function_list( ) 3288 .getResultColumn( i ) 3289 .accept( this ); 3290 if ( i != node.getAggregation_function_list( ).size( ) - 1 ) 3291 acceptSymbol( "," ); 3292 } 3293 if ( node.getAggregation_function_list( ).size( ) > 1 ) 3294 acceptSymbol( ")" ); 3295 } 3296 acceptKeyword( "for" ); 3297 3298 if ( node.getPivotColumnList( ).size( ) > 1 ) 3299 acceptSymbol( "(" ); 3300 for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ ) 3301 { 3302 node.getPivotColumnList( ).getElement( i ).accept( this ); 3303 if ( i != node.getPivotColumnList( ).size( ) - 1 ) 3304 acceptSymbol( "," ); 3305 } 3306 if ( node.getPivotColumnList( ).size( ) > 1 ) 3307 acceptSymbol( ")" ); 3308 3309 node.getPivotInClause( ).accept( this ); 3310 3311 acceptSymbol( ")" ); 3312 } 3313 else 3314 { 3315 acceptKeyword( "unpivot" ); 3316 acceptSymbol( "(" ); 3317 if ( node.getValueColumnList( ).size( ) > 1 ) 3318 acceptSymbol( "(" ); 3319 for ( int i = 0; i < node.getValueColumnList( ).size( ); i++ ) 3320 { 3321 node.getValueColumnList( ).getObjectName( i ).accept( this ); 3322 if ( i != node.getValueColumnList( ).size( ) - 1 ) 3323 acceptSymbol( "," ); 3324 } 3325 if ( node.getValueColumnList( ).size( ) > 1 ) 3326 acceptSymbol( ")" ); 3327 3328 acceptKeyword( "for" ); 3329 3330 if ( node.getPivotColumnList( ).size( ) > 1 ) 3331 acceptSymbol( "(" ); 3332 for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ ) 3333 { 3334 node.getPivotColumnList( ).getElement( i ).accept( this ); 3335 if ( i != node.getPivotColumnList( ).size( ) - 1 ) 3336 acceptSymbol( "," ); 3337 } 3338 if ( node.getPivotColumnList( ).size( ) > 1 ) 3339 acceptSymbol( ")" ); 3340 3341 node.getUnpivotInClause( ).accept( this ); 3342 3343 acceptSymbol( ")" ); 3344 } 3345 } 3346 3347 public void preVisit( TUnpivotInClauseItem node ) 3348 { 3349 3350 if ( node.getColumn( ) != null ) 3351 { 3352 node.getColumn( ).accept( this ); 3353 } 3354 else if ( node.getColumnList( ) != null ) 3355 { 3356 acceptSymbol( "(" ); 3357 for ( int i = 0; i < node.getColumnList( ).size( ); i++ ) 3358 { 3359 node.getColumnList( ).getObjectName( i ).accept( this ); 3360 if ( i != node.getColumnList( ).size( ) - 1 ) 3361 acceptSymbol( "," ); 3362 } 3363 acceptSymbol( ")" ); 3364 } 3365 3366 if ( node.getConstant( ) != null ) 3367 { 3368 acceptKeyword( "as" ); 3369 node.getConstant( ).accept( this ); 3370 } 3371 else if ( node.getConstantList( ) != null ) 3372 { 3373 acceptKeyword( "as" ); 3374 acceptSymbol( "(" ); 3375 for ( int i = 0; i < node.getConstantList( ).size( ); i++ ) 3376 { 3377 node.getConstantList( ).getElement( i ).accept( this ); 3378 if ( i != node.getConstantList( ).size( ) - 1 ) 3379 acceptSymbol( "," ); 3380 } 3381 acceptSymbol( ")" ); 3382 } 3383 3384 } 3385 3386 public void preVisit( TUnpivotInClause node ) 3387 { 3388 acceptKeyword( "in" ); 3389 acceptSymbol( "(" ); 3390 for ( int i = 0; i < node.getItems( ).size( ); i++ ) 3391 { 3392 node.getItems( ).getElement( i ).accept( this ); 3393 if ( i != node.getItems( ).size( ) - 1 ) 3394 acceptSymbol( "," ); 3395 } 3396 acceptSymbol( ")" ); 3397 } 3398 3399 public void preVisit( TCaseExpression node ) 3400 { 3401 3402 acceptKeyword( "case" ); 3403 if ( node.getInput_expr( ) != null ) 3404 { 3405 node.getInput_expr( ).accept( this ); 3406 } 3407 3408 for ( int i = 0; i < node.getWhenClauseItemList( ).size( ); i++ ) 3409 { 3410 node.getWhenClauseItemList( ).getWhenClauseItem( i ).accept( this ); 3411 if ( i != node.getWhenClauseItemList( ).size( ) - 1 ) 3412 acceptNewline( ); 3413 } 3414 3415 if ( node.getElse_expr( ) != null ) 3416 { 3417 acceptNewline( ); 3418 acceptKeyword( "else" ); 3419 node.getElse_expr( ).accept( this ); 3420 } 3421 3422 if ( node.getElse_statement_list( ).size( ) > 0 ) 3423 { 3424 node.getElse_statement_list( ).accept( this ); 3425 } 3426 3427 acceptNewline( ); 3428 acceptKeyword( "end" ); 3429 } 3430 3431 public void preVisit( TWhenClauseItem node ) 3432 { 3433 acceptKeyword( "when" ); 3434 node.getComparison_expr( ).accept( this ); 3435 acceptNewline( ); 3436 acceptKeyword( "then" ); 3437 if ( node.getReturn_expr( ) != null ) 3438 { 3439 node.getReturn_expr( ).accept( this ); 3440 } 3441 else if ( node.getStatement_list( ).size( ) > 0 ) 3442 { 3443 for ( int i = 0; i < node.getStatement_list( ).size( ); i++ ) 3444 { 3445 node.getStatement_list( ).get( i ).accept( this ); 3446 } 3447 3448 } 3449 } 3450 3451 public void preVisit( TForUpdate node ) 3452 { 3453 switch ( node.getForUpdateType( ) ) 3454 { 3455 case forReadOnly : 3456 acceptKeyword( "read" ); 3457 acceptKeyword( "only" ); 3458 break; 3459 case forUpdate : 3460 acceptKeyword( "for" ); 3461 acceptKeyword( "update" ); 3462 break; 3463 case forUpdateOf : 3464 acceptKeyword( "for" ); 3465 acceptKeyword( "update" ); 3466 acceptKeyword( "of" ); 3467 break; 3468 } 3469 3470 if ( node.getColumnRefs( ) != null ) 3471 { 3472 visitObjectNameList( node.getColumnRefs( ) ); 3473 } 3474 if ( node.isNowait( ) ) 3475 acceptKeyword( "nowait" ); 3476 if ( node.isWait( ) ) 3477 { 3478 acceptKeyword( "wait" ); 3479 acceptIdentifier( node.getWaitValue( ) ); 3480 } 3481 3482 } 3483 3484 public void preVisit( TDeleteSqlStatement stmt ) 3485 { 3486 3487 if ( stmt.getCteList( ) != null ) 3488 { 3489 acceptKeyword( "with" ); 3490 visitCTEList( stmt.getCteList( ) ); 3491 } 3492 3493 acceptKeyword( "delete" ); 3494 3495 if ( stmt.getTopClause( ) != null ) 3496 { 3497 stmt.getTopClause( ).accept( this ); 3498 } 3499 3500 if ( stmt.isFromKeyword( ) ) 3501 acceptKeyword( "from" ); 3502 stmt.getTargetTable( ).accept( this ); 3503 3504 if ( stmt.joins.size( ) > 0 ) 3505 { 3506 acceptNewline( ); 3507 acceptKeyword( "from" ); 3508 visitJoinList( stmt.joins ); 3509 } 3510 3511 if ( stmt.getOutputClause( ) != null ) 3512 { 3513 stmt.getOutputClause( ).accept( this ); 3514 } 3515 3516 if ( stmt.getWhereClause( ) != null ) 3517 { 3518 acceptNewline( ); 3519 stmt.getWhereClause( ).accept( this ); 3520 } 3521 3522 if ( stmt.getReturningClause( ) != null ) 3523 { 3524 stmt.getReturningClause( ).accept( this ); 3525 } 3526 3527 } 3528 3529 public void preVisit( TUpdateSqlStatement stmt ) 3530 { 3531 3532 if ( stmt.getCteList( ) != null ) 3533 { 3534 acceptKeyword( "with" ); 3535 visitCTEList( stmt.getCteList( ) ); 3536 } 3537 3538 acceptKeyword( "update" ); 3539 3540 if ( stmt.getTopClause( ) != null ) 3541 { 3542 stmt.getTopClause( ).accept( this ); 3543 } 3544 3545 if ( getDBVerdor(stmt) == EDbVendor.dbvmysql ) 3546 { 3547 if ( stmt.joins.size( ) > 0 ) 3548 { 3549 visitJoinList( stmt.joins ); 3550 } 3551 else 3552 { 3553 stmt.getTargetTable( ).accept( this ); 3554 } 3555 } 3556 else 3557 { 3558 stmt.getTargetTable( ).accept( this ); 3559 } 3560 3561 acceptNewline( ); 3562 acceptKeyword( "set" ); 3563 visitResultColumnList( stmt.getResultColumnList( ) ); 3564 3565 if ( getDBVerdor( stmt ) != EDbVendor.dbvmysql ) 3566 { 3567 if ( stmt.joins.size( ) > 0 ) 3568 { 3569 acceptNewline( ); 3570 acceptKeyword( "from" ); 3571 visitJoinList( stmt.joins ); 3572 } 3573 } 3574 3575 if ( stmt.getWhereClause( ) != null ) 3576 { 3577 acceptNewline( ); 3578 stmt.getWhereClause( ).accept( this ); 3579 } 3580 3581 if ( stmt.getOrderByClause( ) != null ) 3582 { 3583 stmt.getOrderByClause( ).accept( this ); 3584 } 3585 3586 if ( stmt.getLimitClause( ) != null ) 3587 { 3588 stmt.getLimitClause( ).accept( this ); 3589 } 3590 3591 if ( stmt.getOutputClause( ) != null ) 3592 { 3593 stmt.getOutputClause( ).accept( this ); 3594 } 3595 3596 if ( stmt.getReturningClause( ) != null ) 3597 { 3598 stmt.getReturningClause( ).accept( this ); 3599 } 3600 3601 } 3602 3603 private EDbVendor getDBVerdor( TCustomSqlStatement stmt ) 3604 { 3605 if ( stmt.dbvendor != null ) 3606 { 3607 return stmt.dbvendor; 3608 } 3609 else if ( stmt.getGsqlparser( ) != null ) 3610 { 3611 return stmt.getGsqlparser( ).getDbVendor( ); 3612 } 3613 return null; 3614 } 3615 3616 public void preVisit( TInsertSqlStatement stmt ) 3617 { 3618 3619 boolean insertAll = false; 3620 3621 if ( stmt.getCteList( ) != null ) 3622 { 3623 acceptKeyword( "with" ); 3624 visitCTEList( stmt.getCteList( ) ); 3625 } 3626 3627 acceptKeyword( "insert" ); 3628 if ( stmt.isInsertAll( ) ) 3629 acceptKeyword( "all" ); 3630 if ( stmt.isInsertFirst( ) ) 3631 acceptKeyword( "first" ); 3632 3633 if ( stmt.getInsertConditions( ) != null 3634 && stmt.getInsertConditions( ).size( ) > 0 ) 3635 { 3636 for ( int i = 0; i < stmt.getInsertConditions( ).size( ); i++ ) 3637 { 3638 TInsertCondition condition = stmt.getInsertConditions( ) 3639 .getElement( i ); 3640 preVisit( condition ); 3641 } 3642 3643 insertAll = true; 3644 } 3645 3646 if ( stmt.getElseIntoValues( ) != null ) 3647 { 3648 acceptKeyword( "else" ); 3649 for ( int i = 0; i < stmt.getElseIntoValues( ).size( ); i++ ) 3650 { 3651 stmt.getElseIntoValues( ).getElement( i ).accept( this ); 3652 } 3653 insertAll = true; 3654 } 3655 3656 if ( insertAll ) 3657 { 3658 if ( stmt.getSubQuery( ) != null ) 3659 { 3660 acceptNewline( ); 3661 stmt.getSubQuery( ).accept( this ); 3662 } 3663 } 3664 3665 if ( !insertAll ) 3666 { 3667 acceptKeyword( "into" ); 3668 3669 if ( stmt.getTargetTable( ) != null ) 3670 { 3671 stmt.getTargetTable( ).accept( this ); 3672 } 3673 else 3674 { 3675 // hive insert may have no target table 3676 } 3677 3678 if ( stmt.getColumnList( ) != null ) 3679 { 3680 acceptSymbol( "(" ); 3681 visitObjectNameList( stmt.getColumnList( ) ); 3682 acceptSymbol( ")" ); 3683 } 3684 3685 switch ( stmt.getInsertSource( ) ) 3686 { 3687 case values : 3688 acceptNewline( ); 3689 acceptKeyword( "values" ); 3690 TMultiTargetList multiTargetList = stmt.getValues( ); 3691 visitMultiTargetList( multiTargetList ); 3692 break; 3693 case subquery : 3694 acceptNewline( ); 3695 stmt.getSubQuery( ).accept( this ); 3696 break; 3697 case values_empty : 3698 break; 3699 case values_function : 3700 acceptNewline( ); 3701 acceptKeyword( "values" ); 3702 stmt.getFunctionCall( ).accept( this ); 3703 break; 3704 case values_oracle_record : 3705 acceptNewline( ); 3706 acceptKeyword( "values" ); 3707 stmt.getRecordName( ).accept( this ); 3708 break; 3709 case set_column_value : 3710 // stmt.getSetColumnValues().accept(this); 3711 break; 3712 default : 3713 break; 3714 } 3715 } 3716 3717 if ( stmt.getOnDuplicateKeyUpdate( ) != null ) 3718 { 3719 acceptKeyword( "on" ); 3720 acceptKeyword( "duplicate" ); 3721 acceptKeyword( "key" ); 3722 acceptKeyword( "update" ); 3723 visitResultColumnList( stmt.getOnDuplicateKeyUpdate( ) ); 3724 } 3725 3726 if ( stmt.getReturningClause( ) != null ) 3727 { 3728 acceptNewline( ); 3729 stmt.getReturningClause( ).accept( this ); 3730 } 3731 3732 } 3733 3734 public void preVisit( TInsertCondition node ) 3735 { 3736 if ( node.getCondition( ) != null ) 3737 { 3738 acceptNewline( ); 3739 acceptKeyword( "when" ); 3740 preVisit( node.getCondition( ) ); 3741 acceptKeyword( "then" ); 3742 } 3743 3744 if ( node.getInsertIntoValues( ) != null 3745 && node.getInsertIntoValues( ).size( ) > 0 ) 3746 { 3747 acceptNewline( ); 3748 for ( int i = 0; i < node.getInsertIntoValues( ).size( ); i++ ) 3749 { 3750 TInsertIntoValue value = node.getInsertIntoValues( ) 3751 .getElement( i ); 3752 preVisit( value ); 3753 } 3754 } 3755 } 3756 3757 public void preVisit( TInsertIntoValue node ) 3758 { 3759 if ( node.getTable( ) != null ) 3760 { 3761 acceptKeyword( "into" ); 3762 preVisit( node.getTable( ) ); 3763 if ( node.getColumnList( ) != null 3764 && node.getColumnList( ).size( ) > 0 ) 3765 { 3766 acceptSymbol( "(" ); 3767 visitObjectNameList( node.getColumnList( ) ); 3768 acceptSymbol( ")" ); 3769 } 3770 if ( node.getTargetList( ) != null 3771 && node.getTargetList( ).size( ) > 0 ) 3772 { 3773 acceptKeyword( "values" ); 3774 TMultiTargetList multiTargetList = node.getTargetList( ); 3775 visitMultiTargetList( multiTargetList ); 3776 } 3777 } 3778 } 3779 3780 private void visitMultiTargetList( TMultiTargetList multiTargetList ) 3781 { 3782 for ( int i = 0; i < multiTargetList.size( ); i++ ) 3783 { 3784 TMultiTarget multiTarget = multiTargetList.getMultiTarget( i ); 3785 acceptSymbol( "(" ); 3786 3787 for ( int j = 0; j < multiTarget.getColumnList( ).size( ); j++ ) 3788 { 3789 if ( multiTarget.getColumnList( ) 3790 .getResultColumn( j ) 3791 .isPlaceHolder( ) ) 3792 continue; // teradata allow empty value 3793 multiTarget.getColumnList( ) 3794 .getResultColumn( j ) 3795 .getExpr( ) 3796 .accept( this ); 3797 if ( j != multiTarget.getColumnList( ).size( ) - 1 ) 3798 acceptSymbol( "," ); 3799 } 3800 3801 acceptSymbol( ")" ); 3802 3803 if ( i != multiTargetList.size( ) - 1 ) 3804 acceptSymbol( "," ); 3805 3806 } 3807 } 3808 3809 public void preVisit( TMergeSqlStatement stmt ) 3810 { 3811 3812 if ( stmt.getCteList( ) != null ) 3813 { 3814 acceptKeyword( "with" ); 3815 visitCTEList( stmt.getCteList( ) ); 3816 } 3817 3818 acceptKeyword( "merge" ); 3819 acceptKeyword( "into" ); 3820 stmt.getTargetTable( ).accept( this ); 3821 acceptKeyword( "using" ); 3822 stmt.getUsingTable( ).accept( this ); 3823 acceptKeyword( "on" ); 3824 acceptSymbol( "(" ); 3825 stmt.getCondition( ).accept( this ); 3826 acceptSymbol( ")" ); 3827 acceptNewline( ); 3828 3829 if ( stmt.getWhenClauses( ) != null ) 3830 { 3831 for ( int i = 0; i < stmt.getWhenClauses( ).size( ); i++ ) 3832 { 3833 TMergeWhenClause whenClause = stmt.getWhenClauses( ) 3834 .getElement( i ); 3835 whenClause.accept( this ); 3836 } 3837 } 3838 } 3839 3840 public void preVisit( TMergeWhenClause node ) 3841 { 3842 switch ( node.getType( ) ) 3843 { 3844 case TMergeWhenClause.matched : 3845 acceptKeyword( "when" ); 3846 acceptKeyword( "matched" ); 3847 acceptKeyword( "then" ); 3848 break; 3849 case TMergeWhenClause.not_matched : 3850 acceptKeyword( "when" ); 3851 acceptKeyword( "not" ); 3852 acceptKeyword( "matched" ); 3853 acceptKeyword( "then" ); 3854 break; 3855 case TMergeWhenClause.matched_with_condition : 3856 acceptKeyword( "when" ); 3857 acceptKeyword( "matched" ); 3858 acceptKeyword( "and" ); 3859 node.getCondition( ).accept( this ); 3860 acceptKeyword( "then" ); 3861 break; 3862 case TMergeWhenClause.not_matched_with_condition : 3863 acceptKeyword( "when" ); 3864 acceptKeyword( "not" ); 3865 acceptKeyword( "matched" ); 3866 acceptKeyword( "and" ); 3867 node.getCondition( ).accept( this ); 3868 acceptKeyword( "then" ); 3869 break; 3870 case TMergeWhenClause.not_matched_by_target : 3871 acceptKeyword( "when" ); 3872 acceptKeyword( "not" ); 3873 acceptKeyword( "matched" ); 3874 acceptKeyword( "by" ); 3875 acceptKeyword( "target" ); 3876 acceptKeyword( "then" ); 3877 break; 3878 case TMergeWhenClause.not_matched_by_target_with_condition : 3879 acceptKeyword( "when" ); 3880 acceptKeyword( "not" ); 3881 acceptKeyword( "matched" ); 3882 acceptKeyword( "by" ); 3883 acceptKeyword( "target" ); 3884 acceptKeyword( "and" ); 3885 node.getCondition( ).accept( this ); 3886 acceptKeyword( "then" ); 3887 break; 3888 case TMergeWhenClause.not_matched_by_source : 3889 acceptKeyword( "when" ); 3890 acceptKeyword( "not" ); 3891 acceptKeyword( "matched" ); 3892 acceptKeyword( "by" ); 3893 acceptKeyword( "source" ); 3894 acceptKeyword( "then" ); 3895 break; 3896 case TMergeWhenClause.not_matched_by_source_with_condition : 3897 acceptKeyword( "when" ); 3898 acceptKeyword( "not" ); 3899 acceptKeyword( "matched" ); 3900 acceptKeyword( "by" ); 3901 acceptKeyword( "source" ); 3902 acceptKeyword( "and" ); 3903 node.getCondition( ).accept( this ); 3904 acceptKeyword( "then" ); 3905 break; 3906 default : 3907 break; 3908 } 3909 3910 if ( node.getUpdateClause( ) != null ) 3911 { 3912 node.getUpdateClause( ).accept( this ); 3913 } 3914 3915 if ( node.getInsertClause( ) != null ) 3916 { 3917 node.getInsertClause( ).accept( this ); 3918 } 3919 3920 if ( node.getDeleteClause( ) != null ) 3921 { 3922 node.getDeleteClause( ).accept( this ); 3923 } 3924 3925 } 3926 3927 public void preVisit( TMergeUpdateClause node ) 3928 { 3929 3930 acceptKeyword( "update" ); 3931 acceptKeyword( "set" ); 3932 if ( node.getUpdateColumnList( ) != null ) 3933 { 3934 visitResultColumnList( node.getUpdateColumnList( ) ); 3935 } 3936 3937 if ( node.getUpdateWhereClause( ) != null ) 3938 { 3939 acceptNewline( ); 3940 acceptKeyword( "where" ); 3941 node.getUpdateWhereClause( ).accept( this ); 3942 } 3943 3944 if ( node.getDeleteWhereClause( ) != null ) 3945 { 3946 acceptNewline( ); 3947 acceptKeyword( "delete" ); 3948 node.getDeleteWhereClause( ).accept( this ); 3949 } 3950 3951 } 3952 3953 public void preVisit( TMergeInsertClause node ) 3954 { 3955 3956 acceptKeyword( "insert" ); 3957 if ( node.getColumnList( ) != null ) 3958 { 3959 acceptSymbol( "(" ); 3960 visitObjectNameList( node.getColumnList( ) ); 3961 acceptSymbol( ")" ); 3962 } 3963 3964 acceptKeyword( "values" ); 3965 if ( node.getValuelist( ) != null ) 3966 { 3967 acceptSymbol( "(" ); 3968 visitResultColumnList( node.getValuelist( ) ); 3969 acceptSymbol( ")" ); 3970 } 3971 3972 if ( node.getInsertWhereClause( ) != null ) 3973 { 3974 acceptNewline( ); 3975 acceptKeyword( "where" ); 3976 node.getInsertWhereClause( ).accept( this ); 3977 } 3978 3979 } 3980 3981 public void preVisit( TMergeDeleteClause node ) 3982 { 3983 3984 } 3985 3986 public void preVisit( TCreateTableSqlStatement stmt ) 3987 { 3988 acceptKeyword( "create" ); 3989 3990 if ( !stmt.getTableKinds( ).isEmpty( ) ) 3991 { 3992 if ( stmt.getTableKinds( ).contains( ETableKind.etkBase ) ) 3993 { 3994 acceptKeyword( "base" ); 3995 } 3996 if ( stmt.getTableKinds( ).contains( ETableKind.etkTemporary ) ) 3997 { 3998 acceptKeyword( "temporary" ); 3999 } 4000 if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemporary ) ) 4001 { 4002 acceptKeyword( "global" ); 4003 acceptKeyword( "temporary" ); 4004 } 4005 if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemporary ) ) 4006 { 4007 acceptKeyword( "local" ); 4008 acceptKeyword( "temporary" ); 4009 } 4010 if ( stmt.getTableKinds( ).contains( ETableKind.etkTemp ) ) 4011 { 4012 acceptKeyword( "temp" ); 4013 } 4014 if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemp ) ) 4015 { 4016 acceptKeyword( "global" ); 4017 acceptKeyword( "temp" ); 4018 } 4019 if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemp ) ) 4020 { 4021 acceptKeyword( "local" ); 4022 acceptKeyword( "temp" ); 4023 } 4024 if ( stmt.getTableKinds( ).contains( ETableKind.etkVolatile ) ) 4025 { 4026 acceptKeyword( "volatile" ); 4027 } 4028 if ( stmt.getTableKinds( ).contains( ETableKind.etkSet ) ) 4029 { 4030 acceptKeyword( "set" ); 4031 } 4032 if ( stmt.getTableKinds( ).contains( ETableKind.etkMultiset ) ) 4033 { 4034 acceptKeyword( "multiset" ); 4035 } 4036 if ( stmt.getTableKinds( ).contains( ETableKind.etkExternal ) ) 4037 { 4038 acceptKeyword( "external" ); 4039 } 4040 } 4041 acceptKeyword( "table" ); 4042 stmt.getTargetTable( ).accept( this ); 4043 4044 if ( stmt.getSubQuery( ) != null ) 4045 { 4046 acceptKeyword( "as" ); 4047 acceptNewline( ); 4048 stmt.getSubQuery( ).accept( this ); 4049 4050 } 4051 else 4052 { 4053 acceptSymbol( "(" ); 4054 acceptNewline( ); 4055 for ( int i = 0; i < stmt.getColumnList( ).size( ); i++ ) 4056 { 4057 stmt.getColumnList( ).getColumn( i ).accept( this ); 4058 if ( i != stmt.getColumnList( ).size( ) - 1 ){ 4059 acceptSymbol( "," ); 4060 acceptNewline(); 4061 } 4062 4063 } 4064 4065 if ( ( stmt.getTableConstraints( ) != null ) 4066 && ( stmt.getTableConstraints( ).size( ) > 0 ) ) 4067 { 4068 acceptNewline( ); 4069 acceptSymbol( "," ); 4070 for ( int i = 0; i < stmt.getTableConstraints( ).size( ); i++ ) 4071 { 4072 stmt.getTableConstraints( ) 4073 .getConstraint( i ) 4074 .accept( this ); 4075 if ( i != stmt.getTableConstraints( ).size( ) - 1 ) 4076 acceptSymbol( "," ); 4077 } 4078 } 4079 4080 acceptNewline( ); 4081 acceptSymbol( ")" ); 4082 } 4083 4084 if (stmt.getOnFilegroup() != null){ 4085 4086 visitNodeByToken(stmt.getOnFilegroup()); 4087 } 4088 4089 if ( stmt.getMySQLTableOptionList( ) != null 4090 && stmt.getMySQLTableOptionList( ).size( ) > 0 ) 4091 { 4092 preVisit( stmt.getMySQLTableOptionList( ) ); 4093 } 4094 4095 } 4096 4097 public void preVisit( TPTNodeList options ) 4098 { 4099 for ( int i = 0; i < options.size( ); i++ ) 4100 { 4101 Object element = options.getElement( i ); 4102 if ( element instanceof TMySQLCreateTableOption ) 4103 { 4104 preVisit( (TMySQLCreateTableOption) options.getElement( i ) ); 4105 } 4106 } 4107 } 4108 4109 public void preVisit( TMySQLCreateTableOption option ) 4110 { 4111 acceptKeyword( option.getOptionName( ) ); 4112 acceptSymbol( "=" ); 4113 acceptKeyword( option.getOptionValue( ) ); 4114 } 4115 4116 public void preVisit( TColumnDefinition node ) 4117 { 4118 4119 node.getColumnName( ).accept( this ); 4120 4121 if ( node.getDatatype( ) != null ) 4122 { 4123 node.getDatatype( ).accept( this ); 4124 } 4125 4126 if ( node.getDefaultExpression( ) != null ) 4127 { 4128 acceptKeyword( "default" ); 4129 node.getDefaultExpression( ).accept( this ); 4130 } 4131 4132 if ( node.isNull( ) ) 4133 acceptKeyword( "null" ); 4134 4135 if ( ( node.getConstraints( ) != null ) 4136 && ( node.getConstraints( ).size( ) > 0 ) ) 4137 { 4138 for ( int i = 0; i < node.getConstraints( ).size( ); i++ ) 4139 { 4140 node.getConstraints( ).getConstraint( i ).accept( this ); 4141 } 4142 } 4143 4144 if ( node.isIdentity( ) ) 4145 { 4146 acceptKeyword( "identity" ); 4147 if ( node.getSeed( ) != null ) 4148 { 4149 acceptSymbol( "(" ); 4150 node.getSeed( ).accept( this ); 4151 acceptSymbol( "," ); 4152 node.getIncrement( ).accept( this ); 4153 acceptSymbol( ")" ); 4154 } 4155 } 4156 4157 } 4158 4159 public void preVisit( TColumnWithSortOrder node ) 4160 { 4161 node.getColumnName( ).accept( this ); 4162 if ( node.getLength( ) != null ) 4163 { 4164 acceptSymbol( "(" ); 4165 node.getLength( ).accept( this ); 4166 acceptSymbol( ")" ); 4167 } 4168 if ( node.getSortType( ) == ESortType.desc ) 4169 { 4170 acceptKeyword( "desc" ); 4171 } 4172 if ( node.getSortType( ) == ESortType.asc ) 4173 { 4174 acceptKeyword( "asc" ); 4175 } 4176 } 4177 4178 public void preVisit( TConstraint node ) 4179 { 4180 4181 if ( node.getConstraintName( ) != null ) 4182 { 4183 acceptKeyword( "constraint" ); 4184 node.getConstraintName( ).accept( this ); 4185 } 4186 4187 switch ( node.getConstraint_type( ) ) 4188 { 4189 case notnull : 4190 acceptKeyword( "not" ); 4191 acceptKeyword( "null" ); 4192 break; 4193 case table_index: 4194 //acceptKeyword("index"); 4195 visitNodeByToken(node); 4196 break; 4197 case unique : 4198 acceptKeyword( "unique" ); 4199 if ( node.isClustered( ) ) 4200 acceptKeyword( "clustered" ); 4201 if ( node.isNonClustered( ) ) 4202 acceptKeyword( "nonclustered" ); 4203 if ( node.getColumnList( ) != null ) 4204 { 4205 acceptSymbol( "(" ); 4206 // visitObjectNameList( node.getColumnList( ) ); 4207 for ( int i = 0; i < node.getColumnList( ).size( ); i++ ) 4208 { 4209 node.getColumnList( ).getElement( i ).accept( this ); 4210 if ( i != node.getColumnList( ).size( ) - 1 ) 4211 { 4212 acceptSymbol( "," ); 4213 } 4214 } 4215 acceptSymbol( ")" ); 4216 } 4217 break; 4218 case check : 4219 acceptKeyword( "check" ); 4220 if ( node.getCheckCondition( ) != null ) 4221 { 4222 acceptSymbol( "(" ); 4223 node.getCheckCondition( ).accept( this ); 4224 acceptSymbol( ")" ); 4225 } 4226 else 4227 { 4228 // db2 functional dependency 4229 } 4230 4231 break; 4232 case primary_key : 4233 acceptKeyword( "primary" ); 4234 acceptKeyword( "key" ); 4235 if ( node.isClustered( ) ) 4236 acceptKeyword( "clustered" ); 4237 if ( node.isNonClustered( ) ) 4238 acceptKeyword( "nonclustered" ); 4239 4240 if ( node.getColumnList( ) != null ) 4241 { 4242 acceptSymbol( "(" ); 4243 // visitObjectNameList( node.getColumnList( ) ); 4244 for ( int i = 0; i < node.getColumnList( ).size( ); i++ ) 4245 { 4246 node.getColumnList( ).getElement( i ).accept( this ); 4247 if ( i != node.getColumnList( ).size( ) - 1 ) 4248 { 4249 acceptSymbol( "," ); 4250 } 4251 } 4252 acceptSymbol( ")" ); 4253 } 4254 break; 4255 case foreign_key : 4256 acceptKeyword( "foreign" ); 4257 acceptKeyword( "key" ); 4258 if ( node.getColumnList( ) != null ) 4259 { 4260 acceptSymbol( "(" ); 4261 // visitObjectNameList( node.getColumnList( ) ); 4262 for ( int i = 0; i < node.getColumnList( ).size( ); i++ ) 4263 { 4264 node.getColumnList( ).getElement( i ).accept( this ); 4265 if ( i != node.getColumnList( ).size( ) - 1 ) 4266 { 4267 acceptSymbol( "," ); 4268 } 4269 } 4270 acceptSymbol( ")" ); 4271 } 4272 4273 if ( node.getReferencedObject( ) != null ) 4274 { 4275 acceptKeyword( "references" ); 4276 node.getReferencedObject( ).accept( this ); 4277 } 4278 4279 if ( node.getReferencedColumnList( ) != null ) 4280 { 4281 acceptSymbol( "(" ); 4282 visitObjectNameList( node.getReferencedColumnList( ) ); 4283 acceptSymbol( ")" ); 4284 } 4285 4286 if ( node.getKeyActions( ) != null 4287 && node.getKeyActions( ).size( ) > 0 ) 4288 { 4289 for ( int i = 0; i < node.getKeyActions( ).size( ); i++ ) 4290 { 4291 TKeyAction keyAction = node.getKeyActions( ) 4292 .getElement( i ); 4293 preVisit( keyAction ); 4294 } 4295 } 4296 4297 break; 4298 case reference : 4299 acceptKeyword( "references" ); 4300 if ( node.getReferencedObject( ) != null ) 4301 { 4302 node.getReferencedObject( ).accept( this ); 4303 } 4304 4305 if ( node.getReferencedColumnList( ) != null ) 4306 { 4307 acceptSymbol( "(" ); 4308 visitObjectNameList( node.getReferencedColumnList( ) ); 4309 acceptSymbol( ")" ); 4310 } 4311 4312 if ( node.getKeyActions( ) != null 4313 && node.getKeyActions( ).size( ) > 0 ) 4314 { 4315 for ( int i = 0; i < node.getKeyActions( ).size( ); i++ ) 4316 { 4317 TKeyAction keyAction = node.getKeyActions( ) 4318 .getElement( i ); 4319 preVisit( keyAction ); 4320 } 4321 } 4322 4323 break; 4324 case default_value : 4325 acceptKeyword( "default" ); 4326 node.getDefaultExpression( ).accept( this ); 4327 //add by grq 2023.04.29 issue=I6ZJ3V 4328 if (node.getForObjectName()!= null){ 4329 acceptKeyword( "for" ); 4330 node.getForObjectName().accept(this); 4331 } 4332 //end by grq 4333 break; 4334 default : 4335 break; 4336 } 4337 4338 if (node.getWithIndexoption() != null){ 4339 acceptNewline(); 4340 visitNodeByToken(node.getWithIndexoption()); 4341 } 4342 if (node.getOnFilegroup() != null){ 4343 acceptNewline(); 4344 visitNodeByToken(node.getOnFilegroup()); 4345 } 4346 4347 } 4348 4349 public void preVisit( TKeyAction node ) 4350 { 4351 if ( node.getActionType( ) == EKeyActionType.delete ) 4352 { 4353 acceptKeyword( "on" ); 4354 acceptKeyword( "delete" ); 4355 } 4356 4357 if ( node.getActionType( ) == EKeyActionType.update ) 4358 { 4359 acceptKeyword( "on" ); 4360 acceptKeyword( "update" ); 4361 } 4362 4363 if ( node.getKeyReference( ) != null ) 4364 { 4365 preVisit( node.getKeyReference( ) ); 4366 } 4367 } 4368 4369 public void preVisit( TKeyReference node ) 4370 { 4371 if ( node.getReferenceType( ) == EKeyReferenceType.set_null ) 4372 { 4373 acceptKeyword( "set" ); 4374 acceptKeyword( "null" ); 4375 } 4376 4377 if ( node.getReferenceType( ) == EKeyReferenceType.set_default ) 4378 { 4379 acceptKeyword( "set" ); 4380 acceptKeyword( "default" ); 4381 } 4382 4383 if ( node.getReferenceType( ) == EKeyReferenceType.cascade ) 4384 { 4385 acceptKeyword( "cascade" ); 4386 } 4387 4388 if ( node.getReferenceType( ) == EKeyReferenceType.restrict ) 4389 { 4390 acceptKeyword( "restrict" ); 4391 } 4392 4393 if ( node.getReferenceType( ) == EKeyReferenceType.no_action ) 4394 { 4395 acceptKeyword( "no" ); 4396 acceptKeyword( "action" ); 4397 } 4398 } 4399 4400 public void preVisit( TTypeName node ) 4401 { 4402 acceptKeyword( node.getDataTypeName( ) ); 4403 4404 switch ( node.getDataType( ) ) 4405 { 4406 case bigint_t : 4407 case bit_t : 4408 case money_t : 4409 case smallmoney_t : 4410 case smallint_t : 4411 case tinyint_t : 4412 case real_t : 4413 case smalldatetime_t : 4414 case datetime_t : 4415 case datetime2_t : 4416 case text_t : 4417 case ntext_t : 4418 case image_t : 4419 case rowversion_t : 4420 case uniqueidentifier_t : 4421 case sql_variant_t : 4422 case binary_float_t : 4423 case binary_double_t : 4424 case integer_t : 4425 case int_t : 4426 case double_t : 4427 case date_t : 4428 if ( node.getPrecision( ) != null ) 4429 { 4430 acceptSymbol( "(" ); 4431 node.getPrecision( ).accept( this ); 4432 if ( node.getScale( ) != null ) 4433 { 4434 acceptSymbol( "," ); 4435 node.getScale( ).accept( this ); 4436 } 4437 acceptSymbol( ")" ); 4438 } 4439 break; 4440 4441 case binary_t : 4442 case varbinary_t : 4443 case long_t : 4444 case raw_t : 4445 case long_raw_t : 4446 case blob_t : 4447 case clob_t : 4448 case nclob_t : 4449 case bfile_t : 4450 case urowid_t : 4451 if ( node.getLength( ) != null ) 4452 { 4453 acceptSymbol( "(" ); 4454 node.getLength( ).accept( this ); 4455 acceptSymbol( ")" ); 4456 } 4457 break; 4458 case timestamp_t : 4459 if ( node.getScale( ) != null ) 4460 { 4461 acceptSymbol( "(" ); 4462 node.getScale( ).accept( this ); 4463 acceptSymbol( ")" ); 4464 } 4465 break; 4466 case decimal_t : 4467 case dec_t : 4468 case numeric_t : 4469 case number_t : 4470 case float_t : 4471 4472 if ( node.getPrecision( ) != null ) 4473 { 4474 acceptSymbol( "(" ); 4475 node.getPrecision( ).accept( this ); 4476 if ( node.getScale( ) != null ) 4477 { 4478 acceptSymbol( "," ); 4479 node.getScale( ).accept( this ); 4480 } 4481 acceptSymbol( ")" ); 4482 } 4483 break; 4484 4485 case char_t : 4486 case character_t : 4487 case varchar_t : 4488 case nchar_t : 4489 case nvarchar_t : 4490 case ncharacter_t : 4491 case nvarchar2_t : 4492 case varchar2_t : 4493 if ( node.isVarying( ) ) 4494 acceptKeyword( "varying" ); 4495 if ( node.getLength( ) != null ) 4496 { 4497 acceptSymbol( "(" ); 4498 node.getLength( ).accept( this ); 4499 if ( node.isByteUnit( ) ) 4500 acceptKeyword( "byte" ); 4501 if ( node.isCharUnit( ) ) 4502 acceptKeyword( "char" ); 4503 acceptSymbol( ")" ); 4504 } 4505 if ( node.getCharsetName( ) != null ) 4506 { 4507 if ( node.getGsqlparser( ) != null 4508 && node.getGsqlparser( ).getDbVendor( ) == EDbVendor.dbvmysql ) 4509 { 4510 acceptKeyword( "CHARACTER" ); 4511 acceptKeyword( "SET" ); 4512 acceptSpace( 1 ); 4513 acceptIdentifier( node.getCharsetName( ) ); 4514 } 4515 else 4516 { 4517 acceptSpace( 1 ); 4518 acceptIdentifier( node.getCharsetName( ) ); 4519 } 4520 } 4521 break; 4522 case datetimeoffset_t : 4523 //case datetime2_t : 4524 case time_t : 4525 if ( node.getFractionalSecondsPrecision( ) != null ) 4526 { 4527 acceptSymbol( "(" ); 4528 node.getFractionalSecondsPrecision( ).accept( this ); 4529 acceptSymbol( ")" ); 4530 } 4531 break; 4532 case timestamp_with_time_zone_t : 4533 4534 if ( node.getFractionalSecondsPrecision( ) != null ) 4535 { 4536 acceptSymbol( "(" ); 4537 node.getFractionalSecondsPrecision( ).accept( this ); 4538 acceptSymbol( ")" ); 4539 } 4540 acceptKeyword( "with" ); 4541 acceptKeyword( "time" ); 4542 acceptKeyword( "zone" ); 4543 break; 4544 case timestamp_with_local_time_zone_t : 4545 if ( node.getFractionalSecondsPrecision( ) != null ) 4546 { 4547 acceptSymbol( "(" ); 4548 node.getFractionalSecondsPrecision( ).accept( this ); 4549 acceptSymbol( ")" ); 4550 } 4551 acceptKeyword( "with" ); 4552 acceptKeyword( "local" ); 4553 acceptKeyword( "time" ); 4554 acceptKeyword( "zone" ); 4555 break; 4556 case interval_year_to_month_t : 4557 if ( node.getPrecision( ) != null ) 4558 { 4559 acceptSymbol( "(" ); 4560 node.getPrecision( ).accept( this ); 4561 acceptSymbol( ")" ); 4562 } 4563 acceptKeyword( "to" ); 4564 acceptKeyword( "month" ); 4565 break; 4566 case interval_day_to_second_t : 4567 if ( node.getPrecision( ) != null ) 4568 { 4569 acceptSymbol( "(" ); 4570 node.getPrecision( ).accept( this ); 4571 acceptSymbol( ")" ); 4572 } 4573 acceptKeyword( "to" ); 4574 acceptKeyword( "second" ); 4575 if ( node.getSecondsPrecision( ) != null ) 4576 { 4577 acceptSymbol( "(" ); 4578 node.getSecondsPrecision( ).accept( this ); 4579 acceptSymbol( ")" ); 4580 } 4581 break; 4582 case generic_t : 4583 // if ( node.getDataTypeObjectName( ) != null ) 4584 // { 4585 // acceptSpace( 1 ); 4586 // node.getDataTypeObjectName( ).accept( this ); 4587 // } 4588 // else if ( node.getDataTypeName( ) != null ) 4589 // { 4590 // acceptSpace( 1 ); 4591 // acceptIdentifier( node.getDataTypeName( ) ); 4592 // } 4593 break; 4594 default : 4595 break; 4596 } 4597 4598 if (node.getArrays() != null && node.getArrays().size() > 0) 4599 { 4600 for (int i = 0; i < node.getArrays().size(); i++) 4601 { 4602 TIndices array = node.getArrays().getElement(i); 4603 if (array.getAttributeName() != null) 4604 { 4605 array.getAttributeName().accept(this); 4606 } 4607 acceptSymbol("["); 4608 if (array.getLowerSubscript() != null) 4609 { 4610 array.getLowerSubscript().accept(this); 4611 } 4612 if (array.getUpperSubscript() != null) 4613 { 4614 if (array.getLowerSubscript() != null) 4615 { 4616 acceptSymbol(":"); 4617 } 4618 array.getUpperSubscript().accept(this); 4619 } 4620 acceptSymbol("]"); 4621 } 4622 } 4623 } 4624 4625 public void preVisit( TKeepDenseRankClause node ) 4626 { 4627 acceptKeyword( "keep" ); 4628 acceptSymbol( "(" ); 4629 acceptKeyword( "dense_rank" ); 4630 if ( node.isFirst( ) ) 4631 acceptKeyword( "first" ); 4632 if ( node.isLast( ) ) 4633 acceptKeyword( "last" ); 4634 node.getOrderBy( ).accept( this ); 4635 acceptSymbol( ")" ); 4636 } 4637 4638 public void preVisit( TRollupCube node ) 4639 { 4640 if ( node.getOperation( ) == TRollupCube.cube ) 4641 { 4642 acceptKeyword( "cube" ); 4643 } 4644 else if ( node.getOperation( ) == TRollupCube.rollup ) 4645 { 4646 acceptKeyword( "rollup" ); 4647 } 4648 acceptSymbol( "(" ); 4649 visitExprList( node.getItems( ) ); 4650 acceptSymbol( ")" ); 4651 } 4652 4653 public void preVisit( TGroupingSet node ) 4654 { 4655 acceptKeyword( "grouping" ); 4656 acceptKeyword( "sets" ); 4657 acceptSymbol( "(" ); 4658 for ( int i = 0; i < node.getItems( ).size( ); i++ ) 4659 { 4660 node.getItems( ).getGroupingSetItem( i ).accept( this ); 4661 if ( i != node.getItems( ).size( ) - 1 ) 4662 acceptSymbol( "," ); 4663 } 4664 acceptSymbol( ")" ); 4665 4666 } 4667 4668 public void preVisit( TGroupingSetItem node ) 4669 { 4670 if ( node.getRollupCubeClause( ) != null ) 4671 { 4672 node.getRollupCubeClause( ).accept( this ); 4673 } 4674 else if ( node.getGrouping_expression( ) != null ) 4675 { 4676 node.getGrouping_expression( ).accept( this ); 4677 } 4678 4679 } 4680 4681 public void preVisit( TReturningClause node ) 4682 { 4683 acceptKeyword( "returning" ); 4684 visitExprList( node.getColumnValueList( ) ); 4685 if ( node.isBulkCollect( ) ) 4686 { 4687 acceptKeyword( "bulk" ); 4688 acceptKeyword( "collect" ); 4689 } 4690 acceptKeyword( "into" ); 4691 visitExprList( node.getVariableList( ) ); 4692 } 4693 4694 public void preVisit( TDropIndexSqlStatement dropIndex ) 4695 { 4696 acceptKeyword( "drop" ); 4697 acceptKeyword( "index" ); 4698 4699 4700 if ( dropIndex.getDropIndexItemList( ) != null 4701 && dropIndex.getDropIndexItemList( ).size( ) > 0 ) 4702 { 4703 for ( int i = 0; i < dropIndex.getDropIndexItemList( ).size( ); i++ ) 4704 { 4705 TDropIndexItem item = dropIndex.getDropIndexItemList( ) 4706 .getDropIndexItem( i ); 4707 if ( item.getIndexName( ) != null ) 4708 { 4709 item.getIndexName( ).accept( this ); 4710 } 4711 if ( item.getObjectName( ) != null ) 4712 { 4713 acceptKeyword( "on" ); 4714 item.getObjectName( ).accept( this ); 4715 } 4716 } 4717 }else{ 4718 if ( dropIndex.getIndexName( ) != null ) 4719 { 4720 dropIndex.getIndexName( ).accept( this ); 4721 } 4722 } 4723 } 4724 4725 public void preVisit( TCreateIndexSqlStatement createIndex ) 4726 { 4727 acceptKeyword( "create" ); 4728 4729 if ( createIndex.isNonClustered( ) ) 4730 { 4731 acceptKeyword( "nonclustered" ); 4732 } 4733 4734 if ( createIndex.isClustered( ) ) 4735 { 4736 acceptKeyword( "clustered" ); 4737 } 4738 4739 if ( createIndex.getIndexType( ) == EIndexType.itUnique ) 4740 { 4741 acceptKeyword( "unique" ); 4742 } 4743 4744 acceptKeyword( "index" ); 4745 4746 if ( createIndex.getIndexName( ) != null ) 4747 { 4748 createIndex.getIndexName( ).accept( this ); 4749 } 4750 4751 if ( createIndex.getTableName( ) != null ) 4752 { 4753 acceptKeyword( "on" ); 4754 4755 createIndex.getTableName( ).accept( this ); 4756 4757 if ( createIndex.getColumnNameList( ) != null 4758 && createIndex.getColumnNameList( ).size( ) > 0 ) 4759 { 4760 acceptSpace( 1 ); 4761 acceptSymbol( "(" ); 4762 createIndex.getColumnNameList( ).accept( this ); 4763 acceptSymbol( ")" ); 4764 } 4765 } 4766 if ( createIndex.getFilegroupOrPartitionSchemeName( ) != null ) 4767 { 4768 acceptKeyword( "on" ); 4769 4770 createIndex.getFilegroupOrPartitionSchemeName( ).accept( this ); 4771 4772 if ( createIndex.getPartitionSchemeColumns( ) != null 4773 && createIndex.getPartitionSchemeColumns( ).size( ) > 0 ) 4774 { 4775 acceptSpace( 1 ); 4776 acceptSymbol( "(" ); 4777 createIndex.getPartitionSchemeColumns( ).accept( this ); 4778 acceptSymbol( ")" ); 4779 } 4780 } 4781 } 4782 4783 public void preVisit( TOrderByItemList orderByList ) 4784 { 4785 for ( int i = 0; i < orderByList.size( ); i++ ) 4786 { 4787 orderByList.getOrderByItem( i ).accept( this ); 4788 if ( i != orderByList.size( ) - 1 ) 4789 acceptSymbol( "," ); 4790 } 4791 } 4792 4793 public void preVisit( TUseDatabase useDataBase ) 4794 { 4795 acceptKeyword( "use" ); 4796 4797 if ( useDataBase.getDatabaseName( ) != null ) 4798 { 4799 useDataBase.getDatabaseName( ).accept( this ); 4800 } 4801 } 4802 4803 public void preVisit( TPlsqlCreateProcedure procedure ) 4804 { 4805 acceptKeyword( "create" ); 4806 acceptKeyword( "procedure" ); 4807 4808 if ( procedure.getProcedureName( ) != null ) 4809 { 4810 procedure.getProcedureName( ).accept( this ); 4811 } 4812 4813 if ( procedure.getParameterDeclarations( ) != null 4814 && procedure.getParameterDeclarations( ).size( ) > 0 ) 4815 { 4816 acceptSymbol( "(" ); 4817 procedure.getParameterDeclarations( ).accept( this ); 4818 acceptSymbol( ")" ); 4819 } 4820 4821 acceptNewline( ); 4822 4823 if ( procedure.getInvokerRightsClause( ) != null ) 4824 { 4825 procedure.getInvokerRightsClause( ).accept( this ); 4826 } 4827 4828 acceptKeyword( "as" ); 4829 4830 if ( procedure.getDeclareStatements( ) != null 4831 && procedure.getDeclareStatements( ).size( ) > 0 ) 4832 { 4833 acceptNewline( ); 4834 procedure.getDeclareStatements( ).accept( this ); 4835 if ( procedure.getDeclareStatements( ).size( ) == 1 ) 4836 { 4837 acceptSemicolon( ); 4838 } 4839 } 4840 4841 acceptNewline( ); 4842 acceptKeyword( "begin" ); 4843 4844 if ( procedure.getBodyStatements( ) != null 4845 && procedure.getBodyStatements( ).size( ) > 0 ) 4846 { 4847 acceptNewline( ); 4848 procedure.getBodyStatements( ).accept( this ); 4849 if ( procedure.getBodyStatements( ).size( ) == 1 ) 4850 { 4851 acceptSemicolon( ); 4852 } 4853 } 4854 4855 acceptNewline( ); 4856 acceptKeyword( "end" ); 4857 acceptSemicolon( ); 4858 } 4859 4860 public void preVisit( TInvokerRightsClause clause ) 4861 { 4862 acceptKeyword( "authid" ); 4863 if ( clause.getDefiner( ) != null ) 4864 { 4865 clause.getDefiner( ).accept( this ); 4866 } 4867 } 4868 4869 void visitPrecisionScale( TConstant precision, TConstant scale ) 4870 { 4871 if ( precision != null ) 4872 { 4873 acceptSymbol( "(" ); 4874 precision.accept( this ); 4875 if ( scale != null ) 4876 { 4877 acceptSymbol( "," ); 4878 scale.accept( this ); 4879 } 4880 acceptSymbol( ")" ); 4881 } 4882 } 4883 4884 void visitExprList( TExpressionList expressionList ) 4885 { 4886 for ( int i = 0; i < expressionList.size( ); i++ ) 4887 { 4888 expressionList.getExpression( i ).accept( this ); 4889 if ( i != expressionList.size( ) - 1 ) 4890 acceptSymbol( "," ); 4891 } 4892 } 4893 4894 void visitObjectNameList( TObjectNameList objectNameList ) 4895 { 4896 for ( int i = 0; i < objectNameList.size( ); i++ ) 4897 { 4898 objectNameList.getObjectName( i ).accept( this ); 4899 if ( i != objectNameList.size( ) - 1 ) 4900 acceptSymbol( "," ); 4901 } 4902 } 4903 4904 void visitCTEList( TCTEList cteList ) 4905 { 4906 for ( int i = 0; i < cteList.size( ); i++ ) 4907 { 4908 cteList.getCTE( i ).accept( this ); 4909 if ( i != cteList.size( ) - 1 ) 4910 { 4911 acceptSymbol( "," ); 4912 acceptNewline( ); 4913 } 4914 } 4915 } 4916 4917 void visitJoinList( TJoinList joinList ) 4918 { 4919 for ( int i = 0; i < joinList.size( ); i++ ) 4920 { 4921 acceptNewline( ); 4922 joinList.getJoin( i ).accept( this ); 4923 if ( i != joinList.size( ) - 1 ) 4924 acceptSymbol( "," ); 4925 } 4926 } 4927 4928 void visitResultColumnList( TResultColumnList resultColumnList ) 4929 { 4930 for ( int i = 0; i < resultColumnList.size( ); i++ ) 4931 { 4932 resultColumnList.getElement( i ).accept( this ); 4933 if ( i != resultColumnList.size( ) - 1 ) 4934 { 4935 acceptSymbol( "," ); 4936 } 4937 } 4938 } 4939 4940 void visitNodeByToken( TParseTreeNode node ) 4941 { 4942 if ( node.getStartToken( ) == null ) 4943 return; 4944 if ( node.getEndToken( ) == null ) 4945 return; 4946 if ( node.getStartToken( ).container == null ) 4947 return; 4948 acceptSpace( 1 ); 4949 4950 TSourceToken nextToken = node.getStartToken( ); 4951 while (nextToken != null && nextToken != node.getEndToken( )) 4952 { 4953 acceptToken( nextToken ); 4954 nextToken = nextToken.getNextTokenInChain( ); 4955 } 4956 if (nextToken != null) 4957 { 4958 acceptToken( nextToken ); 4959 } 4960 4961 4962// if ((node.getStartToken().container !=null) && (node.getStartToken( ).container.size() > node.getEndToken().posinlist)){ 4963// for ( int i = node.getStartToken( ).posinlist; i <= node.getEndToken( ).posinlist; i++ ) 4964// { 4965// acceptToken( node.getStartToken( ).container.get( i ) ); 4966// } 4967// }else{ 4968// TSourceToken nextToken = node.getStartToken( ); 4969// while (nextToken != null && nextToken != node.getEndToken( )) 4970// { 4971// acceptToken( nextToken ); 4972// nextToken = nextToken.getNextTokenInChain( ); 4973// } 4974// if (nextToken != null) 4975// { 4976// acceptToken( nextToken ); 4977// } 4978// } 4979 acceptSpace( 1 ); 4980 } 4981 4982}