Azavea.Open.DAO.SQL.SqlUtilities.MakeUpdateStatement C# (CSharp) Method

MakeUpdateStatement() public static method

Generates an update statement to update rows where "key" = whereCols["key"] for everything in whereCols.
public static MakeUpdateStatement ( string table, object>.IDictionary whereCols, object>.IDictionary columns, IList sqlParams ) : string
table string Name of the table to be inserted into.
whereCols object>.IDictionary Dictionary of object column values keyed by string column names. /// These columns are used in the "where" clause of the statement. If /// this collection is null or empty, all rows will be updated.
columns object>.IDictionary Dictionary of object column values keyed by string column names. These /// columns are the values that will be set on the row(s). This collection /// may not be null or empty.
sqlParams IList List to insert sql param values (in order) into.
return string
        public static string MakeUpdateStatement(string table, IDictionary<string, object> whereCols,
            IDictionary<string, object> columns, IList<object> sqlParams)
        {
            // Create the string list of columns to update (and put the matching values in sqlParams).
            StringBuilder sb = DbCaches.StringBuilders.Get();
            sb.Append("UPDATE ");
            sb.Append(table);
            sb.Append(" SET ");
            bool first = true;
            foreach (string key in columns.Keys)
            {
                if (!first)
                {
                    sb.Append(", ");
                }
                else
                {
                    first = false;
                }
                sb.Append(key);
                sb.Append(" = ?");
                object val = columns[key];
                sqlParams.Add(val);
            }

            // Create the string list of where clauses (and put the matching values in sqlParams).
            sb.Append(MakeWhereClause(whereCols, sqlParams));

            string retVal = sb.ToString();
            DbCaches.StringBuilders.Return(sb);
            return retVal;
        }