mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 测试 KingbaseES 数组等特殊类型;
This commit is contained in:
@ -84,14 +84,9 @@ namespace FreeSql.Custom.PostgreSQL
|
||||
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)
|
||||
{
|
||||
|
@ -23,6 +23,8 @@ namespace FreeSql.Custom.PostgreSQL
|
||||
}
|
||||
|
||||
public bool IsPg10 => ServerVersion >= 10;
|
||||
public bool IsPg95 { get; private set; }
|
||||
public bool IsPg96 { get; private set; }
|
||||
public int ServerVersion
|
||||
{
|
||||
get
|
||||
@ -33,6 +35,8 @@ namespace FreeSql.Custom.PostgreSQL
|
||||
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
|
||||
{
|
||||
|
@ -247,8 +247,9 @@ t.typname,
|
||||
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
|
||||
@ -284,7 +285,8 @@ where ns.nspname = {{0}} and c.relname = {{1}}", tboldname ?? tbname);
|
||||
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])
|
||||
};
|
||||
|
@ -355,7 +355,8 @@ case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.at
|
||||
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,
|
||||
@ -381,7 +382,8 @@ where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || c.relname")
|
||||
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]));
|
||||
@ -635,5 +637,24 @@ where a.typtype = 'e' and ns.nspname in (SELECT schema_name FROM information_sch
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -85,14 +85,9 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
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)
|
||||
{
|
||||
|
@ -23,7 +23,10 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
_commonExpression = commonExpression;
|
||||
}
|
||||
|
||||
|
||||
public bool IsPg10 => ServerVersion >= 10;
|
||||
public bool IsPg95 { get; private set; }
|
||||
public bool IsPg96 { get; private set; }
|
||||
public int ServerVersion
|
||||
{
|
||||
get
|
||||
@ -34,6 +37,8 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
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
|
||||
{
|
||||
|
@ -140,14 +140,9 @@ namespace FreeSql.PostgreSQL
|
||||
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)
|
||||
{
|
||||
|
@ -29,6 +29,8 @@ namespace FreeSql.PostgreSQL
|
||||
}
|
||||
|
||||
public bool IsPg10 => ServerVersion >= 10;
|
||||
public bool IsPg95 { get; private set; }
|
||||
public bool IsPg96 { get; private set; }
|
||||
public int ServerVersion
|
||||
{
|
||||
get
|
||||
@ -39,6 +41,8 @@ namespace FreeSql.PostgreSQL
|
||||
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
|
||||
{
|
||||
|
Reference in New Issue
Block a user