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.getOffsetClause( ) != null )
1416                        {
1417                                node.getOffsetClause( ).accept( this );
1418                        }
1419
1420                        if ( node.getFetchFirstClause( ) != null )
1421                        {
1422                                node.getFetchFirstClause( ).accept( this );
1423                        }
1424
1425                        if ( node.getForUpdateClause( ) != null )
1426                        {
1427                                node.getForUpdateClause( ).accept( this );
1428                        }
1429
1430                        if ( node.getComputeClause( ) != null )
1431                        {
1432                                node.getComputeClause( ).accept( this );
1433                        }
1434
1435                        if (node.getOptionClause() != null){
1436                                visitNodeByToken(node.getOptionClause());
1437                        }
1438
1439                        for ( int i = 0; i < node.getParenthesisCount( ); i++ )
1440                        {
1441                                acceptSymbol( ")" );
1442                        }
1443
1444                        return;
1445                }
1446
1447                if ( node.getValueClause( ) != null )
1448                {
1449                        // DB2 values constructor
1450                        return;
1451                }
1452
1453                acceptKeyword( "select" );
1454                if ( node.getSelectDistinct( ) != null )
1455                {
1456                        switch ( node.getSelectDistinct( ).getUniqueRowFilter( ) )
1457                        {
1458                                case urfDistinct :
1459                                        acceptKeyword( "distinct" );
1460                                        break;
1461                                case urfAll :
1462                                        acceptKeyword( "all" );
1463                                        break;
1464                                case urfUnique :
1465                                        acceptKeyword( "unique" );
1466                                        break;
1467                                case urfDistinctOn :
1468                                        acceptKeyword( "distinct" );
1469                                        acceptKeyword( "on" );
1470                                        break;
1471                        }
1472
1473                        if (node.getSelectDistinct( ).getExpressionList( ) != null )
1474                        {
1475                                acceptSymbol( "(" );
1476                                for ( int i = 0; i < node.getSelectDistinct( ).getExpressionList( )
1477                                                .size( ); i++ )
1478                                {
1479                                        node.getSelectDistinct( ).getExpressionList( )
1480                                                        .getElement( i )
1481                                                        .accept( this );
1482                                        if ( i != node.getSelectDistinct( ).getExpressionList( )
1483                                                        .size( ) - 1 )
1484                                        {
1485                                                acceptSymbol( "," );
1486                                        }
1487                                }
1488                                acceptSymbol( ")" );
1489                        }
1490
1491                }
1492
1493                if ( ( node.getOracleHint( ) != null ) )
1494                {
1495                        if ( node.getOracleHint( ).length( ) > 0 )
1496                                acceptOracleHint( node.getOracleHint( ) );
1497                }
1498
1499                if ( node.getTopClause( ) != null )
1500                {
1501                        node.getTopClause( ).accept( this );
1502                }
1503
1504                if (node.getSelectModifiers() != null){
1505                        for(int i=0;i<node.getSelectModifiers().size();i++){
1506                                node.getSelectModifiers().get(i).accept(this);
1507                        }
1508                }
1509
1510                if ( node.getResultColumnList( ) != null )
1511                {
1512                        acceptNewline( );
1513                        visitResultColumnList( node.getResultColumnList( ) );
1514                }
1515                else
1516                {
1517                        // hive transform clause with no select list
1518                }
1519
1520                if ( node.getIntoClause( ) != null )
1521                {
1522                        acceptNewline( );
1523                        node.getIntoClause( ).accept( this );
1524                }
1525
1526                if ( node.joins.size( ) > 0 )
1527                {
1528                        acceptNewline( );
1529                        acceptKeyword( "from" );
1530                        visitJoinList( node.joins );
1531                }
1532
1533                if ( node.getWhereClause( ) != null )
1534                {
1535                        acceptNewline( );
1536                        node.getWhereClause( ).accept( this );
1537                }
1538
1539                if ( node.getHierarchicalClause( ) != null )
1540                {
1541                        acceptNewline( );
1542                        node.getHierarchicalClause( ).accept( this );
1543                }
1544
1545                if ( node.getGroupByClause( ) != null )
1546                {
1547                        acceptNewline( );
1548                        node.getGroupByClause( ).accept( this );
1549                }
1550
1551                if ( node.getQualifyClause( ) != null )
1552                {
1553                        node.getQualifyClause( ).accept( this );
1554                }
1555
1556                for ( int i = 0; i < node.getParenthesisCountBeforeOrder( ); i++ )
1557                {
1558                        acceptSymbol( ")" );
1559                }
1560
1561                if ( node.getOrderbyClause( ) != null )
1562                {
1563                        acceptNewline( );
1564                        node.getOrderbyClause( ).accept( this );
1565                }
1566
1567                if ( node.getLimitClause( ) != null )
1568                {
1569                        node.getLimitClause( ).accept( this );
1570                }
1571
1572                if ( node.getOffsetClause( ) != null )
1573                {
1574                        node.getOffsetClause( ).accept( this );
1575                }
1576
1577                if ( node.getFetchFirstClause( ) != null )
1578                {
1579                        node.getFetchFirstClause( ).accept( this );
1580                }
1581
1582                if ( node.getForUpdateClause( ) != null )
1583                {
1584                        node.getForUpdateClause( ).accept( this );
1585                }
1586
1587                if ( node.getComputeClause( ) != null )
1588                {
1589                        node.getComputeClause( ).accept( this );
1590                }
1591
1592                if (node.getOptionClause() != null){
1593                        visitNodeByToken(node.getOptionClause());
1594                }
1595
1596                if (node.getHintClause() != null){
1597                        visitNodeByToken(node.getHintClause());
1598                }
1599
1600                for ( int i = 0; i < node.getParenthesisCount( ); i++ )
1601                {
1602                        acceptSymbol( ")" );
1603                }
1604
1605        }
1606
1607        public void preVisit( TComputeClause computeClause )
1608        {
1609                for ( int i = 0; i < computeClause.getItems( ).size( ); i++ )
1610                {
1611                        computeClause.getItems( ).getElement( i ).accept( this );
1612                }
1613        }
1614
1615        public void preVisit( TComputeExpr computeExpr )
1616        {
1617                switch ( computeExpr.getComputeFunctionType( ) )
1618                {
1619                        case cftNone :
1620                                break;
1621                        case cftCount :
1622                                acceptKeyword( "count" );
1623                                break;
1624                        case cftMax :
1625                                acceptKeyword( "max" );
1626                                break;
1627                        case cftMin :
1628                                acceptKeyword( "min" );
1629                                break;
1630                        case cftSum :
1631                                acceptKeyword( "sum" );
1632                                break;
1633                        case cftAvg :
1634                                acceptKeyword( "avg" );
1635                                break;
1636                        case cftStdev :
1637                                acceptKeyword( "stdev" );
1638                                break;
1639                        case cftStdevp :
1640                                acceptKeyword( "stdevp" );
1641                                break;
1642                        case cftVar :
1643                                acceptKeyword( "var" );
1644                                break;
1645                        case cftVarp :
1646                                acceptKeyword( "varp" );
1647                                break;
1648                }
1649                acceptSymbol( "(" );
1650                computeExpr.getExpr( ).accept( this );
1651                acceptSymbol( ")" );
1652
1653        }
1654
1655        public void preVisit( TComputeClauseItem computeClauseItem )
1656        {
1657                acceptNewline( );
1658                acceptKeyword( "compute" );
1659                if ( computeClauseItem.getComputerExprList( ) != null )
1660                {
1661                        for ( int i = 0; i < computeClauseItem.getComputerExprList( )
1662                                        .size( ); i++ )
1663                        {
1664                                computeClauseItem.getComputerExprList( )
1665                                                .getElement( i )
1666                                                .accept( this );
1667                                if ( i != computeClauseItem.getComputerExprList( ).size( ) - 1 )
1668                                {
1669                                        acceptSymbol( "," );
1670                                }
1671                        }
1672                }
1673
1674                if ( computeClauseItem.getByExprlist( ) != null )
1675                {
1676                        acceptKeyword( "by" );
1677                        for ( int i = 0; i < computeClauseItem.getByExprlist( ).size( ); i++ )
1678                        {
1679                                computeClauseItem.getByExprlist( )
1680                                                .getExpression( i )
1681                                                .accept( this );
1682                                if ( i != computeClauseItem.getByExprlist( ).size( ) - 1 )
1683                                {
1684                                        acceptSymbol( "," );
1685                                }
1686                        }
1687                }
1688        }
1689
1690        public void preVisit( TCreateViewSqlStatement stmt )
1691        {
1692                if ( stmt.getCteList( ) != null )
1693                {
1694                        acceptKeyword( "with" );
1695                        visitCTEList( stmt.getCteList( ) );
1696                }
1697
1698                acceptKeyword( "create" );
1699
1700                if ( stmt.getStReplace( ) != null )
1701                {
1702                        acceptKeyword( "or" );
1703                        acceptKeyword( "replace" );
1704                }
1705
1706                if ( stmt.getStForce( ) != null )
1707                {
1708                        if ( stmt.isForce( ) )
1709                        {
1710                                acceptKeyword( "force" );
1711                        }
1712                        if ( stmt.isNoForce( ) )
1713                        {
1714                                acceptKeyword( "noforce" );
1715                        }
1716                }
1717
1718                acceptKeyword( "view" );
1719                stmt.getViewName( ).accept( this );
1720                if ( stmt.getViewAliasClause( ) != null )
1721                {
1722                        stmt.getViewAliasClause( ).accept( this );
1723                }
1724                acceptNewline( );
1725                acceptKeyword( "as" );
1726                acceptNewline( );
1727
1728                if ( stmt.getSubquery( ) != null )
1729                {
1730                        stmt.getSubquery( ).accept( this );
1731                }
1732
1733                if ( stmt.getRestrictionClause( ) != null )
1734                {
1735                        acceptNewline( );
1736                        preVisit( stmt.getRestrictionClause( ) );
1737                }
1738        }
1739
1740        public void preVisit( TRestrictionClause clause )
1741        {
1742                if ( clause.getRestrictionType( ) == ERestrictionType.withCheckOption )
1743                {
1744                        acceptKeyword( "with" );
1745                        acceptKeyword( "check" );
1746                        acceptKeyword( "option" );
1747                }
1748                else if ( clause.getRestrictionType( ) == ERestrictionType.withReadOnly )
1749                {
1750                        acceptKeyword( "with" );
1751                        acceptKeyword( "read" );
1752                        acceptKeyword( "only" );
1753                }
1754                else if ( clause.getRestrictionType( ) == ERestrictionType.withLocalCheckOption )
1755                {
1756                        acceptKeyword( "with" );
1757                        acceptKeyword( "local" );
1758                        acceptKeyword( "check" );
1759                        acceptKeyword( "option" );
1760                }
1761                else if ( clause.getRestrictionType( ) == ERestrictionType.withCascadedCheckOption )
1762                {
1763                        acceptKeyword( "with" );
1764                        acceptKeyword( "cascaded" );
1765                        acceptKeyword( "check" );
1766                        acceptKeyword( "option" );
1767                }
1768                if ( clause.getConstraintName( ) != null )
1769                {
1770                        clause.getConstraintName( ).accept( this );
1771                }
1772        }
1773
1774        public void preVisit( TViewAliasClause clause )
1775        {
1776                acceptSymbol( "(" );
1777                visitViewAliasItemList( clause.getViewAliasItemList( ) );
1778                acceptSymbol( ")" );
1779        }
1780
1781        void visitViewAliasItemList( TViewAliasItemList viewAliasItemList )
1782        {
1783                for ( int i = 0; i < viewAliasItemList.size( ); i++ )
1784                {
1785                        TViewAliasItem aliasItem = viewAliasItemList.getViewAliasItem( i );
1786                        visitViewAliasItem( aliasItem );
1787                        if ( i != viewAliasItemList.size( ) - 1 )
1788                                acceptSymbol( "," );
1789                }
1790        }
1791
1792        private void visitViewAliasItem( TViewAliasItem aliasItem )
1793        {
1794                aliasItem.getAlias( ).accept( this );
1795        }
1796
1797        public void preVisit( TResultColumn node )
1798        {
1799                node.getExpr( ).accept( this );
1800                if (( node.getAliasClause( ) != null )&&(node.getExpr().getExpressionType() != EExpressionType.sqlserver_proprietary_column_alias_t))
1801                {
1802                        acceptSpace( 1 );
1803                        node.getAliasClause( ).accept( this );
1804                }
1805        }
1806
1807        public void preVisit( TColumnDefinitionList node )
1808        {
1809
1810                for ( int i = 0; i < node.size( ); i++ )
1811                {
1812                        node.getColumn( i ).accept( this );
1813                        if ( i != node.size( ) - 1 )
1814                        {
1815                                acceptSymbol( "," );
1816                        }
1817                }
1818        }
1819
1820        public void preVisit( TObjectNameList node )
1821        {
1822
1823                for ( int i = 0; i < node.size( ); i++ )
1824                {
1825                        node.getObjectName( i ).accept( this );
1826                        if ( i != node.size( ) - 1 )
1827                        {
1828                                acceptSymbol( "," );
1829                        }
1830                }
1831        }
1832
1833        public void preVisit( TConstraintList node )
1834        {
1835
1836                for ( int i = 0; i < node.size( ); i++ )
1837                {
1838                        node.getConstraint( i ).accept( this );
1839                        if ( i != node.size( ) - 1 )
1840                        {
1841                                acceptSymbol( "," );
1842                        }
1843                }
1844        }
1845
1846        public void preVisit( TParameterDeclarationList params )
1847        {
1848                for ( int i = 0; i < params.size( ); i++ )
1849                {
1850                        TParameterDeclaration param = params.getParameterDeclarationItem( i );
1851                        param.accept( this );
1852                        if ( i != params.size( ) - 1 )
1853                        {
1854                                acceptSymbol( "," );
1855                        }
1856                }
1857        }
1858
1859        public void preVisit( TParameterDeclaration param )
1860        {
1861                if ( param.getParameterName( ) != null )
1862                {
1863                        param.getParameterName( ).accept( this );
1864                }
1865                if ( param.getDataType( ) != null )
1866                {
1867                        param.getDataType( ).accept( this );
1868                }
1869        }
1870
1871        public void preVisit( TMssqlCreateFunction function )
1872        {
1873                acceptKeyword( "create" );
1874                acceptKeyword( "function" );
1875
1876                if ( function.getFunctionName( ) != null )
1877                {
1878                        function.getFunctionName( ).accept( this );
1879                }
1880
1881                if ( function.getParameterDeclarations( ) != null
1882                                && function.getParameterDeclarations( ).size( ) > 0 )
1883                {
1884                        acceptSymbol( "(" );
1885                        function.getParameterDeclarations( ).accept( this );
1886                        acceptSymbol( ")" );
1887                }
1888
1889                if ( function.getReturnDataType( ) != null )
1890                {
1891                        acceptNewline( );
1892                        acceptSpace( 4 );
1893                        acceptKeyword( "returns" );
1894                        function.getReturnDataType( ).accept( this );
1895                }
1896
1897                acceptNewline( );
1898                acceptKeyword( "as" );
1899                acceptNewline( );
1900
1901                if ( function.getBodyStatements( ) != null )
1902                {
1903                        function.getBodyStatements( ).accept( this );
1904                }
1905        }
1906
1907
1908        public void preVisit( TDmlEventItem node ){
1909                switch (node.getDmlType()){
1910                        case sstinsert:
1911                                acceptKeyword( "insert" );
1912                                break;
1913                        case sstdelete:
1914                                acceptKeyword( "delete" );
1915                                break;
1916                        case sstupdate:
1917                                acceptKeyword( "update" );
1918                                if (node.getColumnList() != null){
1919                                        acceptKeyword("of");
1920                                        node.getColumnList().accept(this);
1921                                }
1922                                break;
1923                }
1924        }
1925
1926        public void preVisit( TDdlEventItem node ){
1927                acceptIdentifier(node.getEventName().toString());
1928        }
1929
1930        public void preVisit( TSimpleDmlTriggerClause node ){
1931                acceptNewline( );
1932                acceptSpace( 4 );
1933
1934                acceptKeyword( "on" );
1935                TDmlEventClause dmlEventClause = (TDmlEventClause)node.getEventClause();
1936                dmlEventClause.getTableName().accept(this);
1937
1938                acceptNewline( );
1939                switch(node.getActionTime()){
1940                        case tatFor:
1941                                acceptKeyword( "for" );
1942                                break;
1943                        case tatBefore:
1944                                acceptKeyword( "before" );
1945                                break;
1946                        case tatAfter:
1947                                acceptKeyword( "after" );
1948                                break;
1949                        case tatInsteadOf:
1950                                acceptKeyword( "instead of" );
1951                                break;
1952                }
1953
1954                for(int i=0;i<dmlEventClause.getEventItems().size();i++){
1955                        dmlEventClause.getEventItems().get(i).accept(this);
1956                        if (i != dmlEventClause.getEventItems().size() - 1){
1957                                acceptSymbol( "," );
1958                        }
1959                }
1960
1961
1962        }
1963
1964        public void preVisit( TCreateTriggerStmt trigger )
1965        {
1966                if ( trigger.isAlterTrigger( ) )
1967                        acceptKeyword( "alter" );
1968                else
1969                        acceptKeyword( "create" );
1970                acceptKeyword( "trigger" );
1971
1972                if ( trigger.getTriggerName( ) != null )
1973                {
1974                        trigger.getTriggerName( ).accept( this );
1975                }
1976
1977                trigger.getTriggeringClause().accept(this);
1978
1979//              if ( trigger.getOnTable( ) != null )
1980//              {
1981//                      acceptNewline( );
1982//                      acceptSpace( 4 );
1983//
1984//                      acceptKeyword( "on" );
1985//                      trigger.getOnTable( ).accept( this );
1986//              }
1987//
1988//              acceptNewline( );
1989//
1990//              if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpFor )
1991//                      acceptKeyword( "for" );
1992//              if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpTinsteadOf )
1993//              {
1994//                      acceptKeyword( "instead" );
1995//                      acceptKeyword( "of" );
1996//              }
1997//              if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpAfter )
1998//                      acceptKeyword( "after" );
1999//              if ( trigger.getTimingPoint( ) == ETriggerTimingPoint.ttpBefore )
2000//                      acceptKeyword( "before" );
2001//
2002//              if ( trigger.getDmlTypes( ) != null
2003//                              && trigger.getDmlTypes( ).size( ) > 0 )
2004//              {
2005//                      EnumSet<ETriggerDmlType> types = trigger.getDmlTypes( );
2006//                      for ( Iterator<ETriggerDmlType> iterator = types.iterator( ); iterator.hasNext( ); )
2007//                      {
2008//                              ETriggerDmlType eTriggerDmlType = (ETriggerDmlType) iterator.next( );
2009//                              if ( eTriggerDmlType == ETriggerDmlType.tdtInsert )
2010//                              {
2011//                                      acceptKeyword( "insert" );
2012//                              }
2013//                              if ( eTriggerDmlType == ETriggerDmlType.tdtUpdate )
2014//                              {
2015//                                      acceptKeyword( "update" );
2016//                              }
2017//                              if ( eTriggerDmlType == ETriggerDmlType.tdtDelete )
2018//                              {
2019//                                      acceptKeyword( "delete" );
2020//                              }
2021//                              if ( iterator.hasNext( ) )
2022//                              {
2023//                                      acceptSymbol( "," );
2024//                              }
2025//                      }
2026//              }
2027
2028                acceptNewline( );
2029                acceptKeyword( "as" );
2030                acceptNewline( );
2031
2032                if ( trigger.getBodyStatements( ) != null )
2033                {
2034                        trigger.getBodyStatements( ).accept( this );
2035                }
2036        }
2037
2038        public void preVisit( TProcedureOption option )
2039        {
2040                if ( option.getOptionType( ) == EProcedureOptionType.potExecuteAs )
2041                {
2042                        acceptKeyword( "execute" );
2043                        acceptKeyword( "as" );
2044                        acceptKeyword( "caller" );
2045                }
2046                if ( option.getOptionType( ) == EProcedureOptionType.potCalledOnNullInput )
2047                {
2048                        acceptKeyword( "called" );
2049                        acceptKeyword( "on" );
2050                        acceptKeyword( "null" );
2051                        acceptKeyword( "input" );
2052                }
2053                if ( option.getOptionType( ) == EProcedureOptionType.potEncryption )
2054                {
2055                        acceptKeyword( "encryption" );
2056                }
2057                if ( option.getOptionType( ) == EProcedureOptionType.potNativeCompilation )
2058                {
2059                        acceptKeyword( "native" );
2060                        acceptKeyword( "compilation" );
2061                }
2062                if ( option.getOptionType( ) == EProcedureOptionType.potRecompile )
2063                {
2064                        acceptKeyword( "recompile" );
2065                }
2066                if ( option.getOptionType( ) == EProcedureOptionType.potReturnsNullOnNullInput )
2067                {
2068                        acceptKeyword( "returns" );
2069                        acceptKeyword( "null" );
2070                        acceptKeyword( "on" );
2071                        acceptKeyword( "null" );
2072                        acceptKeyword( "input" );
2073                }
2074                if ( option.getOptionType( ) == EProcedureOptionType.potSchemaBinding )
2075                {
2076                        acceptKeyword( "schema" );
2077                        acceptKeyword( "binding" );
2078                }
2079        }
2080
2081        public void preVisit( TMssqlCreateProcedure procedure )
2082        {
2083                acceptKeyword( "create" );
2084                acceptKeyword( "procedure" );
2085
2086                if ( procedure.getProcedureName( ) != null )
2087                {
2088                        procedure.getProcedureName( ).accept( this );
2089                }
2090
2091                acceptNewline( );
2092                acceptSpace( 4 );
2093
2094                if ( procedure.getParameterDeclarations( ) != null
2095                                && procedure.getDeclareStatements( ).size( ) > 0 )
2096                {
2097                        procedure.getParameterDeclarations( ).accept( this );
2098                }
2099
2100                if ( procedure.getProcedureOptions( ) != null
2101                                && procedure.getProcedureOptions( ).size( ) > 0 )
2102                {
2103                        acceptKeyword( "with" );
2104
2105                        for ( int i = 0; i < procedure.getProcedureOptions( ).size( ); i++ )
2106                        {
2107                                TProcedureOption option = procedure.getProcedureOptions( )
2108                                                .getElement( i );
2109                                option.accept( this );
2110                                if ( i != procedure.getProcedureOptions( ).size( ) - 1 )
2111                                {
2112                                        acceptSymbol( "," );
2113                                }
2114                        }
2115                }
2116
2117                if ( procedure.isForReplication( ) )
2118                {
2119                        acceptKeyword( "for" );
2120                        acceptKeyword( "replication" );
2121                }
2122
2123                acceptNewline( );
2124                acceptKeyword( "as" );
2125                acceptNewline( );
2126
2127                acceptKeyword( "begin" );
2128                acceptNewline( );
2129
2130                if ( procedure.getBodyStatements( ) != null )
2131                {
2132                        procedure.getBodyStatements( ).accept( this );
2133                }
2134
2135                acceptKeyword( "end" );
2136        }
2137
2138        public void preVisit( TMssqlFetch stmt )
2139        {
2140                acceptKeyword( "fetch" );
2141                acceptKeyword( "from" );
2142                if ( stmt.getCursorName( ) != null )
2143                {
2144                        stmt.getCursorName( ).accept( this );
2145                }
2146                acceptKeyword( "into" );
2147                if ( stmt.getVariableNames( ) != null )
2148                {
2149                        stmt.getVariableNames( ).accept( this );
2150                }
2151        }
2152        public void preVisit( TMssqlBlock block )
2153        {
2154                acceptKeyword( "begin" );
2155                acceptNewline( );
2156                if ( block.getBodyStatements( ) != null )
2157                {
2158                        block.getBodyStatements( ).accept( this );
2159                        acceptNewline( );
2160                }
2161                acceptKeyword( "end" );
2162        }
2163
2164        public void preVisit( TMssqlRollback rollback )
2165        {
2166                acceptKeyword( "rollback" );
2167                if ( rollback.getTrans_or_work( ) != null )
2168                {
2169                        acceptToken( rollback.getTrans_or_work( ) );
2170                }
2171                if ( rollback.getTransactionName( ) != null )
2172                {
2173                        rollback.getTransactionName( ).accept( this );
2174                }
2175        }
2176
2177        public void preVisit( TMssqlRaiserror raiseError )
2178        {
2179                acceptKeyword( "raiserror" );
2180                acceptSymbol( "(" );
2181                if ( raiseError.getMessageText( ) != null )
2182                {
2183                        raiseError.getMessageText( ).accept( this );
2184                }
2185
2186                if ( raiseError.getSeverity( ) != null )
2187                {
2188                        acceptSymbol( "," );
2189                        raiseError.getSeverity( ).accept( this );
2190                }
2191
2192                if ( raiseError.getState( ) != null )
2193                {
2194                        acceptSymbol( "," );
2195                        raiseError.getState( ).accept( this );
2196                }
2197
2198                if ( raiseError.getArgs( ) != null && raiseError.getArgs( ).size( ) > 0 )
2199                {
2200                        for ( int i = 0; i < raiseError.getArgs( ).size( ); i++ )
2201                        {
2202                                acceptSymbol( "," );
2203                                raiseError.getArgs( ).getExpression( i ).accept( this );
2204                        }
2205                }
2206                acceptSymbol( ")" );;
2207        }
2208
2209        public void preVisit( TMssqlPrint stmt )
2210        {
2211                acceptKeyword( "print" );
2212                if ( stmt.getMessages( ) != null )
2213                {
2214                        stmt.getMessages( ).accept( this );
2215                }
2216        }
2217
2218        public void preVisit( TMssqlDeclare stmt )
2219        {
2220                acceptKeyword( "declare" );
2221                if ( stmt.getVariables( ) != null )
2222                {
2223                        stmt.getVariables( ).accept( this );
2224                }
2225                
2226                if ( stmt.getCursorName( ) != null )
2227                {
2228                        stmt.getCursorName( ).accept( this );
2229                        acceptKeyword( "cursor" );
2230                        if ( stmt.getSubquery( ) != null )
2231                        {
2232                                acceptKeyword( "for" );
2233                                stmt.getSubquery( ).accept( this );
2234                        }
2235                }
2236        }
2237
2238        public void preVisit( TVarDeclStmt stmt )
2239        {
2240                if ( stmt.getElementName( ) != null )
2241                {
2242                        stmt.getElementName( ).accept( this );
2243                }
2244                if ( stmt.getDataType( ) != null )
2245                {
2246                        stmt.getDataType( ).accept( this );
2247                }
2248                if ( stmt.getDefaultValue( ) != null )
2249                {
2250                        if ( stmt.getDeclareType( ) == EDeclareType.variable )
2251                        {
2252                                acceptKeyword( "default" );
2253                                stmt.getDefaultValue( ).accept( this );
2254                        }
2255                        else if ( stmt.getDeclareType( ) == EDeclareType.constant )
2256                        {
2257                                acceptSymbol( ":=" );
2258                                stmt.getDefaultValue( ).accept( this );
2259                        }
2260                }
2261        }
2262
2263        public void preVisit( TMssqlSet stmt )
2264        {
2265                acceptKeyword( "set" );
2266                if ( stmt.getVarName( ) != null )
2267                {
2268                        stmt.getVarName( ).accept( this );
2269                        acceptSymbol( "=" );
2270                }
2271                if ( stmt.getVarExpr( ) != null )
2272                {
2273                        stmt.getVarExpr( ).accept( this );
2274                }
2275        }
2276
2277        public void preVisit( TMssqlReturn stmt )
2278        {
2279                acceptKeyword( "return" );
2280                if ( stmt.getReturnExpr( ) != null )
2281                {
2282                        stmt.getReturnExpr( ).accept( this );
2283                }
2284        }
2285
2286        public void preVisit( TMssqlLabel stmt )
2287        {
2288                super.preVisit( stmt );
2289        }
2290
2291        public void preVisit( TDeclareVariableList variables )
2292        {
2293                for ( int i = 0; i < variables.size( ); i++ )
2294                {
2295                        variables.getDeclareVariable( i ).accept( this );
2296                        if ( i != variables.size( ) - 1 )
2297                        {
2298                                acceptSymbol( "," );
2299                        }
2300                }
2301        }
2302
2303        public void preVisit( TDeclareVariable variable )
2304        {
2305                if ( variable.getVariableName( ) != null )
2306                {
2307                        variable.getVariableName( ).accept( this );
2308                }
2309
2310                if ( variable.getDatatype( ) != null )
2311                {
2312                        variable.getDatatype( ).accept( this );
2313                }
2314        }
2315
2316        public void preVisit( TMssqlExecute stmt )
2317        {
2318                acceptKeyword( "exec" );
2319                if ( stmt.getModuleName( ) != null )
2320                {
2321                        stmt.getModuleName( ).accept( this );
2322                }
2323                if ( stmt.getParameters( ) != null && stmt.getParameters( ).size( ) > 0 )
2324                {
2325                        acceptSpace( 1 );
2326                        stmt.getParameters( ).accept( this );
2327                }
2328        }
2329
2330        public void preVisit( TMssqlExecuteAs stmt )
2331        {
2332                acceptKeyword( "execute" );
2333                acceptKeyword( "as" );
2334                if ( stmt.getExecuteAsOption( ) != null )
2335                {
2336                        switch ( stmt.getExecuteAsOption( ) )
2337                        {
2338                                case eaoCaller :
2339                                        acceptKeyword( "caller" );
2340                                        break;
2341                                case eaoLogin :
2342                                        acceptKeyword( "login" );
2343                                        break;
2344                                case eaoOwner :
2345                                        acceptKeyword( "owner" );
2346                                        break;
2347                                case eaoSelf :
2348                                        acceptKeyword( "self" );
2349                                        break;
2350                                case eaoString :
2351                                        acceptKeyword( "string" );
2352                                        break;
2353                                case eaoUser :
2354                                        acceptKeyword( "user" );
2355                                        break;
2356                                default :
2357                                        break;
2358                        }
2359                }
2360                if ( stmt.getLoginName( ) != null )
2361                {
2362                        stmt.getLoginName( ).accept( this );
2363                        // TScriptGenerator generator = new TScriptGenerator( this.dbVendor
2364                        // );
2365                        // generator.createObjectName( stmt.getUserName( ) ).accept( this );
2366                }
2367        }
2368
2369        public void preVisit( TMssqlRevert stmt )
2370        {
2371                acceptKeyword( "revert" );
2372                if ( stmt.getCookie( ) != null )
2373                {
2374                        acceptKeyword( "with" );
2375                        acceptIdentifier( "cookie" );
2376                        acceptSymbol( "=" );
2377                        stmt.getCookie( ).accept( this );
2378                }
2379        }
2380
2381        public void preVisit( TMssqlStmtStub stmt )
2382        {
2383                super.preVisit( stmt );
2384        }
2385
2386        public void preVisit( TExecParameter param )
2387        {
2388                if ( param.getParameterName( ) != null )
2389                {
2390                        param.getParameterName( ).accept( this );
2391                }
2392                if ( param.getParameterValue( ) != null )
2393                {
2394                        param.getParameterValue( ).accept( this );
2395                }
2396        }
2397
2398        public void preVisit( TExecParameterList params )
2399        {
2400                for ( int i = 0; i < params.size( ); i++ )
2401                {
2402                        params.getExecParameter( i ).accept( this );
2403                        if ( i != params.size( ) - 1 )
2404                        {
2405                                acceptSymbol( "," );
2406                        }
2407                }
2408        }
2409
2410        public void preVisit( TAlterTableOption node )
2411        {
2412
2413                switch ( node.getOptionType( ) )
2414                {
2415                        case AddColumn :
2416                                acceptKeyword( "add" );
2417                                if (( node.getColumnDefinitionList( ).size( ) > 1 )&&(TGSqlParser.getCurrentDBVendor() != EDbVendor.dbvmssql))
2418                                        acceptSymbol( "(" );
2419                                node.getColumnDefinitionList( ).accept( this );
2420                                if(( node.getColumnDefinitionList( ).size( ) > 1 )&&(TGSqlParser.getCurrentDBVendor() != EDbVendor.dbvmssql))
2421                                        acceptSymbol( ")" );
2422                                break;
2423                        case AlterColumn :
2424                                acceptKeyword( "alter" );
2425                                acceptKeyword( "column" );
2426                                node.getColumnName( ).accept( this );
2427                                break;
2428                        case ChangeColumn :
2429                                acceptKeyword( "change" );
2430                                node.getColumnName( ).accept( this );
2431                                break;
2432                        case DropColumn :
2433                                acceptKeyword( "drop" );
2434                                acceptKeyword( "column" );
2435                                if ( node.getColumnNameList( ).size( ) > 1 )
2436                                        acceptSymbol( "(" );
2437                                node.getColumnNameList( ).accept( this );
2438                                if ( node.getColumnNameList( ).size( ) > 1 )
2439                                        acceptSymbol( ")" );
2440
2441                                break;
2442                        case ModifyColumn :
2443                                acceptKeyword( "modify" );
2444                                acceptKeyword( "column" );
2445                                if ( node.getColumnDefinitionList( ).size( ) > 1 )
2446                                        acceptSymbol( "(" );
2447                                node.getColumnDefinitionList( ).accept( this );
2448                                if ( node.getColumnDefinitionList( ).size( ) > 1 )
2449                                        acceptSymbol( ")" );
2450                                break;
2451                        case RenameColumn :
2452                                acceptKeyword( "rename" );
2453                                acceptKeyword( "column" );
2454                                node.getColumnName( ).accept( this );
2455                                acceptKeyword( "to" );
2456                                node.getNewColumnName( ).accept( this );
2457                                break;
2458                        case AddConstraint :
2459                                acceptKeyword( "add" );
2460                                node.getConstraintList( ).accept( this );
2461                                break;
2462                        default :
2463                }
2464
2465        }
2466
2467        public void preVisit( TAlterTableStatement stmt )
2468        {
2469
2470                acceptKeyword( "alter" );
2471                acceptKeyword( "table" );
2472                stmt.getTableName( ).accept( this );
2473                acceptNewline( );
2474
2475                if ( stmt.getAlterTableOptionList( ) != null )
2476                {
2477                        for ( int i = 0; i < stmt.getAlterTableOptionList( ).size( ); i++ )
2478                        {
2479                                stmt.getAlterTableOptionList( )
2480                                                .getAlterTableOption( i )
2481                                                .accept( this );
2482                                if ( i != stmt.getAlterTableOptionList( ).size( ) - 1 )
2483                                {
2484                                        acceptSymbol( "," );
2485                                        acceptNewline( );
2486                                }
2487                        }
2488                }
2489
2490        }
2491
2492        public void preVisit( TStatementList stmts )
2493        {
2494                for ( int i = 0; i < stmts.size( ); i++ )
2495                {
2496                        TCustomSqlStatement stmt = stmts.get( i );
2497                        preVisit( stmt );
2498                        if ( stmts.size( ) > 1 )
2499                                acceptSemicolon( );
2500
2501                        if ( i != stmts.size( ) - 1 )
2502                        {
2503                                acceptNewline( );
2504                        }
2505                }
2506        }
2507
2508        protected void preVisit( TCustomSqlStatement stmt )
2509        {
2510                try
2511                {
2512                        Class<?> clazz = stmt.getClass( );
2513                        Method m = this.getClass( ).getMethod( "preVisit", clazz );
2514                        m.setAccessible( true );
2515                        m.invoke( this, stmt );
2516                }
2517                catch ( Exception e )
2518                {
2519                        throw new UnsupportedOperationException( stmt.sqlstatementtype.name( ),
2520                                        e );
2521                }
2522        }
2523
2524        public void preVisit( TElsifStmt elsifStmt )
2525        {
2526                acceptKeyword( "elsif" );
2527                if ( elsifStmt.getCondition( ) != null )
2528                {
2529                        elsifStmt.getCondition( ).accept( this );
2530                }
2531                if ( elsifStmt.getThenStatements( ) != null
2532                                && elsifStmt.getThenStatements( ).size( ) > 0 )
2533                {
2534                        acceptKeyword( "then" );
2535                        acceptNewline( );
2536                        acceptSpace( 4 );
2537                        preVisit( elsifStmt.getThenStatements( ) );
2538                        acceptNewline( );
2539                }
2540        }
2541
2542        public void preVisit( TAssignStmt assignStmt )
2543        {
2544                assignStmt.getLeft( ).accept( this );
2545                scriptWriter.addComparisonOperator( EComparisonType.equals );
2546                assignStmt.getExpression( ).accept( this );
2547        }
2548
2549        public void preVisit( TIfStmt ifStmt )
2550        {
2551                acceptKeyword( "if" );
2552                if ( ifStmt.getCondition( ) != null )
2553                {
2554                        ifStmt.getCondition( ).accept( this );
2555                }
2556                if ( ifStmt.getThenStatements( ) != null
2557                                && ifStmt.getThenStatements( ).size( ) > 0 )
2558                {
2559                        acceptKeyword( "then" );
2560                        acceptNewline( );
2561                        acceptSpace( 4 );
2562                        preVisit( ifStmt.getThenStatements( ) );
2563                        acceptNewline( );
2564                }
2565                if ( ifStmt.getElseifStatements( ) != null )
2566                {
2567                        preVisit( ifStmt.getElseifStatements( ) );
2568                }
2569                if ( ifStmt.getElseStatements( ) != null
2570                                && ifStmt.getElseStatements( ).size( ) > 0 )
2571                {
2572                        acceptKeyword( "else" );
2573                        preVisit( ifStmt.getElseStatements( ) );
2574                        acceptNewline( );
2575                }
2576
2577                acceptKeyword( "end" );
2578                acceptKeyword( "if" );
2579                acceptNewline( );
2580        }
2581
2582        public void preVisit( TMssqlIfElse ifElse )
2583        {
2584                acceptKeyword( "if" );
2585                if ( ifElse.getCondition( ) != null )
2586                {
2587                        ifElse.getCondition( ).accept( this );
2588                }
2589                if ( ifElse.getStmt( ) != null )
2590                {
2591                        acceptNewline( );
2592                        acceptSpace( 4 );
2593                        preVisit( ifElse.getStmt( ) );
2594                }
2595                if ( ifElse.getElseStmt( ) != null )
2596                {
2597                        acceptNewline( );
2598                        acceptSpace( 4 );
2599                        acceptKeyword( "else" );
2600                        acceptNewline( );
2601                        acceptSpace( 4 );
2602                        preVisit( ifElse.getElseStmt( ) );
2603                }
2604        }
2605
2606        public void preVisit( TAliasClause node )
2607        {
2608                if ( node.isHasAs( ) )
2609                {
2610                        acceptKeyword( "as" );
2611                }
2612                node.getAliasName( ).accept( this );
2613
2614                if ( node.getColumns( ) != null )
2615                {
2616                        acceptSpace( 1 );
2617                        acceptSymbol( "(" );
2618                        visitObjectNameList(  node.getColumns( ) );
2619                        acceptSymbol( ")" );
2620                }
2621        }
2622
2623        
2624        public void preVisit( TWhereClause node )
2625        {
2626                if ( node.getCondition( ) == null )
2627                        return;
2628                acceptKeyword( "where" );
2629                node.getCondition( ).accept( this );
2630        }
2631
2632        public void preVisit( TIntoClause node )
2633        {
2634                if ( node.isBulkCollect( ) )
2635                {
2636                        acceptKeyword( "bulk" );
2637                        acceptKeyword( "collect" );
2638                }
2639                acceptKeyword( "into" );
2640                if ( node.getExprList( ) != null )
2641                {
2642                        acceptNewline( );
2643                        node.getExprList( ).accept( this );
2644                }
2645                else
2646                {
2647                        node.getIntoName( ).accept( this );
2648                }
2649        }
2650
2651        public void preVisit( TTopClause node )
2652        {
2653                acceptKeyword( "top" );
2654                node.getExpr( ).accept( this );
2655                if ( node.isPercent( ) )
2656                        acceptKeyword( "percent" );
2657                if ( node.isWithties( ) )
2658                {
2659                        acceptKeyword( "with ties" );
2660                }
2661        }
2662
2663        public void preVisit( TLimitClause node )
2664        {
2665                acceptNewline( );
2666
2667                // SQL:2008 FETCH FIRST/NEXT syntax (PostgreSQL, Oracle, SQL Server, etc.)
2668                if ( node.getSelectFetchFirstValue( ) != null )
2669                {
2670                        if ( node.getOffset( ) != null )
2671                        {
2672                                acceptKeyword( "offset" );
2673                                node.getOffset( ).accept( this );
2674                                acceptKeyword( "rows" );
2675                        }
2676                        acceptKeyword( "fetch" );
2677                        acceptKeyword( "next" );
2678                        node.getSelectFetchFirstValue( ).accept( this );
2679                        acceptKeyword( "rows" );
2680                        acceptKeyword( "only" );
2681                        return;
2682                }
2683
2684                EDbVendor v = TGSqlParser.getCurrentDBVendor( );
2685
2686                // PostgreSQL uses "LIMIT count OFFSET offset" or standalone
2687                // "OFFSET offset" / "LIMIT count", never MySQL-style "LIMIT offset, count".
2688                if ( v == EDbVendor.dbvpostgresql )
2689                {
2690                        if ( node.getRow_count( ) != null )
2691                        {
2692                                acceptKeyword( "limit" );
2693                                node.getRow_count( ).accept( this );
2694                        }
2695                        if ( node.getOffset( ) != null )
2696                        {
2697                                acceptKeyword( "offset" );
2698                                node.getOffset( ).accept( this );
2699                        }
2700                        return;
2701                }
2702
2703                // Generic MySQL-style: LIMIT offset, count
2704                acceptKeyword( "limit" );
2705
2706                if ( node.getOffset( ) != null )
2707                {
2708                        node.getOffset( ).accept( this );
2709                        if (node.getRow_count( ) != null){
2710                                acceptSymbol( "," );
2711                                node.getRow_count( ).accept( this );
2712                        }
2713                }
2714                else
2715                {
2716                        node.getRow_count( ).accept( this );
2717                }
2718        }
2719
2720        public void preVisit( TOffsetClause node )
2721        {
2722                acceptNewline( );
2723                acceptKeyword( "offset" );
2724                if ( node.getSelectOffsetValue( ) != null )
2725                {
2726                        node.getSelectOffsetValue( ).accept( this );
2727                }
2728        }
2729
2730        public void preVisit( TFetchFirstClause node )
2731        {
2732                acceptNewline( );
2733                acceptKeyword( "fetch" );
2734                acceptKeyword( "next" );
2735                if ( node.getFetchValue( ) != null )
2736                {
2737                        node.getFetchValue( ).accept( this );
2738                }
2739                acceptKeyword( "rows" );
2740                acceptKeyword( "only" );
2741        }
2742
2743        public void preVisit( TJoin node )
2744        {
2745
2746                if ( node.getJoinItems( ).size( ) > 0 )
2747                {
2748                        if ( node.getTable( ) != null )
2749                        {
2750                                node.setKind( TBaseType.join_source_table );
2751                        }
2752                        else if ( node.getJoin( ) != null )
2753                        {
2754                                node.setKind( TBaseType.join_source_join );
2755                        }
2756                }
2757
2758                if ( node.isWithParen( ) )
2759                {
2760                        for ( int i = 0; i < node.getNestedParen( ); i++ )
2761                        {
2762                                acceptSymbol( "(" );
2763                        }
2764                }
2765                switch ( node.getKind( ) )
2766                {
2767                        case TBaseType.join_source_fake :
2768                                node.getTable( ).accept( this );
2769                                break;
2770                        case TBaseType.join_source_table :
2771                        case TBaseType.join_source_join :
2772
2773                                if ( node.getKind( ) == TBaseType.join_source_table )
2774                                {
2775                                        node.getTable( ).accept( this );
2776                                }
2777                                else if ( node.getKind( ) == TBaseType.join_source_join )
2778                                {
2779                                        // preVisit(node.getJoin());
2780                                        node.getJoin( ).accept( this );
2781                                }
2782
2783                                for ( int i = 0; i < node.getJoinItems( ).size( ); i++ )
2784                                {
2785                                        TJoinItem joinItem = node.getJoinItems( ).getJoinItem( i );
2786                                        acceptNewline( );
2787                                        joinItem.accept( this );
2788                                }
2789                                break;
2790                }
2791                if ( node.isWithParen( ) )
2792                {
2793                        for ( int i = 0; i < node.getNestedParen( ); i++ )
2794                        {
2795                                acceptSymbol( ")" );
2796                        }
2797                }
2798
2799                if ( node.getAliasClause( ) != null )
2800                {
2801                        acceptSpace( 1 );
2802                        node.getAliasClause( ).accept( this );
2803                }
2804        }
2805
2806        public void preVisit( TJoinItem joinItem )
2807        {
2808
2809                switch ( joinItem.getJoinType( ) )
2810                {
2811                        case inner :
2812                                acceptKeyword( "inner" );
2813                                acceptKeyword( "join" );
2814                                break;
2815                        case join :
2816                                acceptKeyword( "join" );
2817                                break;
2818                        case left :
2819                                acceptKeyword( "left" );
2820                                acceptKeyword( "join" );
2821                                break;
2822                        case leftouter :
2823                                acceptKeyword( "left" );
2824                                acceptKeyword( "outer" );
2825                                acceptKeyword( "join" );
2826                                break;
2827                        case right :
2828                                acceptKeyword( "right" );
2829                                acceptKeyword( "join" );
2830                                break;
2831                        case rightouter :
2832                                acceptKeyword( "right" );
2833                                acceptKeyword( "outer" );
2834                                acceptKeyword( "join" );
2835                                break;
2836                        case full :
2837                                acceptKeyword( "full" );
2838                                acceptKeyword( "join" );
2839                                break;
2840                        case fullouter :
2841                                acceptKeyword( "full" );
2842                                acceptKeyword( "outer" );
2843                                acceptKeyword( "join" );
2844                                break;
2845                        case cross :
2846                                acceptKeyword( "cross" );
2847                                acceptKeyword( "join" );
2848                                break;
2849                        case natural :
2850                                acceptKeyword( "natural" );
2851                                acceptKeyword( "join" );
2852                                break;
2853                        case natural_inner :
2854                                acceptKeyword( "natural" );
2855                                acceptKeyword( "inner" );
2856                                acceptKeyword( "join" );
2857                                break;
2858                        case crossapply :
2859                                acceptKeyword( "cross" );
2860                                acceptKeyword( "apply" );
2861                                break;
2862                        case outerapply :
2863                                acceptKeyword( "outer" );
2864                                acceptKeyword( "apply" );
2865                                break;
2866                        default :
2867                                acceptKeyword( "join" );
2868                                break;
2869                }
2870
2871                if ( joinItem.getTable( ) != null )
2872                {
2873                        joinItem.getTable( ).accept( this );
2874                }
2875                else if ( joinItem.getJoin( ) != null )
2876                {
2877                        joinItem.getJoin( ).accept( this );
2878                }
2879
2880                if ( joinItem.getOnCondition( ) != null )
2881                {
2882                        acceptKeyword( "on" );
2883                        joinItem.getOnCondition( ).accept( this );
2884                }
2885
2886                if ( joinItem.getUsingColumns( ) != null )
2887                {
2888                        acceptKeyword( "using" );
2889                        acceptSymbol( "(" );
2890                        visitObjectNameList( joinItem.getUsingColumns( ) );
2891                        acceptSymbol( ")" );
2892                }
2893
2894                // already implemented in public void preVisit(TJoin node){
2895
2896                // if (node.getKind() == TBaseType.join_source_table){
2897                // node.getTable().accept(this);
2898                // }else if (node.getKind() == TBaseType.join_source_join){
2899                // node.getJoin().accept(this);
2900                // }
2901
2902                // if (node.getTable() != null){
2903                // node.getTable().accept(this);
2904                // }else if (node.getJoin() != null){
2905                // node.getJoin().accept(this);
2906                // }
2907                //
2908                //
2909                // if (node.getOnCondition() != null){
2910                // node.getOnCondition().accept(this);
2911                // }
2912                //
2913                // if (node.getUsingColumns() != null){
2914                // node.getUsingColumns().accept(this);
2915                // }
2916        }
2917
2918
2919        public void preVisit(TJsonTable node) {
2920                visitNodeByToken(node);
2921        }
2922
2923        public void preVisit( TTable node )
2924        {
2925
2926                if ( node.getParenthesisCount( ) > 0 )
2927                {
2928                        for ( int i = 0; i < node.getParenthesisCount( ); i++ )
2929                        {
2930                                acceptSymbol( "(" );
2931                        }
2932                }
2933                if ( node.getParenthesisAfterAliasCount( ) > 0 )
2934                {
2935                        for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ )
2936                        {
2937                                acceptSymbol( "(" );
2938                        }
2939                }
2940
2941                if ( node.isTableKeyword( ) )
2942                {
2943                        acceptKeyword( "table" );
2944                        acceptSymbol( "(" );
2945                }
2946
2947                if ( node.isOnlyKeyword( ) )
2948                {
2949                        acceptKeyword( "only" );
2950                        acceptSymbol( "(" );
2951                }
2952
2953                switch ( node.getTableType( ) )
2954                {
2955                        case objectname :
2956                        {
2957                                node.getTableName( ).accept( this );
2958                                if ( node.getFlashback( ) != null )
2959                                {
2960                                        acceptNewline( );
2961                                        visitNodeByToken( node.getFlashback( ) );
2962                                }
2963                                break;
2964                        }
2965                        case tableExpr :
2966                        {
2967                                node.getTableExpr( ).accept( this );
2968                                break;
2969                        }
2970                        case subquery :
2971                        {
2972                                node.getSubquery( ).accept( this );
2973                                break;
2974                        }
2975                        case function :
2976                        {
2977                                node.getFuncCall( ).accept( this );
2978                                break;
2979                        }
2980                        case pivoted_table :
2981                        {
2982                                node.getPivotedTable( ).accept( this );
2983                                break;
2984                        }
2985                        case output_merge :
2986                        {
2987                                // e_table_reference.setTextContent(node.getOutputMerge().toString());
2988                                break;
2989                        }
2990                        case containsTable :
2991                        {
2992                                node.getContainsTable( ).accept( this );
2993                                break;
2994                        }
2995
2996                        case openrowset :
2997                        {
2998                                node.getOpenRowSet( ).accept( this );
2999                                break;
3000                        }
3001
3002                        case openxml :
3003                        {
3004                                node.getOpenXML( ).accept( this );
3005                                break;
3006                        }
3007
3008                        case opendatasource :
3009                        {
3010                                node.getOpenDatasource( ).accept( this );
3011                                break;
3012                        }
3013
3014                        case openquery :
3015                        {
3016                                node.getOpenquery( ).accept( this );
3017                                break;
3018                        }
3019                        case datachangeTable :
3020                        {
3021                                node.getDatachangeTable( ).accept( this );
3022                                break;
3023                        }
3024                        case rowList :
3025                        {
3026                                node.getValueClause( ).accept( this );
3027                                break;
3028                        }
3029                        case xmltable :
3030                        {
3031                                node.getXmlTable( ).accept( this );
3032                                break;
3033                        }
3034
3035                        case informixOuter :
3036                        {
3037                                node.getOuterClause( ).accept( this );
3038                                break;
3039                        }
3040
3041                        case table_ref_list :
3042                        {
3043                                node.getFromTableList( ).accept( this );
3044                                break;
3045                        }
3046                        case hiveFromQuery :
3047                        {
3048                                node.getHiveFromQuery( ).accept( this );
3049                                break;
3050                        }
3051                        case jsonTable :
3052                        {
3053                                node.getJsonTable( ).accept( this );
3054                                break;
3055                        }
3056
3057                        default :
3058                                // sb.append(node.toString().replace(">","&#62;").replace("<","&#60;"));
3059                                break;
3060
3061                }
3062
3063                if ( node.isTableKeyword( ) )
3064                {
3065                        acceptSymbol( ")" );
3066                }
3067
3068                if ( node.isOnlyKeyword( ) )
3069                {
3070                        acceptSymbol( ")" );
3071                }
3072
3073                if ( node.getParenthesisCount( ) > 0 )
3074                {
3075                        for ( int i = 0; i < node.getParenthesisCount( ); i++ )
3076                        {
3077                                acceptSymbol( ")" );
3078                        }
3079                }
3080
3081                if ( node.getPxGranule( ) != null )
3082                {
3083                        // node.getPxGranule().accept(this);
3084                        acceptNewline( );
3085                        visitNodeByToken( node.getPxGranule( ) );
3086                }
3087
3088                if ( node.getTableSample( ) != null )
3089                {
3090                        // node.getTableSample().accept(this);
3091                        acceptNewline( );
3092                        visitNodeByToken( node.getTableSample( ) );
3093                }
3094
3095                if ( node.getAliasClause( ) != null )
3096                {
3097                        acceptSpace( 1 );
3098                        node.getAliasClause( ).accept( this );
3099                }
3100
3101                if ( node.getParenthesisAfterAliasCount( ) > 0 )
3102                {
3103                        for ( int i = 0; i < node.getParenthesisAfterAliasCount( ); i++ )
3104                        {
3105                                acceptSymbol( ")" );
3106                        }
3107                }
3108
3109                if ( node.getTableHintList( ) != null )
3110                {
3111                        for ( int i = 0; i < node.getTableHintList( ).size( ); i++ )
3112                        {
3113                                TTableHint tableHint = node.getTableHintList( ).getElement( i );
3114                                tableHint.accept( this );
3115                        }
3116                }
3117
3118        }
3119
3120        public void preVisit( THierarchical node )
3121        {
3122                if ( node.getStartWithClause( ) != null )
3123                {
3124                        acceptKeyword( "start" );
3125                        acceptKeyword( "with" );
3126                        node.getStartWithClause( ).accept( this );
3127                }
3128
3129                for ( int i = 0; i < node.getConnectByList( ).size( ); i++ )
3130                {
3131                        node.getConnectByList( ).getElement( i ).accept( this );
3132                        if ( i != node.getConnectByList( ).size( ) - 1 )
3133                        {
3134                                acceptNewline( );
3135                        }
3136                }
3137
3138        }
3139
3140        public void preVisit( TConnectByClause node )
3141        {
3142                acceptKeyword( "connect" );
3143                acceptKeyword( "by" );
3144                if ( node.isNoCycle( ) )
3145                {
3146                        acceptKeyword( "nocycle" );
3147                }
3148                node.getCondition( ).accept( this );
3149        }
3150
3151        public void preVisit( TGroupBy node )
3152        {
3153                if ( node.getItems( ) != null && node.getItems( ).size( ) > 0 )
3154                {
3155                        acceptKeyword( "group" );
3156                        acceptKeyword( "by" );
3157                        for ( int i = 0; i < node.getItems( ).size( ); i++ )
3158                        {
3159                                node.getItems( ).getElement( i ).accept( this );
3160                                if ( i != node.getItems( ).size( ) - 1 )
3161                                        acceptSymbol( "," );
3162                        }
3163
3164                        if (node.isRollupModifier()){
3165                                acceptKeyword("with");
3166                                acceptKeyword("rollup");
3167                        }
3168
3169                        if (node.isCubeModifier()){
3170                                acceptKeyword("with");
3171                                acceptKeyword("cube");
3172                        }
3173                }
3174                if ( node.getHavingClause( ) != null )
3175                {
3176                        acceptKeyword( "having" );
3177                        node.getHavingClause( ).accept( this );
3178                }
3179        }
3180
3181        public void preVisit( TGroupByItem node )
3182        {
3183
3184                if ( node.getExpr( ) != null )
3185                {
3186                        node.getExpr( ).accept( this );
3187                }
3188                else if ( node.getGroupingSet( ) != null )
3189                {
3190                        node.getGroupingSet( ).accept( this );
3191                }
3192                else if ( node.getRollupCube( ) != null )
3193                {
3194                        node.getRollupCube( ).accept( this );
3195                }
3196
3197        }
3198
3199        public void preVisit( TOrderBy node )
3200        {
3201                if ( node.getItems( ).size( ) == 0 )
3202                        return;
3203
3204                acceptKeyword( "order" );
3205                if ( node.isSiblings( ) )
3206                        acceptKeyword( "siblings" );
3207                acceptKeyword( "by" );
3208                for ( int i = 0; i < node.getItems( ).size( ); i++ )
3209                {
3210                        node.getItems( ).getOrderByItem( i ).accept( this );
3211                        if ( i != node.getItems( ).size( ) - 1 )
3212                                acceptSymbol( "," );
3213                }
3214
3215        }
3216
3217        public void preVisit( TOrderByItem node )
3218        {
3219                if ( node.getSortKey( ) != null )
3220                {
3221                        node.getSortKey( ).accept( this );
3222                }
3223                if ( node.getSortOrder( ) == ESortType.asc )
3224                {
3225                        acceptKeyword( "asc" );
3226                }
3227                else if ( node.getSortOrder( ) == ESortType.desc )
3228                {
3229                        acceptKeyword( "desc" );
3230                }
3231
3232                if (node.getNullOrder() == ENullOrder.nullsFirst){
3233                        acceptKeyword( "nulls" );
3234                        acceptKeyword( "first" );
3235                }else if (node.getNullOrder() == ENullOrder.nullsLast){
3236                        acceptKeyword( "nulls" );
3237                        acceptKeyword( "last" );
3238                }
3239                // e_order_by_item.setAttribute("sort_order",node.getSortOrder().toString());
3240        }
3241
3242        public void preVisit( TCTE node )
3243        {
3244                if (node.isRecursive()){
3245                        acceptKeyword( "recursive" );
3246                }
3247
3248                node.getTableName( ).accept( this );
3249
3250                if ( node.getColumnList( ) != null )
3251                {
3252                        acceptSymbol( "(" );
3253                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
3254                        {
3255                                node.getColumnList( ).getObjectName( i ).accept( this );
3256                                if ( i != node.getColumnList( ).size( ) - 1 )
3257                                        acceptSymbol( "," );
3258                        }
3259                        acceptSymbol( ")" );
3260
3261                }
3262
3263                acceptKeyword( "as" );
3264                acceptNewline( );
3265
3266                if (node.dbvendor == EDbVendor.dbvpostgresql){
3267                        acceptSymbol( "(" );
3268                }
3269
3270                if ( node.getSubquery( ) != null )
3271                {
3272                        node.getSubquery( ).accept( this );
3273                }
3274                else if ( node.getUpdateStmt( ) != null )
3275                {
3276                        node.getUpdateStmt( ).accept( this );
3277                }
3278                else if ( node.getInsertStmt( ) != null )
3279                {
3280                        node.getInsertStmt( ).accept( this );
3281                }
3282                else if ( node.getDeleteStmt( ) != null )
3283                {
3284                        node.getDeleteStmt( ).accept( this );
3285                }
3286
3287                if (node.dbvendor == EDbVendor.dbvpostgresql) {
3288                        acceptSymbol(")");
3289                }
3290
3291
3292        }
3293
3294        public void preVisit( TPivotInClause node )
3295        {
3296                acceptKeyword( "in" );
3297                if ( node.getItems( ) != null )
3298                {
3299                        acceptSymbol( "(" );
3300                        visitResultColumnList( node.getItems( ) );
3301                        acceptSymbol( ")" );
3302                }
3303                if ( node.getSubQuery( ) != null )
3304                        node.getSubQuery( ).accept( this );
3305
3306        }
3307
3308        public void preVisit( TPivotedTable node )
3309        {
3310                TPivotClause pivotClause;
3311
3312                for ( int i = 0; i < node.getPivotClauseList( ).size( ); i++ )
3313                {
3314
3315                        if ( i == 0 )
3316                        {
3317                                node.getTableSource( ).accept( this );
3318                        }
3319                        else
3320                        {
3321                        }
3322
3323                        pivotClause = node.getPivotClauseList( ).getElement( i );
3324                        if ( pivotClause.getAliasClause( ) != null )
3325                        {
3326                                pivotClause.getAliasClause( ).accept( this );
3327                        }
3328                        pivotClause.accept( this );
3329
3330                }
3331
3332        }
3333
3334        public void preVisit( TPivotClause node )
3335        {
3336                if ( node.getType( ) == TPivotClause.pivot )
3337                {
3338                        acceptKeyword( "pivot" );
3339                        acceptSymbol( "(" );
3340                        if ( node.getAggregation_function( ) != null )
3341                        {
3342                                node.getAggregation_function( ).accept( this );
3343                        }
3344                        else if ( node.getAggregation_function_list( ) != null )
3345                        {
3346                                if ( node.getAggregation_function_list( ).size( ) > 1 )
3347                                        acceptSymbol( "(" );
3348                                for ( int i = 0; i < node.getAggregation_function_list( )
3349                                                .size( ); i++ )
3350                                {
3351                                        node.getAggregation_function_list( )
3352                                                        .getResultColumn( i )
3353                                                        .accept( this );
3354                                        if ( i != node.getAggregation_function_list( ).size( ) - 1 )
3355                                                acceptSymbol( "," );
3356                                }
3357                                if ( node.getAggregation_function_list( ).size( ) > 1 )
3358                                        acceptSymbol( ")" );
3359                        }
3360                        acceptKeyword( "for" );
3361
3362                        if ( node.getPivotColumnList( ).size( ) > 1 )
3363                                acceptSymbol( "(" );
3364                        for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ )
3365                        {
3366                                node.getPivotColumnList( ).getElement( i ).accept( this );
3367                                if ( i != node.getPivotColumnList( ).size( ) - 1 )
3368                                        acceptSymbol( "," );
3369                        }
3370                        if ( node.getPivotColumnList( ).size( ) > 1 )
3371                                acceptSymbol( ")" );
3372
3373                        node.getPivotInClause( ).accept( this );
3374
3375                        acceptSymbol( ")" );
3376                }
3377                else
3378                {
3379                        acceptKeyword( "unpivot" );
3380                        acceptSymbol( "(" );
3381                        if ( node.getValueColumnList( ).size( ) > 1 )
3382                                acceptSymbol( "(" );
3383                        for ( int i = 0; i < node.getValueColumnList( ).size( ); i++ )
3384                        {
3385                                node.getValueColumnList( ).getObjectName( i ).accept( this );
3386                                if ( i != node.getValueColumnList( ).size( ) - 1 )
3387                                        acceptSymbol( "," );
3388                        }
3389                        if ( node.getValueColumnList( ).size( ) > 1 )
3390                                acceptSymbol( ")" );
3391
3392                        acceptKeyword( "for" );
3393
3394                        if ( node.getPivotColumnList( ).size( ) > 1 )
3395                                acceptSymbol( "(" );
3396                        for ( int i = 0; i < node.getPivotColumnList( ).size( ); i++ )
3397                        {
3398                                node.getPivotColumnList( ).getElement( i ).accept( this );
3399                                if ( i != node.getPivotColumnList( ).size( ) - 1 )
3400                                        acceptSymbol( "," );
3401                        }
3402                        if ( node.getPivotColumnList( ).size( ) > 1 )
3403                                acceptSymbol( ")" );
3404
3405                        node.getUnpivotInClause( ).accept( this );
3406
3407                        acceptSymbol( ")" );
3408                }
3409        }
3410
3411        public void preVisit( TUnpivotInClauseItem node )
3412        {
3413
3414                if ( node.getColumn( ) != null )
3415                {
3416                        node.getColumn( ).accept( this );
3417                }
3418                else if ( node.getColumnList( ) != null )
3419                {
3420                        acceptSymbol( "(" );
3421                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
3422                        {
3423                                node.getColumnList( ).getObjectName( i ).accept( this );
3424                                if ( i != node.getColumnList( ).size( ) - 1 )
3425                                        acceptSymbol( "," );
3426                        }
3427                        acceptSymbol( ")" );
3428                }
3429
3430                if ( node.getConstant( ) != null )
3431                {
3432                        acceptKeyword( "as" );
3433                        node.getConstant( ).accept( this );
3434                }
3435                else if ( node.getConstantList( ) != null )
3436                {
3437                        acceptKeyword( "as" );
3438                        acceptSymbol( "(" );
3439                        for ( int i = 0; i < node.getConstantList( ).size( ); i++ )
3440                        {
3441                                node.getConstantList( ).getElement( i ).accept( this );
3442                                if ( i != node.getConstantList( ).size( ) - 1 )
3443                                        acceptSymbol( "," );
3444                        }
3445                        acceptSymbol( ")" );
3446                }
3447
3448        }
3449
3450        public void preVisit( TUnpivotInClause node )
3451        {
3452                acceptKeyword( "in" );
3453                acceptSymbol( "(" );
3454                for ( int i = 0; i < node.getItems( ).size( ); i++ )
3455                {
3456                        node.getItems( ).getElement( i ).accept( this );
3457                        if ( i != node.getItems( ).size( ) - 1 )
3458                                acceptSymbol( "," );
3459                }
3460                acceptSymbol( ")" );
3461        }
3462
3463        public void preVisit( TCaseExpression node )
3464        {
3465
3466                acceptKeyword( "case" );
3467                if ( node.getInput_expr( ) != null )
3468                {
3469                        node.getInput_expr( ).accept( this );
3470                }
3471
3472                for ( int i = 0; i < node.getWhenClauseItemList( ).size( ); i++ )
3473                {
3474                        node.getWhenClauseItemList( ).getWhenClauseItem( i ).accept( this );
3475                        if ( i != node.getWhenClauseItemList( ).size( ) - 1 )
3476                                acceptNewline( );
3477                }
3478
3479                if ( node.getElse_expr( ) != null )
3480                {
3481                        acceptNewline( );
3482                        acceptKeyword( "else" );
3483                        node.getElse_expr( ).accept( this );
3484                }
3485
3486                if ( node.getElse_statement_list( ).size( ) > 0 )
3487                {
3488                        node.getElse_statement_list( ).accept( this );
3489                }
3490
3491                acceptNewline( );
3492                acceptKeyword( "end" );
3493        }
3494
3495        public void preVisit( TWhenClauseItem node )
3496        {
3497                acceptKeyword( "when" );
3498                node.getComparison_expr( ).accept( this );
3499                acceptNewline( );
3500                acceptKeyword( "then" );
3501                if ( node.getReturn_expr( ) != null )
3502                {
3503                        node.getReturn_expr( ).accept( this );
3504                }
3505                else if ( node.getStatement_list( ).size( ) > 0 )
3506                {
3507                        for ( int i = 0; i < node.getStatement_list( ).size( ); i++ )
3508                        {
3509                                node.getStatement_list( ).get( i ).accept( this );
3510                        }
3511
3512                }
3513        }
3514
3515        public void preVisit( TForUpdate node )
3516        {
3517                switch ( node.getForUpdateType( ) )
3518                {
3519                        case forReadOnly :
3520                                acceptKeyword( "read" );
3521                                acceptKeyword( "only" );
3522                                break;
3523                        case forUpdate :
3524                                acceptKeyword( "for" );
3525                                acceptKeyword( "update" );
3526                                break;
3527                        case forUpdateOf :
3528                                acceptKeyword( "for" );
3529                                acceptKeyword( "update" );
3530                                acceptKeyword( "of" );
3531                                break;
3532                }
3533
3534                if ( node.getColumnRefs( ) != null )
3535                {
3536                        visitObjectNameList( node.getColumnRefs( ) );
3537                }
3538                if ( node.isNowait( ) )
3539                        acceptKeyword( "nowait" );
3540                if ( node.isWait( ) )
3541                {
3542                        acceptKeyword( "wait" );
3543                        acceptIdentifier( node.getWaitValue( ) );
3544                }
3545
3546        }
3547
3548        public void preVisit( TDeleteSqlStatement stmt )
3549        {
3550
3551                if ( stmt.getCteList( ) != null )
3552                {
3553                        acceptKeyword( "with" );
3554                        visitCTEList( stmt.getCteList( ) );
3555                }
3556
3557                acceptKeyword( "delete" );
3558
3559                if ( stmt.getTopClause( ) != null )
3560                {
3561                        stmt.getTopClause( ).accept( this );
3562                }
3563
3564                if ( stmt.isFromKeyword( ) )
3565                        acceptKeyword( "from" );
3566                stmt.getTargetTable( ).accept( this );
3567
3568                if ( stmt.joins.size( ) > 0 )
3569                {
3570                        acceptNewline( );
3571                        acceptKeyword( "from" );
3572                        visitJoinList( stmt.joins );
3573                }
3574
3575                if ( stmt.getOutputClause( ) != null )
3576                {
3577                        stmt.getOutputClause( ).accept( this );
3578                }
3579
3580                if ( stmt.getWhereClause( ) != null )
3581                {
3582                        acceptNewline( );
3583                        stmt.getWhereClause( ).accept( this );
3584                }
3585
3586                if ( stmt.getReturningClause( ) != null )
3587                {
3588                        stmt.getReturningClause( ).accept( this );
3589                }
3590
3591        }
3592
3593        public void preVisit( TUpdateSqlStatement stmt )
3594        {
3595
3596                if ( stmt.getCteList( ) != null )
3597                {
3598                        acceptKeyword( "with" );
3599                        visitCTEList( stmt.getCteList( ) );
3600                }
3601
3602                acceptKeyword( "update" );
3603
3604                if ( stmt.getTopClause( ) != null )
3605                {
3606                        stmt.getTopClause( ).accept( this );
3607                }
3608
3609                if ( getDBVerdor(stmt) == EDbVendor.dbvmysql )
3610                {
3611                        if ( stmt.joins.size( ) > 0 )
3612                        {
3613                                visitJoinList( stmt.joins );
3614                        }
3615                        else
3616                        {
3617                                stmt.getTargetTable( ).accept( this );
3618                        }
3619                }
3620                else
3621                {
3622                        stmt.getTargetTable( ).accept( this );
3623                }
3624                
3625                acceptNewline( );
3626                acceptKeyword( "set" );
3627                visitResultColumnList( stmt.getResultColumnList( ) );
3628
3629                if ( getDBVerdor( stmt ) != EDbVendor.dbvmysql )
3630                {
3631                        if ( stmt.joins.size( ) > 0 )
3632                        {
3633                                acceptNewline( );
3634                                acceptKeyword( "from" );
3635                                visitJoinList( stmt.joins );
3636                        }
3637                }
3638
3639                if ( stmt.getWhereClause( ) != null )
3640                {
3641                        acceptNewline( );
3642                        stmt.getWhereClause( ).accept( this );
3643                }
3644
3645                if ( stmt.getOrderByClause( ) != null )
3646                {
3647                        stmt.getOrderByClause( ).accept( this );
3648                }
3649
3650                if ( stmt.getLimitClause( ) != null )
3651                {
3652                        stmt.getLimitClause( ).accept( this );
3653                }
3654
3655                if ( stmt.getOutputClause( ) != null )
3656                {
3657                        stmt.getOutputClause( ).accept( this );
3658                }
3659
3660                if ( stmt.getReturningClause( ) != null )
3661                {
3662                        stmt.getReturningClause( ).accept( this );
3663                }
3664
3665        }
3666
3667        private EDbVendor getDBVerdor( TCustomSqlStatement stmt )
3668        {
3669                if ( stmt.dbvendor != null )
3670                {
3671                        return stmt.dbvendor;
3672                }
3673                else if ( stmt.getGsqlparser( ) != null )
3674                {
3675                        return stmt.getGsqlparser( ).getDbVendor( );
3676                }
3677                return null;
3678        }
3679
3680        public void preVisit( TInsertSqlStatement stmt )
3681        {
3682
3683                boolean insertAll = false;
3684
3685                if ( stmt.getCteList( ) != null )
3686                {
3687                        acceptKeyword( "with" );
3688                        visitCTEList( stmt.getCteList( ) );
3689                }
3690
3691                acceptKeyword( "insert" );
3692                if ( stmt.isInsertAll( ) )
3693                        acceptKeyword( "all" );
3694                if ( stmt.isInsertFirst( ) )
3695                        acceptKeyword( "first" );
3696
3697                if ( stmt.getInsertConditions( ) != null
3698                                && stmt.getInsertConditions( ).size( ) > 0 )
3699                {
3700                        for ( int i = 0; i < stmt.getInsertConditions( ).size( ); i++ )
3701                        {
3702                                TInsertCondition condition = stmt.getInsertConditions( )
3703                                                .getElement( i );
3704                                preVisit( condition );
3705                        }
3706
3707                        insertAll = true;
3708                }
3709
3710                if ( stmt.getElseIntoValues( ) != null )
3711                {
3712                        acceptKeyword( "else" );
3713                        for ( int i = 0; i < stmt.getElseIntoValues( ).size( ); i++ )
3714                        {
3715                                stmt.getElseIntoValues( ).getElement( i ).accept( this );
3716                        }
3717                        insertAll = true;
3718                }
3719
3720                if ( insertAll )
3721                {
3722                        if ( stmt.getSubQuery( ) != null )
3723                        {
3724                                acceptNewline( );
3725                                stmt.getSubQuery( ).accept( this );
3726                        }
3727                }
3728
3729                if ( !insertAll )
3730                {
3731                        acceptKeyword( "into" );
3732
3733                        if ( stmt.getTargetTable( ) != null )
3734                        {
3735                                stmt.getTargetTable( ).accept( this );
3736                        }
3737                        else
3738                        {
3739                                // hive insert may have no target table
3740                        }
3741
3742                        if ( stmt.getColumnList( ) != null )
3743                        {
3744                                acceptSymbol( "(" );
3745                                visitObjectNameList( stmt.getColumnList( ) );
3746                                acceptSymbol( ")" );
3747                        }
3748
3749                        switch ( stmt.getInsertSource( ) )
3750                        {
3751                                case values :
3752                                        acceptNewline( );
3753                                        acceptKeyword( "values" );
3754                                        TMultiTargetList multiTargetList = stmt.getValues( );
3755                                        visitMultiTargetList( multiTargetList );
3756                                        break;
3757                                case subquery :
3758                                        acceptNewline( );
3759                                        stmt.getSubQuery( ).accept( this );
3760                                        break;
3761                                case values_empty :
3762                                        break;
3763                                case values_function :
3764                                        acceptNewline( );
3765                                        acceptKeyword( "values" );
3766                                        stmt.getFunctionCall( ).accept( this );
3767                                        break;
3768                                case values_oracle_record :
3769                                        acceptNewline( );
3770                                        acceptKeyword( "values" );
3771                                        stmt.getRecordName( ).accept( this );
3772                                        break;
3773                                case set_column_value :
3774                                        // stmt.getSetColumnValues().accept(this);
3775                                        break;
3776                                default :
3777                                        break;
3778                        }
3779                }
3780                
3781                if ( stmt.getOnDuplicateKeyUpdate( ) != null )
3782                {
3783                        acceptKeyword( "on" );
3784                        acceptKeyword( "duplicate" );
3785                        acceptKeyword( "key" );
3786                        acceptKeyword( "update" );
3787                        visitResultColumnList( stmt.getOnDuplicateKeyUpdate( ) );
3788                }
3789
3790                if ( stmt.getReturningClause( ) != null )
3791                {
3792                        acceptNewline( );
3793                        stmt.getReturningClause( ).accept( this );
3794                }
3795
3796        }
3797
3798        public void preVisit( TInsertCondition node )
3799        {
3800                if ( node.getCondition( ) != null )
3801                {
3802                        acceptNewline( );
3803                        acceptKeyword( "when" );
3804                        preVisit( node.getCondition( ) );
3805                        acceptKeyword( "then" );
3806                }
3807
3808                if ( node.getInsertIntoValues( ) != null
3809                                && node.getInsertIntoValues( ).size( ) > 0 )
3810                {
3811                        acceptNewline( );
3812                        for ( int i = 0; i < node.getInsertIntoValues( ).size( ); i++ )
3813                        {
3814                                TInsertIntoValue value = node.getInsertIntoValues( )
3815                                                .getElement( i );
3816                                preVisit( value );
3817                        }
3818                }
3819        }
3820
3821        public void preVisit( TInsertIntoValue node )
3822        {
3823                if ( node.getTable( ) != null )
3824                {
3825                        acceptKeyword( "into" );
3826                        preVisit( node.getTable( ) );
3827                        if ( node.getColumnList( ) != null
3828                                        && node.getColumnList( ).size( ) > 0 )
3829                        {
3830                                acceptSymbol( "(" );
3831                                visitObjectNameList( node.getColumnList( ) );
3832                                acceptSymbol( ")" );
3833                        }
3834                        if ( node.getTargetList( ) != null
3835                                        && node.getTargetList( ).size( ) > 0 )
3836                        {
3837                                acceptKeyword( "values" );
3838                                TMultiTargetList multiTargetList = node.getTargetList( );
3839                                visitMultiTargetList( multiTargetList );
3840                        }
3841                }
3842        }
3843
3844        private void visitMultiTargetList( TMultiTargetList multiTargetList )
3845        {
3846                for ( int i = 0; i < multiTargetList.size( ); i++ )
3847                {
3848                        TMultiTarget multiTarget = multiTargetList.getMultiTarget( i );
3849                        acceptSymbol( "(" );
3850
3851                        for ( int j = 0; j < multiTarget.getColumnList( ).size( ); j++ )
3852                        {
3853                                if ( multiTarget.getColumnList( )
3854                                                .getResultColumn( j )
3855                                                .isPlaceHolder( ) )
3856                                        continue; // teradata allow empty value
3857                                multiTarget.getColumnList( )
3858                                                .getResultColumn( j )
3859                                                .getExpr( )
3860                                                .accept( this );
3861                                if ( j != multiTarget.getColumnList( ).size( ) - 1 )
3862                                        acceptSymbol( "," );
3863                        }
3864
3865                        acceptSymbol( ")" );
3866
3867                        if ( i != multiTargetList.size( ) - 1 )
3868                                acceptSymbol( "," );
3869
3870                }
3871        }
3872
3873        public void preVisit( TMergeSqlStatement stmt )
3874        {
3875
3876                if ( stmt.getCteList( ) != null )
3877                {
3878                        acceptKeyword( "with" );
3879                        visitCTEList( stmt.getCteList( ) );
3880                }
3881
3882                acceptKeyword( "merge" );
3883                acceptKeyword( "into" );
3884                stmt.getTargetTable( ).accept( this );
3885                acceptKeyword( "using" );
3886                stmt.getUsingTable( ).accept( this );
3887                acceptKeyword( "on" );
3888                acceptSymbol( "(" );
3889                stmt.getCondition( ).accept( this );
3890                acceptSymbol( ")" );
3891                acceptNewline( );
3892
3893                if ( stmt.getWhenClauses( ) != null )
3894                {
3895                        for ( int i = 0; i < stmt.getWhenClauses( ).size( ); i++ )
3896                        {
3897                                TMergeWhenClause whenClause = stmt.getWhenClauses( )
3898                                                .getElement( i );
3899                                whenClause.accept( this );
3900                        }
3901                }
3902        }
3903
3904        public void preVisit( TMergeWhenClause node )
3905        {
3906                switch ( node.getType( ) )
3907                {
3908                        case TMergeWhenClause.matched :
3909                                acceptKeyword( "when" );
3910                                acceptKeyword( "matched" );
3911                                acceptKeyword( "then" );
3912                                break;
3913                        case TMergeWhenClause.not_matched :
3914                                acceptKeyword( "when" );
3915                                acceptKeyword( "not" );
3916                                acceptKeyword( "matched" );
3917                                acceptKeyword( "then" );
3918                                break;
3919                        case TMergeWhenClause.matched_with_condition :
3920                                acceptKeyword( "when" );
3921                                acceptKeyword( "matched" );
3922                                acceptKeyword( "and" );
3923                                node.getCondition( ).accept( this );
3924                                acceptKeyword( "then" );
3925                                break;
3926                        case TMergeWhenClause.not_matched_with_condition :
3927                                acceptKeyword( "when" );
3928                                acceptKeyword( "not" );
3929                                acceptKeyword( "matched" );
3930                                acceptKeyword( "and" );
3931                                node.getCondition( ).accept( this );
3932                                acceptKeyword( "then" );
3933                                break;
3934                        case TMergeWhenClause.not_matched_by_target :
3935                                acceptKeyword( "when" );
3936                                acceptKeyword( "not" );
3937                                acceptKeyword( "matched" );
3938                                acceptKeyword( "by" );
3939                                acceptKeyword( "target" );
3940                                acceptKeyword( "then" );
3941                                break;
3942                        case TMergeWhenClause.not_matched_by_target_with_condition :
3943                                acceptKeyword( "when" );
3944                                acceptKeyword( "not" );
3945                                acceptKeyword( "matched" );
3946                                acceptKeyword( "by" );
3947                                acceptKeyword( "target" );
3948                                acceptKeyword( "and" );
3949                                node.getCondition( ).accept( this );
3950                                acceptKeyword( "then" );
3951                                break;
3952                        case TMergeWhenClause.not_matched_by_source :
3953                                acceptKeyword( "when" );
3954                                acceptKeyword( "not" );
3955                                acceptKeyword( "matched" );
3956                                acceptKeyword( "by" );
3957                                acceptKeyword( "source" );
3958                                acceptKeyword( "then" );
3959                                break;
3960                        case TMergeWhenClause.not_matched_by_source_with_condition :
3961                                acceptKeyword( "when" );
3962                                acceptKeyword( "not" );
3963                                acceptKeyword( "matched" );
3964                                acceptKeyword( "by" );
3965                                acceptKeyword( "source" );
3966                                acceptKeyword( "and" );
3967                                node.getCondition( ).accept( this );
3968                                acceptKeyword( "then" );
3969                                break;
3970                        default :
3971                                break;
3972                }
3973
3974                if ( node.getUpdateClause( ) != null )
3975                {
3976                        node.getUpdateClause( ).accept( this );
3977                }
3978
3979                if ( node.getInsertClause( ) != null )
3980                {
3981                        node.getInsertClause( ).accept( this );
3982                }
3983
3984                if ( node.getDeleteClause( ) != null )
3985                {
3986                        node.getDeleteClause( ).accept( this );
3987                }
3988
3989        }
3990
3991        public void preVisit( TMergeUpdateClause node )
3992        {
3993
3994                acceptKeyword( "update" );
3995                acceptKeyword( "set" );
3996                if ( node.getUpdateColumnList( ) != null )
3997                {
3998                        visitResultColumnList( node.getUpdateColumnList( ) );
3999                }
4000
4001                if ( node.getUpdateWhereClause( ) != null )
4002                {
4003                        acceptNewline( );
4004                        acceptKeyword( "where" );
4005                        node.getUpdateWhereClause( ).accept( this );
4006                }
4007
4008                if ( node.getDeleteWhereClause( ) != null )
4009                {
4010                        acceptNewline( );
4011                        acceptKeyword( "delete" );
4012                        node.getDeleteWhereClause( ).accept( this );
4013                }
4014
4015        }
4016
4017        public void preVisit( TMergeInsertClause node )
4018        {
4019
4020                acceptKeyword( "insert" );
4021                if ( node.getColumnList( ) != null )
4022                {
4023                        acceptSymbol( "(" );
4024                        visitObjectNameList( node.getColumnList( ) );
4025                        acceptSymbol( ")" );
4026                }
4027
4028                acceptKeyword( "values" );
4029                if ( node.getValuelist( ) != null )
4030                {
4031                        acceptSymbol( "(" );
4032                        visitResultColumnList( node.getValuelist( ) );
4033                        acceptSymbol( ")" );
4034                }
4035
4036                if ( node.getInsertWhereClause( ) != null )
4037                {
4038                        acceptNewline( );
4039                        acceptKeyword( "where" );
4040                        node.getInsertWhereClause( ).accept( this );
4041                }
4042
4043        }
4044
4045        public void preVisit( TMergeDeleteClause node )
4046        {
4047
4048        }
4049
4050        public void preVisit( TCreateTableSqlStatement stmt )
4051        {
4052                acceptKeyword( "create" );
4053
4054                if ( !stmt.getTableKinds( ).isEmpty( ) )
4055                {
4056                        if ( stmt.getTableKinds( ).contains( ETableKind.etkBase ) )
4057                        {
4058                                acceptKeyword( "base" );
4059                        }
4060                        if ( stmt.getTableKinds( ).contains( ETableKind.etkTemporary ) )
4061                        {
4062                                acceptKeyword( "temporary" );
4063                        }
4064                        if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemporary ) )
4065                        {
4066                                acceptKeyword( "global" );
4067                                acceptKeyword( "temporary" );
4068                        }
4069                        if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemporary ) )
4070                        {
4071                                acceptKeyword( "local" );
4072                                acceptKeyword( "temporary" );
4073                        }
4074                        if ( stmt.getTableKinds( ).contains( ETableKind.etkTemp ) )
4075                        {
4076                                acceptKeyword( "temp" );
4077                        }
4078                        if ( stmt.getTableKinds( ).contains( ETableKind.etkGlobalTemp ) )
4079                        {
4080                                acceptKeyword( "global" );
4081                                acceptKeyword( "temp" );
4082                        }
4083                        if ( stmt.getTableKinds( ).contains( ETableKind.etkLocalTemp ) )
4084                        {
4085                                acceptKeyword( "local" );
4086                                acceptKeyword( "temp" );
4087                        }
4088                        if ( stmt.getTableKinds( ).contains( ETableKind.etkVolatile ) )
4089                        {
4090                                acceptKeyword( "volatile" );
4091                        }
4092                        if ( stmt.getTableKinds( ).contains( ETableKind.etkSet ) )
4093                        {
4094                                acceptKeyword( "set" );
4095                        }
4096                        if ( stmt.getTableKinds( ).contains( ETableKind.etkMultiset ) )
4097                        {
4098                                acceptKeyword( "multiset" );
4099                        }
4100                        if ( stmt.getTableKinds( ).contains( ETableKind.etkExternal ) )
4101                        {
4102                                acceptKeyword( "external" );
4103                        }
4104                }
4105                acceptKeyword( "table" );
4106                stmt.getTargetTable( ).accept( this );
4107
4108                if ( stmt.getSubQuery( ) != null )
4109                {
4110                        acceptKeyword( "as" );
4111                        acceptNewline( );
4112                        stmt.getSubQuery( ).accept( this );
4113
4114                }
4115                else
4116                {
4117                        acceptSymbol( "(" );
4118                        acceptNewline( );
4119                        for ( int i = 0; i < stmt.getColumnList( ).size( ); i++ )
4120                        {
4121                                stmt.getColumnList( ).getColumn( i ).accept( this );
4122                                if ( i != stmt.getColumnList( ).size( ) - 1 ){
4123                                        acceptSymbol( "," );
4124                                        acceptNewline();
4125                                }
4126
4127                        }
4128
4129                        if ( ( stmt.getTableConstraints( ) != null )
4130                                        && ( stmt.getTableConstraints( ).size( ) > 0 ) )
4131                        {
4132                                acceptNewline( );
4133                                acceptSymbol( "," );
4134                                for ( int i = 0; i < stmt.getTableConstraints( ).size( ); i++ )
4135                                {
4136                                        stmt.getTableConstraints( )
4137                                                        .getConstraint( i )
4138                                                        .accept( this );
4139                                        if ( i != stmt.getTableConstraints( ).size( ) - 1 )
4140                                                acceptSymbol( "," );
4141                                }
4142                        }
4143
4144                        acceptNewline( );
4145                        acceptSymbol( ")" );
4146                }
4147
4148                if (stmt.getOnFilegroup() != null){
4149
4150                        visitNodeByToken(stmt.getOnFilegroup());
4151                }
4152
4153                if ( stmt.getMySQLTableOptionList( ) != null
4154                                && stmt.getMySQLTableOptionList( ).size( ) > 0 )
4155                {
4156                        preVisit( stmt.getMySQLTableOptionList( ) );
4157                }
4158
4159        }
4160
4161        public void preVisit( TPTNodeList options )
4162        {
4163                for ( int i = 0; i < options.size( ); i++ )
4164                {
4165                        Object element = options.getElement( i );
4166                        if ( element instanceof TMySQLCreateTableOption )
4167                        {
4168                                preVisit( (TMySQLCreateTableOption) options.getElement( i ) );
4169                        }
4170                }
4171        }
4172
4173        public void preVisit( TMySQLCreateTableOption option )
4174        {
4175                acceptKeyword( option.getOptionName( ) );
4176                acceptSymbol( "=" );
4177                acceptKeyword( option.getOptionValue( ) );
4178        }
4179
4180        public void preVisit( TColumnDefinition node )
4181        {
4182
4183                node.getColumnName( ).accept( this );
4184
4185                if ( node.getDatatype( ) != null )
4186                {
4187                        node.getDatatype( ).accept( this );
4188                }
4189
4190                if ( node.getDefaultExpression( ) != null )
4191                {
4192                        acceptKeyword( "default" );
4193                        node.getDefaultExpression( ).accept( this );
4194                }
4195
4196                if ( node.isNull( ) )
4197                        acceptKeyword( "null" );
4198
4199                if ( ( node.getConstraints( ) != null )
4200                                && ( node.getConstraints( ).size( ) > 0 ) )
4201                {
4202                        for ( int i = 0; i < node.getConstraints( ).size( ); i++ )
4203                        {
4204                                node.getConstraints( ).getConstraint( i ).accept( this );
4205                        }
4206                }
4207
4208                if ( node.isIdentity( ) )
4209                {
4210                        acceptKeyword( "identity" );
4211                        if ( node.getSeed( ) != null )
4212                        {
4213                                acceptSymbol( "(" );
4214                                node.getSeed( ).accept( this );
4215                                acceptSymbol( "," );
4216                                node.getIncrement( ).accept( this );
4217                                acceptSymbol( ")" );
4218                        }
4219                }
4220
4221        }
4222
4223        public void preVisit( TColumnWithSortOrder node )
4224        {
4225                node.getColumnName( ).accept( this );
4226                if ( node.getLength( ) != null )
4227                {
4228                        acceptSymbol( "(" );
4229                        node.getLength( ).accept( this );
4230                        acceptSymbol( ")" );
4231                }
4232                if ( node.getSortType( ) == ESortType.desc )
4233                {
4234                        acceptKeyword( "desc" );
4235                }
4236                if ( node.getSortType( ) == ESortType.asc )
4237                {
4238                        acceptKeyword( "asc" );
4239                }
4240        }
4241
4242        public void preVisit( TConstraint node )
4243        {
4244
4245                if ( node.getConstraintName( ) != null )
4246                {
4247                        acceptKeyword( "constraint" );
4248                        node.getConstraintName( ).accept( this );
4249                }
4250
4251                switch ( node.getConstraint_type( ) )
4252                {
4253                        case notnull :
4254                                acceptKeyword( "not" );
4255                                acceptKeyword( "null" );
4256                                break;
4257                        case table_index:
4258                                //acceptKeyword("index");
4259                                visitNodeByToken(node);
4260                                break;
4261                        case unique :
4262                                acceptKeyword( "unique" );
4263                                if ( node.isClustered( ) )
4264                                        acceptKeyword( "clustered" );
4265                                if ( node.isNonClustered( ) )
4266                                        acceptKeyword( "nonclustered" );
4267                                if ( node.getColumnList( ) != null )
4268                                {
4269                                        acceptSymbol( "(" );
4270                                        // visitObjectNameList( node.getColumnList( ) );
4271                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4272                                        {
4273                                                node.getColumnList( ).getElement( i ).accept( this );
4274                                                if ( i != node.getColumnList( ).size( ) - 1 )
4275                                                {
4276                                                        acceptSymbol( "," );
4277                                                }
4278                                        }
4279                                        acceptSymbol( ")" );
4280                                }
4281                                break;
4282                        case check :
4283                                acceptKeyword( "check" );
4284                                if ( node.getCheckCondition( ) != null )
4285                                {
4286                                        acceptSymbol( "(" );
4287                                        node.getCheckCondition( ).accept( this );
4288                                        acceptSymbol( ")" );
4289                                }
4290                                else
4291                                {
4292                                        // db2 functional dependency
4293                                }
4294
4295                                break;
4296                        case primary_key :
4297                                acceptKeyword( "primary" );
4298                                acceptKeyword( "key" );
4299                                if ( node.isClustered( ) )
4300                                        acceptKeyword( "clustered" );
4301                                if ( node.isNonClustered( ) )
4302                                        acceptKeyword( "nonclustered" );
4303
4304                                if ( node.getColumnList( ) != null )
4305                                {
4306                                        acceptSymbol( "(" );
4307                                        // visitObjectNameList( node.getColumnList( ) );
4308                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4309                                        {
4310                                                node.getColumnList( ).getElement( i ).accept( this );
4311                                                if ( i != node.getColumnList( ).size( ) - 1 )
4312                                                {
4313                                                        acceptSymbol( "," );
4314                                                }
4315                                        }
4316                                        acceptSymbol( ")" );
4317                                }
4318                                break;
4319                        case foreign_key :
4320                                acceptKeyword( "foreign" );
4321                                acceptKeyword( "key" );
4322                                if ( node.getColumnList( ) != null )
4323                                {
4324                                        acceptSymbol( "(" );
4325                                        // visitObjectNameList( node.getColumnList( ) );
4326                                        for ( int i = 0; i < node.getColumnList( ).size( ); i++ )
4327                                        {
4328                                                node.getColumnList( ).getElement( i ).accept( this );
4329                                                if ( i != node.getColumnList( ).size( ) - 1 )
4330                                                {
4331                                                        acceptSymbol( "," );
4332                                                }
4333                                        }
4334                                        acceptSymbol( ")" );
4335                                }
4336
4337                                if ( node.getReferencedObject( ) != null )
4338                                {
4339                                        acceptKeyword( "references" );
4340                                        node.getReferencedObject( ).accept( this );
4341                                }
4342
4343                                if ( node.getReferencedColumnList( ) != null )
4344                                {
4345                                        acceptSymbol( "(" );
4346                                        visitObjectNameList( node.getReferencedColumnList( ) );
4347                                        acceptSymbol( ")" );
4348                                }
4349
4350                                if ( node.getKeyActions( ) != null
4351                                                && node.getKeyActions( ).size( ) > 0 )
4352                                {
4353                                        for ( int i = 0; i < node.getKeyActions( ).size( ); i++ )
4354                                        {
4355                                                TKeyAction keyAction = node.getKeyActions( )
4356                                                                .getElement( i );
4357                                                preVisit( keyAction );
4358                                        }
4359                                }
4360
4361                                break;
4362                        case reference :
4363                                acceptKeyword( "references" );
4364                                if ( node.getReferencedObject( ) != null )
4365                                {
4366                                        node.getReferencedObject( ).accept( this );
4367                                }
4368
4369                                if ( node.getReferencedColumnList( ) != null )
4370                                {
4371                                        acceptSymbol( "(" );
4372                                        visitObjectNameList( node.getReferencedColumnList( ) );
4373                                        acceptSymbol( ")" );
4374                                }
4375
4376                                if ( node.getKeyActions( ) != null
4377                                                && node.getKeyActions( ).size( ) > 0 )
4378                                {
4379                                        for ( int i = 0; i < node.getKeyActions( ).size( ); i++ )
4380                                        {
4381                                                TKeyAction keyAction = node.getKeyActions( )
4382                                                                .getElement( i );
4383                                                preVisit( keyAction );
4384                                        }
4385                                }
4386
4387                                break;
4388                        case default_value :
4389                                acceptKeyword( "default" );
4390                                node.getDefaultExpression( ).accept( this );
4391                                //add by grq 2023.04.29 issue=I6ZJ3V
4392                                if (node.getForObjectName()!= null){
4393                                        acceptKeyword( "for" );
4394                                        node.getForObjectName().accept(this);
4395                                }
4396                                //end by grq
4397                                break;
4398                        default :
4399                                break;
4400                }
4401
4402                if (node.getWithIndexoption() != null){
4403                        acceptNewline();
4404                        visitNodeByToken(node.getWithIndexoption());
4405                }
4406                if (node.getOnFilegroup() != null){
4407                        acceptNewline();
4408                        visitNodeByToken(node.getOnFilegroup());
4409                }
4410
4411        }
4412
4413        public void preVisit( TKeyAction node )
4414        {
4415                if ( node.getActionType( ) == EKeyActionType.delete )
4416                {
4417                        acceptKeyword( "on" );
4418                        acceptKeyword( "delete" );
4419                }
4420
4421                if ( node.getActionType( ) == EKeyActionType.update )
4422                {
4423                        acceptKeyword( "on" );
4424                        acceptKeyword( "update" );
4425                }
4426
4427                if ( node.getKeyReference( ) != null )
4428                {
4429                        preVisit( node.getKeyReference( ) );
4430                }
4431        }
4432
4433        public void preVisit( TKeyReference node )
4434        {
4435                if ( node.getReferenceType( ) == EKeyReferenceType.set_null )
4436                {
4437                        acceptKeyword( "set" );
4438                        acceptKeyword( "null" );
4439                }
4440
4441                if ( node.getReferenceType( ) == EKeyReferenceType.set_default )
4442                {
4443                        acceptKeyword( "set" );
4444                        acceptKeyword( "default" );
4445                }
4446
4447                if ( node.getReferenceType( ) == EKeyReferenceType.cascade )
4448                {
4449                        acceptKeyword( "cascade" );
4450                }
4451
4452                if ( node.getReferenceType( ) == EKeyReferenceType.restrict )
4453                {
4454                        acceptKeyword( "restrict" );
4455                }
4456
4457                if ( node.getReferenceType( ) == EKeyReferenceType.no_action )
4458                {
4459                        acceptKeyword( "no" );
4460                        acceptKeyword( "action" );
4461                }
4462        }
4463
4464        public void preVisit( TTypeName node )
4465        {
4466                acceptKeyword( node.getDataTypeName( ) );
4467
4468                switch ( node.getDataType( ) )
4469                {
4470                        case bigint_t :
4471                        case bit_t :
4472                        case money_t :
4473                        case smallmoney_t :
4474                        case smallint_t :
4475                        case tinyint_t :
4476                        case real_t :
4477                        case smalldatetime_t :
4478                        case datetime_t :
4479                        case datetime2_t :
4480                        case text_t :
4481                        case ntext_t :
4482                        case image_t :
4483                        case rowversion_t :
4484                        case uniqueidentifier_t :
4485                        case sql_variant_t :
4486                        case binary_float_t :
4487                        case binary_double_t :
4488                        case integer_t :
4489                        case int_t :
4490                        case double_t :
4491                        case date_t :
4492                                if ( node.getPrecision( ) != null )
4493                                {
4494                                        acceptSymbol( "(" );
4495                                        node.getPrecision( ).accept( this );
4496                                        if ( node.getScale( ) != null )
4497                                        {
4498                                                acceptSymbol( "," );
4499                                                node.getScale( ).accept( this );
4500                                        }
4501                                        acceptSymbol( ")" );
4502                                }
4503                                break;
4504
4505                        case binary_t :
4506                        case varbinary_t :
4507                        case long_t :
4508                        case raw_t :
4509                        case long_raw_t :
4510                        case blob_t :
4511                        case clob_t :
4512                        case nclob_t :
4513                        case bfile_t :
4514                        case urowid_t :
4515                                if ( node.getLength( ) != null )
4516                                {
4517                                        acceptSymbol( "(" );
4518                                        node.getLength( ).accept( this );
4519                                        acceptSymbol( ")" );
4520                                }
4521                                break;
4522                        case timestamp_t :
4523                                if ( node.getScale( ) != null )
4524                                {
4525                                        acceptSymbol( "(" );
4526                                        node.getScale( ).accept( this );
4527                                        acceptSymbol( ")" );
4528                                }
4529                                break;
4530                        case decimal_t :
4531                        case dec_t :
4532                        case numeric_t :
4533                        case number_t :
4534                        case float_t :
4535
4536                                if ( node.getPrecision( ) != null )
4537                                {
4538                                        acceptSymbol( "(" );
4539                                        node.getPrecision( ).accept( this );
4540                                        if ( node.getScale( ) != null )
4541                                        {
4542                                                acceptSymbol( "," );
4543                                                node.getScale( ).accept( this );
4544                                        }
4545                                        acceptSymbol( ")" );
4546                                }
4547                                break;
4548
4549                        case char_t :
4550                        case character_t :
4551                        case varchar_t :
4552                        case nchar_t :
4553                        case nvarchar_t :
4554                        case ncharacter_t :
4555                        case nvarchar2_t :
4556                        case varchar2_t :
4557                                if ( node.isVarying( ) )
4558                                        acceptKeyword( "varying" );
4559                                if ( node.getLength( ) != null )
4560                                {
4561                                        acceptSymbol( "(" );
4562                                        node.getLength( ).accept( this );
4563                                        if ( node.isByteUnit( ) )
4564                                                acceptKeyword( "byte" );
4565                                        if ( node.isCharUnit( ) )
4566                                                acceptKeyword( "char" );
4567                                        acceptSymbol( ")" );
4568                                }
4569                                if ( node.getCharsetName( ) != null )
4570                                {
4571                                        if ( node.getGsqlparser( ) != null
4572                                                        && node.getGsqlparser( ).getDbVendor( ) == EDbVendor.dbvmysql )
4573                                        {
4574                                                acceptKeyword( "CHARACTER" );
4575                                                acceptKeyword( "SET" );
4576                                                acceptSpace( 1 );
4577                                                acceptIdentifier( node.getCharsetName( ) );
4578                                        }
4579                                        else
4580                                        {
4581                                                acceptSpace( 1 );
4582                                                acceptIdentifier( node.getCharsetName( ) );
4583                                        }
4584                                }
4585                                break;
4586                        case datetimeoffset_t :
4587                        //case datetime2_t :
4588                        case time_t :
4589                                if ( node.getFractionalSecondsPrecision( ) != null )
4590                                {
4591                                        acceptSymbol( "(" );
4592                                        node.getFractionalSecondsPrecision( ).accept( this );
4593                                        acceptSymbol( ")" );
4594                                }
4595                                break;
4596                        case timestamp_with_time_zone_t :
4597
4598                                if ( node.getFractionalSecondsPrecision( ) != null )
4599                                {
4600                                        acceptSymbol( "(" );
4601                                        node.getFractionalSecondsPrecision( ).accept( this );
4602                                        acceptSymbol( ")" );
4603                                }
4604                                acceptKeyword( "with" );
4605                                acceptKeyword( "time" );
4606                                acceptKeyword( "zone" );
4607                                break;
4608                        case timestamp_with_local_time_zone_t :
4609                                if ( node.getFractionalSecondsPrecision( ) != null )
4610                                {
4611                                        acceptSymbol( "(" );
4612                                        node.getFractionalSecondsPrecision( ).accept( this );
4613                                        acceptSymbol( ")" );
4614                                }
4615                                acceptKeyword( "with" );
4616                                acceptKeyword( "local" );
4617                                acceptKeyword( "time" );
4618                                acceptKeyword( "zone" );
4619                                break;
4620                        case interval_year_to_month_t :
4621                                if ( node.getPrecision( ) != null )
4622                                {
4623                                        acceptSymbol( "(" );
4624                                        node.getPrecision( ).accept( this );
4625                                        acceptSymbol( ")" );
4626                                }
4627                                acceptKeyword( "to" );
4628                                acceptKeyword( "month" );
4629                                break;
4630                        case interval_day_to_second_t :
4631                                if ( node.getPrecision( ) != null )
4632                                {
4633                                        acceptSymbol( "(" );
4634                                        node.getPrecision( ).accept( this );
4635                                        acceptSymbol( ")" );
4636                                }
4637                                acceptKeyword( "to" );
4638                                acceptKeyword( "second" );
4639                                if ( node.getSecondsPrecision( ) != null )
4640                                {
4641                                        acceptSymbol( "(" );
4642                                        node.getSecondsPrecision( ).accept( this );
4643                                        acceptSymbol( ")" );
4644                                }
4645                                break;
4646                        case generic_t :
4647                                // if ( node.getDataTypeObjectName( ) != null )
4648                                // {
4649                                // acceptSpace( 1 );
4650                                // node.getDataTypeObjectName( ).accept( this );
4651                                // }
4652                                // else if ( node.getDataTypeName( ) != null )
4653                                // {
4654                                // acceptSpace( 1 );
4655                                // acceptIdentifier( node.getDataTypeName( ) );
4656                                // }
4657                                break;
4658                        default :
4659                                break;
4660                }
4661
4662                if (node.getArrays() != null && node.getArrays().size() > 0)
4663                {
4664                        for (int i = 0; i < node.getArrays().size(); i++)
4665                        {
4666                                TIndices array = node.getArrays().getElement(i);
4667                                if (array.getAttributeName() != null)
4668                                {
4669                                        array.getAttributeName().accept(this);
4670                                }
4671                                acceptSymbol("[");
4672                                if (array.getLowerSubscript() != null)
4673                                {
4674                                        array.getLowerSubscript().accept(this);
4675                                }
4676                                if (array.getUpperSubscript() != null)
4677                                {
4678                                        if (array.getLowerSubscript() != null)
4679                                        {
4680                                                acceptSymbol(":");
4681                                        }
4682                                        array.getUpperSubscript().accept(this);
4683                                }
4684                                acceptSymbol("]");
4685                        }
4686                }
4687        }
4688
4689        public void preVisit( TKeepDenseRankClause node )
4690        {
4691                acceptKeyword( "keep" );
4692                acceptSymbol( "(" );
4693                acceptKeyword( "dense_rank" );
4694                if ( node.isFirst( ) )
4695                        acceptKeyword( "first" );
4696                if ( node.isLast( ) )
4697                        acceptKeyword( "last" );
4698                node.getOrderBy( ).accept( this );
4699                acceptSymbol( ")" );
4700        }
4701
4702        public void preVisit( TRollupCube node )
4703        {
4704                if ( node.getOperation( ) == TRollupCube.cube )
4705                {
4706                        acceptKeyword( "cube" );
4707                }
4708                else if ( node.getOperation( ) == TRollupCube.rollup )
4709                {
4710                        acceptKeyword( "rollup" );
4711                }
4712                acceptSymbol( "(" );
4713                visitExprList( node.getItems( ) );
4714                acceptSymbol( ")" );
4715        }
4716
4717        public void preVisit( TGroupingSet node )
4718        {
4719                acceptKeyword( "grouping" );
4720                acceptKeyword( "sets" );
4721                acceptSymbol( "(" );
4722                for ( int i = 0; i < node.getItems( ).size( ); i++ )
4723                {
4724                        node.getItems( ).getGroupingSetItem( i ).accept( this );
4725                        if ( i != node.getItems( ).size( ) - 1 )
4726                                acceptSymbol( "," );
4727                }
4728                acceptSymbol( ")" );
4729
4730        }
4731
4732        public void preVisit( TGroupingSetItem node )
4733        {
4734                if ( node.getRollupCubeClause( ) != null )
4735                {
4736                        node.getRollupCubeClause( ).accept( this );
4737                }
4738                else if ( node.getGrouping_expression( ) != null )
4739                {
4740                        node.getGrouping_expression( ).accept( this );
4741                }
4742
4743        }
4744
4745        public void preVisit( TReturningClause node )
4746        {
4747                acceptKeyword( "returning" );
4748                visitExprList( node.getColumnValueList( ) );
4749                if ( node.isBulkCollect( ) )
4750                {
4751                        acceptKeyword( "bulk" );
4752                        acceptKeyword( "collect" );
4753                }
4754                acceptKeyword( "into" );
4755                visitExprList( node.getVariableList( ) );
4756        }
4757
4758        public void preVisit( TDropIndexSqlStatement dropIndex )
4759        {
4760                acceptKeyword( "drop" );
4761                acceptKeyword( "index" );
4762
4763
4764                if ( dropIndex.getDropIndexItemList( ) != null
4765                                && dropIndex.getDropIndexItemList( ).size( ) > 0 )
4766                {
4767                        for ( int i = 0; i < dropIndex.getDropIndexItemList( ).size( ); i++ )
4768                        {
4769                                TDropIndexItem item = dropIndex.getDropIndexItemList( )
4770                                                .getDropIndexItem( i );
4771                                if ( item.getIndexName( ) != null )
4772                                {
4773                                        item.getIndexName( ).accept( this );
4774                                }
4775                                if ( item.getObjectName( ) != null )
4776                                {
4777                                        acceptKeyword( "on" );
4778                                        item.getObjectName( ).accept( this );
4779                                }
4780                        }
4781                }else{
4782                        if ( dropIndex.getIndexName( ) != null )
4783                        {
4784                                dropIndex.getIndexName( ).accept( this );
4785                        }
4786                }
4787        }
4788
4789        public void preVisit( TCreateIndexSqlStatement createIndex )
4790        {
4791                acceptKeyword( "create" );
4792
4793                if ( createIndex.isNonClustered( ) )
4794                {
4795                        acceptKeyword( "nonclustered" );
4796                }
4797
4798                if ( createIndex.isClustered( ) )
4799                {
4800                        acceptKeyword( "clustered" );
4801                }
4802
4803                if ( createIndex.getIndexType( ) == EIndexType.itUnique )
4804                {
4805                        acceptKeyword( "unique" );
4806                }
4807
4808                acceptKeyword( "index" );
4809
4810                if ( createIndex.getIndexName( ) != null )
4811                {
4812                        createIndex.getIndexName( ).accept( this );
4813                }
4814
4815                if ( createIndex.getTableName( ) != null )
4816                {
4817                        acceptKeyword( "on" );
4818
4819                        createIndex.getTableName( ).accept( this );
4820
4821                        if ( createIndex.getColumnNameList( ) != null
4822                                        && createIndex.getColumnNameList( ).size( ) > 0 )
4823                        {
4824                                acceptSpace( 1 );
4825                                acceptSymbol( "(" );
4826                                createIndex.getColumnNameList( ).accept( this );
4827                                acceptSymbol( ")" );
4828                        }
4829                }
4830                if ( createIndex.getFilegroupOrPartitionSchemeName( ) != null )
4831                {
4832                        acceptKeyword( "on" );
4833
4834                        createIndex.getFilegroupOrPartitionSchemeName( ).accept( this );
4835
4836                        if ( createIndex.getPartitionSchemeColumns( ) != null
4837                                        && createIndex.getPartitionSchemeColumns( ).size( ) > 0 )
4838                        {
4839                                acceptSpace( 1 );
4840                                acceptSymbol( "(" );
4841                                createIndex.getPartitionSchemeColumns( ).accept( this );
4842                                acceptSymbol( ")" );
4843                        }
4844                }
4845        }
4846
4847        public void preVisit( TOrderByItemList orderByList )
4848        {
4849                for ( int i = 0; i < orderByList.size( ); i++ )
4850                {
4851                        orderByList.getOrderByItem( i ).accept( this );
4852                        if ( i != orderByList.size( ) - 1 )
4853                                acceptSymbol( "," );
4854                }
4855        }
4856
4857        public void preVisit( TUseDatabase useDataBase )
4858        {
4859                acceptKeyword( "use" );
4860
4861                if ( useDataBase.getDatabaseName( ) != null )
4862                {
4863                        useDataBase.getDatabaseName( ).accept( this );
4864                }
4865        }
4866
4867        public void preVisit( TPlsqlCreateProcedure procedure )
4868        {
4869                acceptKeyword( "create" );
4870                acceptKeyword( "procedure" );
4871
4872                if ( procedure.getProcedureName( ) != null )
4873                {
4874                        procedure.getProcedureName( ).accept( this );
4875                }
4876
4877                if ( procedure.getParameterDeclarations( ) != null
4878                                && procedure.getParameterDeclarations( ).size( ) > 0 )
4879                {
4880                        acceptSymbol( "(" );
4881                        procedure.getParameterDeclarations( ).accept( this );
4882                        acceptSymbol( ")" );
4883                }
4884
4885                acceptNewline( );
4886
4887                if ( procedure.getInvokerRightsClause( ) != null )
4888                {
4889                        procedure.getInvokerRightsClause( ).accept( this );
4890                }
4891
4892                acceptKeyword( "as" );
4893
4894                if ( procedure.getDeclareStatements( ) != null
4895                                && procedure.getDeclareStatements( ).size( ) > 0 )
4896                {
4897                        acceptNewline( );
4898                        procedure.getDeclareStatements( ).accept( this );
4899                        if ( procedure.getDeclareStatements( ).size( ) == 1 )
4900                        {
4901                                acceptSemicolon( );
4902                        }
4903                }
4904
4905                acceptNewline( );
4906                acceptKeyword( "begin" );
4907
4908                if ( procedure.getBodyStatements( ) != null
4909                                && procedure.getBodyStatements( ).size( ) > 0 )
4910                {
4911                        acceptNewline( );
4912                        procedure.getBodyStatements( ).accept( this );
4913                        if ( procedure.getBodyStatements( ).size( ) == 1 )
4914                        {
4915                                acceptSemicolon( );
4916                        }
4917                }
4918
4919                acceptNewline( );
4920                acceptKeyword( "end" );
4921                acceptSemicolon( );
4922        }
4923
4924        public void preVisit( TInvokerRightsClause clause )
4925        {
4926                acceptKeyword( "authid" );
4927                if ( clause.getDefiner( ) != null )
4928                {
4929                        clause.getDefiner( ).accept( this );
4930                }
4931        }
4932
4933        void visitPrecisionScale( TConstant precision, TConstant scale )
4934        {
4935                if ( precision != null )
4936                {
4937                        acceptSymbol( "(" );
4938                        precision.accept( this );
4939                        if ( scale != null )
4940                        {
4941                                acceptSymbol( "," );
4942                                scale.accept( this );
4943                        }
4944                        acceptSymbol( ")" );
4945                }
4946        }
4947
4948        void visitExprList( TExpressionList expressionList )
4949        {
4950                for ( int i = 0; i < expressionList.size( ); i++ )
4951                {
4952                        expressionList.getExpression( i ).accept( this );
4953                        if ( i != expressionList.size( ) - 1 )
4954                                acceptSymbol( "," );
4955                }
4956        }
4957
4958        void visitObjectNameList( TObjectNameList objectNameList )
4959        {
4960                for ( int i = 0; i < objectNameList.size( ); i++ )
4961                {
4962                        objectNameList.getObjectName( i ).accept( this );
4963                        if ( i != objectNameList.size( ) - 1 )
4964                                acceptSymbol( "," );
4965                }
4966        }
4967
4968        void visitCTEList( TCTEList cteList )
4969        {
4970                for ( int i = 0; i < cteList.size( ); i++ )
4971                {
4972                        cteList.getCTE( i ).accept( this );
4973                        if ( i != cteList.size( ) - 1 )
4974                        {
4975                                acceptSymbol( "," );
4976                                acceptNewline( );
4977                        }
4978                }
4979        }
4980
4981        void visitJoinList( TJoinList joinList )
4982        {
4983                for ( int i = 0; i < joinList.size( ); i++ )
4984                {
4985                        acceptNewline( );
4986                        joinList.getJoin( i ).accept( this );
4987                        if ( i != joinList.size( ) - 1 )
4988                                acceptSymbol( "," );
4989                }
4990        }
4991
4992        void visitResultColumnList( TResultColumnList resultColumnList )
4993        {
4994                for ( int i = 0; i < resultColumnList.size( ); i++ )
4995                {
4996                        resultColumnList.getElement( i ).accept( this );
4997                        if ( i != resultColumnList.size( ) - 1 )
4998                        {
4999                                acceptSymbol( "," );
5000                        }
5001                }
5002        }
5003
5004        void visitNodeByToken( TParseTreeNode node )
5005        {
5006                if ( node.getStartToken( ) == null )
5007                        return;
5008                if ( node.getEndToken( ) == null )
5009                        return;
5010                if ( node.getStartToken( ).container == null )
5011                        return;
5012                acceptSpace( 1 );
5013
5014                TSourceToken nextToken = node.getStartToken( );
5015                while (nextToken != null && nextToken != node.getEndToken( ))
5016                {
5017                        acceptToken( nextToken );
5018                        nextToken = nextToken.getNextTokenInChain( );
5019                }
5020                if (nextToken != null)
5021                {
5022                        acceptToken( nextToken );
5023                }
5024
5025
5026//              if ((node.getStartToken().container !=null) && (node.getStartToken( ).container.size() > node.getEndToken().posinlist)){
5027//                      for ( int i = node.getStartToken( ).posinlist; i <= node.getEndToken( ).posinlist; i++ )
5028//                      {
5029//                              acceptToken( node.getStartToken( ).container.get( i ) );
5030//                      }
5031//              }else{
5032//                      TSourceToken nextToken = node.getStartToken( );
5033//                      while (nextToken != null && nextToken != node.getEndToken( ))
5034//                      {
5035//                              acceptToken( nextToken );
5036//                              nextToken = nextToken.getNextTokenInChain( );
5037//                      }
5038//                      if (nextToken != null)
5039//                      {
5040//                              acceptToken( nextToken );
5041//                      }
5042//              }
5043                acceptSpace( 1 );
5044        }
5045
5046}