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

A container for the FROM clause of a select statement. More...

Inheritance diagram for Deveel.Data.Sql.Expressions.FromClause:
Deveel.Data.Sql.Expressions.IPreparable Deveel.Data.Serialization.ISerializable

Public Member Functions

 FromClause ()
 
void AddTable (string alias, FromTable table)
 Adds a table as source to the query with a given alias. More...
 
void AddTable (string alias, string tableName)
 Adds a simple table reference as the source of the query with a given alias. More...
 
void AddTable (string tableName)
 Adds a simple table reference as the source of the query. More...
 
void AddSubQuery (SqlQueryExpression subQuery)
 Adds a sub-query expression as source of the query. More...
 
void AddSubQuery (string alias, SqlQueryExpression subQuery)
 Adds a sub-query expression as source of the query. More...
 
void Join (JoinType joinType, SqlExpression onExpression)
 Sets a join between the last added table and the one that preceeds it. More...
 
JoinPart GetJoinPart (int offset)
 Gets the descriptor of the join at the given offset. More...
 

Properties

IEnumerable< FromTableAllTables [get]
 Gets an enumeration of all the tables that are the source of the query. More...
 
int JoinPartCount [get]
 Gets a count of all the joins happening in the clause. More...
 
bool IsEmpty [get]
 

Private Member Functions

 FromClause (ObjectData data)
 
String CreateNewKey ()
 
object IPreparable. Prepare (IExpressionPreparer preparer)
 Converts the underlying value of this instance into an object that can be evaluated by an expression. More...
 
void ISerializable. GetData (SerializeData data)
 

Private Attributes

readonly List< string > tableNames
 
readonly List< FromTablefromTables
 
readonly List< JoinPartjoinParts
 
int tableKey
 An id used for making unique names for anonymous inner selects. More...
 

Detailed Description

A container for the FROM clause of a select statement.

This handles the different types of joins.

Definition at line 32 of file FromClause.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Expressions.FromClause.FromClause ( )
inline

Definition at line 33 of file FromClause.cs.

