3using System.Threading.Tasks;
60 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node);
84 public Task
Update(
bool Lazy, IEnumerable<object> Objects)
86 throw InvalidOperation();
89 private static Exception InvalidOperation()
91 return new InvalidOperationException(
"Operation not permitted on joined sources.");
106 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
108 throw InvalidOperation();
116 public Task
Insert(
bool Lazy,
object Object)
118 throw InvalidOperation();
126 get =>
throw InvalidOperation();
134 get =>
throw InvalidOperation();
140 public string Name =>
string.Empty;
149 return this.left.IsSource(
Name) || this.right.IsSource(
Name);
160 await this.left.IsLabel(Label) ||
161 await this.right.IsLabel(Label);
177 return new Operators.Logical.And(Where, On, 0, 0, Where.
Expression);
188 KeyValuePair<ScriptNode, int> P = await
Reduce(Source,
null, Where, 1);
201 KeyValuePair<ScriptNode, int> P = await
Reduce(Source, Source2, Where, 1);
215 KeyValuePair<ScriptNode, int> P1, P2;
224 else if (Where is Operators.Comparisons.Range Range)
226 if (Range.LeftInclusive)
227 Op1 =
new Operators.Comparisons.LesserThanOrEqualTo(Range.LeftOperand, Range.MiddleOperand, Range.Start, Range.Length, Range.Expression);
229 Op1 =
new Operators.Comparisons.LesserThan(Range.LeftOperand, Range.MiddleOperand, Range.Start, Range.Length, Range.Expression);
231 if (Range.RightInclusive)
232 Op2 =
new Operators.Comparisons.GreaterThanOrEqualTo(Range.MiddleOperand, Range.RightOperand, Range.Start, Range.Length, Range.Expression);
234 Op2 =
new Operators.Comparisons.GreaterThan(Range.MiddleOperand, Range.RightOperand, Range.Start, Range.Length, Range.Expression);
236 return await
Reduce(Source, Source2,
new Operators.Logical.And(Op1, Op2, Range.Start, Range.Length, Range.Expression), Mask);
240 P1 = await
Reduce(Source, Source2, BinOp.LeftOperand, Mask);
244 P2 = await
Reduce(Source, Source2, BinOp.RightOperand, Mask);
260 else if (Op2 is
null)
263 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.And(Op1, Op2, 0, 0, BinOp.Expression), s);
265 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.Or(Op1, Op2, 0, 0, BinOp.Expression), s);
267 else if (Op1 is
null || Op2 is
null)
269 else if (Op1 == BinOp.LeftOperand && Op2 == BinOp.RightOperand)
270 return new KeyValuePair<ScriptNode, int>(Where, s);
271 else if (BinOp is Operators.Comparisons.EqualTo)
272 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.EqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
273 else if (BinOp is Operators.Comparisons.GreaterThan)
274 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.GreaterThan(Op1, Op2, 0, 0, BinOp.Expression), s);
275 else if (BinOp is Operators.Comparisons.GreaterThanOrEqualTo)
276 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.GreaterThanOrEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
277 else if (BinOp is Operators.Comparisons.LesserThan)
278 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.LesserThan(Op1, Op2, 0, 0, BinOp.Expression), s);
279 else if (BinOp is Operators.Comparisons.LesserThanOrEqualTo)
280 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.LesserThanOrEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
281 else if (BinOp is Operators.Comparisons.Like)
282 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.Like(Op1, Op2, 0, 0, BinOp.Expression), s);
283 else if (BinOp is Operators.Comparisons.NotEqualTo)
284 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.NotEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
285 else if (BinOp is Operators.Comparisons.NotLike)
286 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.NotLike(Op1, Op2, 0, 0, BinOp.Expression), s);
288 else if (Where is Operators.Membership.NamedMember N)
292 if (Source.
IsSource(Ref.VariableName))
293 return new KeyValuePair<ScriptNode, int>(N, 1);
294 else if (Source2?.
IsSource(Ref.VariableName) ??
false)
295 return new KeyValuePair<ScriptNode, int>(N, 2);
304 P1 = await
Reduce(Source, Source2, UnOp.Operand, Mask);
311 if (UnOp is Operators.Logical.Not)
312 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.Not(Op1, 0, 0, UnOp.Expression), s1);
316 if (await Source.
IsLabel(Ref.VariableName))
317 return new KeyValuePair<ScriptNode, int>(Ref, 1);
318 else if (!(Source2 is
null) && await Source2.
IsLabel(Ref.VariableName))
319 return new KeyValuePair<ScriptNode, int>(Ref, 2);
324 return new KeyValuePair<ScriptNode, int>(C, 0);
329 private static readonly KeyValuePair<ScriptNode, int> Null =
new KeyValuePair<ScriptNode, int>(
null, 0);
338 KeyValuePair<VariableReference, bool>[] Order)
343 int i, c = Order.Length;
345 for (i = 0; i < c; i++)
347 if (!await Source.
IsLabel(Order[i].Key.VariableName))
352 Array.Resize(ref Order, c);
364 throw InvalidOperation();
374 throw InvalidOperation();
382 throw InvalidOperation();
Base class for all binary operators.
Represents a constant element value.
Base class for all nodes in a parsed script tree.
Expression Expression
Expression of which the node is a part.
Base class for all unary operators.
Represents a variable reference.
And(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Logical And.
Abstract base classes of joined sources.
JoinedSource(IDataSource Left, IDataSource Right, ScriptNode Conditions)
Abstract base classes of joined sources.
Task Insert(bool Lazy, object Object)
Inserts an object.
ScriptNode Conditions
Conditions for join.
Task Update(bool Lazy, IEnumerable< object > Objects)
Updates a set of objects.
static async Task< ScriptNode > Reduce(IDataSource Source, IDataSource Source2, ScriptNode Where)
Reduces a where clause to fit the current data sources.
Task DropCollection()
Drops the collection specified by the source.
abstract Task< bool > Process(IProcessor< object > Processor, int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Processes objects matching filter conditions in Where .
string CollectionName
Name of corresponding collection.
Task< bool > DropIndex(string Name)
Drops an index from the source.
ScriptNode Combine(ScriptNode Where, ScriptNode On)
Combines one or two restrictions.
IDataSource Left
Left source
abstract Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
Task CreateIndex(string Name, string[] Fields)
Creates an index in the source.
Task< int?> Delete(bool Lazy, int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Deletes a set of objects.
static async Task< ScriptNode > Reduce(IDataSource Source, ScriptNode Where)
Reduces a where clause to fit the current data source.
async Task< bool > IsLabel(string Label)
Checks if the label is a label in the source.
bool IsSource(string Name)
Checks if the name refers to the source.
static async Task< KeyValuePair< VariableReference, bool >[]> Reduce(IDataSource Source, KeyValuePair< VariableReference, bool >[] Order)
Reduces a sort order clause to fit the current data source.
IDataSource Right
Right source
string Name
Collection name or alias.
string TypeName
Name of corresponding type.
Interface for processors of objects.
Interface for data sources that can be used in SQL statements.
bool IsSource(string Name)
Checks if the name refers to the source.
Task< bool > IsLabel(string Label)
Checks if the label is a label in the source.