Skip to content

AsInsert doesn't work if value count is different than column count  #731

@ccambier

Description

@ccambier

Hi,

In this method in QueryBuilder.Query.Insert.cs, the columnsList.Count and valuesList.Count cannot be compared as same values. It seems to be that the number of rows inserted must be the same as the number of column in the table.

Is it possible to fix it?

public Query AsInsert(IEnumerable<string> columns, IEnumerable<object> values)
        {
            var columnsList = columns?.ToList();
            var valuesList = values?.ToList();

            if ((columnsList?.Count ?? 0) == 0 || (valuesList?.Count ?? 0) == 0)
            {
                throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty");
            }

            if (columnsList.Count != valuesList.Count)
            {
                throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty");
            }

            Method = "insert";

            ClearComponent("insert").AddComponent("insert", new InsertClause
            {
                Columns = columnsList,
                Values = valuesList
            });

            return this;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions