DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Deveel.Data.Sql.Query.QuerySelectColumns Class Reference

Public Member Functions

 QuerySelectColumns (QueryExpressionFrom fromSet)
 
void SelectSingleColumn (SelectColumn col)
 
void SelectAllColumnsFromSource (ObjectName tableName)
 
void SelectAllColumnsFromAllSources ()
 
PreparedQuerySelectColumns Prepare (IRequest context)
 

Private Member Functions

void AddAllFromTable (IFromTableSource table)
 
SelectColumn PrepareColumn (SelectColumn column, IRequest context, IList< SelectColumn > functionColumns, ref int aggregateCount)
 

Private Attributes

readonly QueryExpressionFrom fromSet
 The tables we are selecting from. More...
 
readonly List< SelectColumnselectedColumns
 

Static Private Attributes

static readonly ObjectName FunctionTableName = new ObjectName("FUNCTIONTABLE")
 The name of the table where functions are defined. More...
 

Detailed Description

Definition at line 26 of file QuerySelectColumns.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Query.QuerySelectColumns.QuerySelectColumns ( QueryExpressionFrom  fromSet)
inline

Definition at line 43 of file QuerySelectColumns.cs.

43  {
44  this.fromSet = fromSet;
45  selectedColumns = new List<SelectColumn>();
46  }
readonly QueryExpressionFrom fromSet
The tables we are selecting from.
readonly List< SelectColumn > selectedColumns

Member Function Documentation

void Deveel.Data.Sql.Query.QuerySelectColumns.AddAllFromTable ( IFromTableSource  table)
inlineprivate

Definition at line 52 of file QuerySelectColumns.cs.

52  {
53  // Select all the tables
54  var columns = table.ColumnNames;
55  foreach (ObjectName name in columns) {
56  // Make up the SelectColumn
58  var column = new SelectColumn(e) {
59  ResolvedName = name,
60  InternalName = name
61  };
62 
63  // Add to the list of columns selected
64  SelectSingleColumn(column);
65  }
66  }
Represents a column selected to be in the output of a select statement.
Definition: SelectColumn.cs:31
static SqlReferenceExpression Reference(ObjectName objectName)
Defines the base class for instances that represent SQL expression tree nodes.
PreparedQuerySelectColumns Deveel.Data.Sql.Query.QuerySelectColumns.Prepare ( IRequest  context)
inline

Definition at line 137 of file QuerySelectColumns.cs.

137  {
138  int aggregateCount = 0;
139  var functionColumns = new List<SelectColumn>();
140  var preparedColumns = new List<SelectColumn>();
141  foreach (var column in selectedColumns) {
142  var prepared = PrepareColumn(column, context, functionColumns, ref aggregateCount);
143  preparedColumns.Add(prepared);
144  }
145 
146  return new PreparedQuerySelectColumns(preparedColumns, functionColumns, aggregateCount);
147  }
SelectColumn PrepareColumn(SelectColumn column, IRequest context, IList< SelectColumn > functionColumns, ref int aggregateCount)
readonly List< SelectColumn > selectedColumns
SelectColumn Deveel.Data.Sql.Query.QuerySelectColumns.PrepareColumn ( SelectColumn  column,
IRequest  context,
IList< SelectColumn functionColumns,
ref int  aggregateCount 
)
inlineprivate

Definition at line 88 of file QuerySelectColumns.cs.

89  {
90  if (column.Expression is SqlQueryExpression)
91  throw new InvalidOperationException("Sub-query expressions are invalid in select columns.");
92 
93  SelectColumn newColumn;
94 
95  var exp = column.Expression;
96  if (exp != null)
98 
99  if (exp is SqlReferenceExpression) {
100  var sqlRef = (SqlReferenceExpression) exp;
101  var colName = sqlRef.ReferenceName;
102  ObjectName resolvedName = null;
103 
104  var alias = column.Alias;
105  if (String.IsNullOrEmpty(alias)) {
106  resolvedName = colName;
107  } else {
108  resolvedName = new ObjectName(alias);
109  }
110 
111  newColumn = new SelectColumn(exp, alias) {
112  InternalName = colName,
113  ResolvedName = resolvedName
114  };
115  } else {
116  var funcAlias = functionColumns.Count.ToString(CultureInfo.InvariantCulture);
117  if (column.Expression.HasAggregate(context)) {
118  aggregateCount++;
119  funcAlias += "_A";
120  }
121 
122  var alias = column.Alias;
123  if (string.IsNullOrEmpty(alias))
124  alias = exp.ToString();
125 
126  newColumn = new SelectColumn(exp, alias) {
127  InternalName = new ObjectName(FunctionTableName, funcAlias),
128  ResolvedName = new ObjectName(alias)
129  };
130 
131  functionColumns.Add(newColumn);
132  }
133 
134  return newColumn;
135  }
An expression that references an object within a context.
A long string in the system.
readonly QueryExpressionFrom fromSet
The tables we are selecting from.
virtual SqlExpression Prepare(IExpressionPreparer preparer)
Represents a column selected to be in the output of a select statement.
Definition: SelectColumn.cs:31
SqlExpression Expression
Gets the expression used to select the column.
Definition: SelectColumn.cs:65
string Alias
Gets the name used to alias the select expression.
Definition: SelectColumn.cs:70
static readonly ObjectName FunctionTableName
The name of the table where functions are defined.
void Deveel.Data.Sql.Query.QuerySelectColumns.SelectAllColumnsFromAllSources ( )
inline

Definition at line 81 of file QuerySelectColumns.cs.

81  {
82  for (int p = 0; p < fromSet.SourceCount; ++p) {
83  IFromTableSource table = fromSet.GetTableSource(p);
84  AddAllFromTable(table);
85  }
86  }
IFromTableSource GetTableSource(int offset)
readonly QueryExpressionFrom fromSet
The tables we are selecting from.
void AddAllFromTable(IFromTableSource table)
void Deveel.Data.Sql.Query.QuerySelectColumns.SelectAllColumnsFromSource ( ObjectName  tableName)
inline

Definition at line 68 of file QuerySelectColumns.cs.

68  {
69  // Attempt to find the table in the from set.
70  string schema = null;
71  if (tableName.Parent != null)
72  schema = tableName.Parent.Name;
73 
74  IFromTableSource table = fromSet.FindTable(schema, tableName.Name);
75  if (table == null)
76  throw new InvalidOperationException(tableName + ".* is not a valid reference.");
77 
78  AddAllFromTable(table);
79  }
readonly QueryExpressionFrom fromSet
The tables we are selecting from.
void AddAllFromTable(IFromTableSource table)
IFromTableSource FindTable(string schema, string name)
void Deveel.Data.Sql.Query.QuerySelectColumns.SelectSingleColumn ( SelectColumn  col)
inline

Definition at line 48 of file QuerySelectColumns.cs.

48  {
49  selectedColumns.Add(col);
50  }
readonly List< SelectColumn > selectedColumns

Member Data Documentation

readonly QueryExpressionFrom Deveel.Data.Sql.Query.QuerySelectColumns.fromSet
private

The tables we are selecting from.

Definition at line 35 of file QuerySelectColumns.cs.

readonly ObjectName Deveel.Data.Sql.Query.QuerySelectColumns.FunctionTableName = new ObjectName("FUNCTIONTABLE")
staticprivate

The name of the table where functions are defined.

Definition at line 30 of file QuerySelectColumns.cs.

readonly List<SelectColumn> Deveel.Data.Sql.Query.QuerySelectColumns.selectedColumns
private

Definition at line 37 of file QuerySelectColumns.cs.


The documentation for this class was generated from the following file: