using System.Application.Columns; using System.Runtime.CompilerServices; namespace System { /// /// SQL语句字符串常量,使用字符串拼接时应注意防止 SQL注入攻击 /// EFCore 可采用 参数化传入参数 /// public static partial class SQLStrings { /// /// "select * from " /// 查询所有列 /// public const string SelectALLFrom = "select * from "; /// /// "select count(Id) from " /// 查询总数,仅Id列 /// public const string SelectCountFrom = "select count(Id) from "; /// /// "select count({0}) from " /// 查询总数,仅某一列 /// 注意:参数仅使用列名固定值,不可传递变量,防止SQL注入攻击 /// public const string SelectCountFrom_0 = "select count({0}) from "; /// /// " order by CreationTime desc" /// 根据 创建时间 倒序 /// public const string OrderByCreationTimeDescending = " order by CreationTime desc"; /// /// " order by ReceiveTime, CreationTime desc" /// 根据 接收时间, 创建时间 倒序 /// public const string OrderByReceiveTimeThenByCreationTimeDescending = " order by ReceiveTime, CreationTime desc"; /// /// " order by {0} desc" /// 根据 某一列 倒序 /// 注意:参数仅使用列名固定值,不可传递变量,防止SQL注入攻击 /// public const string OrderBy_Descending_0 = " order by {0} desc"; /// /// "delete from " /// public const string DeleteFrom = "delete from "; /// /// " where Id = {0}" /// 注意:参数仅使用列名固定值,不可传递变量,防止SQL注入攻击 /// public const string WhereIdEqual_0 = " where Id = {0}"; /// /// "delete from {tableName} where Id = {0}" /// /// /// /// public static FormattableString DeleteFromTableNameWhereIdEqual(string tableName, object id) { var sql = DeleteFrom + tableName + WhereIdEqual_0; return FormattableStringFactory.Create(sql, id); } /// /// "update from {tableName} set IsSoftDeleted = 1 where Id = {0}" /// /// /// /// public static FormattableString SoftDeleteFromTableNameWhereIdEqual(string tableName, object id) { var sql = UpdateFrom + tableName + " set " + nameof(ISoftDeleted.SoftDeleted) + " = 1" + WhereIdEqual_0; return FormattableStringFactory.Create(sql, id); } /// /// "update from " /// public const string UpdateFrom = "update from "; /// /// " where Id in (" /// public const string WhereInIds_ = " where Id in ("; /// /// 右括号 /// public const char RightBracket = ')'; } }