diff --git a/XCode/Configuration/TableItem.cs b/XCode/Configuration/TableItem.cs
index 7c24ae7aa..946cd38f9 100644
--- a/XCode/Configuration/TableItem.cs
+++ b/XCode/Configuration/TableItem.cs
@@ -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;
}
diff --git a/XCode/DataAccessLayer/Database/PostgreSQL.cs b/XCode/DataAccessLayer/Database/PostgreSQL.cs
index 8687dc6ed..f31fe1f3a 100644
--- a/XCode/DataAccessLayer/Database/PostgreSQL.cs
+++ b/XCode/DataAccessLayer/Database/PostgreSQL.cs
@@ -87,7 +87,7 @@ public override String FormatKeyWord(String keyWord)
}
/// 格式化数据为SQL数据
- /// 字段
+ /// 字段
/// 数值
///
public override String FormatValue(IDataColumn? column, Object? value)
@@ -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)
{
@@ -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
{
@@ -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))
diff --git a/XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs b/XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs
index b32df88b5..b6a2c31e6 100644
--- a/XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs
+++ b/XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs
@@ -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)
@@ -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);