DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Properties | Private Member Functions | List of all members
Deveel.Data.Sql.Statements.CreateViewStatement Class Reference
Inheritance diagram for Deveel.Data.Sql.Statements.CreateViewStatement:
Deveel.Data.Sql.Statements.SqlStatement Deveel.Data.Sql.Statements.IPreparableStatement Deveel.Data.Sql.Statements.IStatement Deveel.Data.Serialization.ISerializable Deveel.Data.Sql.Statements.IStatement Deveel.Data.Sql.IExecutable Deveel.Data.Sql.IExecutable

Classes

class  Prepared
 

Public Member Functions

 CreateViewStatement (string viewName, SqlQueryExpression queryExpression)
 
 CreateViewStatement (string viewName, IEnumerable< string > columnNames, SqlQueryExpression queryExpression)
 
- Public Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
ITable Execute (IRequest context)
 Prepares and evaluates this statement into a tabular result. More...
 

Properties

string ViewName [get, private set]
 
IEnumerable< string > ColumnNames [get, private set]
 
SqlQueryExpression QueryExpression [get, private set]
 
bool ReplaceIfExists [get, set]
 
- Properties inherited from Deveel.Data.Sql.Statements.SqlStatement
SqlQuery SourceQuery [get, set]
 Gets the SqlQuery that is the origin of this statement. More...
 
bool IsFromQuery [get, private set]
 Gets a boolean value indicating if this object was formed from the parsing of a SqlQuery or if it was manually created. More...
 
- Properties inherited from Deveel.Data.Sql.Statements.IStatement
SqlQuery SourceQuery [get]
 

Private Member Functions

IStatement IPreparableStatement. Prepare (IRequest context)
 

Additional Inherited Members

- Static Public Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
static IEnumerable< SqlStatementParse (string sqlSource)
 Parses a given string into one of more statements. More...
 
static IEnumerable< SqlStatementParse (IContext context, string sqlSource)
 Parses a given string into one of more statements. More...
 
static IEnumerable< SqlStatementParse (IContext context, SqlQuery query)
 
- Protected Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
 SqlStatement ()
 
 SqlStatement (ObjectData data)
 
virtual void ExecuteStatement (ExecutionContext context)
 
virtual void GetData (SerializeData data)
 
- Package Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
void SetSource (SqlQuery query)
 

Detailed Description

Definition at line 29 of file CreateViewStatement.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Statements.CreateViewStatement.CreateViewStatement ( string  viewName,
SqlQueryExpression  queryExpression 
)
inline

Definition at line 30 of file CreateViewStatement.cs.

31  : this(viewName, null, queryExpression) {
32  }
Deveel.Data.Sql.Statements.CreateViewStatement.CreateViewStatement ( string  viewName,
IEnumerable< string >  columnNames,
SqlQueryExpression  queryExpression 
)
inline

Definition at line 34 of file CreateViewStatement.cs.

34  {
35  if (viewName == null)
36  throw new ArgumentNullException("viewName");
37  if (queryExpression == null)
38  throw new ArgumentNullException("queryExpression");
39 
40  ViewName = viewName;
41  ColumnNames = columnNames;
42  QueryExpression = queryExpression;
43  }

Member Function Documentation

IStatement IPreparableStatement. Deveel.Data.Sql.Statements.CreateViewStatement.Prepare ( IRequest  context)
inlineprivate

Implements Deveel.Data.Sql.Statements.IPreparableStatement.

Definition at line 53 of file CreateViewStatement.cs.

53  {
54  var viewName = context.Query.ResolveTableName(ViewName);
55 
56  var queryFrom = QueryExpressionFrom.Create(context, QueryExpression);
57  var queryPlan = context.Query.Context.QueryPlanner().PlanQuery(new QueryInfo(context, QueryExpression));
58 
59  var colList = ColumnNames == null ? new string[0] : ColumnNames.ToArray();
60 
61  // Wrap the result around a SubsetNode to alias the columns in the
62  // table correctly for this view.
63  int sz = colList.Length;
64  var originalNames = queryFrom.GetResolvedColumns();
65  var newColumnNames = new ObjectName[originalNames.Length];
66 
67  if (sz > 0) {
68  if (sz != originalNames.Length)
69  throw new InvalidOperationException("Column list is not the same size as the columns selected.");
70 
71  for (int i = 0; i < sz; ++i) {
72  var colName = colList[i];
73  newColumnNames[i] = new ObjectName(viewName, colName);
74  }
75  } else {
76  sz = originalNames.Length;
77  for (int i = 0; i < sz; ++i) {
78  newColumnNames[i] = new ObjectName(viewName, originalNames[i].Name);
79  }
80  }
81 
82  // Check there are no repeat column names in the table.
83  for (int i = 0; i < sz; ++i) {
84  var columnName = newColumnNames[i];
85  for (int n = i + 1; n < sz; ++n) {
86  if (newColumnNames[n].Equals(columnName))
87  throw new InvalidOperationException(String.Format("Duplicate column name '{0}' in view. A view may not contain duplicate column names.", columnName));
88  }
89  }
90 
91  // Wrap the plan around a SubsetNode plan
92  queryPlan = new SubsetNode(queryPlan, originalNames, newColumnNames);
93 
94  return new Prepared(viewName, QueryExpression, queryPlan, ReplaceIfExists);
95  }
A long string in the system.
static QueryExpressionFrom Create(IRequest context, SqlQueryExpression expression)

Property Documentation

IEnumerable<string> Deveel.Data.Sql.Statements.CreateViewStatement.ColumnNames
getprivate set

Definition at line 47 of file CreateViewStatement.cs.

SqlQueryExpression Deveel.Data.Sql.Statements.CreateViewStatement.QueryExpression
getprivate set

Definition at line 49 of file CreateViewStatement.cs.

bool Deveel.Data.Sql.Statements.CreateViewStatement.ReplaceIfExists
getset

Definition at line 51 of file CreateViewStatement.cs.

string Deveel.Data.Sql.Statements.CreateViewStatement.ViewName
getprivate set

Definition at line 45 of file CreateViewStatement.cs.


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