Пример #1
0
        private string GetSqlValue(object value, int index)
        {
            if (this.Options?.SkipFormatRows.Any(rowIndex => rowIndex == index) == true)
            {
                return(value?.ToString());
            }

            return(SqlValueParser.ParseValue(value, this.Options));
        }
Пример #2
0
        public void VerifyEnumerableParseWorks()
        {
            var values = new List <string>
            {
                "fisk 1",
                "fisk 2"
            };
            var value = SqlValueParser.ParseValue(values, new SqlValueOptions());

            value.ShouldBe("('fisk 1', 'fisk 2')");
        }
Пример #3
0
        private string GenerateConditionSql(Condition condition)
        {
            var comparison = string.Empty;

            switch (condition.Comparison)
            {
            case ComparisonType.Equal:
                comparison = "=";
                break;

            case ComparisonType.NotEqual:
                comparison = "<>";
                break;

            case ComparisonType.Like:
                comparison = "LIKE";
                break;

            case ComparisonType.GreaterThan:
                comparison = ">";
                break;

            case ComparisonType.LesserThan:
                comparison = "<";
                break;

            case ComparisonType.EqualToOrGreaterThan:
                comparison = ">=";
                break;

            case ComparisonType.EqualToOrLesserThan:
                comparison = "<=";
                break;

            case ComparisonType.InArray:
                comparison = "IN";
                break;

            case ComparisonType.Is:
                comparison = "IS";
                break;

            case ComparisonType.IsNot:
                comparison = "IS NOT";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return($" ({condition.Key} {comparison} {SqlValueParser.ParseValue(condition.Value, condition.Options ?? this.Options)})");
        }
Пример #4
0
        public override string GenerateQuery()
        {
            this.ValidateQuery();

            var builder = new StringBuilder();

            builder.AppendLine($"UPDATE {this.TableName}");
            var parsedValues = this.SetValues.Select(pair => $"{pair.Key}={SqlValueParser.ParseValue(pair.Value, this.Options)}").ToArray();

            builder.Append($"SET {string.Join(", ", parsedValues)}");
            if (this.Where != null)
            {
                builder.AppendLine();
                builder.Append(this.Where.GenerateQuery());
            }

            builder.Append(";");

            return(builder.ToString());
        }