1
- // Copyright (C) 2011-2021 Xtensive LLC.
1
+ // Copyright (C) 2011-2022 Xtensive LLC.
2
2
// This code is distributed under MIT license terms.
3
3
// See the License.txt file in the project root for more information.
4
4
// Created by: Csaba Beer
@@ -29,7 +29,7 @@ public override void Visit(SqlSelect node)
29
29
using ( context . EnterScope ( node ) ) {
30
30
var comment = node . Comment ;
31
31
VisitCommentIfBefore ( comment ) ;
32
- context . Output . AppendText ( translator . Translate ( context , node , SelectSection . Entry ) ) ;
32
+ AppendTranslatedEntry ( node ) ;
33
33
VisitCommentIfWithin ( comment ) ;
34
34
VisitSelectLimitOffset ( node ) ;
35
35
VisitSelectColumns ( node ) ;
@@ -38,40 +38,42 @@ public override void Visit(SqlSelect node)
38
38
VisitSelectGroupBy ( node ) ;
39
39
VisitSelectOrderBy ( node ) ;
40
40
VisitSelectLock ( node ) ;
41
- context . Output . AppendText ( translator . Translate ( context , node , SelectSection . Exit ) ) ;
41
+ AppendTranslatedExit ( node ) ;
42
42
VisitCommentIfAfter ( comment ) ;
43
43
}
44
44
}
45
45
46
46
/// <inheritdoc/>
47
- public override void VisitSelectFrom ( SqlSelect node )
47
+ protected override void VisitSelectFrom ( SqlSelect node )
48
48
{
49
- if ( node . From != null )
49
+ if ( node . From != null ) {
50
50
base . VisitSelectFrom ( node ) ;
51
- else
52
- context . Output . AppendText ( "FROM RDB$DATABASE" ) ;
51
+ }
52
+ else {
53
+ _ = context . Output . Append ( " FROM RDB$DATABASE" ) ;
54
+ }
53
55
}
54
56
55
57
/// <inheritdoc/>
56
58
public override void Visit ( SqlQueryExpression node )
57
59
{
58
60
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 ("(");
64
66
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 ("(");
71
73
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 ) ;
75
77
}
76
78
}
77
79
@@ -105,17 +107,19 @@ public override void Visit(SqlExtract node)
105
107
Visit ( SqlDml . Add ( node , SqlDml . Literal ( 1 ) ) ) ;
106
108
case_SqlDateTimePart_DayOfYear = false ;
107
109
}
108
- else
110
+ else {
109
111
base . Visit ( node ) ;
112
+ }
110
113
return ;
111
114
case SqlDateTimePart . Second :
112
115
if ( ! case_SqlDateTimePart_Second ) {
113
116
case_SqlDateTimePart_Second = true ;
114
117
Visit ( SqlDml . Truncate ( node ) ) ;
115
118
case_SqlDateTimePart_Second = false ;
116
119
}
117
- else
120
+ else {
118
121
base . Visit ( node ) ;
122
+ }
119
123
return ;
120
124
}
121
125
base . Visit ( node ) ;
@@ -124,7 +128,7 @@ public override void Visit(SqlExtract node)
124
128
/// <inheritdoc/>
125
129
public override void Visit ( SqlUnary node )
126
130
{
127
- if ( node . NodeType == SqlNodeType . BitNot ) {
131
+ if ( node . NodeType == SqlNodeType . BitNot ) {
128
132
Visit ( BitNot ( node . Operand ) ) ;
129
133
return ;
130
134
}
@@ -145,7 +149,7 @@ public override void Visit(SqlBinary node)
145
149
DateTimeSubtractDateTime ( node . Left , node . Right ) . AcceptVisitor ( this ) ;
146
150
return ;
147
151
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 ) ) ;
149
153
return ;
150
154
case SqlNodeType . BitAnd :
151
155
BitAnd ( node . Left , node . Right ) . AcceptVisitor ( this ) ;
@@ -201,25 +205,24 @@ public override void Visit(SqlFunctionCall node)
201
205
base . Visit ( node ) ;
202
206
}
203
207
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 ( ) ;
208
210
211
+ /// <inheritdoc/>
209
212
public override void Visit ( SqlAlterSequence node )
210
213
{
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 ) ;
213
216
}
214
217
215
218
#region Static helpers
216
219
217
220
protected static SqlExpression DateTimeSubtractDateTime ( SqlExpression date1 , SqlExpression date2 )
218
221
{
219
- return CastToLong ( DateDiffDay ( date2 , date1 ) ) * NanosecondsPerDay
222
+ return ( CastToLong ( DateDiffDay ( date2 , date1 ) ) * NanosecondsPerDay )
220
223
+
221
- CastToLong ( DateDiffMillisecond ( DateAddDay ( date2 , DateDiffDay ( date2 , date1 ) ) , date1 ) ) *
222
- NanosecondsPerMillisecond ;
224
+ ( CastToLong ( DateDiffMillisecond ( DateAddDay ( date2 , DateDiffDay ( date2 , date1 ) ) , date1 ) ) *
225
+ NanosecondsPerMillisecond ) ;
223
226
}
224
227
225
228
protected static SqlExpression DateTimeAddInterval ( SqlExpression date , SqlExpression interval )
@@ -229,75 +232,46 @@ protected static SqlExpression DateTimeAddInterval(SqlExpression date, SqlExpres
229
232
( interval / NanosecondsPerMillisecond ) % ( MillisecondsPerDay ) ) ;
230
233
}
231
234
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 ) ;
236
236
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 ) ;
241
239
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 ) ;
246
242
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 ) ;
251
245
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 ) ;
256
248
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 ) ;
261
251
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 ) ;
266
254
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 ) ;
271
257
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 ) ;
276
260
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 ) ;
281
263
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 ) ;
286
266
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 ) ;
291
269
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 ) ;
296
272
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 ) ;
301
275
302
276
protected static SqlConcat DateTimeToStringIso ( SqlExpression dateTime )
303
277
{
0 commit comments