/// <summary> /// Formats the right comparison value and hands it back /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { var isValueDate = (comparisonValue.Value is DateTime); var value = Convert.ToString(comparisonValue.Value, CultureInfo.InvariantCulture); string result; if (isValueDate) { //result = comparisonValue.Value.ToString(); var dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("o"); result = string.Format( "DateTime.Parse({0}, null, DateTimeStyles.RoundtripKind)", Quote(string.Format("{0}", value))); } else if (comparisonValue.ValueType == ComparisonValueType.Constant) { //if it's a constant value type and a string, wrap it in quotes: result = comparisonValue.Value is string ?string.Format("{0}", Quote(value)) : value; } else { //otherwise, just return the raw value: result = value; } return(result); }
/// <summary> /// Provide the query for insert data by parsing the input DataEntity /// </summary> /// <param name="input"></param> /// <returns></returns> private string ParseInsertQuery(DataEntity input) { StringBuilder columnNames = new StringBuilder(); StringBuilder columnValues = new StringBuilder(); columnNames.Append("("); columnValues.Append("("); // parse through the column names and values foreach (KeyValuePair <string, object> property in input.Properties) { columnNames.Append(string.Format(" [{0}],", property.Key)); if (property.Value == null) { columnValues.Append("'',"); } else { //create a new comparison value for the column value ComparisonValue value = new ComparisonValue(ComparisonValueType.Constant, property.Value); columnValues.Append(GetRightFormattedComparisonValue(value)); columnValues.Append(","); } } //remove the trailing commas and replace them with a closing brace columnNames = columnNames.Replace(',', ')', columnNames.Length - 1, 1); columnValues = columnValues.Replace(',', ')', columnValues.Length - 1, 1); return(string.Format(" into [{0}] {1} {2}values {3}", input.ObjectDefinitionFullName, columnNames, Environment.NewLine, columnValues)); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { // Values that are constant need to be enclosed in single quotes. var formattedComparisonValue = string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "[{0}]" : "{0}", comparisonValue.Value); return(formattedComparisonValue); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedComparisonValue = new StringBuilder(); //Check if value is of type Property, which would indicate a reference to a column name in sql if (comparisonValue.ValueType == ComparisonValueType.Property) { //split property hierarchy var comparisonHierarchy = comparisonValue.Value.ToString().Split('.'); //The format for the incomming data is 'TableName.ColumnName' //Split the properties appart and create a 'formal' data link resulting in [TableName].[ColumnName] foreach (string t in comparisonHierarchy) { formattedComparisonValue.Append("["); formattedComparisonValue.Append(t); formattedComparisonValue.Append("]."); } formattedComparisonValue.Remove(formattedComparisonValue.Length - 1, 1); } else { // Values that are constant need to be enclosed in single quotes. formattedComparisonValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", comparisonValue.Value)); } return(formattedComparisonValue.ToString()); }
/// <summary> /// Formats the right comparison value and hands it back /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { var isValueDate = (comparisonValue.Value is DateTime); var value = Convert.ToString(comparisonValue.Value, CultureInfo.InvariantCulture); string result; if (isValueDate) { //result = comparisonValue.Value.ToString(); var dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("o"); //TODO: Convert to the proper date format result = QuoteSingle(value); } else if (comparisonValue.ValueType == ComparisonValueType.Constant) { //if it's a constant value type and a string, wrap it in quotes: result = comparisonValue.Value is string ?string.Format("{0}", QuoteSingle(value)) : value; } else { //otherwise, just return the raw value: result = value; } return(result); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { // Values that are constant need to be enclosed in single quotes. var formattedComparisonValue = string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "[{0}]" : "{0}", comparisonValue.Value); return formattedComparisonValue; }
private static string ParseWhereClause(EntityProperties properties) { var whereClause = new StringBuilder(); if (properties != null && properties.Count > 0) { whereClause.AppendFormat(" {0} ", WhereKeyword); int index = 1; foreach (var property in properties) { if (property.Value == null) { whereClause.AppendFormat("[{0}] IS NULL", property.Key); } else { var rightComparisonValue = new ComparisonValue(ComparisonValueType.Constant, property.Value); whereClause.AppendFormat("[{0}] = {1}", property.Key, GetRightFormattedComparisonValue(rightComparisonValue)); } if (index != properties.Count) { whereClause.Append(" AND "); } index++; } } return(whereClause.ToString()); }
/// <summary> /// Provide the query for an update by parsing the input DataEntity. /// This however does not include the where clause /// </summary> /// <param name="input"></param> /// <returns></returns> private string ParseUpdateQuery(DataEntity input) { StringBuilder updateValues = new StringBuilder(); // parse through the column names and values foreach (var property in input.Properties) { string rightValue; if (property.Value == null) { rightValue = "NULL"; } else { //create a new comparison value for the column value var value = new ComparisonValue(ComparisonValueType.Constant, property.Value); rightValue = GetRightFormattedComparisonValue(property.Key, value); } updateValues.Append(string.Format("[{0}] = {1},", property.Key, rightValue)); } //remove the trailing comma updateValues = updateValues.Remove(updateValues.Length - 1, 1); return(string.Format(" [{0}] " + SetKeyword + " {1}", input.ObjectDefinitionFullName, updateValues)); }
public override bool Equals(object obj) { var other = obj as Field; if (other == null) { return(false); } return(ComparisonValue.Equals(other.ComparisonValue)); }
/// <inheritdoc/> public virtual string GetPrivateFilterValue( ComparisonValue publicValue, Dictionary<string, string> privateConfigurationValues ) { var values = new List<string>(); if ( publicValue.ComparisonType.HasValue ) { values.Add( publicValue.ComparisonType.ConvertToInt().ToString() ); } values.Add( publicValue.Value != null ? GetPrivateEditValue( publicValue.Value, privateConfigurationValues ) : string.Empty ); return values.ToJson(); }
private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedValue = new StringBuilder(); if (comparisonValue.ValueType == ComparisonValueType.Property) { var propertyParts = comparisonValue.Value.ToString().Split('.'); var propertyName = propertyParts[propertyParts.Length - 1]; formattedValue.AppendFormat("{0}", propertyName); } else { formattedValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? Quote("{0}") : "{0}", comparisonValue.Value)); } return(formattedValue.ToString()); }
private string GetRightFormattedComparisonValue(ComparisonValue leftValue, ComparisonValue rightValue) { object comparisonValue; ////check if the left value is a property, which in this case would be a column name //if (leftValue.ValueType == ComparisonValueType.Property && _columnDefinitions != null) //{ // //retrieve the name of the column from the right value. // //The Incomming format is [Column Name] // //use the datatypes stored in the column definitions to propery convert the data stored in the right value // comparisonValue = DataTypeConverter.ToSqlValue(leftValue.Value.ToString().Split('.').Last(), rightValue.Value, _columnDefinitions); //} //else //{ comparisonValue = rightValue.Value; //} //bool valueIsDate = (comparisonValue is DateTime); string value = comparisonValue.ToString(); string result; //if (valueIsDate) //{ // DateTime dateTimeValue = ((DateTime)(comparisonValue)); // if (dateTimeValue.Kind != DateTimeKind.Utc) // { // dateTimeValue = dateTimeValue.ToUniversalTime(); // } // value = dateTimeValue.ToString("s"); // result = string.Format("{0}({1}, '{2}')", "CONVERT", "DATETIME", value); //} //else //{ result = string.Format(rightValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", value); //} return(result); }
/// <summary> /// Formats the left comparison value and hands it back. /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedValue = new StringBuilder(); if (comparisonValue.ValueType == ComparisonValueType.Property) { var propertyParts = comparisonValue.Value.ToString().Split('.'); var propertyName = propertyParts[propertyParts.Length - 1]; formattedValue.AppendFormat("[{0}]", propertyName.Replace("'", "''")); } else { //if the value is constant, wrap it in quotes, otherwise, just append it. formattedValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? QuoteSingle("{0}") : "{0}", comparisonValue.Value)); } return(formattedValue.ToString()); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// This is used for query execution /// </summary> /// <param name="columnName">name of the column used in the comparison</param> /// <param name="rightValue">value to be formatted in the comparison</param> /// <returns>The value formatted for use in a sql statement.</returns> private string GetRightFormattedComparisonValue(string columnName, ComparisonValue rightValue) { string rightFormattedValue = string.Empty; //Determine whether or not column definitions have been implemented, //if they havn't then we know that the query is requested from the ExecuteOpertion method if (_columnDefinitions == null) { rightFormattedValue = GetRightFormattedComparisonValue(rightValue); } else { //create a new comparison value for the left side of the statement using the column name ComparisonValue leftValue = new ComparisonValue(); leftValue.ValueType = ComparisonValueType.Property; leftValue.Value = columnName; rightFormattedValue = GetRightFormattedComparisonValue(leftValue, rightValue); } return(rightFormattedValue); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { bool valueIsDate = (comparisonValue.Value.GetType() == typeof(DateTime)); string value = comparisonValue.Value.ToString(); string result; if (valueIsDate) { DateTime dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("s"); result = string.Format("convert(datetime, '{0}')", value); } else { result = string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", value.Replace("'", "''")); } return(result); }
private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedComparisonValue = new StringBuilder(); //Check if value is of type Property, which would indicate a reference to a column name in sql if (comparisonValue.ValueType == ComparisonValueType.Property) { //split property hierarchy var comparisonHierarchy = comparisonValue.Value.ToString().Split('.')[1].ToString(); formattedComparisonValue.Append(comparisonHierarchy); } else { // Values that are constant need to be enclosed in single quotes. formattedComparisonValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", comparisonValue.Value)); } return(formattedComparisonValue.ToString()); }
private FilterExpression(FilterExpression other) { if (null == other) { throw new ArgumentNullException(nameof(other)); } this.Text = other.Text; this.attributePath = other.attributePath; this.comparisonOperator = other.comparisonOperator; this.filterOperator = other.filterOperator; this.Group = other.Group; this.Level = other.Level; this.logicalOperator = other.logicalOperator; this.value = other.value; if (other.next != null) { this.next = new FilterExpression(other.next); this.next.Previous = this; } }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedComparisonValue = new StringBuilder(); //Check if value is of type Property, which would indicate a reference to a column name in sql if (comparisonValue.ValueType == ComparisonValueType.Property) { //split property hierarchy var comparisonHierarchy = comparisonValue.Value.ToString().Split('.'); //The format for the incomming data is 'TableName.ColumnName' //Split the properties appart and create a 'formal' data link resulting in [TableName].[ColumnName] foreach (string t in comparisonHierarchy) { formattedComparisonValue.Append("["); formattedComparisonValue.Append(t); formattedComparisonValue.Append("]."); } formattedComparisonValue.Remove(formattedComparisonValue.Length - 1, 1); } else { // Values that are constant need to be enclosed in single quotes. formattedComparisonValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", comparisonValue.Value)); } return formattedComparisonValue.ToString(); }
public void Render(VisualPayload payload, IMetaSelectable selectable) { RenderAxisLabel(payload); // Optional 'Axis title' // Labels along an axis: var mode = AxisMode.GetLastKeyValue(payload.Data); if (mode == AxialLabelAxisMode.Discrete) { // create equality criteria var normalSelector = PayloadSelectorFactory.InstantiateCriterionEqualsSelect(selectable); normalSelector.SelectionMode.OperationToPerform = SelectionOperation.SelectOnly; normalSelector.CriterionField = (mut) => AxisIndexVariable.GetValue(mut); normalSelector.ArrityLevels = AxisIndexVariable.NumberOfIntermediates; var toggleSelector = PayloadSelectorFactory.InstantiateCriterionEqualsSelect(selectable); toggleSelector.SelectionMode.OperationToPerform = SelectionOperation.ToggleFullySelected; toggleSelector.RequiredModifiers = new InputModifiers() { Control = true }; toggleSelector.CriterionField = (mut) => AxisIndexVariable.GetValue(mut); toggleSelector.ArrityLevels = AxisIndexVariable.NumberOfIntermediates; normalSelector.FieldLastKey = AxisIndexVariable.AbsoluteKey; toggleSelector.FieldLastKey = AxisIndexVariable.AbsoluteKey; var discreteCriterionSelectors = new List <ICriterionMetaSelector>() { normalSelector, toggleSelector }; RenderItemLabelsDiscrete(payload, discreteCriterionSelectors); } else if (mode == AxialLabelAxisMode.Continuous) { // create range criteria var normalRangeSelector = PayloadSelectorFactory.InstantiateCriterionRangeSelect(selectable); normalRangeSelector.SelectionMode.OperationToPerform = SelectionOperation.SelectOnly; normalRangeSelector.CriterionField = (mut) => ComparisonValue.GetValue(mut); normalRangeSelector.ArrityLevels = ComparisonValue.NumberOfIntermediates; var toggleRangeSelector = PayloadSelectorFactory.InstantiateCriterionRangeSelect(selectable); toggleRangeSelector.SelectionMode.OperationToPerform = SelectionOperation.ToggleFullySelected; toggleRangeSelector.RequiredModifiers = new InputModifiers() { Control = true }; toggleRangeSelector.CriterionField = (mut) => ComparisonValue.GetValue(mut); toggleRangeSelector.ArrityLevels = ComparisonValue.NumberOfIntermediates; normalRangeSelector.FieldLastKey = ComparisonValue.AbsoluteKey; toggleRangeSelector.FieldLastKey = ComparisonValue.AbsoluteKey; var continuousCriterionSelectors = new List <ICriterionMetaSelector>() { normalRangeSelector, toggleRangeSelector }; RenderItemLabelsContinuous(payload, continuousCriterionSelectors); } }
/// <summary> /// Formats the left comparison value and hands it back. /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetLeftFormattedComparisonValue(ComparisonValue comparisonValue) { var formattedValue = new StringBuilder(); if (comparisonValue.ValueType == ComparisonValueType.Property) { var propertyParts = comparisonValue.Value.ToString().Split('.'); var propertyName = propertyParts[propertyParts.Length - 1]; formattedValue.AppendFormat("{0}", propertyName); } else { //if the value is constant, wrap it in quotes, otherwise, just append it. formattedValue.Append( string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? Quote("{0}") : "{0}", comparisonValue.Value)); } return formattedValue.ToString(); }
private void Initialize(Group left, Group @operator, Group right) { if (null == left) { throw new ArgumentNullException(nameof(left)); } if (null == @operator) { throw new ArgumentNullException(nameof(@operator)); } if (null == right) { throw new ArgumentNullException(nameof(right)); } if ( !left.Success || !right.Success || string.IsNullOrEmpty(left.Value) || string.IsNullOrEmpty(right.Value) ) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.attributePath = left.Value; if (!Enum.TryParse <ComparisonOperatorValue>(@operator.Value, out ComparisonOperatorValue comparisonOperatorValue)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.Operator = comparisonOperatorValue; if (!FilterExpression.TryParse(right.Value, out string comparisonValue)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } this.value = new ComparisonValue(comparisonValue, FilterExpression.Quote == right.Value[0]); int indexRemainder = right.Value.IndexOf(comparisonValue, StringComparison.Ordinal) + comparisonValue.Length; if (indexRemainder >= right.Value.Length) { return; } string remainder = right.Value.Substring(indexRemainder); int indexAnd = remainder.IndexOf(FilterExpression.LogicalOperatorAnd.Value, StringComparison.Ordinal); int indexOr = remainder.IndexOf(FilterExpression.LogicalOperatorOr.Value, StringComparison.Ordinal); int indexNextFilter; int indexLogicalOperator; if (indexAnd >= 0 && (indexOr < 0 || indexAnd < indexOr)) { indexNextFilter = indexAnd + FilterExpression.LogicalOperatorAnd.Value.Length; this.logicalOperator = LogicalOperatorValue.and; indexLogicalOperator = indexAnd; } else if (indexOr >= 0) { indexNextFilter = indexOr + FilterExpression.LogicalOperatorOr.Value.Length; this.logicalOperator = LogicalOperatorValue.or; indexLogicalOperator = indexOr; } else { string tail = remainder.Trim().TrimEnd(FilterExpression.TrailingCharacters.Value); if (!string.IsNullOrWhiteSpace(tail)) { string message = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementProtocolResources.ExceptionInvalidFilterTemplate, this.Text); throw new InvalidOperationException(message); } else { return; } } string nextExpression = remainder.Substring(indexNextFilter); int indexClosingBracket = remainder.IndexOf(FilterExpression.BracketClose); int nextExpressionLevel; int nextExpressionGroup; if (indexClosingBracket >= 0 && indexClosingBracket < indexLogicalOperator) { nextExpressionLevel = this.Level - 1; nextExpressionGroup = this.Group - 1; } else { nextExpressionLevel = this.Level; nextExpressionGroup = this.Group; } this.next = new FilterExpression(nextExpression, nextExpressionGroup, nextExpressionLevel); this.next.Previous = this; }
/// <summary> /// Formats the right comparison value and hands it back /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { var isValueDate = (comparisonValue.Value is DateTime); var value = Convert.ToString(comparisonValue.Value, CultureInfo.InvariantCulture); string result; if (isValueDate) { //result = comparisonValue.Value.ToString(); var dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("o"); //TODO: Convert to the proper date format result = QuoteSingle(value); } else if (comparisonValue.ValueType == ComparisonValueType.Constant) { //if it's a constant value type and a string, wrap it in quotes: result = comparisonValue.Value is string ? string.Format("{0}", QuoteSingle(value)) : value; } else { //otherwise, just return the raw value: result = value; } return result; }
/// <summary> /// Provide the query for an update by parsing the input DataEntity. /// This however does not include the where clause /// </summary> /// <param name="input"></param> /// <returns></returns> private string ParseUpdateQuery(DataEntity input) { StringBuilder updateValues = new StringBuilder(); // parse through the column names and values foreach (var property in input.Properties) { string rightValue; if (property.Value == null) { rightValue = "NULL"; } else { //create a new comparison value for the column value var value = new ComparisonValue(ComparisonValueType.Constant, property.Value); rightValue = GetRightFormattedComparisonValue(property.Key, value); } updateValues.Append(string.Format("[{0}] = {1},", property.Key, rightValue)); } //remove the trailing comma updateValues = updateValues.Remove(updateValues.Length - 1, 1); return string.Format(" [{0}] " + SetKeyword + " {1}", input.ObjectDefinitionFullName, updateValues); }
/// <summary> /// Provide the query for insert data by parsing the input DataEntity /// </summary> /// <param name="input"></param> /// <returns></returns> private string ParseInsertQuery(DataEntity input) { StringBuilder columnNames = new StringBuilder(); StringBuilder columnValues = new StringBuilder(); columnNames.Append("("); columnValues.Append("("); // parse through the column names and values foreach (KeyValuePair<string, object> property in input.Properties) { columnNames.Append(string.Format(" [{0}],", property.Key)); if (property.Value == null) { columnValues.Append("null,"); } else { //create a the right comparison value ComparisonValue rightValue = new ComparisonValue(ComparisonValueType.Constant, property.Value); columnValues.Append(GetRightFormattedComparisonValue(property.Key, rightValue)); columnValues.Append(","); } } //remove the trailing commas and replace them with a closing brace columnNames = columnNames.Replace(',', ')', columnNames.Length - 1, 1); columnValues = columnValues.Replace(',', ')', columnValues.Length - 1, 1); return string.Format(" {0} [{1}] {2} {3}{4} {5}", IntoKeyword, input.ObjectDefinitionFullName, columnNames, Environment.NewLine, ValuesKeyword, columnValues); }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// This is used for query execution /// </summary> /// <param name="leftValue"></param> /// <param name="rightValue"></param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private string GetRightFormattedComparisonValue(ComparisonValue leftValue, ComparisonValue rightValue) { object comparisonValue; //check if the left value is a property, which in this case would be a column name if (leftValue.ValueType == ComparisonValueType.Property && _columnDefinitions != null) { //retrieve the name of the column from the right value. //The Incomming format is [Column Name] //use the datatypes stored in the column definitions to propery convert the data stored in the right value comparisonValue = DataTypeConverter.ToSqlValue(leftValue.Value.ToString().Split('.').Last(), rightValue.Value, _columnDefinitions); } else { comparisonValue = rightValue.Value; } bool valueIsDate = (comparisonValue is DateTime); string value = comparisonValue.ToString(); string result; if (valueIsDate) { DateTime dateTimeValue = ((DateTime)(comparisonValue)); if (dateTimeValue.Kind != DateTimeKind.Utc) { dateTimeValue = dateTimeValue.ToUniversalTime(); } value = dateTimeValue.ToString("s"); result = string.Format("{0}({1}, '{2}')", ConvertKeyword, DateTimeKeyword, value); } else { result = string.Format(rightValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", value); } return result; }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// </summary> /// <param name="comparisonValue"> /// The comparison value. /// </param> /// <returns> /// The value formatted for use in a sql statement. /// </returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { bool valueIsDate = (comparisonValue.Value.GetType() == typeof(DateTime)); string value = comparisonValue.Value.ToString(); string result; if (valueIsDate) { DateTime dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("s"); result = string.Format("convert(datetime, '{0}')", value); } else { result = string.Format(comparisonValue.ValueType == ComparisonValueType.Constant ? "'{0}'" : "{0}", value.Replace("'", "''")); } return result; }
private static string ParseWhereClause(EntityProperties properties) { var whereClause = new StringBuilder(); if (properties != null && properties.Count > 0) { whereClause.AppendFormat(" {0} ", WhereKeyword); int index = 1; foreach (var property in properties) { if (property.Value == null) { whereClause.AppendFormat("[{0}] IS NULL", property.Key); } else { var rightComparisonValue = new ComparisonValue(ComparisonValueType.Constant, property.Value); whereClause.AppendFormat("[{0}] = {1}", property.Key, GetRightFormattedComparisonValue(rightComparisonValue)); } if (index != properties.Count) { whereClause.Append(" AND "); } index++; } } return whereClause.ToString(); }
/// <summary> /// Formats the right comparison value and hands it back /// </summary> /// <param name="comparisonValue"></param> /// <returns></returns> private static string GetRightFormattedComparisonValue(ComparisonValue comparisonValue) { var isValueDate = (comparisonValue.Value is DateTime); var value = Convert.ToString(comparisonValue.Value, CultureInfo.InvariantCulture); string result; if (isValueDate) { //result = comparisonValue.Value.ToString(); var dateTimeValue = ((DateTime)(comparisonValue.Value)); value = dateTimeValue.ToString("o"); result = string.Format( "DateTime.Parse({0}, null, DateTimeStyles.RoundtripKind)", Quote(string.Format("{0}", value))); } else if (comparisonValue.ValueType == ComparisonValueType.Constant) { //if it's a constant value type and a string, wrap it in quotes: result = comparisonValue.Value is string ? string.Format("{0}", Quote(value)) : value; } else { //otherwise, just return the raw value: result = value; } return result; }
/// <summary> /// Gets the comparison value formatted for use in a sql statement. /// This is used for query execution /// </summary> /// <param name="columnName">name of the column used in the comparison</param> /// <param name="rightValue">value to be formatted in the comparison</param> /// <returns>The value formatted for use in a sql statement.</returns> private string GetRightFormattedComparisonValue(string columnName, ComparisonValue rightValue) { string rightFormattedValue = string.Empty; //Determine whether or not column definitions have been implemented, //if they havn't then we know that the query is requested from the ExecuteOpertion method if (_columnDefinitions == null) { rightFormattedValue = GetRightFormattedComparisonValue(rightValue); } else { //create a new comparison value for the left side of the statement using the column name ComparisonValue leftValue = new ComparisonValue(); leftValue.ValueType = ComparisonValueType.Property; leftValue.Value = columnName; rightFormattedValue = GetRightFormattedComparisonValue(leftValue, rightValue); } return rightFormattedValue; }
public override int GetHashCode() { return((ComparisonValue != null) ? ComparisonValue.GetHashCode() : 0); }
public override int GetHashCode() => ComparisonValue?.GetHashCode() ?? 0;