2 using System.Collections.Generic;
11 namespace Deveel.Data.Sql.Tables {
14 return DeleteFrom(context, tableName, query, -1);
18 return DeleteFrom(context, tableName, expression, -1);
23 return context.DeleteFrom(tableName, (SqlQueryExpression)expression, limit);
25 var table = context.GetMutableTable(tableName);
29 var queryExpression =
new SqlQueryExpression(
new List<SelectColumn> {
SelectColumn.
Glob(
"*") });
30 queryExpression.FromClause.AddTable(tableName.
Name);
31 queryExpression.WhereExpression = expression;
33 var planExpression = queryExpression.
Evaluate(context, null);
35 var deleteSet = plan.QueryPlan.
Evaluate(context);
37 return context.DeleteFrom(tableName, deleteSet, limit);
44 var planValue = query.EvaluateToConstant(context, null);
45 if (planValue == null)
46 throw new InvalidOperationException();
49 throw new InvalidOperationException();
56 }
catch (Exception ex) {
57 throw new InvalidOperationException(
String.Format(
"Could not delete from table '{0}': unable to form the delete set.", tableName), ex);
60 var deleteSet = plan.
Evaluate(context);
61 return context.DeleteFrom(tableName, deleteSet, limit);
65 if (!context.UserCanDeleteFromTable(tableName))
68 var table = context.GetMutableTable(tableName);
72 return table.Delete(deleteSet, limit);
76 IEnumerable<SqlAssignExpression> assignments,
int limit) {
77 var columnNames = assignments.Select(x => x.ReferenceExpression)
79 .
Select(x => x.ReferenceName.Name).ToArray();
81 if (!context.UserCanUpdateTable(tableName, columnNames))
84 if (!context.UserCanSelectFromPlan(queryPlan))
85 throw new InvalidOperationException();
87 var table = context.GetMutableTable(tableName);
91 var updateSet = queryPlan.
Evaluate(context);
92 return table.Update(context, updateSet, assignments, limit);
97 assignments.Select(x => x.ReferenceExpression)
99 .
Select(x => x.ReferenceName.Name).ToArray();
100 if (!context.UserCanInsertIntoTable(tableName, columnNames))
103 var table = context.GetMutableTable(tableName);
105 var row = table.NewRow();
106 foreach (var expression
in assignments) {
107 row.EvaluateAssignment(expression, context);
117 foreach (var assignment
in assignments) {
118 context.InsertIntoTable(tableName, assignment);
Defines the contract to access the data contained into a table of a database.
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query, int limit)
An expression that references an object within a context.
A long string in the system.
ITable Evaluate(IRequest context)
Describes the name of an object within a database.
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query)
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)
static int InsertIntoTable(this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression[]> assignments)
static int UpdateTable(this IQuery context, ObjectName tableName, IQueryPlanNode queryPlan, IEnumerable< SqlAssignExpression > assignments, int limit)
Represents a column selected to be in the output of a select statement.
An expression that holds a constant value.
string Name
Gets the name of the object being referenced.
static int DeleteFrom(this IQuery context, ObjectName tableName, ITable deleteSet, int limit)
static void InsertIntoTable(this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression > assignments)
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, SqlExpression expression, int limit)