33  {
34  fromTables = new List<FromTable>();
35  joinParts = new List<JoinPart>();
36  tableNames = new List<string>();
37  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
readonly List< string > tableNames
Definition: FromClause.cs:56
readonly List< FromTable > fromTables
Definition: FromClause.cs:57
Deveel.Data.Sql.Expressions.FromClause.FromClause ( ObjectData  data)
inlineprivate

Definition at line 39 of file FromClause.cs.

39  {
40  var tableNames = data.GetValue<string[]>("TableNames");
41  var fromTables = data.GetValue<FromTable[]>("FromTables");
42  var joinParts = data.GetValue<JoinPart[]>("JoinParts");
43 
44  this.tableNames = new List<string>();
45  this.fromTables = new List<FromTable>();
46  this.joinParts = new List<JoinPart>();
47 
48  if (tableNames != null)
49  this.tableNames.AddRange(tableNames);
50  if (fromTables != null)
51  this.fromTables.AddRange(fromTables);
52  if (joinParts != null)
53  this.joinParts.AddRange(joinParts);
54  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
readonly List< string > tableNames
Definition: FromClause.cs:56
readonly List< FromTable > fromTables
Definition: FromClause.cs:57

Member Function Documentation

void Deveel.Data.Sql.Expressions.FromClause.AddSubQuery ( SqlQueryExpression  subQuery)
inline

Adds a sub-query expression as source of the query.

Parameters
subQueryThe sub-query expression as source of the query.
See also
AddSubQuery(string, SqlQueryExpression)

Definition at line 134 of file FromClause.cs.

134  {
135  AddSubQuery(null, subQuery);
136  }
void AddSubQuery(SqlQueryExpression subQuery)
Adds a sub-query expression as source of the query.
Definition: FromClause.cs:134
void Deveel.Data.Sql.Expressions.FromClause.AddSubQuery ( string  alias,
SqlQueryExpression  subQuery 
)
inline

Adds a sub-query expression as source of the query.

Parameters
aliasThe unique alias name of the expression within the clause.
subQueryThe sub-query expression as source of the query.
See also
AddTable(string, FromTable), SqlQueryExpression

Definition at line 145 of file FromClause.cs.

145  {
146  AddTable(alias, new FromTable(subQuery, alias));
147  }
void AddTable(string alias, FromTable table)
Adds a table as source to the query with a given alias.
Definition: FromClause.cs:93
void Deveel.Data.Sql.Expressions.FromClause.AddTable ( string  alias,
FromTable  table 
)
inline

Adds a table as source to the query with a given alias.

Parameters
aliasThe unique name alias of the table source within the clause.
tableThe table source object to query from.

Definition at line 93 of file FromClause.cs.

93  {
94  if (table == null)
95  throw new ArgumentNullException("table");
96 
97  if (!String.IsNullOrEmpty(alias)) {
98  if (tableNames.Contains(alias))
99  throw new ArgumentException(String.Format("Duplicated table name {0} is FROM clause.", alias));
100 
101  tableNames.Add(alias);
102  }
103 
104  // Create a new unique key for this table
105  string key = CreateNewKey();
106  table.UniqueKey = key;
107  fromTables.Add(table);
108  }
A long string in the system.
readonly List< string > tableNames
Definition: FromClause.cs:56
readonly List< FromTable > fromTables
Definition: FromClause.cs:57
void Deveel.Data.Sql.Expressions.FromClause.AddTable ( string  alias,
string  tableName 
)
inline

Adds a simple table reference as the source of the query with a given alias.

Parameters
aliasThe unique name alias of the table source within the clause.
tableNameThe name of the table in the database to query from.
See also
AddTable(string, FromTable)

Definition at line 116 of file FromClause.cs.

116  {
117  AddTable(alias, new FromTable(tableName, alias));
118  }
void AddTable(string alias, FromTable table)
Adds a table as source to the query with a given alias.
Definition: FromClause.cs:93
void Deveel.Data.Sql.Expressions.FromClause.AddTable ( string  tableName)
inline

Adds a simple table reference as the source of the query.

Parameters
tableNameThe name of the table in the database to query from.
See also
AddTable(string, string)

Definition at line 125 of file FromClause.cs.

125  {
126  AddTable(null, tableName);
127  }
void AddTable(string alias, FromTable table)
Adds a table as source to the query with a given alias.
Definition: FromClause.cs:93
String Deveel.Data.Sql.Expressions.FromClause.CreateNewKey ( )
inlineprivate

Definition at line 83 of file FromClause.cs.

83  {
84  ++tableKey;
85  return tableKey.ToString(CultureInfo.InvariantCulture);
86  }
int tableKey
An id used for making unique names for anonymous inner selects.
Definition: FromClause.cs:63
void ISerializable. Deveel.Data.Sql.Expressions.FromClause.GetData ( SerializeData  data)
inlineprivate

Implements Deveel.Data.Serialization.ISerializable.

Definition at line 210 of file FromClause.cs.

210  {
211  if (tableNames != null)
212  data.SetValue("TableNames", tableNames.ToArray());
213  if (fromTables != null)
214  data.SetValue("FromTables", fromTables.ToArray());
215  if (joinParts != null)
216  data.SetValue("JoinParts", joinParts.ToArray());
217  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
void SetValue(string key, Type type, object value)
readonly List< string > tableNames
Definition: FromClause.cs:56
readonly List< FromTable > fromTables
Definition: FromClause.cs:57
JoinPart Deveel.Data.Sql.Expressions.FromClause.GetJoinPart ( int  offset)
inline

Gets the descriptor of the join at the given offset.

Parameters
offsetThe offset of the join descriptor to get.
Returns
Returns an instance of
See also
JoinPart
that describes the type of join at the given offset within the clause.
See also
Join

Definition at line 174 of file FromClause.cs.

174  {
175  return joinParts[offset];
176  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
void Deveel.Data.Sql.Expressions.FromClause.Join ( JoinType  joinType,
SqlExpression  onExpression 
)
inline

Sets a join between the last added table and the one that preceeds it.

Parameters
joinTypeThe type of join to apply to the two tables.
onExpressionThe condition for the two tables to join.

Definition at line 154 of file FromClause.cs.

154  {
155  var lastTable = fromTables[fromTables.Count - 1];
156  if (lastTable.IsSubQuery) {
157  var subQuery = lastTable.SubQuery;
158  joinParts.Add(new JoinPart(joinType, subQuery, onExpression));
159  } else {
160  var tableName = ObjectName.Parse(lastTable.Name);
161  joinParts.Add(new JoinPart(joinType, tableName, onExpression));
162  }
163  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
readonly List< FromTable > fromTables
Definition: FromClause.cs:57
object IPreparable. Deveel.Data.Sql.Expressions.FromClause.Prepare ( IExpressionPreparer  preparer)
inlineprivate

Converts the underlying value of this instance into an object that can be evaluated by an expression.

Parameters
preparerThe context used to prepare this object.
Returns
Returns an object that can be evaluated by an expression.

Implements Deveel.Data.Sql.Expressions.IPreparable.

Definition at line 178 of file FromClause.cs.

178  {
179  var clause = new FromClause();
180 
181  // Prepare expressions in the JoiningSet first
182  int size = joinParts.Count;
183  for (int i = 0; i < size; ++i) {
184  var part = joinParts[i];
185  var exp = part.OnExpression;
186  if (exp != null) {
187  exp = exp.Prepare(preparer);
188  if (part.SubQuery != null) {
189  part = new JoinPart(part.JoinType, part.SubQuery, exp);
190  } else {
191  part = new JoinPart(part.JoinType, part.TableName, exp);
192  }
193  }
194 
195  clause.joinParts.Add(part);
196  }
197 
198  // Prepare the StatementTree sub-queries in the from tables
199  for (int i = 0; i < fromTables.Count; i++) {
200  var table = fromTables[i];
201  var preparedTable = (FromTable) ((IPreparable) table).Prepare(preparer);
202  var tableAlias = tableNames[i];
203  clause.tableNames.Insert(i, tableAlias);
204  clause.fromTables.Insert(i, preparedTable);
205  }
206 
207  return clause;
208  }
readonly List< JoinPart > joinParts
Definition: FromClause.cs:58
object IPreparable. Prepare(IExpressionPreparer preparer)
Converts the underlying value of this instance into an object that can be evaluated by an expression...
Definition: FromClause.cs:178
readonly List< string > tableNames
Definition: FromClause.cs:56
readonly List< FromTable > fromTables
Definition: FromClause.cs:57

Member Data Documentation

readonly List<FromTable> Deveel.Data.Sql.Expressions.FromClause.fromTables
private

Definition at line 57 of file FromClause.cs.

readonly List<JoinPart> Deveel.Data.Sql.Expressions.FromClause.joinParts
private

Definition at line 58 of file FromClause.cs.

int Deveel.Data.Sql.Expressions.FromClause.tableKey
private

An id used for making unique names for anonymous inner selects.

Definition at line 63 of file FromClause.cs.

readonly List<string> Deveel.Data.Sql.Expressions.FromClause.tableNames
private

Definition at line 56 of file FromClause.cs.

Property Documentation

IEnumerable<FromTable> Deveel.Data.Sql.Expressions.FromClause.AllTables
get

Gets an enumeration of all the tables that are the source of the query.

Definition at line 68 of file FromClause.cs.

bool Deveel.Data.Sql.Expressions.FromClause.IsEmpty
get

Definition at line 79 of file FromClause.cs.

int Deveel.Data.Sql.Expressions.FromClause.JoinPartCount
get

Gets a count of all the joins happening in the clause.

Definition at line 75 of file FromClause.cs.


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