@@ -41,7 +41,8 @@ public partial class SqlGenerator : IErrorReporter
41
41
private readonly SqlStringBuilder sqlStringBuilder = new SqlStringBuilder ( ) ;
42
42
private ISqlWriter writer ;
43
43
44
- public SqlGenerator ( ISessionFactoryImplementor sfi , ITreeNodeStream input ) : this ( input )
44
+ public SqlGenerator ( ISessionFactoryImplementor sfi , ITreeNodeStream input )
45
+ : this ( input )
45
46
{
46
47
parseErrorHandler = new ErrorCounter ( ) ;
47
48
sessionFactory = sfi ;
@@ -134,7 +135,7 @@ private void Out(IASTNode n)
134
135
}
135
136
else if ( n is SqlNode )
136
137
{
137
- Out ( ( ( SqlNode ) n ) . RenderText ( sessionFactory ) ) ;
138
+ Out ( ( ( SqlNode ) n ) . RenderText ( sessionFactory ) ) ;
138
139
}
139
140
else
140
141
{
@@ -147,7 +148,7 @@ private void Out(IASTNode n)
147
148
}
148
149
else if ( n is IParameterContainer )
149
150
{
150
- var parameterContainer = ( IParameterContainer ) n ;
151
+ var parameterContainer = ( IParameterContainer ) n ;
151
152
if ( parameterContainer . HasEmbeddedParameters )
152
153
{
153
154
IParameterSpecification [ ] specifications = parameterContainer . GetEmbeddedParameters ( ) ;
@@ -178,8 +179,8 @@ protected virtual void FromFragmentSeparator(IASTNode a)
178
179
return ;
179
180
}
180
181
181
- var left = ( FromElement ) a ;
182
- var right = ( FromElement ) next ;
182
+ var left = ( FromElement ) a ;
183
+ var right = ( FromElement ) next ;
183
184
184
185
///////////////////////////////////////////////////////////////////////
185
186
// HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -192,7 +193,7 @@ protected virtual void FromFragmentSeparator(IASTNode a)
192
193
// writes something to the SQL
193
194
while ( right != null && ! HasText ( right ) )
194
195
{
195
- right = ( FromElement ) right . NextSibling ;
196
+ right = ( FromElement ) right . NextSibling ;
196
197
}
197
198
198
199
if ( right == null )
@@ -235,8 +236,8 @@ protected virtual void NestedFromFragment(IASTNode d, IASTNode parent)
235
236
if ( parent != null && HasText ( parent ) )
236
237
{
237
238
// again, both should be FromElements
238
- var left = ( FromElement ) parent ;
239
- var right = ( FromElement ) d ;
239
+ var left = ( FromElement ) parent ;
240
+ var right = ( FromElement ) d ;
240
241
if ( right . RealOrigin == left )
241
242
{
242
243
// right represents a joins originating from left...
@@ -268,7 +269,7 @@ private SqlStringBuilder GetStringBuilder()
268
269
269
270
private void BeginFunctionTemplate ( IASTNode m , IASTNode i )
270
271
{
271
- var methodNode = ( MethodNode ) m ;
272
+ var methodNode = ( MethodNode ) m ;
272
273
ISQLFunction template = methodNode . SQLFunction ;
273
274
if ( template == null )
274
275
{
@@ -286,7 +287,7 @@ private void BeginFunctionTemplate(IASTNode m, IASTNode i)
286
287
287
288
private void EndFunctionTemplate ( IASTNode m )
288
289
{
289
- var methodNode = ( MethodNode ) m ;
290
+ var methodNode = ( MethodNode ) m ;
290
291
ISQLFunction template = methodNode . SQLFunction ;
291
292
if ( template == null )
292
293
{
@@ -295,7 +296,7 @@ private void EndFunctionTemplate(IASTNode m)
295
296
else
296
297
{
297
298
// this function has a template -> restore output, apply the template and write the result out
298
- var functionArguments = ( FunctionArguments ) writer ; // TODO: Downcast to avoid using an interface? Yuck.
299
+ var functionArguments = ( FunctionArguments ) writer ; // TODO: Downcast to avoid using an interface? Yuck.
299
300
writer = outputStack [ 0 ] ;
300
301
outputStack . RemoveAt ( 0 ) ;
301
302
Out ( template . Render ( functionArguments . Args , sessionFactory ) ) ;
@@ -315,7 +316,7 @@ private void StartQuery()
315
316
316
317
private void EndQuery ( )
317
318
{
318
- SqlString sqlString = GetSqlStringWithLimitsIfNeeded ( ( QueryWriter ) writer ) ;
319
+ SqlString sqlString = GetSqlStringWithLimitsIfNeeded ( ( QueryWriter ) writer ) ;
319
320
320
321
writer = outputStack [ 0 ] ;
321
322
outputStack . RemoveAt ( 0 ) ;
@@ -381,6 +382,28 @@ private void Take(IASTNode node)
381
382
queryWriter . Take = Convert . ToInt32 ( node . Text ) ;
382
383
}
383
384
385
+ private void BeginBitwiseOp ( string op )
386
+ {
387
+ var function = sessionFactory . SQLFunctionRegistry . FindSQLFunction ( op . ToLowerInvariant ( ) ) ;
388
+ if ( function == null )
389
+ return ;
390
+
391
+ outputStack . Insert ( 0 , writer ) ;
392
+ writer = new BitwiseOperation ( ) ;
393
+ }
394
+
395
+ private void EndBitwiseOp ( string op )
396
+ {
397
+ ISQLFunction function = sessionFactory . SQLFunctionRegistry . FindSQLFunction ( op . ToLowerInvariant ( ) ) ;
398
+ if ( function == null )
399
+ return ;
400
+
401
+ var functionArguments = ( BitwiseOperation ) writer ;
402
+ writer = outputStack [ 0 ] ;
403
+ outputStack . RemoveAt ( 0 ) ;
404
+ Out ( function . Render ( functionArguments . Args , sessionFactory ) ) ;
405
+ }
406
+
384
407
#region Nested type: DefaultWriter
385
408
386
409
/// <summary>
@@ -534,6 +557,43 @@ public void CommaBetweenParameters(string comma)
534
557
535
558
#endregion
536
559
560
+ #region Nested type: BitwiseOperation
561
+
562
+ private class BitwiseOperation : ISqlWriter
563
+ {
564
+ private readonly List < SqlString > _args = new List < SqlString > ( ) ;
565
+
566
+ #region ISqlWriter Members
567
+
568
+ public void Clause ( string clause )
569
+ {
570
+ Clause ( SqlString . Parse ( clause ) ) ;
571
+ }
572
+
573
+ public void Clause ( SqlString clause )
574
+ {
575
+ _args . Add ( clause ) ;
576
+ }
577
+
578
+ public void PushParameter ( Parameter parameter )
579
+ {
580
+ _args . Add ( new SqlString ( parameter ) ) ;
581
+ }
582
+
583
+ public void CommaBetweenParameters ( string comma )
584
+ {
585
+ }
586
+
587
+ #endregion
588
+
589
+ public IList Args
590
+ {
591
+ get { return _args ; }
592
+ }
593
+ }
594
+
595
+ #endregion
596
+
537
597
#region Nested type: ISqlWriter
538
598
539
599
/// <summary>
0 commit comments