1- // Copyright (C) 2011-2021 Xtensive LLC.
1+ // Copyright (C) 2011-2022 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Csaba Beer
@@ -29,7 +29,7 @@ public override void Visit(SqlSelect node)
2929 using ( context . EnterScope ( node ) ) {
3030 var comment = node . Comment ;
3131 VisitCommentIfBefore ( comment ) ;
32- context . Output . AppendText ( translator . Translate ( context , node , SelectSection . Entry ) ) ;
32+ AppendTranslatedEntry ( node ) ;
3333 VisitCommentIfWithin ( comment ) ;
3434 VisitSelectLimitOffset ( node ) ;
3535 VisitSelectColumns ( node ) ;
@@ -38,40 +38,42 @@ public override void Visit(SqlSelect node)
3838 VisitSelectGroupBy ( node ) ;
3939 VisitSelectOrderBy ( node ) ;
4040 VisitSelectLock ( node ) ;
41- context . Output . AppendText ( translator . Translate ( context , node , SelectSection . Exit ) ) ;
41+ AppendTranslatedExit ( node ) ;
4242 VisitCommentIfAfter ( comment ) ;
4343 }
4444 }
4545
4646 /// <inheritdoc/>
47- public override void VisitSelectFrom ( SqlSelect node )
47+ protected override void VisitSelectFrom ( SqlSelect node )
4848 {
49- if ( node . From != null )
49+ if ( node . From != null ) {
5050 base . VisitSelectFrom ( node ) ;
51- else
52- context . Output . AppendText ( "FROM RDB$DATABASE" ) ;
51+ }
52+ else {
53+ _ = context . Output . Append ( " FROM RDB$DATABASE" ) ;
54+ }
5355 }
5456
5557 /// <inheritdoc/>
5658 public override void Visit ( SqlQueryExpression node )
5759 {
5860 using ( context . EnterScope ( node ) ) {
59- bool needOpeningParenthesis = false ;
60- bool needClosingParenthesis = false ;
61- context . Output . AppendText ( translator . Translate ( context , node , QueryExpressionSection . Entry ) ) ;
62- if ( needOpeningParenthesis )
63- context . Output . AppendText ( "(" ) ;
61+ // bool needOpeningParenthesis = false;
62+ // bool needClosingParenthesis = false;
63+ AppendTranslated ( node , QueryExpressionSection . Entry ) ;
64+ // if (needOpeningParenthesis)
65+ // context.Output.Append ("(");
6466 node . Left . AcceptVisitor ( this ) ;
65- if ( needClosingParenthesis )
66- context . Output . AppendText ( ")" ) ;
67- context . Output . AppendText ( translator . Translate ( node . NodeType ) ) ;
68- context . Output . AppendText ( translator . Translate ( context , node , QueryExpressionSection . All ) ) ;
69- if ( needOpeningParenthesis )
70- context . Output . AppendText ( "(" ) ;
67+ // if (needClosingParenthesis)
68+ // context.Output.Append (")");
69+ AppendTranslated ( node . NodeType ) ;
70+ AppendTranslated ( node , QueryExpressionSection . All ) ;
71+ // if (needOpeningParenthesis)
72+ // context.Output.Append ("(");
7173 node . Right . AcceptVisitor ( this ) ;
72- if ( needClosingParenthesis )
73- context . Output . AppendText ( ")" ) ;
74- context . Output . AppendText ( translator . Translate ( context , node , QueryExpressionSection . Exit ) ) ;
74+ // if (needClosingParenthesis)
75+ // context.Output.Append (")");
76+ AppendTranslated ( node , QueryExpressionSection . Exit ) ;
7577 }
7678 }
7779
@@ -105,17 +107,19 @@ public override void Visit(SqlExtract node)
105107 Visit ( SqlDml . Add ( node , SqlDml . Literal ( 1 ) ) ) ;
106108 case_SqlDateTimePart_DayOfYear = false ;
107109 }
108- else
110+ else {
109111 base . Visit ( node ) ;
112+ }
110113 return ;
111114 case SqlDateTimePart . Second :
112115 if ( ! case_SqlDateTimePart_Second ) {
113116 case_SqlDateTimePart_Second = true ;
114117 Visit ( SqlDml . Truncate ( node ) ) ;
115118 case_SqlDateTimePart_Second = false ;
116119 }
117- else
120+ else {
118121 base . Visit ( node ) ;
122+ }
119123 return ;
120124 }
121125 base . Visit ( node ) ;
@@ -124,7 +128,7 @@ public override void Visit(SqlExtract node)
124128 /// <inheritdoc/>
125129 public override void Visit ( SqlUnary node )
126130 {
127- if ( node . NodeType == SqlNodeType . BitNot ) {
131+ if ( node . NodeType == SqlNodeType . BitNot ) {
128132 Visit ( BitNot ( node . Operand ) ) ;
129133 return ;
130134 }
@@ -145,7 +149,7 @@ public override void Visit(SqlBinary node)
145149 DateTimeSubtractDateTime ( node . Left , node . Right ) . AcceptVisitor ( this ) ;
146150 return ;
147151 case SqlNodeType . Modulo :
148- Visit ( SqlDml . FunctionCall ( translator . Translate ( SqlNodeType . Modulo ) , node . Left , node . Right ) ) ;
152+ Visit ( SqlDml . FunctionCall ( translator . TranslateToString ( SqlNodeType . Modulo ) , node . Left , node . Right ) ) ;
149153 return ;
150154 case SqlNodeType . BitAnd :
151155 BitAnd ( node . Left , node . Right ) . AcceptVisitor ( this ) ;
@@ -201,25 +205,24 @@ public override void Visit(SqlFunctionCall node)
201205 base . Visit ( node ) ;
202206 }
203207
204- public override void Visit ( SqlRenameTable node )
205- {
206- throw new NotSupportedException ( ) ;
207- }
208+ /// <inheritdoc/>
209+ public override void Visit ( SqlRenameTable node ) => throw new NotSupportedException ( ) ;
208210
211+ /// <inheritdoc/>
209212 public override void Visit ( SqlAlterSequence node )
210213 {
211- context . Output . AppendText ( translator . Translate ( context , node , NodeSection . Entry ) ) ;
212- context . Output . AppendText ( translator . Translate ( context , node , NodeSection . Exit ) ) ;
214+ translator . Translate ( context , node , NodeSection . Entry ) ;
215+ translator . Translate ( context , node , NodeSection . Exit ) ;
213216 }
214217
215218 #region Static helpers
216219
217220 protected static SqlExpression DateTimeSubtractDateTime ( SqlExpression date1 , SqlExpression date2 )
218221 {
219- return CastToLong ( DateDiffDay ( date2 , date1 ) ) * NanosecondsPerDay
222+ return ( CastToLong ( DateDiffDay ( date2 , date1 ) ) * NanosecondsPerDay )
220223 +
221- CastToLong ( DateDiffMillisecond ( DateAddDay ( date2 , DateDiffDay ( date2 , date1 ) ) , date1 ) ) *
222- NanosecondsPerMillisecond ;
224+ ( CastToLong ( DateDiffMillisecond ( DateAddDay ( date2 , DateDiffDay ( date2 , date1 ) ) , date1 ) ) *
225+ NanosecondsPerMillisecond ) ;
223226 }
224227
225228 protected static SqlExpression DateTimeAddInterval ( SqlExpression date , SqlExpression interval )
@@ -229,75 +232,46 @@ protected static SqlExpression DateTimeAddInterval(SqlExpression date, SqlExpres
229232 ( interval / NanosecondsPerMillisecond ) % ( MillisecondsPerDay ) ) ;
230233 }
231234
232- protected static SqlCast CastToLong ( SqlExpression arg )
233- {
234- return SqlDml . Cast ( arg , SqlType . Int64 ) ;
235- }
235+ protected static SqlCast CastToLong ( SqlExpression arg ) => SqlDml . Cast ( arg , SqlType . Int64 ) ;
236236
237- protected static SqlUserFunctionCall DateDiffDay ( SqlExpression date1 , SqlExpression date2 )
238- {
239- return SqlDml . FunctionCall ( "DATEDIFF" , SqlDml . Native ( "DAY" ) , date1 , date2 ) ;
240- }
237+ protected static SqlUserFunctionCall DateDiffDay ( SqlExpression date1 , SqlExpression date2 ) =>
238+ SqlDml . FunctionCall ( "DATEDIFF" , SqlDml . Native ( "DAY" ) , date1 , date2 ) ;
241239
242- protected static SqlUserFunctionCall DateDiffMillisecond ( SqlExpression date1 , SqlExpression date2 )
243- {
244- return SqlDml . FunctionCall ( "DATEDIFF" , SqlDml . Native ( "MILLISECOND" ) , date1 , date2 ) ;
245- }
240+ protected static SqlUserFunctionCall DateDiffMillisecond ( SqlExpression date1 , SqlExpression date2 ) =>
241+ SqlDml . FunctionCall ( "DATEDIFF" , SqlDml . Native ( "MILLISECOND" ) , date1 , date2 ) ;
246242
247- protected static SqlUserFunctionCall DateAddYear ( SqlExpression date , SqlExpression years )
248- {
249- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "YEAR" ) , years , date ) ;
250- }
243+ protected static SqlUserFunctionCall DateAddYear ( SqlExpression date , SqlExpression years ) =>
244+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "YEAR" ) , years , date ) ;
251245
252- protected static SqlUserFunctionCall DateAddMonth ( SqlExpression date , SqlExpression months )
253- {
254- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MONTH" ) , months , date ) ;
255- }
246+ protected static SqlUserFunctionCall DateAddMonth ( SqlExpression date , SqlExpression months ) =>
247+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MONTH" ) , months , date ) ;
256248
257- protected static SqlUserFunctionCall DateAddDay ( SqlExpression date , SqlExpression days )
258- {
259- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "DAY" ) , days , date ) ;
260- }
249+ protected static SqlUserFunctionCall DateAddDay ( SqlExpression date , SqlExpression days ) =>
250+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "DAY" ) , days , date ) ;
261251
262- protected static SqlUserFunctionCall DateAddHour ( SqlExpression date , SqlExpression hours )
263- {
264- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "HOUR" ) , hours , date ) ;
265- }
252+ protected static SqlUserFunctionCall DateAddHour ( SqlExpression date , SqlExpression hours ) =>
253+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "HOUR" ) , hours , date ) ;
266254
267- protected static SqlUserFunctionCall DateAddMinute ( SqlExpression date , SqlExpression minutes )
268- {
269- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MINUTE" ) , minutes , date ) ;
270- }
255+ protected static SqlUserFunctionCall DateAddMinute ( SqlExpression date , SqlExpression minutes ) =>
256+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MINUTE" ) , minutes , date ) ;
271257
272- protected static SqlUserFunctionCall DateAddSecond ( SqlExpression date , SqlExpression seconds )
273- {
274- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "SECOND" ) , seconds , date ) ;
275- }
258+ protected static SqlUserFunctionCall DateAddSecond ( SqlExpression date , SqlExpression seconds ) =>
259+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "SECOND" ) , seconds , date ) ;
276260
277- protected static SqlUserFunctionCall DateAddMillisecond ( SqlExpression date , SqlExpression milliseconds )
278- {
279- return SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MILLISECOND" ) , milliseconds , date ) ;
280- }
261+ protected static SqlUserFunctionCall DateAddMillisecond ( SqlExpression date , SqlExpression milliseconds ) =>
262+ SqlDml . FunctionCall ( "DATEADD" , SqlDml . Native ( "MILLISECOND" ) , milliseconds , date ) ;
281263
282- protected static SqlUserFunctionCall BitAnd ( SqlExpression left , SqlExpression right )
283- {
284- return SqlDml . FunctionCall ( "BIN_AND" , left , right ) ;
285- }
264+ protected static SqlUserFunctionCall BitAnd ( SqlExpression left , SqlExpression right ) =>
265+ SqlDml . FunctionCall ( "BIN_AND" , left , right ) ;
286266
287- protected static SqlUserFunctionCall BitOr ( SqlExpression left , SqlExpression right )
288- {
289- return SqlDml . FunctionCall ( "BIN_OR" , left , right ) ;
290- }
267+ protected static SqlUserFunctionCall BitOr ( SqlExpression left , SqlExpression right ) =>
268+ SqlDml . FunctionCall ( "BIN_OR" , left , right ) ;
291269
292- protected static SqlUserFunctionCall BitXor ( SqlExpression left , SqlExpression right )
293- {
294- return SqlDml . FunctionCall ( "BIN_XOR" , left , right ) ;
295- }
270+ protected static SqlUserFunctionCall BitXor ( SqlExpression left , SqlExpression right ) =>
271+ SqlDml . FunctionCall ( "BIN_XOR" , left , right ) ;
296272
297- protected static SqlUserFunctionCall BitNot ( SqlExpression operand )
298- {
299- return SqlDml . FunctionCall ( "BIN_NOT" , operand ) ;
300- }
273+ protected static SqlUserFunctionCall BitNot ( SqlExpression operand ) =>
274+ SqlDml . FunctionCall ( "BIN_NOT" , operand ) ;
301275
302276 protected static SqlConcat DateTimeToStringIso ( SqlExpression dateTime )
303277 {
0 commit comments