2using System.Collections.Generic;
3using System.Threading.Tasks;
59 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node);
66 public Task
Update(
bool Lazy, IEnumerable<object> Objects)
68 throw InvalidOperation();
71 private static Exception InvalidOperation()
73 return new InvalidOperationException(
"Operation not permitted on joined sources.");
88 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
90 throw InvalidOperation();
98 public Task
Insert(
bool Lazy,
object Object)
100 throw InvalidOperation();
108 get =>
throw InvalidOperation();
116 get =>
throw InvalidOperation();
122 public string Name =>
string.Empty;
131 return this.left.IsSource(
Name) || this.right.IsSource(
Name);
142 await this.left.IsLabel(Label) ||
143 await this.right.IsLabel(Label);
159 return new Operators.Logical.And(Where, On, 0, 0, Where.
Expression);
170 KeyValuePair<ScriptNode, int> P = await
Reduce(Source,
null, Where, 1);
183 KeyValuePair<ScriptNode, int> P = await
Reduce(Source, Source2, Where, 1);
197 KeyValuePair<ScriptNode, int> P1, P2;
206 else if (Where is Operators.Comparisons.Range Range)
208 if (Range.LeftInclusive)
209 Op1 =
new Operators.Comparisons.LesserThanOrEqualTo(Range.LeftOperand, Range.MiddleOperand, Range.Start, Range.Length, Range.Expression);
211 Op1 =
new Operators.Comparisons.LesserThan(Range.LeftOperand, Range.MiddleOperand, Range.Start, Range.Length, Range.Expression);
213 if (Range.RightInclusive)
214 Op2 =
new Operators.Comparisons.GreaterThanOrEqualTo(Range.MiddleOperand, Range.RightOperand, Range.Start, Range.Length, Range.Expression);
216 Op2 =
new Operators.Comparisons.GreaterThan(Range.MiddleOperand, Range.RightOperand, Range.Start, Range.Length, Range.Expression);
218 return await
Reduce(Source, Source2,
new Operators.Logical.And(Op1, Op2, Range.Start, Range.Length, Range.Expression), Mask);
222 P1 = await
Reduce(Source, Source2, BinOp.LeftOperand, Mask);
226 P2 = await
Reduce(Source, Source2, BinOp.RightOperand, Mask);
242 else if (Op2 is
null)
245 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.And(Op1, Op2, 0, 0, BinOp.Expression), s);
247 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.Or(Op1, Op2, 0, 0, BinOp.Expression), s);
249 else if (Op1 is
null || Op2 is
null)
251 else if (Op1 == BinOp.LeftOperand && Op2 == BinOp.RightOperand)
252 return new KeyValuePair<ScriptNode, int>(Where, s);
253 else if (BinOp is Operators.Comparisons.EqualTo)
254 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.EqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
255 else if (BinOp is Operators.Comparisons.GreaterThan)
256 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.GreaterThan(Op1, Op2, 0, 0, BinOp.Expression), s);
257 else if (BinOp is Operators.Comparisons.GreaterThanOrEqualTo)
258 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.GreaterThanOrEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
259 else if (BinOp is Operators.Comparisons.LesserThan)
260 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.LesserThan(Op1, Op2, 0, 0, BinOp.Expression), s);
261 else if (BinOp is Operators.Comparisons.LesserThanOrEqualTo)
262 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.LesserThanOrEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
263 else if (BinOp is Operators.Comparisons.Like)
264 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.Like(Op1, Op2, 0, 0, BinOp.Expression), s);
265 else if (BinOp is Operators.Comparisons.NotEqualTo)
266 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.NotEqualTo(Op1, Op2, 0, 0, BinOp.Expression), s);
267 else if (BinOp is Operators.Comparisons.NotLike)
268 return new KeyValuePair<ScriptNode, int>(
new Operators.Comparisons.NotLike(Op1, Op2, 0, 0, BinOp.Expression), s);
270 else if (Where is Operators.Membership.NamedMember N)
274 if (Source.
IsSource(Ref.VariableName))
275 return new KeyValuePair<ScriptNode, int>(N, 1);
276 else if (Source2?.
IsSource(Ref.VariableName) ??
false)
277 return new KeyValuePair<ScriptNode, int>(N, 2);
286 P1 = await
Reduce(Source, Source2, UnOp.Operand, Mask);
293 if (UnOp is Operators.Logical.Not)
294 return new KeyValuePair<ScriptNode, int>(
new Operators.Logical.Not(Op1, 0, 0, UnOp.Expression), s1);
298 if (await Source.
IsLabel(Ref.VariableName))
299 return new KeyValuePair<ScriptNode, int>(Ref, 1);
300 else if (!(Source2 is
null) && await Source2.
IsLabel(Ref.VariableName))
301 return new KeyValuePair<ScriptNode, int>(Ref, 2);
306 return new KeyValuePair<ScriptNode, int>(C, 0);
311 private static readonly KeyValuePair<ScriptNode, int> Null =
new KeyValuePair<ScriptNode, int>(
null, 0);
320 KeyValuePair<VariableReference, bool>[] Order)
325 int i, c = Order.Length;
327 for (i = 0; i < c; i++)
329 if (!await Source.
IsLabel(Order[i].Key.VariableName))
334 Array.Resize(ref Order, c);
346 throw InvalidOperation();
356 throw InvalidOperation();
364 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 from the source.
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?> FindDelete(bool Lazy, int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds and 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 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.