public ICommandBuilder GetMaxCommand(string tableName, string columnName, SimpleExpression criteria) { _commandBuilder.Append(GetMaxClause(tableName, columnName)); if (criteria != null) { _commandBuilder.Append(" where "); _commandBuilder.Append(_expressionFormatter.Format(criteria)); } return(_commandBuilder); }
public string Simplify(string input) { mTokenizer.Tokenize(input, null); var expressionTree = mModelBuilder.BuildFrom(mTokenizer.Tokens); var simplified = mSimplifier.Simplify(expressionTree); return(mFormatter.Format(simplified)); }
public ICommandBuilder GetUpdateCommand(string tableName, IDictionary <string, object> data, SimpleExpression criteria) { _commandBuilder.Append(GetUpdateClause(tableName, data)); if (criteria != null) { _commandBuilder.Append(" where "); _commandBuilder.Append(_expressionFormatter.Format(criteria)); } return(_commandBuilder); }
public IEnumerable <IDictionary <string, object> > Find(MongoCollection <BsonDocument> collection, SimpleQuery query, out IEnumerable <SimpleQueryClauseBase> unhandledClauses) { var builder = MongoQueryBuilder.BuildFrom(query); unhandledClauses = builder.UnprocessedClauses; if (builder.IsTotalCountQuery) { long count; if (builder.Criteria == null) { count = collection.Count(); } else { count = collection.Count(_expressionFormatter.Format(builder.Criteria)); } //TODO: figure out how to make count a long builder.SetTotalCount((int)count); } if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1) { return new[] { FindOne(collection, builder.Criteria) } } ; var cursor = CreateCursor(collection, builder.Criteria); ApplyFields(cursor, builder.Columns); ApplySorting(cursor, builder.Order); ApplySkip(cursor, builder.SkipCount); ApplyTake(cursor, builder.TakeCount); var aliases = builder.Columns.OfType <ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias()); return(cursor.Select(x => x.ToSimpleDictionary(aliases))); }
public int Delete(MongoCollection <BsonDocument> collection, SimpleExpression criteria) { var condition = _expressionFormatter.Format(criteria); var result = collection.Remove(condition); if (result != null) { return((int)result.DocumentsAffected); } return(int.MaxValue); }
public void FormattingExpressionVisitor_Return_Proper_String() { var tokenizer = Substitute.For <ITokenizer>(); var expression = Substitute.For <IExpression>(); mModelBuilder.BuildFrom(tokenizer.Tokens).Returns(expression); mSimplifier.Simplify(expression).Returns(expression); const string simplifyResult = "2a"; mExpressionFormatter.Format(expression).Returns(simplifyResult); mUnderTest.Simplify(tokenizer).Should().Be(simplifyResult); }
public ICommandBuilder GetFindByCommand(ObjectName tableName, SimpleExpression criteria) { _commandBuilder.Append(GetSelectClause(tableName)); if (criteria != null) { _commandBuilder.Append(" "); _commandBuilder.Append(string.Join(" ", new Joiner(JoinType.Inner, _schema).GetJoinClauses(tableName, criteria))); _commandBuilder.Append(" where "); _commandBuilder.Append(_expressionFormatter.Format(criteria)); } return(_commandBuilder); }
public ICommandBuilder GetUpdateCommand(string tableName, IDictionary <string, object> data, SimpleExpression criteria) { var table = _schema.FindTable(tableName); var updateClause = GetUpdateClause(table, data); if (string.IsNullOrWhiteSpace(updateClause)) { throw new InvalidOperationException("No columns to update."); } _commandBuilder.Append(updateClause); if (criteria != null) { string whereStatement = null; if (criteria.GetOperandsOfType <ObjectReference>().Any(o => IsTableChain(tableName, o))) { if (table.PrimaryKey.Length == 1) { whereStatement = CreateWhereInStatement(criteria, table); } else if (table.PrimaryKey.Length > 1) { whereStatement = CreateWhereExistsStatement(criteria, table); } } else { whereStatement = _expressionFormatter.Format(criteria); } if (!string.IsNullOrEmpty(whereStatement)) { _commandBuilder.Append(" where " + whereStatement); } } return(_commandBuilder); }
public ICommandBuilder GetUpdateCommand(string tableName, IDictionary <string, object> data, SimpleExpression criteria) { _commandBuilder.Append(GetUpdateClause(tableName, data)); if (criteria != null) { var whereStatement = _expressionFormatter.Format(criteria); if (!string.IsNullOrEmpty(whereStatement)) { _commandBuilder.Append(" where " + whereStatement); } } return(_commandBuilder); }
public ICommandBuilder GetDeleteCommand(string tableName, SimpleExpression criteria) { _commandBuilder.Append(GetDeleteClause(tableName)); if (criteria != null) { var whereCondition = _expressionFormatter.Format(criteria); if (!string.IsNullOrEmpty(whereCondition)) { _commandBuilder.Append(" where " + whereCondition); } } return(_commandBuilder); }
public int Update(MongoCollection <BsonDocument> collection, IDictionary <string, object> data, SimpleExpression criteria) { var condition = _expressionFormatter.Format(criteria); MongoIdKeys.ReplaceId(data); var update = new UpdateDocument("$set", data.ToBsonDocument()); var result = collection.Update(condition, update, UpdateFlags.Multi); if (result != null) { return((int)result.DocumentsAffected); } return(int.MaxValue); }
public int Update(MongoCollection <BsonDocument> collection, IDictionary <string, object> data, SimpleExpression criteria) { var condition = _expressionFormatter.Format(criteria); if (data.ContainsKey("Id")) { data["_id"] = data["Id"]; data.Remove("Id"); } var update = new UpdateDocument("$set", data.ToBsonDocument()); var result = collection.Update(condition, update, UpdateFlags.Multi); if (result != null) { return((int)result.DocumentsAffected); } return(int.MaxValue); }
public double Evaluate(string expression, IDictionary <string, double> constants) { var code = string.Format(codeFormat, GetConstantsString(constants), formatter.Format(expression)); CompilerResults result = csharpProvider.CompileAssemblyFromSource(compilerParameters, code); if (result.Errors.HasErrors) { StringBuilder strB = new StringBuilder(); foreach (CompilerError error in result.Errors) { strB.AppendLine(string.Format("[pos: {0}] - {1}", error.Column, error.ErrorText)); } throw new ArgumentException($"Ошибка в выражении:\r\n{strB}", "expression"); } return((double)result .CompiledAssembly .GetType("DynamicExpression") .GetMethod("Eval") .Invoke(null, null)); }
string UseFormattingExpressionVisitor(IExpression expression) => mExpressionFormatter.Format(expression);