forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlSelectGenerator.cs
More file actions
61 lines (55 loc) · 2.21 KB
/
SqlSelectGenerator.cs
File metadata and controls
61 lines (55 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#if ENTITIES
using System;
using System.Collections.Generic;
using System.Data.Common;
#if ENTITIES6
using System.Data.Entity.Core.Common.CommandTrees;
#else
using System.Data.Common.CommandTrees;
#endif
namespace Npgsql.SqlGenerators
{
internal class SqlSelectGenerator : SqlBaseGenerator
{
private DbQueryCommandTree _commandTree;
public SqlSelectGenerator(DbQueryCommandTree commandTree)
{
_commandTree = commandTree;
}
protected SqlSelectGenerator()
{
// used only for other generators such as returning
}
public override VisitedExpression Visit(DbPropertyExpression expression)
{
// not quite sure what this does
// may be . notation for seperating
// scopes (such as schema.table.column)
//VisitedExpression variable = expression.Instance.Accept(this);
VariableReferenceExpression variable = new VariableReferenceExpression(expression.Instance.Accept(this).ToString(), _variableSubstitution);
return new PropertyExpression(variable, expression.Property);
}
public override VisitedExpression Visit(DbNullExpression expression)
{
// must provide a NULL of the correct type
// this is necessary for certain types of union queries.
return new CastExpression(new LiteralExpression("NULL"), GetDbType(expression.ResultType.EdmType));
}
public override void BuildCommand(DbCommand command)
{
System.Diagnostics.Debug.Assert(command is NpgsqlCommand);
System.Diagnostics.Debug.Assert(_commandTree.Query is DbProjectExpression);
VisitedExpression ve = _commandTree.Query.Accept(this);
System.Diagnostics.Debug.Assert(ve is ProjectionExpression);
ProjectionExpression pe = (ProjectionExpression)ve;
command.CommandText = pe.ToString();
List<Type> expectedTypes = new List<Type>();
foreach (var column in pe.Columns)
{
expectedTypes.Add(column.CLRType);
}
((NpgsqlCommand)command).ExpectedTypes = expectedTypes.ToArray();
}
}
}
#endif