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