Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改善对 postgresql 的支持 #47

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions XCode/Configuration/TableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ public void Merge(IDataTable table)
if (item.Name.EqualIgnoreCase(name)) return _all[name] = item as Field;
}

foreach (var item in AllFields)
{
if (item.FormatedName.EqualIgnoreCase(name)) return _all[name] = item as Field;
}

return _all[name] = null;
}

Expand Down
29 changes: 21 additions & 8 deletions XCode/DataAccessLayer/Database/PostgreSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override String FormatKeyWord(String keyWord)
}

/// <summary>格式化数据为SQL数据</summary>
/// <param name="field">字段</param>
/// <param name="column">字段</param>
/// <param name="value">数值</param>
/// <returns></returns>
public override String FormatValue(IDataColumn? column, Object? value)
Expand All @@ -110,14 +110,10 @@ public override String FormatValue(IDataColumn? column, Object? value)
// 如果类型是Nullable的,则获取对应的类型
type = Nullable.GetUnderlyingType(type) ?? type;
//如果是数组,就取数组的元素类型
if (type?.IsArray == true)
if (type?.IsArray == true && column?.IsArray == true)
{
//Byte[] 数组可能是 Blob,不应该当作数组字段处理
if (column?.IsArray == true || type != typeof(Byte[]))
{
isArrayField = true;
type = type.GetElementType();
}
isArrayField = true;
type = type.GetElementType();
}
if (isArrayField)
{
Expand All @@ -135,6 +131,8 @@ public override String FormatValue(IDataColumn? column, Object? value)
{
builder.Length--;
builder.Append("]");
var ts = GetElementType(type);
if (!string.IsNullOrWhiteSpace(ts)) builder.Append("::").Append(ts).Append("[]");
}
else
{
Expand All @@ -149,6 +147,21 @@ public override String FormatValue(IDataColumn? column, Object? value)
}
}

private static string? GetElementType(Type? type)
{
if (type != null)
{
if (type == typeof(String)) return "varchar";
if (type == typeof(DateTime)) return "timestamp";
if (type == typeof(Int32)) return "integer";
if (type == typeof(Int64)) return "bigint";
if (type == typeof(Decimal)) return "numeric";
if (type == typeof(double)) return "numeric";
if (type == typeof(float)) return "numeric";
}
return string.Empty;
}

private string ValueToSQL(Type? type, bool isNullable, object? value)
{
if (type == typeof(String))
Expand Down
4 changes: 2 additions & 2 deletions XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected virtual String CheckColumnsChange(IDataTable entitytable, IDataTable d
{
var sb = new StringBuilder();
var etdic = entitytable.Columns.ToDictionary(e => this.FormatName(e), e => e, StringComparer.OrdinalIgnoreCase);
var dbdic = dbtable.Columns.ToDictionary(e => e.ColumnName.ToLower(), e => e, StringComparer.OrdinalIgnoreCase);
var dbdic = dbtable.Columns.ToDictionary(e => this.FormatName(e), e => e, StringComparer.OrdinalIgnoreCase);

#region 新增列
foreach (var item in entitytable.Columns)
Expand Down Expand Up @@ -237,7 +237,7 @@ protected virtual String CheckColumnsChange(IDataTable entitytable, IDataTable d
for (var i = dbtable.Columns.Count - 1; i >= 0; i--)
{
var item = dbtable.Columns[i];
if (!etdic.ContainsKey(item.ColumnName))
if (!etdic.ContainsKey(this.FormatName(item)))
{
if (!String.IsNullOrEmpty(item.Description)) PerformSchema(sb, @readonly || onlyCreate, DDLSchema.DropColumnDescription, item);
PerformSchema(sbDelete, @readonly || onlyCreate, DDLSchema.DropColumn, item);
Expand Down
Loading