Пример #1
0
        public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema,
                                    List <string> columns, List <string> keys, List <string> setParameters, List <string> whereParameters,
                                    string setSuffix = SetSuffix)
        {
            Debug.Assert(columns != null);
            Debug.Assert(columns.Count == setParameters?.Count && columns.Count >= whereParameters?.Count);

            return(Pooling.StringBuilderPool.Scoped(sb =>
            {
                if (!d.BeforeUpdate(descriptor, sb))
                {
                    return;
                }

                sb.Append("UPDATE ");
                sb.AppendTable(d, table, schema).Append(" SET ");

                if (!d.BeforeUpdateColumns(descriptor, sb, columns))
                {
                    return;
                }

                for (var i = 0; i < columns.Count; i++)
                {
                    var column = columns[i];
                    sb.AppendName(d, column).Append(" = ");
                    sb.AppendParameter(d, setParameters[i] + setSuffix);
                    if (i < columns.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }

                if (whereParameters.Count > 0)
                {
                    if (!d.BeforeWhere(descriptor, sb, keys, whereParameters))
                    {
                        return;
                    }
                    sb.AppendWhereClause(d, keys, whereParameters);
                    d.AfterWhere(descriptor, sb, keys);
                }
            }));
        }
Пример #2
0
        public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema,
                                    List <PropertyToColumn> columns, List <string> keys, string setSuffix = SetSuffix)
        {
            return(StringBuilderPool.Scoped(sb =>
            {
                if (!d.BeforeUpdate(descriptor, sb))
                {
                    return;
                }

                sb.Append("UPDATE ");
                sb.AppendTable(d, table, schema).Append(" SET ");

                if (!d.BeforeUpdateColumns(descriptor, sb, columns.Select(x => x.ColumnName).ToList()))
                {
                    return;
                }

                for (var i = 0; i < columns.Count; i++)
                {
                    var column = columns[i];
                    sb.AppendName(d, column.ColumnName).Append(" = ")
                    .AppendParameter(d, column.ColumnName)
                    .Append(setSuffix);

                    if (i < columns.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }

                if (!d.BeforeWhere(descriptor, sb, keys))
                {
                    return;
                }

                sb.AppendWhereClause(d, keys);

                d.AfterWhere(descriptor, sb, keys);
            }));
        }