Skip to content

Commit

Permalink
Merge pull request #35 from Soar360/pgsql_array
Browse files Browse the repository at this point in the history
[fix]pgsql在拼接 Upsert 语句时多输出了逗号。
  • Loading branch information
Soar360 authored Sep 16, 2024
2 parents 0074ea1 + a3a1506 commit 758899a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions XCode/DataAccessLayer/Database/PostgreSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override String FormatValue(IDataColumn? column, Object? value)
}
if (isArrayField)
{
if (value is null) return isNullable ? "NULL" : "ARRAY[]";
if (value is null) return isNullable ? "NULL" : "'{}'";
var count = 0;
var builder = new StringBuilder();
builder.Append("ARRAY[");
Expand All @@ -131,8 +131,16 @@ public override String FormatValue(IDataColumn? column, Object? value)
builder.Append(',');
count++;
}
if (count != 0) builder.Length--;
builder.Append("]");
if (count != 0)
{
builder.Length--;
builder.Append("]");
}
else
{
builder.Clear();
builder.Append("'{}'");
}
return builder.ToString();
}
else
Expand Down Expand Up @@ -414,11 +422,11 @@ public override Int32 Upsert(IDataTable table, IDataColumn[] columns, ICollectio
{
if (dc.Nullable)
{
setters.Add(String.Format("{0} = EXCLUDED.{0},", db.FormatName(dc)));
setters.Add(String.Format("{0} = EXCLUDED.{0}", db.FormatName(dc)));
}
else
{
setters.Add(String.Format("{0} = COALESCE(EXCLUDED.{0},{1}.{0}),", db.FormatName(dc), tb));
setters.Add(String.Format("{0} = COALESCE(EXCLUDED.{0},{1}.{0})", db.FormatName(dc), tb));
}
}
}
Expand All @@ -432,7 +440,7 @@ public override Int32 Upsert(IDataTable table, IDataColumn[] columns, ICollectio

if (addColumns.Contains(dc.Name))
{
setters.Add(String.Format("{0} = EXCLUDED.{0} + {1}.{0},", db.FormatName(dc), tb));
setters.Add(String.Format("{0} = EXCLUDED.{0} + {1}.{0}", db.FormatName(dc), tb));
}
}
}
Expand Down

0 comments on commit 758899a

Please sign in to comment.