Skip to content

Commit

Permalink
- 测试 KingbaseES 数组等特殊类型;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Aug 14, 2024
1 parent d33109c commit 5b2ff93
Show file tree
Hide file tree
Showing 11 changed files with 1,259 additions and 1,064 deletions.
656 changes: 452 additions & 204 deletions FreeSql.Tests/FreeSql.Tests/KingbaseES/KingbaseESCodeFirstTest.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeSql.Tests/FreeSql.Tests/g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class g
public static IFreeSql shentong => shentongLazy.Value;

static Lazy<IFreeSql> kingbaseESLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.KingbaseES, "Server=121.36.59.173;Port=54321;UID=system;PWD=abc.123;database=test;max pool size=4")
.UseConnectionString(FreeSql.DataType.KingbaseES, "Server=123.57.239.39;Port=54322;UID=system;PWD=123456;database=test;max pool size=4")
//.UseConnectionFactory(FreeSql.DataType.KingbaseES, () => new Kdbndp.KdbndpConnection("Server=127.0.0.1;Port=54321;UID=USER2;PWD=123456789;database=TDB2"))
.UseAutoSyncStructure(true)
.UseLazyLoading(true)
Expand Down
1,592 changes: 759 additions & 833 deletions FreeSql/FreeSql.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,9 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列

