mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 优化 pgsql DbFirst 序列的识别,以及 pgsql10 的自增识别;
This commit is contained in:
@ -215,7 +215,7 @@ 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)"),
|
||||
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])
|
||||
};
|
||||
|
@ -247,7 +247,7 @@ 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)");
|
||||
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]));
|
||||
|
@ -227,7 +227,7 @@ 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)"),
|
||||
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])
|
||||
};
|
||||
|
@ -23,6 +23,28 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
_commonExpression = commonExpression;
|
||||
}
|
||||
|
||||
public bool IsPg10 => ServerVersion >= 10;
|
||||
public int ServerVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ServerVersionValue == 0 && _orm.Ado.MasterPool != null)
|
||||
using (var conn = _orm.Ado.MasterPool.Get())
|
||||
{
|
||||
try
|
||||
{
|
||||
_ServerVersionValue = int.Parse(conn.Value.ServerVersion.Split('.')[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_ServerVersionValue = 9;
|
||||
}
|
||||
}
|
||||
return _ServerVersionValue;
|
||||
}
|
||||
}
|
||||
int _ServerVersionValue = 0;
|
||||
|
||||
public int GetDbType(DbColumnInfo column) => (int)GetOdbcType(column);
|
||||
OdbcType GetOdbcType(DbColumnInfo column)
|
||||
{
|
||||
@ -217,7 +239,7 @@ d.description as comment,
|
||||
a.attndims,
|
||||
case when t.typelem = 0 then t.typtype else t2.typtype end,
|
||||
ns2.nspname,
|
||||
a.attnum
|
||||
a.attnum{(IsPg10 ? ", a.attidentity" : "")}
|
||||
from pg_class c
|
||||
inner join pg_attribute a on a.attnum > 0 and a.attrelid = c.oid
|
||||
inner join pg_type t on t.oid = a.atttypid
|
||||
@ -239,7 +261,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)");
|
||||
var is_identity = string.Concat(row[6]).StartsWith(@"nextval('") && (string.Concat(row[6]).EndsWith(@"'::regclass)") || string.Concat(row[6]).EndsWith(@"')"))
|
||||
|| IsPg10 && new[] { "a", "d" }.Contains(string.Concat(row[12])); //pg10 GENERATED { BY DEFAULT | AWAYS } AS IDENTITY
|
||||
var comment = string.Concat(row[7]);
|
||||
var defaultValue = string.Concat(row[6]);
|
||||
int attndims = int.Parse(string.Concat(row[8]));
|
||||
|
Reference in New Issue
Block a user