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.currentDBVendor != EDbVendor.dbvmssql))
2398                                        acceptSymbol( "(" );
2399                                node.getColumnDefinitionList( ).accept( this );
2400                                if(( node.getColumnDefinitionList( ).size( ) > 1 )&&(TGSqlParser.currentDBVendor != 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                acceptKeyword( "limit" );
2647
2648                if ( node.getOffset( ) != null )
2649                {
2650                        node.getOffset( ).accept( this );
2651                        if (node.getRow_count( ) != null){
2652                                acceptSymbol( "," );
2653                                node.getRow_count( ).accept( this );
2654                        }
2655                }
2656                else
2657                {
2658                        node.getRow_count( ).accept( this );
2659                }
2660        }
2661
2662        public void preVisit( TJoin node )
2663        {
2664
2665                if ( node.getJoinItems( ).size( ) > 0 )
2666                {
2667                        if ( node.getTable( ) != null )
2668                        {
2669                                node.setKind( TBaseType.join_source_table );
2670                        }
2671                        else if ( node.getJoin( ) != null )
2672                        {
2673                                node.setKind( TBaseType.join_source_join );
2674                        }
2675                }
2676
2677                if ( node.isWithParen( ) )
2678                {
2679                        for ( int i = 0; i < node.getNestedParen( ); i++ )
2680                        {
2681                                acceptSymbol( "(" );
2682                        }
2683                }
2684                switch ( node.getKind( ) )
2685                {
2686                        case TBaseType.join_source_fake :
2687                                node.getTable( ).accept( this );
2688                                break;
2689                        case TBaseType.join_source_table :
2690                        case TBaseType.join_source_join :
2691
2692                                if ( node.getKind( ) == TBaseType.join_source_table )
2693                                {
2694                                        node.getTable( ).accept( this );
2695                                }
2696                                else if ( node.getKind( ) == TBaseType.join_source_join )
2697                                {
2698                                        // preVisit(node.getJoin());
2699                                        node.getJoin( ).accept( this );
2700                                }
2701
2702                                for ( int i = 0; i < node.getJoinItems( ).size( ); i++ )
2703                                {
2704                                        TJoinItem joinItem = node.getJoinItems( ).getJoinItem( i );
2705                                        acceptNewline( );
2706                                        joinItem.accept( this );
2707                                }
2708                                break;
2709                }
2710                if ( node.isWithParen( ) )
2711                {
2712                        for ( int i = 0; i < node.getNestedParen( ); i++ )
2713                        {
2714                                acceptSymbol( ")" );
2715                        }
2716                }
2717
2718                if ( node.getAliasClause( ) != null )
2719                {
2720                        acceptSpace( 1 );
2721                        node.getAliasClause( ).accept( this );
2722                }
2723        }
2724
2725        public void preVisit( TJoinItem joinItem )
2726        {
2727
2728                switch ( joinItem.getJoinType( ) )
2729                {
2730                        case inner :
2731                                acceptKeyword( "inner" );
2732                                acceptKeyword( "join" );
2733                                break;
2734                        case join :
2735                                acceptKeyword( "join" );
2736                                break;
2737                        case left :
2738                                acceptKeyword( "left" );
2739                                acceptKeyword( "join" );
2740                                break;
2741                        case leftouter :
2742                                acceptKeyword( "left" );
2743                                acceptKeyword( "outer" );
2744                                acceptKeyword( "join" );
2745                                break;
2746                        case right :
2747                                acceptKeyword( "right" );
2748                                acceptKeyword( "join" );
2749                                break;
2750                        case rightouter :
2751                                acceptKeyword( "right" );
2752                                acceptKeyword( "outer" );
2753                                acceptKeyword( "join" );
2754                                break;
2755                        case full :
2756                                acceptKeyword( "full" );
2757                                acceptKeyword( "join" );
2758                                break;
2759                        case fullouter :
2760                                acceptKeyword( "full" );
2761                                acceptKeyword( "outer" );
2762                                acceptKeyword( "join" );
2763                                break;
2764                        case cross :
2765                                acceptKeyword( "cross" );
2766                                acceptKeyword( "join" );
2767                                break;
2768                        case natural :
2769                                acceptKeyword( "natural" );
2770                                acceptKeyword( "join" );
2771                                break;
2772                        case natural_inner :
2773                                acceptKeyword( "natural" );
2774                                acceptKeyword( "inner" );
2775                                acceptKeyword( "join" );
2776                                break;
2777                        case crossapply :
2778                                acceptKeyword( "cross" );
2779                                acceptKeyword( "apply" );
2780                                break;
2781                        case outerapply :
2782                                acceptKeyword( "outer" );
2783                                acceptKeyword( "apply" );
2784                                break;
2785                        default :
2786                                acceptKeyword( "join" );
2787                                break;
2788                }
2789
2790                if ( joinItem.getTable( ) != null )
2791                {
2792                        joinItem.getTable( ).accept( this );
2793                }
2794                else if ( joinItem.getJoin( ) != null )
2795                {
2796                        joinItem.getJoin( ).accept( this );
2797                }
2798
2799                if ( joinItem.getOnCondition( ) != null )
2800                {
2801                        acceptKeyword( "on" );
2802                        joinItem.getOnCondition( ).accept( this );
2803                }
2804
2805                if ( joinItem.getUsingColumns( ) != null )
2806                {
2807                        acceptKeyword( "using" );
2808                        acceptSymbol( "(" );
2809                        visitObjectNameList( joinItem.getUsingColumns( ) );
2810                        acceptSymbol( ")" );
2811                }
2812
2813                // already implemented in public void preVisit(TJoin node){
2814
2815                // if (node.getKind() == TBaseType.join_source_table){
2816                // node.getTable().accept(this);
2817                // }else if (node.getKind() == TBaseType.join_source_join){
2818                // node.getJoin().accept(this);
2819                // }
2820
2821                // if (node.getTable() != null){
2822                // node.getTable().accept(this);
2823                // }else if (node.getJoin() != null){
2824                // node.getJoin().accept(this);
2825                // }
2826                //
2827                //
2828                // if (node.getOnCondition() != null){
2829                // node.getOnCondition().accept(this);
2830                // }
2831                //
2832                // if (node.getUsingColumns() != null){
2833                // node.getUsingColumns().accept(this);
2834                // }
2835        }
2836
2837
2838        public void preVisit(TJsonTable node) {
2839                visitNodeByToken(node);
2840        }
2841
2842        public void preVisit( TTable node )
2843        {
2844
2845                if ( node.getParenthesisCount( ) > 0 )
2846                {
2847                        for ( int i = 0; i < node.getParenthesisCount( ); i++ )
2848                        {
2849                                acceptSymbol( "(" );
2850                        }
2851                }
2852                if ( node.getParenthesisAfterAliasCount( ) > 0 )
2853                {
2854                        for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ )
2855                        {
2856                                acceptSymbol( "(" );
2857                        }
2858                }
2859
2860                if ( node.isTableKeyword( ) )
2861                {
2862                        acceptKeyword( "table" );
2863                        acceptSymbol( "(" );
2864                }
2865
2866                if ( node.isOnlyKeyword( ) )
2867                {
2868                        acceptKeyword( "only" );
2869                        acceptSymbol( "(" );
2870                }
2871
2872                switch ( node.getTableType( ) )
2873                {
2874                        case objectname :
2875                        {
2876                                node.getTableName( ).accept( this );
2877                                if ( node.getFlashback( ) != null )
2878                                {
2879                                        acceptNewline( );
2880                                        visitNodeByToken( node.getFlashback( ) );
2881                                }
2882                                break;
2883                        }
2884                        case tableExpr :
2885                        {
2886                                node.getTableExpr( ).accept( this );
2887                                break;
2888                        }
2889                        case subquery :
2890                        {
2891                                node.getSubquery( ).accept( this );
2892                                break;
2893                        }
2894                        case function :
2895                        {
2896                                node.getFuncCall( ).accept( this );
2897                                break;
2898                        }
2899                        case pivoted_table :
2900                        {
2901                                node.getPivotedTable( ).accept( this );
2902                                break;
2903                        }
2904                        case output_merge :
2905                        {
2906                                // e_table_reference.setTextContent(node.getOutputMerge().toString());
2907                                break;
2908                        }
2909                        case containsTable :
2910                        {
2911                                node.getContainsTable( ).accept( this );
2912                                break;
2913                        }
2914
2915                        case openrowset :
2916                        {
2917                                node.getOpenRowSet( ).accept( this );
2918                                break;
2919                        }
2920
2921                        case openxml :
2922                        {
2923                                node.getOpenXML( ).accept( this );
2924                                break;
2925                        }
2926
2927                        case opendatasource :
2928                        {
2929                                node.getOpenDatasource( ).accept( this );
2930                                break;
2931                        }
2932
2933                        case openquery :
2934                        {
2935                                node.getOpenquery( ).accept( this );
2936                                break;
2937                        }
2938                        case datachangeTable :
2939                        {
2940                                node.getDatachangeTable( ).accept( this );
2941                                break;
2942                        }
2943                        case rowList :
2944                        {
2945                                node.getValueClause( ).accept( this );
2946                                break;
2947                        }
2948                        case xmltable :
2949                        {
2950                                node.getXmlTable( ).accept( this );
2951                                break;
2952                        }
2953
2954                        case informixOuter :
2955                        {
2956                                node.getOuterClause( ).accept( this );
2957                                break;
2958                        }
2959
2960                        case table_ref_list :
2961                        {
2962                                node.getFromTableList( ).accept( this );
2963                                break;
2964                        }
2965                        case hiveFromQuery :
2966                        {
2967                                node.getHiveFromQuery( ).accept( this );
2968                                break;
2969                        }
2970                        case jsonTable :
2971                        {
2972                                node.getJsonTable( ).accept( this );
2973                                break;
2974                        }
2975
2976                        default :
2977                                // sb.append(node.toString().replace(">","&#62;").replace("<","&#60;"));
2978                                break;
2979
2980                }
2981
2982                if ( node.isTableKeyword( ) )
2983                {
2984                        acceptSymbol( ")" );
2985                }
2986
2987                if ( node.isOnlyKeyword( ) )
2988                {
2989                        acceptSymbol( ")" );
2990                }
2991
2992                if ( node.getParenthesisCount( ) > 0 )
2993                {
2994                        for ( int i = 0; i < node.getParenthesisCount( ); i++ )
2995                        {
2996                                acceptSymbol( ")" );
2997                        }
2998                }
2999
3000                if ( node.getPxGranule( ) != null )
3001                {
3002                        // node.getPxGranule().accept(this);
3003                        acceptNewline( );
3004                        visitNodeByToken( node.getPxGranule( ) );
3005                }
3006
3007                if ( node.getTableSample( ) != null )
3008                {
3009                        // node.getTableSample().accept(this);
3010                        acceptNewline( );
3011                        visitNodeByToken( node.getTableSample( ) );
3012                }
3013
3014                if ( node.getAliasClause( ) != null )
3015                {
3016                        acceptSpace( 1 );
3017                        node.getAliasClause( ).accept( this );
3018                }
3019
3020                if ( node.getParenthesisAfterAliasCount( ) > 0 )
3021                {
3022                        for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ )
3023                        {
3024                                acceptSymbol( ")" );
3025                        }
3026                }
3027
3028                if ( node.getTableHintList( ) != null )
3029                {
3030                        for ( int i = 0; i < node.getTableHintList( ).size( ); i++ )
3031                        {
3032                                TTableHint tableHint = node.getTableHintList( ).getElement( i );
3033                                tableHint.accept( this );
3034                        }
3035                }
3036
3037        }
3038
3039        public void preVisit( THierarchical node )
3040        {
3041                if ( node.getStartWithClause( ) != null )
3042                {
3043                        acceptKeyword( "start" );
3044                        acceptKeyword( "with" );
3045                        node.getStartWithClause( ).accept( this );
3046                }
3047
3048                for ( int i = 0; i < node.getConnectByList( ).size( ); i++ )
3049                {
3050                        node.getConnectByList( ).getElement( i ).accept( this );
3051                        if ( i != node.getConnectByList( ).size( ) - 1 )
3052                        {
3053                                acceptNewline( );
3054                        }
3055                }
3056
3057        }
3058
3059        public void preVisit( TConnectByClause node )
3060        {
3061                acceptKeyword( "connect" );
3062                acceptKeyword( "by" );
3063                if ( node.isNoCycle( ) )
3064                {
3065                        acceptKeyword( "nocycle" );
3066                }
3067                node.getCondition( ).accept( this );
3068        }
3069
3070        public void preVisit( TGroupBy node )
3071        {
3072                if ( node.getItems( ) != null && node.getItems( ).size( ) > 0 )
3073                {
3074                        acceptKeyword( "group" );
3075                        acceptKeyword( "by" );
3076                        for ( int i = 0; i < node.getItems( ).size( ); i++ )
3077                        {
3078                                node.getItems( ).getElement( i ).accept( this );
3079                                if ( i != node.getItems( ).size( ) - 1 )
3080                                        acceptSymbol( "," );
3081                        }
3082
3083                        if (node.isRollupModifier()){
3084                                acceptKeyword("with");
3085                                acceptKeyword("rollup");
3086                        }
3087
3088                        if (node.isCubeModifier()){
3089                                acceptKeyword("with");
3090                                acceptKeyword("cube");
3091                        }
3092                }
3093                if ( node.getHavingClause( ) != null )
3094                {
3095                        acceptKeyword( "having" );
3096                        node.getHavingClause( ).accept( this );
3097                }
3098        }
3099
3100        public void preVisit( TGroupByItem node )
3101        {
3102
3103                if ( node.getExpr( ) != null )
3104                {
3105                        node.getExpr( ).accept( this );
3106                }
3107                else if ( node.getGroupingSet( ) != null )
3108                {
3109                        node.getGroupingSet( ).accept( this );
3110                }
3111                else if ( node.getRollupCube( ) != null )
3112                {
3113                        node.getRollupCube( ).accept( this );
3114                }
3115
3116        }
3117
3118        public void preVisit( TOrderBy node )
3119        {
3120                if ( node.getItems( ).size( ) == 0 )
3121                        return;
3122
3123                acceptKeyword( "order" );
3124                if ( node.isSiblings( ) )
3125                        acceptKeyword( "siblings" );
3126                acceptKeyword( "by" );
3127                for ( int i = 0; i < node.getItems( ).size( ); i++ )
3128                {
3129                        node.getItems( ).getOrderByItem( i ).accept( this );
3130                        if ( i != node.getItems( ).size( ) - 1 )
3131                                acceptSymbol( "," );
3132                }
3133
3134        }
3135
3136        public void preVisit( TOrderByItem node )
3137        {
3138                if ( node.getSortKey( ) != null )
3139                {
3140                        node.getSortKey( ).accept( this );
3141                }
3142                if ( node.getSortOrder( ) == ESortType.asc )
3143                {
3144                        acceptKeyword( "asc" );
3145                }
3146                else if ( node.getSortOrder( ) == ESortType.desc )
3147                {
3148                        acceptKeyword( "desc" );
3149                }
3150
3151                if (node.getNullOrder() == ENullOrder.nullsFirst){
3152                        acceptKeyword( "nulls" );
3153                        acceptKeyword( "first" );
3154                }else if (node.getNullOrder() == ENullOrder.nullsLast){
3155                        acceptKeyword( "nulls" );
3156                        acceptKeyword( "last" );
3157                }
3158                // e_order_by_item.setAttribute("sort_order",node.getSortOrder().toString());
3159        }
3160
3161        public void preVisit( TCTE node )
3162        {
3163                if (node.isRecursive()){
3164                        acceptKeyword( "recursive" );
3165                }
3166
3167                node.getTableName( ).accept( this );
3168
3169                if ( node.getColumnList( ) != null )
3170                {
3171                        acceptSymbol( "(" );
3172                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
3173                        {
3174                                node.getColumnList( ).getObjectName( i ).accept( this );
3175                                if ( i != node.getColumnList( ).size( ) - 1 )
3176                                        acceptSymbol( "," );
3177                        }
3178                        acceptSymbol( ")" );
3179
3180                }
3181
3182                acceptKeyword( "as" );
3183                acceptNewline( );
3184
3185                if (node.dbvendor == EDbVendor.dbvpostgresql){
3186                        acceptSymbol( "(" );
3187                }
3188
3189                if ( node.getSubquery( ) != null )
3190                {
3191                        node.getSubquery( ).accept( this );
3192                }
3193                else if ( node.getUpdateStmt( ) != null )
3194                {
3195                        node.getUpdateStmt( ).accept( this );
3196                }
3197                else if ( node.getInsertStmt( ) != null )
3198                {
3199                        node.getInsertStmt( ).accept( this );
3200                }
3201                else if ( node.getDeleteStmt( ) != null )
3202                {
3203                        node.getDeleteStmt( ).accept( this );
3204                }
3205
3206                if (node.dbvendor == EDbVendor.dbvpostgresql) {
3207                        acceptSymbol(")");
3208                }
3209
3210
3211        }
3212
3213        public void preVisit( TPivotInClause node )
3214        {
3215                acceptKeyword( "in" );
3216                if ( node.getItems( ) != null )
3217                {
3218                        acceptSymbol( "(" );
3219                        visitResultColumnList( node.getItems( ) );
3220                        acceptSymbol( ")" );
3221                }
3222                if ( node.getSubQuery( ) != null )
3223                        node.getSubQuery( ).accept( this );
3224
3225        }
3226
3227        public void preVisit( TPivotedTable node )
3228        {
3229                TPivotClause pivotClause;
3230
3231                for ( int i = 0; i < node.getPivotClauseList( ).size( ); i++ )
3232                {
3233
3234                        if ( i == 0 )
3235                        {
3236                                node.getTableSource( ).accept( this );
3237                        }
3238                        else
3239                        {
3240                        }
3241
3242                        pivotClause = node.getPivotClauseList( ).getElement( i );
3243                        if ( pivotClause.getAliasClause( ) != null )
3244                        {
3245                                pivotClause.getAliasClause( ).accept( this );
3246                        }
3247                        pivotClause.accept( this );
3248
3249                }
3250
3251        }
3252
3253        public void preVisit( TPivotClause node )
3254        {
3255                if ( node.getType( ) == TPivotClause.pivot )
3256                {
3257                        acceptKeyword( "pivot" );
3258                        acceptSymbol( "(" );
3259                        if ( node.getAggregation_function( ) != null )
3260                        {
3261                                node.getAggregation_function( ).accept( this );
3262                        }
3263                        else if ( node.getAggregation_function_list( ) != null )
3264                        {
3265                                if ( node.getAggregation_function_list( ).size( ) > 1 )
3266                                        acceptSymbol( "(" );
3267                                for ( int i = 0; i < node.getAggregation_function_list( )
3268                                                .size( ); i++ )
3269                                {
3270                                        node.getAggregation_function_list( )
3271                                                        .getResultColumn( i )
3272                                                        .accept( this );
3273                                        if ( i != node.getAggregation_function_list( ).size( ) - 1 )
3274                                                acceptSymbol( "," );
3275                                }
3276                                if ( node.getAggregation_function_list( ).size( ) > 1 )
3277                                        acceptSymbol( ")" );
3278                        }
3279                        acceptKeyword( "for" );
3280
3281                        if ( node.getPivotColumnList( ).size( ) > 1 )
3282                                acceptSymbol( "(" );
3283                        for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ )
3284                        {
3285                                node.getPivotColumnList( ).getElement( i ).accept( this );
3286                                if ( i != node.getPivotColumnList( ).size( ) - 1 )
3287                                        acceptSymbol( "," );
3288                        }
3289                        if ( node.getPivotColumnList( ).size( ) > 1 )
3290                                acceptSymbol( ")" );
3291
3292                        node.getPivotInClause( ).accept( this );
3293
3294                        acceptSymbol( ")" );
3295                }
3296                else
3297                {
3298                        acceptKeyword( "unpivot" );
3299                        acceptSymbol( "(" );
3300                        if ( node.getValueColumnList( ).size( ) > 1 )
3301                                acceptSymbol( "(" );
3302                        for ( int i = 0; i < node.getValueColumnList( ).size( ); i++ )
3303                        {
3304                                node.getValueColumnList( ).getObjectName( i ).accept( this );
3305                                if ( i != node.getValueColumnList( ).size( ) - 1 )
3306                                        acceptSymbol( "," );
3307                        }
3308                        if ( node.getValueColumnList( ).size( ) > 1 )
3309                                acceptSymbol( ")" );
3310
3311                        acceptKeyword( "for" );
3312
3313                        if ( node.getPivotColumnList( ).size( ) > 1 )
3314                                acceptSymbol( "(" );
3315                        for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ )
3316                        {
3317                                node.getPivotColumnList( ).getElement( i ).accept( this );
3318                                if ( i != node.getPivotColumnList( ).size( ) - 1 )
3319                                        acceptSymbol( "," );
3320                        }
3321                        if ( node.getPivotColumnList( ).size( ) > 1 )
3322                                acceptSymbol( ")" );
3323
3324                        node.getUnpivotInClause( ).accept( this );
3325
3326                        acceptSymbol( ")" );
3327                }
3328        }
3329
3330        public void preVisit( TUnpivotInClauseItem node )
3331        {
3332
3333                if ( node.getColumn( ) != null )
3334                {
3335                        node.getColumn( ).accept( this );
3336                }
3337                else if ( node.getColumnList( ) != null )
3338                {
3339                        acceptSymbol( "(" );
3340                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
3341                        {
3342                                node.getColumnList( ).getObjectName( i ).accept( this );
3343                                if ( i != node.getColumnList( ).size( ) - 1 )
3344                                        acceptSymbol( "," );
3345                        }
3346                        acceptSymbol( ")" );
3347                }
3348
3349                if ( node.getConstant( ) != null )
3350                {
3351                        acceptKeyword( "as" );
3352                        node.getConstant( ).accept( this );
3353                }
3354                else if ( node.getConstantList( ) != null )
3355                {
3356                        acceptKeyword( "as" );
3357                        acceptSymbol( "(" );
3358                        for ( int i = 0; i < node.getConstantList( ).size( ); i++ )
3359                        {
3360                                node.getConstantList( ).getElement( i ).accept( this );
3361                                if ( i != node.getConstantList( ).size( ) - 1 )
3362                                        acceptSymbol( "," );
3363                        }
3364                        acceptSymbol( ")" );
3365                }
3366
3367        }
3368
3369        public void preVisit( TUnpivotInClause node )
3370        {
3371                acceptKeyword( "in" );
3372                acceptSymbol( "(" );
3373                for ( int i = 0; i < node.getItems( ).size( ); i++ )
3374                {
3375                        node.getItems( ).getElement( i ).accept( this );
3376                        if ( i != node.getItems( ).size( ) - 1 )
3377                                acceptSymbol( "," );
3378                }
3379                acceptSymbol( ")" );
3380        }
3381
3382        public void preVisit( TCaseExpression node )
3383        {
3384
3385                acceptKeyword( "case" );
3386                if ( node.getInput_expr( ) != null )
3387                {
3388                        node.getInput_expr( ).accept( this );
3389                }
3390
3391                for ( int i = 0; i < node.getWhenClauseItemList( ).size( ); i++ )
3392                {
3393                        node.getWhenClauseItemList( ).getWhenClauseItem( i ).accept( this );
3394                        if ( i != node.getWhenClauseItemList( ).size( ) - 1 )
3395                                acceptNewline( );
3396                }
3397
3398                if ( node.getElse_expr( ) != null )
3399                {
3400                        acceptNewline( );
3401                        acceptKeyword( "else" );
3402                        node.getElse_expr( ).accept( this );
3403                }
3404
3405                if ( node.getElse_statement_list( ).size( ) > 0 )
3406                {
3407                        node.getElse_statement_list( ).accept( this );
3408                }
3409
3410                acceptNewline( );
3411                acceptKeyword( "end" );
3412        }
3413
3414        public void preVisit( TWhenClauseItem node )
3415        {
3416                acceptKeyword( "when" );
3417                node.getComparison_expr( ).accept( this );
3418                acceptNewline( );
3419                acceptKeyword( "then" );
3420                if ( node.getReturn_expr( ) != null )
3421                {
3422                        node.getReturn_expr( ).accept( this );
3423                }
3424                else if ( node.getStatement_list( ).size( ) > 0 )
3425                {
3426                        for ( int i = 0; i < node.getStatement_list( ).size( ); i++ )
3427                        {
3428                                node.getStatement_list( ).get( i ).accept( this );
3429                        }
3430
3431                }
3432        }
3433
3434        public void preVisit( TForUpdate node )
3435        {
3436                switch ( node.getForUpdateType( ) )
3437                {
3438                        case forReadOnly :
3439                                acceptKeyword( "read" );
3440                                acceptKeyword( "only" );
3441                                break;
3442                        case forUpdate :
3443                                acceptKeyword( "for" );
3444                                acceptKeyword( "update" );
3445                                break;
3446                        case forUpdateOf :
3447                                acceptKeyword( "for" );
3448                                acceptKeyword( "update" );
3449                                acceptKeyword( "of" );
3450                                break;
3451                }
3452
3453                if ( node.getColumnRefs( ) != null )
3454                {
3455                        visitObjectNameList( node.getColumnRefs( ) );
3456                }
3457                if ( node.isNowait( ) )
3458                        acceptKeyword( "nowait" );
3459                if ( node.isWait( ) )
3460                {
3461                        acceptKeyword( "wait" );
3462                        acceptIdentifier( node.getWaitValue( ) );
3463                }
3464
3465        }
3466
3467        public void preVisit( TDeleteSqlStatement stmt )
3468        {
3469
3470                if ( stmt.getCteList( ) != null )
3471                {
3472                        acceptKeyword( "with" );
3473                        visitCTEList( stmt.getCteList( ) );
3474                }
3475
3476                acceptKeyword( "delete" );
3477
3478                if ( stmt.getTopClause( ) != null )
3479                {
3480                        stmt.getTopClause( ).accept( this );
3481                }
3482
3483                if ( stmt.isFromKeyword( ) )
3484                        acceptKeyword( "from" );
3485                stmt.getTargetTable( ).accept( this );
3486
3487                if ( stmt.joins.size( ) > 0 )
3488                {
3489                        acceptNewline( );
3490                        acceptKeyword( "from" );
3491                        visitJoinList( stmt.joins );
3492                }
3493
3494                if ( stmt.getOutputClause( ) != null )
3495                {
3496                        stmt.getOutputClause( ).accept( this );
3497                }
3498
3499                if ( stmt.getWhereClause( ) != null )
3500                {
3501                        acceptNewline( );
3502                        stmt.getWhereClause( ).accept( this );
3503                }
3504
3505                if ( stmt.getReturningClause( ) != null )
3506                {
3507                        stmt.getReturningClause( ).accept( this );
3508                }
3509
3510        }
3511
3512        public void preVisit( TUpdateSqlStatement stmt )
3513        {
3514
3515                if ( stmt.getCteList( ) != null )
3516                {
3517                        acceptKeyword( "with" );
3518                        visitCTEList( stmt.getCteList( ) );
3519                }
3520
3521                acceptKeyword( "update" );
3522
3523                if ( stmt.getTopClause( ) != null )
3524                {
3525                        stmt.getTopClause( ).accept( this );
3526                }
3527
3528                if ( getDBVerdor(stmt) == EDbVendor.dbvmysql )
3529                {
3530                        if ( stmt.joins.size( ) > 0 )
3531                        {
3532                                visitJoinList( stmt.joins );
3533                        }
3534                        else
3535                        {
3536                                stmt.getTargetTable( ).accept( this );
3537                        }
3538                }
3539                else
3540                {
3541                        stmt.getTargetTable( ).accept( this );
3542                }
3543                
3544                acceptNewline( );
3545                acceptKeyword( "set" );
3546                visitResultColumnList( stmt.getResultColumnList( ) );
3547
3548                if ( getDBVerdor( stmt ) != EDbVendor.dbvmysql )
3549                {
3550                        if ( stmt.joins.size( ) > 0 )
3551                        {
3552                                acceptNewline( );
3553                                acceptKeyword( "from" );
3554                                visitJoinList( stmt.joins );
3555                        }
3556                }
3557
3558                if ( stmt.getWhereClause( ) != null )
3559                {
3560                        acceptNewline( );
3561                        stmt.getWhereClause( ).accept( this );
3562                }
3563
3564                if ( stmt.getOrderByClause( ) != null )
3565                {
3566                        stmt.getOrderByClause( ).accept( this );
3567                }
3568
3569                if ( stmt.getLimitClause( ) != null )
3570                {
3571                        stmt.getLimitClause( ).accept( this );
3572                }
3573
3574                if ( stmt.getOutputClause( ) != null )
3575                {
3576                        stmt.getOutputClause( ).accept( this );
3577                }
3578
3579                if ( stmt.getReturningClause( ) != null )
3580                {
3581                        stmt.getReturningClause( ).accept( this );
3582                }
3583
3584        }
3585
3586        private EDbVendor getDBVerdor( TCustomSqlStatement stmt )
3587        {
3588                if ( stmt.dbvendor != null )
3589                {
3590                        return stmt.dbvendor;
3591                }
3592                else if ( stmt.getGsqlparser( ) != null )
3593                {
3594                        return stmt.getGsqlparser( ).getDbVendor( );
3595                }
3596                return null;
3597        }
3598
3599        public void preVisit( TInsertSqlStatement stmt )
3600        {
3601
3602                boolean insertAll = false;
3603
3604                if ( stmt.getCteList( ) != null )
3605                {
3606                        acceptKeyword( "with" );
3607                        visitCTEList( stmt.getCteList( ) );
3608                }
3609
3610                acceptKeyword( "insert" );
3611                if ( stmt.isInsertAll( ) )
3612                        acceptKeyword( "all" );
3613                if ( stmt.isInsertFirst( ) )
3614                        acceptKeyword( "first" );
3615
3616                if ( stmt.getInsertConditions( ) != null
3617                                && stmt.getInsertConditions( ).size( ) > 0 )
3618                {
3619                        for ( int i = 0; i < stmt.getInsertConditions( ).size( ); i++ )
3620                        {
3621                                TInsertCondition condition = stmt.getInsertConditions( )
3622                                                .getElement( i );
3623                                preVisit( condition );
3624                        }
3625
3626                        insertAll = true;
3627                }
3628
3629                if ( stmt.getElseIntoValues( ) != null )
3630                {
3631                        acceptKeyword( "else" );
3632                        for ( int i = 0; i < stmt.getElseIntoValues( ).size( ); i++ )
3633                        {
3634                                stmt.getElseIntoValues( ).getElement( i ).accept( this );
3635                        }
3636                        insertAll = true;
3637                }
3638
3639                if ( insertAll )
3640                {
3641                        if ( stmt.getSubQuery( ) != null )
3642                        {
3643                                acceptNewline( );
3644                                stmt.getSubQuery( ).accept( this );
3645                        }
3646                }
3647
3648                if ( !insertAll )
3649                {
3650                        acceptKeyword( "into" );
3651
3652                        if ( stmt.getTargetTable( ) != null )
3653                        {
3654                                stmt.getTargetTable( ).accept( this );
3655                        }
3656                        else
3657                        {
3658                                // hive insert may have no target table
3659                        }
3660
3661                        if ( stmt.getColumnList( ) != null )
3662                        {
3663                                acceptSymbol( "(" );
3664                                visitObjectNameList( stmt.getColumnList( ) );
3665                                acceptSymbol( ")" );
3666                        }
3667
3668                        switch ( stmt.getInsertSource( ) )
3669                        {
3670                                case values :
3671                                        acceptNewline( );
3672                                        acceptKeyword( "values" );
3673                                        TMultiTargetList multiTargetList = stmt.getValues( );
3674                                        visitMultiTargetList( multiTargetList );
3675                                        break;
3676                                case subquery :
3677                                        acceptNewline( );
3678                                        stmt.getSubQuery( ).accept( this );
3679                                        break;
3680                                case values_empty :
3681                                        break;
3682                                case values_function :
3683                                        acceptNewline( );
3684                                        acceptKeyword( "values" );
3685                                        stmt.getFunctionCall( ).accept( this );
3686                                        break;
3687                                case values_oracle_record :
3688                                        acceptNewline( );
3689                                        acceptKeyword( "values" );
3690                                        stmt.getRecordName( ).accept( this );
3691                                        break;
3692                                case set_column_value :
3693                                        // stmt.getSetColumnValues().accept(this);
3694                                        break;
3695                                default :
3696                                        break;
3697                        }
3698                }
3699                
3700                if ( stmt.getOnDuplicateKeyUpdate( ) != null )
3701                {
3702                        acceptKeyword( "on" );
3703                        acceptKeyword( "duplicate" );
3704                        acceptKeyword( "key" );
3705                        acceptKeyword( "update" );
3706                        visitResultColumnList( stmt.getOnDuplicateKeyUpdate( ) );
3707                }
3708
3709                if ( stmt.getReturningClause( ) != null )
3710                {
3711                        acceptNewline( );
3712                        stmt.getReturningClause( ).accept( this );
3713                }
3714
3715        }
3716
3717        public void preVisit( TInsertCondition node )
3718        {
3719                if ( node.getCondition( ) != null )
3720                {
3721                        acceptNewline( );
3722                        acceptKeyword( "when" );
3723                        preVisit( node.getCondition( ) );
3724                        acceptKeyword( "then" );
3725                }
3726
3727                if ( node.getInsertIntoValues( ) != null
3728                                && node.getInsertIntoValues( ).size( ) > 0 )
3729                {
3730                        acceptNewline( );
3731                        for ( int i = 0; i < node.getInsertIntoValues( ).size( ); i++ )
3732                        {
3733                                TInsertIntoValue value = node.getInsertIntoValues( )
3734                                                .getElement( i );
3735                                preVisit( value );
3736                        }
3737                }
3738        }
3739
3740        public void preVisit( TInsertIntoValue node )
3741        {
3742                if ( node.getTable( ) != null )
3743                {
3744                        acceptKeyword( "into" );
3745                        preVisit( node.getTable( ) );
3746                        if ( node.getColumnList( ) != null
3747                                        && node.getColumnList( ).size( ) > 0 )
3748                        {
3749                                acceptSymbol( "(" );
3750                                visitObjectNameList( node.getColumnList( ) );
3751                                acceptSymbol( ")" );
3752                        }
3753                        if ( node.getTargetList( ) != null
3754                                        && node.getTargetList( ).size( ) > 0 )
3755                        {
3756                                acceptKeyword( "values" );
3757                                TMultiTargetList multiTargetList = node.getTargetList( );
3758                                visitMultiTargetList( multiTargetList );
3759                        }
3760                }
3761        }
3762
3763        private void visitMultiTargetList( TMultiTargetList multiTargetList )
3764        {
3765                for ( int i = 0; i < multiTargetList.size( ); i++ )
3766                {
3767                        TMultiTarget multiTarget = multiTargetList.getMultiTarget( i );
3768                        acceptSymbol( "(" );
3769
3770                        for ( int j = 0; j < multiTarget.getColumnList( ).size( ); j++ )
3771                        {
3772                                if ( multiTarget.getColumnList( )
3773                                                .getResultColumn( j )
3774                                                .isPlaceHolder( ) )
3775                                        continue; // teradata allow empty value
3776                                multiTarget.getColumnList( )
3777                                                .getResultColumn( j )
3778                                                .getExpr( )
3779                                                .accept( this );
3780                                if ( j != multiTarget.getColumnList( ).size( ) - 1 )
3781                                        acceptSymbol( "," );
3782                        }
3783
3784                        acceptSymbol( ")" );
3785
3786                        if ( i != multiTargetList.size( ) - 1 )
3787                                acceptSymbol( "," );
3788
3789                }
3790        }
3791
3792        public void preVisit( TMergeSqlStatement stmt )
3793        {
3794
3795                if ( stmt.getCteList( ) != null )
3796                {
3797                        acceptKeyword( "with" );
3798                        visitCTEList( stmt.getCteList( ) );
3799                }
3800
3801                acceptKeyword( "merge" );
3802                acceptKeyword( "into" );
3803                stmt.getTargetTable( ).accept( this );
3804                acceptKeyword( "using" );
3805                stmt.getUsingTable( ).accept( this );
3806                acceptKeyword( "on" );
3807                acceptSymbol( "(" );
3808                stmt.getCondition( ).accept( this );
3809                acceptSymbol( ")" );
3810                acceptNewline( );
3811
3812                if ( stmt.getWhenClauses( ) != null )
3813                {
3814                        for ( int i = 0; i < stmt.getWhenClauses( ).size( ); i++ )
3815                        {
3816                                TMergeWhenClause whenClause = stmt.getWhenClauses( )
3817                                                .getElement( i );
3818                                whenClause.accept( this );
3819                        }
3820                }
3821        }
3822
3823        public void preVisit( TMergeWhenClause node )
3824        {
3825                switch ( node.getType( ) )
3826                {
3827                        case TMergeWhenClause.matched :
3828                                acceptKeyword( "when" );
3829                                acceptKeyword( "matched" );
3830                                acceptKeyword( "then" );
3831                                break;
3832                        case TMergeWhenClause.not_matched :
3833                                acceptKeyword( "when" );
3834                                acceptKeyword( "not" );
3835                                acceptKeyword( "matched" );
3836                                acceptKeyword( "then" );
3837                                break;
3838                        case TMergeWhenClause.matched_with_condition :
3839                                acceptKeyword( "when" );
3840                                acceptKeyword( "matched" );
3841                                acceptKeyword( "and" );
3842                                node.getCondition( ).accept( this );
3843                                acceptKeyword( "then" );
3844                                break;
3845                        case TMergeWhenClause.not_matched_with_condition :
3846                                acceptKeyword( "when" );
3847                                acceptKeyword( "not" );
3848                                acceptKeyword( "matched" );
3849                                acceptKeyword( "and" );
3850                                node.getCondition( ).accept( this );
3851                                acceptKeyword( "then" );
3852                                break;
3853                        case TMergeWhenClause.not_matched_by_target :
3854                                acceptKeyword( "when" );
3855                                acceptKeyword( "not" );
3856                                acceptKeyword( "matched" );
3857                                acceptKeyword( "by" );
3858                                acceptKeyword( "target" );
3859                                acceptKeyword( "then" );
3860                                break;
3861                        case TMergeWhenClause.not_matched_by_target_with_condition :
3862                                acceptKeyword( "when" );
3863                                acceptKeyword( "not" );
3864                                acceptKeyword( "matched" );
3865                                acceptKeyword( "by" );
3866                                acceptKeyword( "target" );
3867                                acceptKeyword( "and" );
3868                                node.getCondition( ).accept( this );
3869                                acceptKeyword( "then" );
3870                                break;
3871                        case TMergeWhenClause.not_matched_by_source :
3872                                acceptKeyword( "when" );
3873                                acceptKeyword( "not" );
3874                                acceptKeyword( "matched" );
3875                                acceptKeyword( "by" );
3876                                acceptKeyword( "source" );
3877                                acceptKeyword( "then" );
3878                                break;
3879                        case TMergeWhenClause.not_matched_by_source_with_condition :
3880                                acceptKeyword( "when" );
3881                                acceptKeyword( "not" );
3882                                acceptKeyword( "matched" );
3883                                acceptKeyword( "by" );
3884                                acceptKeyword( "source" );
3885                                acceptKeyword( "and" );
3886                                node.getCondition( ).accept( this );
3887                                acceptKeyword( "then" );
3888                                break;
3889                        default :
3890                                break;
3891                }
3892
3893                if ( node.getUpdateClause( ) != null )
3894                {
3895                        node.getUpdateClause( ).accept( this );
3896                }
3897
3898                if ( node.getInsertClause( ) != null )
3899                {
3900                        node.getInsertClause( ).accept( this );
3901                }
3902
3903                if ( node.getDeleteClause( ) != null )
3904                {
3905                        node.getDeleteClause( ).accept( this );
3906                }
3907
3908        }
3909
3910        public void preVisit( TMergeUpdateClause node )
3911        {
3912
3913                acceptKeyword( "update" );
3914                acceptKeyword( "set" );
3915                if ( node.getUpdateColumnList( ) != null )
3916                {
3917                        visitResultColumnList( node.getUpdateColumnList( ) );
3918                }
3919
3920                if ( node.getUpdateWhereClause( ) != null )
3921                {
3922                        acceptNewline( );
3923                        acceptKeyword( "where" );
3924                        node.getUpdateWhereClause( ).accept( this );
3925                }
3926
3927                if ( node.getDeleteWhereClause( ) != null )
3928                {
3929                        acceptNewline( );
3930                        acceptKeyword( "delete" );
3931                        node.getDeleteWhereClause( ).accept( this );
3932                }
3933
3934        }
3935
3936        public void preVisit( TMergeInsertClause node )
3937        {
3938
3939                acceptKeyword( "insert" );
3940                if ( node.getColumnList( ) != null )
3941                {
3942                        acceptSymbol( "(" );
3943                        visitObjectNameList( node.getColumnList( ) );
3944                        acceptSymbol( ")" );
3945                }
3946
3947                acceptKeyword( "values" );
3948                if ( node.getValuelist( ) != null )
3949                {
3950                        acceptSymbol( "(" );
3951                        visitResultColumnList( node.getValuelist( ) );
3952                        acceptSymbol( ")" );
3953                }
3954
3955                if ( node.getInsertWhereClause( ) != null )
3956                {
3957                        acceptNewline( );
3958                        acceptKeyword( "where" );
3959                        node.getInsertWhereClause( ).accept( this );
3960                }
3961
3962        }
3963
3964        public void preVisit( TMergeDeleteClause node )
3965        {
3966
3967        }
3968
3969        public void preVisit( TCreateTableSqlStatement stmt )
3970        {
3971                acceptKeyword( "create" );
3972
3973                if ( !stmt.getTableKinds( ).isEmpty( ) )
3974                {
3975                        if ( stmt.getTableKinds( ).contains( ETableKind.etkBase ) )
3976                        {
3977                                acceptKeyword( "base" );
3978                        }
3979                        if ( stmt.getTableKinds( ).contains( ETableKind.etkTemporary ) )
3980                        {
3981                                acceptKeyword( "temporary" );
3982                        }
3983                        if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemporary ) )
3984                        {
3985                                acceptKeyword( "global" );
3986                                acceptKeyword( "temporary" );
3987                        }
3988                        if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemporary ) )
3989                        {
3990                                acceptKeyword( "local" );
3991                                acceptKeyword( "temporary" );
3992                        }
3993                        if ( stmt.getTableKinds( ).contains( ETableKind.etkTemp ) )
3994                        {
3995                                acceptKeyword( "temp" );
3996                        }
3997                        if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemp ) )
3998                        {
3999                                acceptKeyword( "global" );
4000                                acceptKeyword( "temp" );
4001                        }
4002                        if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemp ) )
4003                        {
4004                                acceptKeyword( "local" );
4005                                acceptKeyword( "temp" );
4006                        }
4007                        if ( stmt.getTableKinds( ).contains( ETableKind.etkVolatile ) )
4008                        {
4009                                acceptKeyword( "volatile" );
4010                        }
4011                        if ( stmt.getTableKinds( ).contains( ETableKind.etkSet ) )
4012                        {
4013                                acceptKeyword( "set" );
4014                        }
4015                        if ( stmt.getTableKinds( ).contains( ETableKind.etkMultiset ) )
4016                        {
4017                                acceptKeyword( "multiset" );
4018                        }
4019                        if ( stmt.getTableKinds( ).contains( ETableKind.etkExternal ) )
4020                        {
4021                                acceptKeyword( "external" );
4022                        }
4023                }
4024                acceptKeyword( "table" );
4025                stmt.getTargetTable( ).accept( this );
4026
4027                if ( stmt.getSubQuery( ) != null )
4028                {
4029                        acceptKeyword( "as" );
4030                        acceptNewline( );
4031                        stmt.getSubQuery( ).accept( this );
4032
4033                }
4034                else
4035                {
4036                        acceptSymbol( "(" );
4037                        acceptNewline( );
4038                        for ( int i = 0; i < stmt.getColumnList( ).size( ); i++ )
4039                        {
4040                                stmt.getColumnList( ).getColumn( i ).accept( this );
4041                                if ( i != stmt.getColumnList( ).size( ) - 1 ){
4042                                        acceptSymbol( "," );
4043                                        acceptNewline();
4044                                }
4045
4046                        }
4047
4048                        if ( ( stmt.getTableConstraints( ) != null )
4049                                        && ( stmt.getTableConstraints( ).size( ) > 0 ) )
4050                        {
4051                                acceptNewline( );
4052                                acceptSymbol( "," );
4053                                for ( int i = 0; i < stmt.getTableConstraints( ).size( ); i++ )
4054                                {
4055                                        stmt.getTableConstraints( )
4056                                                        .getConstraint( i )
4057                                                        .accept( this );
4058                                        if ( i != stmt.getTableConstraints( ).size( ) - 1 )
4059                                                acceptSymbol( "," );
4060                                }
4061                        }
4062
4063                        acceptNewline( );
4064                        acceptSymbol( ")" );
4065                }
4066
4067                if (stmt.getOnFilegroup() != null){
4068
4069                        visitNodeByToken(stmt.getOnFilegroup());
4070                }
4071
4072                if ( stmt.getMySQLTableOptionList( ) != null
4073                                && stmt.getMySQLTableOptionList( ).size( ) > 0 )
4074                {
4075                        preVisit( stmt.getMySQLTableOptionList( ) );
4076                }
4077
4078        }
4079
4080        public void preVisit( TPTNodeList options )
4081        {
4082                for ( int i = 0; i < options.size( ); i++ )
4083                {
4084                        Object element = options.getElement( i );
4085                        if ( element instanceof TMySQLCreateTableOption )
4086                        {
4087                                preVisit( (TMySQLCreateTableOption) options.getElement( i ) );
4088                        }
4089                }
4090        }
4091
4092        public void preVisit( TMySQLCreateTableOption option )
4093        {
4094                acceptKeyword( option.getOptionName( ) );
4095                acceptSymbol( "=" );
4096                acceptKeyword( option.getOptionValue( ) );
4097        }
4098
4099        public void preVisit( TColumnDefinition node )
4100        {
4101
4102                node.getColumnName( ).accept( this );
4103
4104                if ( node.getDatatype( ) != null )
4105                {
4106                        node.getDatatype( ).accept( this );
4107                }
4108
4109                if ( node.getDefaultExpression( ) != null )
4110                {
4111                        acceptKeyword( "default" );
4112                        node.getDefaultExpression( ).accept( this );
4113                }
4114
4115                if ( node.isNull( ) )
4116                        acceptKeyword( "null" );
4117
4118                if ( ( node.getConstraints( ) != null )
4119                                && ( node.getConstraints( ).size( ) > 0 ) )
4120                {
4121                        for ( int i = 0; i < node.getConstraints( ).size( ); i++ )
4122                        {
4123                                node.getConstraints( ).getConstraint( i ).accept( this );
4124                        }
4125                }
4126
4127                if ( node.isIdentity( ) )
4128                {
4129                        acceptKeyword( "identity" );
4130                        if ( node.getSeed( ) != null )
4131                        {
4132                                acceptSymbol( "(" );
4133                                node.getSeed( ).accept( this );
4134                                acceptSymbol( "," );
4135                                node.getIncrement( ).accept( this );
4136                                acceptSymbol( ")" );
4137                        }
4138                }
4139
4140        }
4141
4142        public void preVisit( TColumnWithSortOrder node )
4143        {
4144                node.getColumnName( ).accept( this );
4145                if ( node.getLength( ) != null )
4146                {
4147                        acceptSymbol( "(" );
4148                        node.getLength( ).accept( this );
4149                        acceptSymbol( ")" );
4150                }
4151                if ( node.getSortType( ) == ESortType.desc )
4152                {
4153                        acceptKeyword( "desc" );
4154                }
4155                if ( node.getSortType( ) == ESortType.asc )
4156                {
4157                        acceptKeyword( "asc" );
4158                }
4159        }
4160
4161        public void preVisit( TConstraint node )
4162        {
4163
4164                if ( node.getConstraintName( ) != null )
4165                {
4166                        acceptKeyword( "constraint" );
4167                        node.getConstraintName( ).accept( this );
4168                }
4169
4170                switch ( node.getConstraint_type( ) )
4171                {
4172                        case notnull :
4173                                acceptKeyword( "not" );
4174                                acceptKeyword( "null" );
4175                                break;
4176                        case table_index:
4177                                //acceptKeyword("index");
4178                                visitNodeByToken(node);
4179                                break;
4180                        case unique :
4181                                acceptKeyword( "unique" );
4182                                if ( node.isClustered( ) )
4183                                        acceptKeyword( "clustered" );
4184                                if ( node.isNonClustered( ) )
4185                                        acceptKeyword( "nonclustered" );
4186                                if ( node.getColumnList( ) != null )
4187                                {
4188                                        acceptSymbol( "(" );
4189                                        // visitObjectNameList( node.getColumnList( ) );
4190                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4191                                        {
4192                                                node.getColumnList( ).getElement( i ).accept( this );
4193                                                if ( i != node.getColumnList( ).size( ) - 1 )
4194                                                {
4195                                                        acceptSymbol( "," );
4196                                                }
4197                                        }
4198                                        acceptSymbol( ")" );
4199                                }
4200                                break;
4201                        case check :
4202                                acceptKeyword( "check" );
4203                                if ( node.getCheckCondition( ) != null )
4204                                {
4205                                        acceptSymbol( "(" );
4206                                        node.getCheckCondition( ).accept( this );
4207                                        acceptSymbol( ")" );
4208                                }
4209                                else
4210                                {
4211                                        // db2 functional dependency
4212                                }
4213
4214                                break;
4215                        case primary_key :
4216                                acceptKeyword( "primary" );
4217                                acceptKeyword( "key" );
4218                                if ( node.isClustered( ) )
4219                                        acceptKeyword( "clustered" );
4220                                if ( node.isNonClustered( ) )
4221                                        acceptKeyword( "nonclustered" );
4222
4223                                if ( node.getColumnList( ) != null )
4224                                {
4225                                        acceptSymbol( "(" );
4226                                        // visitObjectNameList( node.getColumnList( ) );
4227                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4228                                        {
4229                                                node.getColumnList( ).getElement( i ).accept( this );
4230                                                if ( i != node.getColumnList( ).size( ) - 1 )
4231                                                {
4232                                                        acceptSymbol( "," );
4233                                                }
4234                                        }
4235                                        acceptSymbol( ")" );
4236                                }
4237                                break;
4238                        case foreign_key :
4239                                acceptKeyword( "foreign" );
4240                                acceptKeyword( "key" );
4241                                if ( node.getColumnList( ) != null )
4242                                {
4243                                        acceptSymbol( "(" );
4244                                        // visitObjectNameList( node.getColumnList( ) );
4245                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4246                                        {
4247                                                node.getColumnList( ).getElement( i ).accept( this );
4248                                                if ( i != node.getColumnList( ).size( ) - 1 )
4249                                                {
4250                                                        acceptSymbol( "," );
4251                                                }
4252                                        }
4253                                        acceptSymbol( ")" );
4254                                }
4255
4256                                if ( node.getReferencedObject( ) != null )
4257                                {
4258                                        acceptKeyword( "references" );
4259                                        node.getReferencedObject( ).accept( this );
4260                                }
4261
4262                                if ( node.getReferencedColumnList( ) != null )
4263                                {
4264                                        acceptSymbol( "(" );
4265                                        visitObjectNameList( node.getReferencedColumnList( ) );
4266                                        acceptSymbol( ")" );
4267                                }
4268
4269                                if ( node.getKeyActions( ) != null
4270                                                && node.getKeyActions( ).size( ) > 0 )
4271                                {
4272                                        for ( int i = 0; i < node.getKeyActions( ).size( ); i++ )
4273                                        {
4274                                                TKeyAction keyAction = node.getKeyActions( )
4275                                                                .getElement( i );
4276                                                preVisit( keyAction );
4277                                        }
4278                                }
4279
4280                                break;
4281                        case reference :
4282                                acceptKeyword( "references" );
4283                                if ( node.getReferencedObject( ) != null )
4284                                {
4285                                        node.getReferencedObject( ).accept( this );
4286                                }
4287
4288                                if ( node.getReferencedColumnList( ) != null )
4289                                {
4290                                        acceptSymbol( "(" );
4291                                        visitObjectNameList( node.getReferencedColumnList( ) );
4292                                        acceptSymbol( ")" );
4293                                }
4294
4295                                if ( node.getKeyActions( ) != null
4296                                                && node.getKeyActions( ).size( ) > 0 )
4297                                {
4298                                        for ( int i = 0; i < node.getKeyActions( ).size( ); i++ )
4299                                        {
4300                                                TKeyAction keyAction = node.getKeyActions( )
4301                                                                .getElement( i );
4302                                                preVisit( keyAction );
4303                                        }
4304                                }
4305
4306                                break;
4307                        case default_value :
4308                                acceptKeyword( "default" );
4309                                node.getDefaultExpression( ).accept( this );
4310                                //add by grq 2023.04.29 issue=I6ZJ3V
4311                                if (node.getForObjectName()!= null){
4312                                        acceptKeyword( "for" );
4313                                        node.getForObjectName().accept(this);
4314                                }
4315                                //end by grq
4316                                break;
4317                        default :
4318                                break;
4319                }
4320
4321                if (node.getWithIndexoption() != null){
4322                        acceptNewline();
4323                        visitNodeByToken(node.getWithIndexoption());
4324                }
4325                if (node.getOnFilegroup() != null){
4326                        acceptNewline();
4327                        visitNodeByToken(node.getOnFilegroup());
4328                }
4329
4330        }
4331
4332        public void preVisit( TKeyAction node )
4333        {
4334                if ( node.getActionType( ) == EKeyActionType.delete )
4335                {
4336                        acceptKeyword( "on" );
4337                        acceptKeyword( "delete" );
4338                }
4339
4340                if ( node.getActionType( ) == EKeyActionType.update )
4341                {
4342                        acceptKeyword( "on" );
4343                        acceptKeyword( "update" );
4344                }
4345
4346                if ( node.getKeyReference( ) != null )
4347                {
4348                        preVisit( node.getKeyReference( ) );
4349                }
4350        }
4351
4352        public void preVisit( TKeyReference node )
4353        {
4354                if ( node.getReferenceType( ) == EKeyReferenceType.set_null )
4355                {
4356                        acceptKeyword( "set" );
4357                        acceptKeyword( "null" );
4358                }
4359
4360                if ( node.getReferenceType( ) == EKeyReferenceType.set_default )
4361                {
4362                        acceptKeyword( "set" );
4363                        acceptKeyword( "default" );
4364                }
4365
4366                if ( node.getReferenceType( ) == EKeyReferenceType.cascade )
4367                {
4368                        acceptKeyword( "cascade" );
4369                }
4370
4371                if ( node.getReferenceType( ) == EKeyReferenceType.restrict )
4372                {
4373                        acceptKeyword( "restrict" );
4374                }
4375
4376                if ( node.getReferenceType( ) == EKeyReferenceType.no_action )
4377                {
4378                        acceptKeyword( "no" );
4379                        acceptKeyword( "action" );
4380                }
4381        }
4382
4383        public void preVisit( TTypeName node )
4384        {
4385                acceptKeyword( node.getDataTypeName( ) );
4386
4387                switch ( node.getDataType( ) )
4388                {
4389                        case bigint_t :
4390                        case bit_t :
4391                        case money_t :
4392                        case smallmoney_t :
4393                        case smallint_t :
4394                        case tinyint_t :
4395                        case real_t :
4396                        case smalldatetime_t :
4397                        case datetime_t :
4398                        case datetime2_t :
4399                        case text_t :
4400                        case ntext_t :
4401                        case image_t :
4402                        case rowversion_t :
4403                        case uniqueidentifier_t :
4404                        case sql_variant_t :
4405                        case binary_float_t :
4406                        case binary_double_t :
4407                        case integer_t :
4408                        case int_t :
4409                        case double_t :
4410                        case date_t :
4411                                if ( node.getPrecision( ) != null )
4412                                {
4413                                        acceptSymbol( "(" );
4414                                        node.getPrecision( ).accept( this );
4415                                        if ( node.getScale( ) != null )
4416                                        {
4417                                                acceptSymbol( "," );
4418                                                node.getScale( ).accept( this );
4419                                        }
4420                                        acceptSymbol( ")" );
4421                                }
4422                                break;
4423
4424                        case binary_t :
4425                        case varbinary_t :
4426                        case long_t :
4427                        case raw_t :
4428                        case long_raw_t :
4429                        case blob_t :
4430                        case clob_t :
4431                        case nclob_t :
4432                        case bfile_t :
4433                        case urowid_t :
4434                                if ( node.getLength( ) != null )
4435                                {
4436                                        acceptSymbol( "(" );
4437                                        node.getLength( ).accept( this );
4438                                        acceptSymbol( ")" );
4439                                }
4440                                break;
4441                        case timestamp_t :
4442                                if ( node.getScale( ) != null )
4443                                {
4444                                        acceptSymbol( "(" );
4445                                        node.getScale( ).accept( this );
4446                                        acceptSymbol( ")" );
4447                                }
4448                                break;
4449                        case decimal_t :
4450                        case dec_t :
4451                        case numeric_t :
4452                        case number_t :
4453                        case float_t :
4454
4455                                if ( node.getPrecision( ) != null )
4456                                {
4457                                        acceptSymbol( "(" );
4458                                        node.getPrecision( ).accept( this );
4459                                        if ( node.getScale( ) != null )
4460                                        {
4461                                                acceptSymbol( "," );
4462                                                node.getScale( ).accept( this );
4463                                        }
4464                                        acceptSymbol( ")" );
4465                                }
4466                                break;
4467
4468                        case char_t :
4469                        case character_t :
4470                        case varchar_t :
4471                        case nchar_t :
4472                        case nvarchar_t :
4473                        case ncharacter_t :
4474                        case nvarchar2_t :
4475                        case varchar2_t :
4476                                if ( node.isVarying( ) )
4477                                        acceptKeyword( "varying" );
4478                                if ( node.getLength( ) != null )
4479                                {
4480                                        acceptSymbol( "(" );
4481                                        node.getLength( ).accept( this );
4482                                        if ( node.isByteUnit( ) )
4483                                                acceptKeyword( "byte" );
4484                                        if ( node.isCharUnit( ) )
4485                                                acceptKeyword( "char" );
4486                                        acceptSymbol( ")" );
4487                                }
4488                                if ( node.getCharsetName( ) != null )
4489                                {
4490                                        if ( node.getGsqlparser( ) != null
4491                                                        && node.getGsqlparser( ).getDbVendor( ) == EDbVendor.dbvmysql )
4492                                        {
4493                                                acceptKeyword( "CHARACTER" );
4494                                                acceptKeyword( "SET" );
4495                                                acceptSpace( 1 );
4496                                                acceptIdentifier( node.getCharsetName( ) );
4497                                        }
4498                                        else
4499                                        {
4500                                                acceptSpace( 1 );
4501                                                acceptIdentifier( node.getCharsetName( ) );
4502                                        }
4503                                }
4504                                break;
4505                        case datetimeoffset_t :
4506                        //case datetime2_t :
4507                        case time_t :
4508                                if ( node.getFractionalSecondsPrecision( ) != null )
4509                                {
4510                                        acceptSymbol( "(" );
4511                                        node.getFractionalSecondsPrecision( ).accept( this );
4512                                        acceptSymbol( ")" );
4513                                }
4514                                break;
4515                        case timestamp_with_time_zone_t :
4516
4517                                if ( node.getFractionalSecondsPrecision( ) != null )
4518                                {
4519                                        acceptSymbol( "(" );
4520                                        node.getFractionalSecondsPrecision( ).accept( this );
4521                                        acceptSymbol( ")" );
4522                                }
4523                                acceptKeyword( "with" );
4524                                acceptKeyword( "time" );
4525                                acceptKeyword( "zone" );
4526                                break;
4527                        case timestamp_with_local_time_zone_t :
4528                                if ( node.getFractionalSecondsPrecision( ) != null )
4529                                {
4530                                        acceptSymbol( "(" );
4531                                        node.getFractionalSecondsPrecision( ).accept( this );
4532                                        acceptSymbol( ")" );
4533                                }
4534                                acceptKeyword( "with" );
4535                                acceptKeyword( "local" );
4536                                acceptKeyword( "time" );
4537                                acceptKeyword( "zone" );
4538                                break;
4539                        case interval_year_to_month_t :
4540                                if ( node.getPrecision( ) != null )
4541                                {
4542                                        acceptSymbol( "(" );
4543                                        node.getPrecision( ).accept( this );
4544                                        acceptSymbol( ")" );
4545                                }
4546                                acceptKeyword( "to" );
4547                                acceptKeyword( "month" );
4548                                break;
4549                        case interval_day_to_second_t :
4550                                if ( node.getPrecision( ) != null )
4551                                {
4552                                        acceptSymbol( "(" );
4553                                        node.getPrecision( ).accept( this );
4554                                        acceptSymbol( ")" );
4555                                }
4556                                acceptKeyword( "to" );
4557                                acceptKeyword( "second" );
4558                                if ( node.getSecondsPrecision( ) != null )
4559                                {
4560                                        acceptSymbol( "(" );
4561                                        node.getSecondsPrecision( ).accept( this );
4562                                        acceptSymbol( ")" );
4563                                }
4564                                break;
4565                        case generic_t :
4566                                // if ( node.getDataTypeObjectName( ) != null )
4567                                // {
4568                                // acceptSpace( 1 );
4569                                // node.getDataTypeObjectName( ).accept( this );
4570                                // }
4571                                // else if ( node.getDataTypeName( ) != null )
4572                                // {
4573                                // acceptSpace( 1 );
4574                                // acceptIdentifier( node.getDataTypeName( ) );
4575                                // }
4576                                break;
4577                        default :
4578                                break;
4579                }
4580
4581                if (node.getArrays() != null && node.getArrays().size() > 0)
4582                {
4583                        for (int i = 0; i < node.getArrays().size(); i++)
4584                        {
4585                                TIndices array = node.getArrays().getElement(i);
4586                                if (array.getAttributeName() != null)
4587                                {
4588                                        array.getAttributeName().accept(this);
4589                                }
4590                                acceptSymbol("[");
4591                                if (array.getLowerSubscript() != null)
4592                                {
4593                                        array.getLowerSubscript().accept(this);
4594                                }
4595                                if (array.getUpperSubscript() != null)
4596                                {
4597                                        if (array.getLowerSubscript() != null)
4598                                        {
4599                                                acceptSymbol(":");
4600                                        }
4601                                        array.getUpperSubscript().accept(this);
4602                                }
4603                                acceptSymbol("]");
4604                        }
4605                }
4606        }
4607
4608        public void preVisit( TKeepDenseRankClause node )
4609        {
4610                acceptKeyword( "keep" );
4611                acceptSymbol( "(" );
4612                acceptKeyword( "dense_rank" );
4613                if ( node.isFirst( ) )
4614                        acceptKeyword( "first" );
4615                if ( node.isLast( ) )
4616                        acceptKeyword( "last" );
4617                node.getOrderBy( ).accept( this );
4618                acceptSymbol( ")" );
4619        }
4620
4621        public void preVisit( TRollupCube node )
4622        {
4623                if ( node.getOperation( ) == TRollupCube.cube )
4624                {
4625                        acceptKeyword( "cube" );
4626                }
4627                else if ( node.getOperation( ) == TRollupCube.rollup )
4628                {
4629                        acceptKeyword( "rollup" );
4630                }
4631                acceptSymbol( "(" );
4632                visitExprList( node.getItems( ) );
4633                acceptSymbol( ")" );
4634        }
4635
4636        public void preVisit( TGroupingSet node )
4637        {
4638                acceptKeyword( "grouping" );
4639                acceptKeyword( "sets" );
4640                acceptSymbol( "(" );
4641                for ( int i = 0; i < node.getItems( ).size( ); i++ )
4642                {
4643                        node.getItems( ).getGroupingSetItem( i ).accept( this );
4644                        if ( i != node.getItems( ).size( ) - 1 )
4645                                acceptSymbol( "," );
4646                }
4647                acceptSymbol( ")" );
4648
4649        }
4650
4651        public void preVisit( TGroupingSetItem node )
4652        {
4653                if ( node.getRollupCubeClause( ) != null )
4654                {
4655                        node.getRollupCubeClause( ).accept( this );
4656                }
4657                else if ( node.getGrouping_expression( ) != null )
4658                {
4659                        node.getGrouping_expression( ).accept( this );
4660                }
4661
4662        }
4663
4664        public void preVisit( TReturningClause node )
4665        {
4666                acceptKeyword( "returning" );
4667                visitExprList( node.getColumnValueList( ) );
4668                if ( node.isBulkCollect( ) )
4669                {
4670                        acceptKeyword( "bulk" );
4671                        acceptKeyword( "collect" );
4672                }
4673                acceptKeyword( "into" );
4674                visitExprList( node.getVariableList( ) );
4675        }
4676
4677        public void preVisit( TDropIndexSqlStatement dropIndex )
4678        {
4679                acceptKeyword( "drop" );
4680                acceptKeyword( "index" );
4681
4682
4683                if ( dropIndex.getDropIndexItemList( ) != null
4684                                && dropIndex.getDropIndexItemList( ).size( ) > 0 )
4685                {
4686                        for ( int i = 0; i < dropIndex.getDropIndexItemList( ).size( ); i++ )
4687                        {
4688                                TDropIndexItem item = dropIndex.getDropIndexItemList( )
4689                                                .getDropIndexItem( i );
4690                                if ( item.getIndexName( ) != null )
4691                                {
4692                                        item.getIndexName( ).accept( this );
4693                                }
4694                                if ( item.getObjectName( ) != null )
4695                                {
4696                                        acceptKeyword( "on" );
4697                                        item.getObjectName( ).accept( this );
4698                                }
4699                        }
4700                }else{
4701                        if ( dropIndex.getIndexName( ) != null )
4702                        {
4703                                dropIndex.getIndexName( ).accept( this );
4704                        }
4705                }
4706        }
4707
4708        public void preVisit( TCreateIndexSqlStatement createIndex )
4709        {
4710                acceptKeyword( "create" );
4711
4712                if ( createIndex.isNonClustered( ) )
4713                {
4714                        acceptKeyword( "nonclustered" );
4715                }
4716
4717                if ( createIndex.isClustered( ) )
4718                {
4719                        acceptKeyword( "clustered" );
4720                }
4721
4722                if ( createIndex.getIndexType( ) == EIndexType.itUnique )
4723                {
4724                        acceptKeyword( "unique" );
4725                }
4726
4727                acceptKeyword( "index" );
4728
4729                if ( createIndex.getIndexName( ) != null )
4730                {
4731                        createIndex.getIndexName( ).accept( this );
4732                }
4733
4734                if ( createIndex.getTableName( ) != null )
4735                {
4736                        acceptKeyword( "on" );
4737
4738                        createIndex.getTableName( ).accept( this );
4739
4740                        if ( createIndex.getColumnNameList( ) != null
4741                                        && createIndex.getColumnNameList( ).size( ) > 0 )
4742                        {
4743                                acceptSpace( 1 );
4744                                acceptSymbol( "(" );
4745                                createIndex.getColumnNameList( ).accept( this );
4746                                acceptSymbol( ")" );
4747                        }
4748                }
4749                if ( createIndex.getFilegroupOrPartitionSchemeName( ) != null )
4750                {
4751                        acceptKeyword( "on" );
4752
4753                        createIndex.getFilegroupOrPartitionSchemeName( ).accept( this );
4754
4755                        if ( createIndex.getPartitionSchemeColumns( ) != null
4756                                        && createIndex.getPartitionSchemeColumns( ).size( ) > 0 )
4757                        {
4758                                acceptSpace( 1 );
4759                                acceptSymbol( "(" );
4760                                createIndex.getPartitionSchemeColumns( ).accept( this );
4761                                acceptSymbol( ")" );
4762                        }
4763                }
4764        }
4765
4766        public void preVisit( TOrderByItemList orderByList )
4767        {
4768                for ( int i = 0; i < orderByList.size( ); i++ )
4769                {
4770                        orderByList.getOrderByItem( i ).accept( this );
4771                        if ( i != orderByList.size( ) - 1 )
4772                                acceptSymbol( "," );
4773                }
4774        }
4775
4776        public void preVisit( TUseDatabase useDataBase )
4777        {
4778                acceptKeyword( "use" );
4779
4780                if ( useDataBase.getDatabaseName( ) != null )
4781                {
4782                        useDataBase.getDatabaseName( ).accept( this );
4783                }
4784        }
4785
4786        public void preVisit( TPlsqlCreateProcedure procedure )
4787        {
4788                acceptKeyword( "create" );
4789                acceptKeyword( "procedure" );
4790
4791                if ( procedure.getProcedureName( ) != null )
4792                {
4793                        procedure.getProcedureName( ).accept( this );
4794                }
4795
4796                if ( procedure.getParameterDeclarations( ) != null
4797                                && procedure.getParameterDeclarations( ).size( ) > 0 )
4798                {
4799                        acceptSymbol( "(" );
4800                        procedure.getParameterDeclarations( ).accept( this );
4801                        acceptSymbol( ")" );
4802                }
4803
4804                acceptNewline( );
4805
4806                if ( procedure.getInvokerRightsClause( ) != null )
4807                {
4808                        procedure.getInvokerRightsClause( ).accept( this );
4809                }
4810
4811                acceptKeyword( "as" );
4812
4813                if ( procedure.getDeclareStatements( ) != null
4814                                && procedure.getDeclareStatements( ).size( ) > 0 )
4815                {
4816                        acceptNewline( );
4817                        procedure.getDeclareStatements( ).accept( this );
4818                        if ( procedure.getDeclareStatements( ).size( ) == 1 )
4819                        {
4820                                acceptSemicolon( );
4821                        }
4822                }
4823
4824                acceptNewline( );
4825                acceptKeyword( "begin" );
4826
4827                if ( procedure.getBodyStatements( ) != null
4828                                && procedure.getBodyStatements( ).size( ) > 0 )
4829                {
4830                        acceptNewline( );
4831                        procedure.getBodyStatements( ).accept( this );
4832                        if ( procedure.getBodyStatements( ).size( ) == 1 )
4833                        {
4834                                acceptSemicolon( );
4835                        }
4836                }
4837
4838                acceptNewline( );
4839                acceptKeyword( "end" );
4840                acceptSemicolon( );
4841        }
4842
4843        public void preVisit( TInvokerRightsClause clause )
4844        {
4845                acceptKeyword( "authid" );
4846                if ( clause.getDefiner( ) != null )
4847                {
4848                        clause.getDefiner( ).accept( this );
4849                }
4850        }
4851
4852        void visitPrecisionScale( TConstant precision, TConstant scale )
4853        {
4854                if ( precision != null )
4855                {
4856                        acceptSymbol( "(" );
4857                        precision.accept( this );
4858                        if ( scale != null )
4859                        {
4860                                acceptSymbol( "," );
4861                                scale.accept( this );
4862                        }
4863                        acceptSymbol( ")" );
4864                }
4865        }
4866
4867        void visitExprList( TExpressionList expressionList )
4868        {
4869                for ( int i = 0; i < expressionList.size( ); i++ )
4870                {
4871                        expressionList.getExpression( i ).accept( this );
4872                        if ( i != expressionList.size( ) - 1 )
4873                                acceptSymbol( "," );
4874                }
4875        }
4876
4877        void visitObjectNameList( TObjectNameList objectNameList )
4878        {
4879                for ( int i = 0; i < objectNameList.size( ); i++ )
4880                {
4881                        objectNameList.getObjectName( i ).accept( this );
4882                        if ( i != objectNameList.size( ) - 1 )
4883                                acceptSymbol( "," );
4884                }
4885        }
4886
4887        void visitCTEList( TCTEList cteList )
4888        {
4889                for ( int i = 0; i < cteList.size( ); i++ )
4890                {
4891                        cteList.getCTE( i ).accept( this );
4892                        if ( i != cteList.size( ) - 1 )
4893                        {
4894                                acceptSymbol( "," );
4895                                acceptNewline( );
4896                        }
4897                }
4898        }
4899
4900        void visitJoinList( TJoinList joinList )
4901        {
4902                for ( int i = 0; i < joinList.size( ); i++ )
4903                {
4904                        acceptNewline( );
4905                        joinList.getJoin( i ).accept( this );
4906                        if ( i != joinList.size( ) - 1 )
4907                                acceptSymbol( "," );
4908                }
4909        }
4910
4911        void visitResultColumnList( TResultColumnList resultColumnList )
4912        {
4913                for ( int i = 0; i < resultColumnList.size( ); i++ )
4914                {
4915                        resultColumnList.getElement( i ).accept( this );
4916                        if ( i != resultColumnList.size( ) - 1 )
4917                        {
4918                                acceptSymbol( "," );
4919                        }
4920                }
4921        }
4922
4923        void visitNodeByToken( TParseTreeNode node )
4924        {
4925                if ( node.getStartToken( ) == null )
4926                        return;
4927                if ( node.getEndToken( ) == null )
4928                        return;
4929                if ( node.getStartToken( ).container == null )
4930                        return;
4931                acceptSpace( 1 );
4932
4933                TSourceToken nextToken = node.getStartToken( );
4934                while (nextToken != null && nextToken != node.getEndToken( ))
4935                {
4936                        acceptToken( nextToken );
4937                        nextToken = nextToken.getNextTokenInChain( );
4938                }
4939                if (nextToken != null)
4940                {
4941                        acceptToken( nextToken );
4942                }
4943
4944
4945//              if ((node.getStartToken().container !=null) && (node.getStartToken( ).container.size() > node.getEndToken().posinlist)){
4946//                      for ( int i = node.getStartToken( ).posinlist; i <= node.getEndToken( ).posinlist; i++ )
4947//                      {
4948//                              acceptToken( node.getStartToken( ).container.get( i ) );
4949//                      }
4950//              }else{
4951//                      TSourceToken nextToken = node.getStartToken( );
4952//                      while (nextToken != null && nextToken != node.getEndToken( ))
4953//                      {
4954//                              acceptToken( nextToken );
4955//                              nextToken = nextToken.getNextTokenInChain( );
4956//                      }
4957//                      if (nextToken != null)
4958//                      {
4959//                              acceptToken( nextToken );
4960//                      }
4961//              }
4962                acceptSpace( 1 );
4963        }
4964
4965}