var isPg95 = true;
var isPg96 = true;
var isPg10 = (_orm.DbFirst as CustomPostgreSQLDbFirst).IsPg10;
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
{
isPg95 = CustomPostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
isPg96 = CustomPostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
var isPg95 = (_orm.DbFirst as CustomPostgreSQLDbFirst).IsPg95;
var isPg96 = (_orm.DbFirst as CustomPostgreSQLDbFirst).IsPg96;

foreach (var obj in objects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public CustomPostgreSQLDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpr
}

public bool IsPg10 => ServerVersion >= 10;
public bool IsPg95 { get; private set; }
public bool IsPg96 { get; private set; }
public int ServerVersion
{
get
Expand All @@ -33,6 +35,8 @@ public int ServerVersion
try
{
_ServerVersionValue = ParsePgVersion(conn.Value.ServerVersion, 10, 0).Item2;
IsPg95 = ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
IsPg96 = ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
catch
{
Expand Down
8 changes: 5 additions & 3 deletions Providers/FreeSql.Provider.KingbaseES/KingbaseESCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
case when t.typelem > 0 and t.typinput::varchar = 'ARRAY_IN' then t2.typname else t.typname end,
case when a.attnotnull then '0' else '1' end as is_nullable,
--e.adsrc,
(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid limit 1) is_identity,
--e.adsrc as is_identity, pg12以下
--case when a.attidentity = 'd' the(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid limit 1) is_identity, pg10以下
case when a.attidentity = 'd' then '1' else '0' end is_identity,
a.attndims,
d.description as comment
from {pg_}class c
Expand Down Expand Up @@ -284,7 +285,8 @@ d.description as comment
sqlType = string.Concat(sqlType),
max_length = long.Parse(string.Concat(a[2])),
is_nullable = string.Concat(a[4]) == "1",
is_identity = string.Concat(a[5]).StartsWith(@"NEXTVAL('") && (string.Concat(a[5]).EndsWith(@"'::REGCLASS)") || string.Concat(a[5]).EndsWith(@"')")),
is_identity = string.Concat(a[5]) == "1", //pg10+
//is_identity = string.Concat(a[5]).StartsWith(@"NEXTVAL('") && (string.Concat(a[5]).EndsWith(@"'::REGCLASS)") || string.Concat(a[5]).EndsWith(@"')")),
attndims,
comment = string.Concat(a[7])
};
Expand Down
25 changes: 23 additions & 2 deletions Providers/FreeSql.Provider.KingbaseES/KingbaseESDbFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ and upper(b.nspname || '.' || a.relname) not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUB
case when t.typelem = 0 then t.typname else t2.typname end,
case when a.attnotnull then 0 else 1 end as is_nullable,
--e.adsrc as is_identity, pg12以下
(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid and adnum = e.adnum limit 1) is_identity,
--(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid and adnum = e.adnum limit 1) is_identity, pg10以下
case when a.attidentity = 'd' then '1' else '0' end is_identity,
d.description as comment,
a.attndims,
case when t.typelem = 0 then t.typtype else t2.typtype end,
Expand All @@ -381,7 +382,8 @@ and upper(b.nspname || '.' || a.relname) not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUB
var max_length = int.Parse(string.Concat(row[3]));
var sqlType = string.Concat(row[4]);
var is_nullable = string.Concat(row[5]) == "1";
var is_identity = string.Concat(row[6]).StartsWith(@"NEXTVAL('") && (string.Concat(row[6]).EndsWith(@"'::REGCLASS)") || string.Concat(row[6]).EndsWith(@"')"));
var is_identity = string.Concat(row[6]) == "1"; //pg10+
//var is_identity = string.Concat(row[6]).StartsWith(@"NEXTVAL('") && (string.Concat(row[6]).EndsWith(@"'::REGCLASS)") || string.Concat(row[6]).EndsWith(@"')"));
var comment = string.Concat(row[7]);
var defaultValue = string.Concat(row[6]);
int attndims = int.Parse(string.Concat(row[8]));
Expand Down Expand Up @@ -635,5 +637,24 @@ b.enumlabel AS label
}
return ret.Select(a => new DbEnumInfo { Name = a.Key, Labels = a.Value }).ToList();
}

public static NativeTuple<bool, int, int> ParsePgVersion(string versionString, int v1, int v2)
{
int[] version = new int[] { 0, 0 };
var vmatch = Regex.Match(versionString, @"(\d+)\.(\d+)");
if (vmatch.Success)
{
version[0] = int.Parse(vmatch.Groups[1].Value);
version[1] = int.Parse(vmatch.Groups[2].Value);
}
else
{
vmatch = Regex.Match(versionString, @"(\d+)");
version[0] = int.Parse(vmatch.Groups[1].Value);
}
if (version[0] > v1) return NativeTuple.Create(true, version[0], version[1]);
if (version[0] == v1 && version[1] >= v2) return NativeTuple.Create(true, version[0], version[1]);
return NativeTuple.Create(false, version[0], version[1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,9 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列

var isPg95 = true;
var isPg96 = true;
var isPg10 = (_orm.DbFirst as OdbcPostgreSQLDbFirst).IsPg10;
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
{
isPg95 = OdbcPostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
isPg96 = OdbcPostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
var isPg95 = (_orm.DbFirst as OdbcPostgreSQLDbFirst).IsPg95;
var isPg96 = (_orm.DbFirst as OdbcPostgreSQLDbFirst).IsPg96;

foreach (var obj in objects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public OdbcPostgreSQLDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpres
_commonExpression = commonExpression;
}


public bool IsPg10 => ServerVersion >= 10;
public bool IsPg95 { get; private set; }
public bool IsPg96 { get; private set; }
public int ServerVersion
{
get
Expand All @@ -34,6 +37,8 @@ public int ServerVersion
try
{
_ServerVersionValue = ParsePgVersion(conn.Value.ServerVersion, 10, 0).Item2;
IsPg95 = ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
IsPg96 = ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
catch
{
Expand Down
9 changes: 2 additions & 7 deletions Providers/FreeSql.Provider.PostgreSQL/PostgreSQLCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,9 @@ protected override string GetComparisonDDLStatements(params TypeSchemaAndName[]
var sb = new StringBuilder();
var seqcols = new List<NativeTuple<ColumnInfo, string[], bool>>(); //序列

var isPg95 = true;
var isPg96 = true;
var isPg10 = (_orm.DbFirst as PostgreSQLDbFirst).IsPg10;
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
{
isPg95 = PostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
isPg96 = PostgreSQLDbFirst.ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
var isPg95 = (_orm.DbFirst as PostgreSQLDbFirst).IsPg95;
var isPg96 = (_orm.DbFirst as PostgreSQLDbFirst).IsPg96;

foreach (var obj in objects)
{
Expand Down
4 changes: 4 additions & 0 deletions Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public PostgreSQLDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression
}

public bool IsPg10 => ServerVersion >= 10;
public bool IsPg95 { get; private set; }
public bool IsPg96 { get; private set; }
public int ServerVersion
{
get
Expand All @@ -39,6 +41,8 @@ public int ServerVersion
try
{
_ServerVersionValue = ParsePgVersion(conn.Value.ServerVersion, 10, 0).Item2;
IsPg95 = ParsePgVersion(conn.Value.ServerVersion, 9, 5).Item1;
IsPg96 = ParsePgVersion(conn.Value.ServerVersion, 9, 6).Item1;
}
catch
{
Expand Down

0 comments on commit 5b2ff93

Please sign in to comment.