18 using System.Collections.Generic;
27 namespace Deveel.Data.Sql.Tables {
30 return DeleteFrom(context, tableName, query, -1);
34 return DeleteFrom(context, tableName, expression, -1);
39 return context.DeleteFrom(tableName, (SqlQueryExpression)expression, limit);
41 var table = context.GetMutableTable(tableName);
45 var queryExpression =
new SqlQueryExpression(
new List<SelectColumn> {
SelectColumn.
Glob(
"*") });
46 queryExpression.FromClause.AddTable(tableName.
Name);
47 queryExpression.WhereExpression = expression;
49 var planExpression = queryExpression.
Evaluate(context, null);
51 var deleteSet = plan.QueryPlan.
Evaluate(context);
53 return context.DeleteFrom(tableName, deleteSet, limit);
60 var planValue = query.EvaluateToConstant(context, null);
61 if (planValue == null)
62 throw new InvalidOperationException();
65 throw new InvalidOperationException();
72 }
catch (Exception ex) {
73 throw new InvalidOperationException(
String.Format(
"Could not delete from table '{0}': unable to form the delete set.", tableName), ex);
76 var deleteSet = plan.
Evaluate(context);
77 return context.DeleteFrom(tableName, deleteSet, limit);
81 if (!context.UserCanDeleteFromTable(tableName))
84 var table = context.GetMutableTable(tableName);
88 return table.Delete(deleteSet, limit);
92 IEnumerable<SqlAssignExpression> assignments,
int limit) {
93 var columnNames = assignments.Select(x => x.ReferenceExpression)
95 .
Select(x => x.ReferenceName.Name).ToArray();
97 if (!context.UserCanUpdateTable(tableName, columnNames))
100 if (!context.UserCanSelectFromPlan(queryPlan))
101 throw new InvalidOperationException();
103 var table = context.GetMutableTable(tableName);
107 var updateSet = queryPlan.
Evaluate(context);
108 return table.Update(context, updateSet, assignments, limit);
113 assignments.Select(x => x.ReferenceExpression)
115 .
Select(x => x.ReferenceName.Name).ToArray();
116 if (!context.UserCanInsertIntoTable(tableName, columnNames))
119 var table = context.GetMutableTable(tableName);
123 var row = table.NewRow();
124 foreach (var expression
in assignments) {
125 row.EvaluateAssignment(expression, context);
134 foreach (var assignment
in assignments) {
135 context.InsertIntoTable(tableName, assignment);
Defines the contract to access the data contained into a table of a database.
An expression that references an object within a context.
A long string in the system.
ITable Evaluate(IRequest context)
static void InsertIntoTable(this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression > assignments)
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlExpression expression)
static int InsertIntoTable(this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression[]> assignments)
Describes the name of an object within a database.
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query)
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query, int limit)
A node element of a query plan tree. /summary>
virtual SqlExpression Evaluate(EvaluateContext context)
When overridden by a derived class, this method evaluates the expression within the provided context...
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlExpression expression, int limit)
Represents a column selected to be in the output of a select statement.
static int UpdateTable(this IQuery context, ObjectName tableName, IQueryPlanNode queryPlan, IEnumerable< SqlAssignExpression > assignments, int limit)
An expression that holds a constant value.
string Name
Gets the name of the object being referenced.
Defines the base class for instances that represent SQL expression tree nodes.
static SelectColumn Glob(string glob)
Creates a special SelectColumn that is used to select all the columns in a table. ...
static int DeleteFrom(this IQuery context, ObjectName tableName, ITable deleteSet, int limit)