@@ -114,41 +114,75 @@ public override void Translate(SqlCompilerContext context, object literalValue)
114114 }
115115
116116 /// <inheritdoc/>
117- public override string Translate ( SqlNodeType type )
117+ public override void Translate ( IOutput output , SqlNodeType type )
118+ {
119+ switch ( type ) {
120+ case SqlNodeType . Equals : _ = output . Append ( "=" ) ; break ;
121+ case SqlNodeType . NotEquals :
122+ _ = output . Append ( "<>" ) ; break ;
123+ case SqlNodeType . Modulo :
124+ _ = output . Append ( "MOD" ) ; break ;
125+ case SqlNodeType . DateTimeMinusDateTime :
126+ _ = output . Append ( "-" ) ; break ;
127+ case SqlNodeType . Except :
128+ case SqlNodeType . Intersect :
129+ case SqlNodeType . Overlaps :
130+ throw SqlHelper . NotSupported ( type . ToString ( ) ) ;
131+ case SqlNodeType . BitAnd :
132+ _ = output . Append ( "BIN_AND" ) ; break ;
133+ case SqlNodeType . BitOr :
134+ _ = output . Append ( "BIN_OR" ) ; break ;
135+ case SqlNodeType . BitXor :
136+ _ = output . Append ( "BIN_XOR" ) ; break ;
137+ default : base . Translate ( output , type ) ; break ;
138+ } ;
139+ }
140+
141+ /// <inheritdoc/>
142+ public override string TranslateToString ( SqlNodeType type )
118143 {
119144 return type switch {
120- SqlNodeType . Equals => "=" ,
121- SqlNodeType . NotEquals => "<>" ,
122145 SqlNodeType . Modulo => "MOD" ,
123- SqlNodeType . DateTimeMinusDateTime => "-" ,
124146 SqlNodeType . Except => throw SqlHelper . NotSupported ( type . ToString ( ) ) ,
125147 SqlNodeType . Intersect => throw SqlHelper . NotSupported ( type . ToString ( ) ) ,
126- SqlNodeType . BitAnd => "BIN_AND" ,
127- SqlNodeType . BitOr => "BIN_OR" ,
128- SqlNodeType . BitXor => "BIN_XOR" ,
129148 SqlNodeType . Overlaps => throw SqlHelper . NotSupported ( type . ToString ( ) ) ,
130- _ => base . Translate ( type ) ,
149+ _ => base . TranslateToString ( type ) ,
131150 } ;
132151 }
133152
134153 /// <inheritdoc/>
135- public override string Translate ( SqlFunctionType type )
154+ public override void Translate ( IOutput output , SqlFunctionType type )
155+ {
156+ switch ( type ) {
157+ case SqlFunctionType . CharLength : _ = output . Append ( "CHAR_LENGTH" ) ; break ;
158+ case SqlFunctionType . BinaryLength : _ = output . Append ( "OCTET_LENGTH" ) ; break ;
159+ case SqlFunctionType . Truncate : _ = output . Append ( "TRUNC" ) ; break ;
160+ case SqlFunctionType . IntervalNegate : _ = output . Append ( "-" ) ; break ;
161+ case SqlFunctionType . Log : _ = output . Append ( "LN" ) ; break ;
162+ case SqlFunctionType . Log10 : _ = output . Append ( "LOG10" ) ; break ;
163+ case SqlFunctionType . Ceiling : _ = output . Append ( "CEIL" ) ; break ;
164+ case SqlFunctionType . PadLeft : _ = output . Append ( "LPAD" ) ; break ;
165+ case SqlFunctionType . PadRight : _ = output . Append ( "RPAD" ) ; break ;
166+ case SqlFunctionType . Concat : _ = output . Append ( "||" ) ; break ;
167+ case SqlFunctionType . SystemUser :
168+ case SqlFunctionType . SessionUser :
169+ base . Translate ( output , SqlFunctionType . CurrentUser ) ; break ;
170+ case SqlFunctionType . Degrees :
171+ case SqlFunctionType . Radians :
172+ case SqlFunctionType . Square :
173+ throw SqlHelper . NotSupported ( type . ToString ( ) ) ;
174+ case SqlFunctionType . IntervalAbs : base . Translate ( output , SqlFunctionType . Abs ) ; break ;
175+ default : base . Translate ( output , type ) ; break ;
176+ } ;
177+ }
178+
179+ /// <inheritdoc/>
180+ public override string TranslateToString ( SqlFunctionType type )
136181 {
137182 return type switch {
138183 SqlFunctionType . CharLength => "CHAR_LENGTH" ,
139- SqlFunctionType . BinaryLength => "OCTET_LENGTH" ,
140- SqlFunctionType . Truncate => "TRUNC" ,
141- SqlFunctionType . IntervalNegate => "-" ,
142- SqlFunctionType . Log => "LN" ,
143- SqlFunctionType . Log10 => "LOG10" ,
144- SqlFunctionType . Ceiling => "CEIL" ,
145- SqlFunctionType . PadLeft => "LPAD" ,
146- SqlFunctionType . PadRight => "RPAD" ,
147- SqlFunctionType . Concat => "||" ,
148- SqlFunctionType . SystemUser or SqlFunctionType . SessionUser => base . Translate ( SqlFunctionType . CurrentUser ) ,
149- SqlFunctionType . Degrees or SqlFunctionType . Radians or SqlFunctionType . Square => throw SqlHelper . NotSupported ( type . ToString ( ) ) ,
150- SqlFunctionType . IntervalAbs => Translate ( SqlFunctionType . Abs ) ,
151- _ => base . Translate ( type ) ,
184+ SqlFunctionType . SystemUser or SqlFunctionType . SessionUser => base . TranslateToString ( SqlFunctionType . CurrentUser ) ,
185+ _ => base . TranslateToString ( type ) ,
152186 } ;
153187 }
154188
@@ -168,21 +202,24 @@ public override void Translate(SqlCompilerContext context, SqlNextValue node, No
168202 }
169203
170204 /// <inheritdoc/>
171- public override string Translate ( SqlLockType lockType )
205+ public override void Translate ( IOutput output , SqlLockType lockType )
172206 {
173- return lockType . Supports ( SqlLockType . Shared ) || lockType . Supports ( SqlLockType . SkipLocked )
174- ? base . Translate ( lockType )
175- : "WITH LOCK" ;
207+ if ( lockType . Supports ( SqlLockType . Shared ) || lockType . Supports ( SqlLockType . SkipLocked ) ) {
208+ base . Translate ( output , lockType ) ;
209+ }
210+ else {
211+ _ = output . Append ( "WITH LOCK" ) ;
212+ }
176213 }
177214
178215 /// <inheritdoc/>
179- public override string Translate ( SqlDateTimePart dateTimePart )
216+ public override void Translate ( IOutput output , SqlDateTimePart dateTimePart )
180217 {
181- return dateTimePart switch {
182- SqlDateTimePart . DayOfYear => "YEARDAY" ,
183- SqlDateTimePart . DayOfWeek => "WEEKDAY" ,
184- _ => base . Translate ( dateTimePart ) ,
185- } ;
218+ switch ( dateTimePart ) {
219+ case SqlDateTimePart . DayOfYear : _ = output . Append ( "YEARDAY" ) ; break ;
220+ case SqlDateTimePart . DayOfWeek : _ = output . Append ( "WEEKDAY" ) ; break ;
221+ default : base . Translate ( output , dateTimePart ) ; break ;
222+ }
186223 }
187224
188225 /// <inheritdoc/>
@@ -262,14 +299,17 @@ public override void Translate(SqlCompilerContext context, Constraint constraint
262299 {
263300 switch ( section ) {
264301 case ConstraintSection . Exit :
265- _ = context . Output . Append ( ")" ) ;
302+ var output = context . Output ;
303+ _ = output . Append ( ")" ) ;
266304 if ( constraint is ForeignKey fk ) {
267305 if ( fk . OnUpdate != ReferentialAction . NoAction ) {
268- _ = context . Output . Append ( " ON UPDATE " ) . Append ( Translate ( fk . OnUpdate ) ) ;
306+ _ = output . Append ( " ON UPDATE " ) ;
307+ Translate ( output , fk . OnUpdate ) ;
269308 }
270309
271310 if ( fk . OnDelete != ReferentialAction . NoAction ) {
272- _ = context . Output . Append ( " ON DELETE " ) . Append ( Translate ( fk . OnDelete ) ) ;
311+ _ = output . Append ( " ON DELETE " ) ;
312+ Translate ( output , fk . OnDelete ) ;
273313 }
274314 }
275315 break ;
0 commit comments