Skip to content

Commit

Permalink
优化 FormatName 方法逻辑并使用继承注释
Browse files Browse the repository at this point in the history
删除了 `FormatName` 方法的注释,并用 `inheritdoc` 标签替代,以继承基类的注释。
修改了 `FormatName` 方法的实现逻辑:
  * 原来的实现是无论如何都给名称加上双引号。
  * 新的实现是只有在名称包含大写字符时才加上双引号,否则保持原样。
  • Loading branch information
Soar360 committed Sep 19, 2024
1 parent 7f63cfb commit fe02796
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions XCode/DataAccessLayer/Database/PostgreSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,17 @@ private string ValueToSQL(Type? type, bool isNullable, object? value)
/// <returns></returns>
public override String StringConcat(String left, String right) => (!String.IsNullOrEmpty(left) ? left : "''") + "||" + (!String.IsNullOrEmpty(right) ? right : "''");

/// <summary>
/// 格式化数据库名称,表名称,字段名称 增加双引号("")
/// PGSQL 默认情况下创建库表时自动转为小写,增加引号强制区分大小写
/// 以解决数据库创建查询时大小写问题
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
/// <inheritdoc/>
public override String FormatName(String name)
{
name = base.FormatName(name);

if (name.StartsWith("\"") || name.EndsWith("\"")) return name;

return $"\"{name}\"";
//如果包含大写字符,就加上引号
if (name.Any(char.IsUpper)) return $"\"{name}\"";

return name;
}

/// <inheritdoc/>
Expand Down

0 comments on commit fe02796

Please sign in to comment.