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