@@ -143,66 +143,65 @@ public override void Visit(SqlAlterTable node)
143143 public override void Visit ( SqlFunctionCall node )
144144 {
145145 switch ( node . FunctionType ) {
146- case SqlFunctionType . CharLength :
147- ( SqlDml . FunctionCall ( "DATALENGTH" , node . Arguments ) / 2 ) . AcceptVisitor ( this ) ;
148- return ;
149- case SqlFunctionType . PadLeft :
150- case SqlFunctionType . PadRight :
151- GenericPad ( node ) . AcceptVisitor ( this ) ;
152- return ;
153- case SqlFunctionType . Round :
154- // Round should always be called with 2 arguments
155- if ( node . Arguments . Count == 1 ) {
146+ case SqlFunctionType . CharLength :
147+ ( SqlDml . FunctionCall ( "DATALENGTH" , node . Arguments ) / 2 ) . AcceptVisitor ( this ) ;
148+ return ;
149+ case SqlFunctionType . PadLeft :
150+ case SqlFunctionType . PadRight :
151+ GenericPad ( node ) . AcceptVisitor ( this ) ;
152+ return ;
153+ case SqlFunctionType . Round :
154+ // Round should always be called with 2 arguments
155+ if ( node . Arguments . Count == 1 ) {
156+ Visit ( SqlDml . FunctionCall (
157+ translator . Translate ( SqlFunctionType . Round ) ,
158+ node . Arguments [ 0 ] ,
159+ SqlDml . Literal ( 0 ) ) ) ;
160+ return ;
161+ }
162+ break ;
163+ case SqlFunctionType . Truncate :
164+ // Truncate is implemented as round(arg, 0, 1) call in MSSQL.
165+ // It's stupid, isn't it?
156166 Visit ( SqlDml . FunctionCall (
157167 translator . Translate ( SqlFunctionType . Round ) ,
158168 node . Arguments [ 0 ] ,
159- SqlDml . Literal ( 0 ) ) ) ;
169+ SqlDml . Literal ( 0 ) ,
170+ SqlDml . Literal ( 1 ) ) ) ;
160171 return ;
161- }
162- break ;
163- case SqlFunctionType . Truncate :
164- // Truncate is implemented as round(arg, 0, 1) call in MSSQL.
165- // It's stupid, isn't it?
166- Visit ( SqlDml . FunctionCall (
167- translator . Translate ( SqlFunctionType . Round ) ,
168- node . Arguments [ 0 ] ,
169- SqlDml . Literal ( 0 ) ,
170- SqlDml . Literal ( 1 ) ) ) ;
171- return ;
172- case SqlFunctionType . Substring :
173- if ( node . Arguments . Count == 2 ) {
174- node = SqlDml . Substring ( node . Arguments [ 0 ] , node . Arguments [ 1 ] ) ;
175- SqlExpression len = SqlDml . CharLength ( node . Arguments [ 0 ] ) ;
176- node . Arguments . Add ( len ) ;
177- Visit ( node ) ;
178- return ;
179- }
180- break ;
181- case SqlFunctionType . IntervalToMilliseconds :
172+ case SqlFunctionType . Substring :
173+ if ( node . Arguments . Count == 2 ) {
174+ SqlExpression len = SqlDml . CharLength ( node . Arguments [ 0 ] ) ;
175+ node = SqlDml . Substring ( node . Arguments [ 0 ] , node . Arguments [ 1 ] , len ) ;
176+ Visit ( node ) ;
177+ return ;
178+ }
179+ break ;
180+ case SqlFunctionType . IntervalToMilliseconds :
182181 Visit ( CastToLong ( node . Arguments [ 0 ] ) / NanosecondsPerMillisecond ) ;
183182 return ;
184- case SqlFunctionType . IntervalConstruct :
185- case SqlFunctionType . IntervalToNanoseconds :
186- Visit ( CastToLong ( node . Arguments [ 0 ] ) ) ;
187- return ;
188- case SqlFunctionType . DateTimeAddMonths :
189- Visit ( DateAddMonth ( node . Arguments [ 0 ] , node . Arguments [ 1 ] ) ) ;
190- return ;
191- case SqlFunctionType . DateTimeAddYears :
192- Visit ( DateAddYear ( node . Arguments [ 0 ] , node . Arguments [ 1 ] ) ) ;
193- return ;
194- case SqlFunctionType . DateTimeTruncate :
195- DateTimeTruncate ( node . Arguments [ 0 ] ) . AcceptVisitor ( this ) ;
196- return ;
197- case SqlFunctionType . DateTimeConstruct :
198- Visit ( DateAddDay ( DateAddMonth ( DateAddYear ( SqlDml . Literal ( new DateTime ( 2001 , 1 , 1 ) ) ,
199- node . Arguments [ 0 ] - 2001 ) ,
200- node . Arguments [ 1 ] - 1 ) ,
201- node . Arguments [ 2 ] - 1 ) ) ;
202- return ;
203- case SqlFunctionType . DateTimeToStringIso :
204- Visit ( DateTimeToStringIso ( node . Arguments [ 0 ] ) ) ;
205- return ;
183+ case SqlFunctionType . IntervalConstruct :
184+ case SqlFunctionType . IntervalToNanoseconds :
185+ Visit ( CastToLong ( node . Arguments [ 0 ] ) ) ;
186+ return ;
187+ case SqlFunctionType . DateTimeAddMonths :
188+ Visit ( DateAddMonth ( node . Arguments [ 0 ] , node . Arguments [ 1 ] ) ) ;
189+ return ;
190+ case SqlFunctionType . DateTimeAddYears :
191+ Visit ( DateAddYear ( node . Arguments [ 0 ] , node . Arguments [ 1 ] ) ) ;
192+ return ;
193+ case SqlFunctionType . DateTimeTruncate :
194+ DateTimeTruncate ( node . Arguments [ 0 ] ) . AcceptVisitor ( this ) ;
195+ return ;
196+ case SqlFunctionType . DateTimeConstruct :
197+ Visit ( DateAddDay ( DateAddMonth ( DateAddYear ( SqlDml . Literal ( new DateTime ( 2001 , 1 , 1 ) ) ,
198+ node . Arguments [ 0 ] - 2001 ) ,
199+ node . Arguments [ 1 ] - 1 ) ,
200+ node . Arguments [ 2 ] - 1 ) ) ;
201+ return ;
202+ case SqlFunctionType . DateTimeToStringIso :
203+ Visit ( DateTimeToStringIso ( node . Arguments [ 0 ] ) ) ;
204+ return ;
206205 }
207206
208207 base . Visit ( node ) ;
0 commit comments