Пример #1
0
        /// <summary>
        /// Generates the DELETE command string.
        /// </summary>
        public string GenerateStatement()
        {
            if (string.IsNullOrEmpty(_table))
            {
                throw new Exception("Table is not set.");
            }

            StringBuilder sb = new StringBuilder($"DELETE FROM {Util.FormatSQL(_table)}");

            if (_condition != null)
            {
                sb.Append($" {_condition.GenerateStatement()}");
            }

            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Generates the actual UPDATE command string.
        /// </summary>
        public string GenerateStatement()
        {
            if (_newColumnValues.Count == 0)
            {
                throw new Exception("Can't update table without columns to be updated.");
            }

            StringBuilder sb = new StringBuilder($"UPDATE {SqlTableHelper.GetTableName<T>()} SET ");

            for (int i = 0; i < _newColumnValues.Count; i++)
            {
                var colVal = _newColumnValues[i];

                sb.Append($"{Util.FormatSQL(colVal.Column)}={colVal.Value}");
                if (i < _newColumnValues.Count - 1)
                {
                    sb.Append(", ");
                }
            }

            sb.Append(_condition?.GenerateStatement());
            return(sb.ToString());
        }