mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 优化 兼容 pgsql 9.4 CodeFirst/DbFirst;
This commit is contained in:
@ -213,9 +213,11 @@ namespace FreeSql.PostgreSQL
|
||||
public List<DbTableInfo> GetTablesByDatabase(params string[] database)
|
||||
{
|
||||
var olddatabase = "";
|
||||
var is96 = true;
|
||||
using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
olddatabase = conn.Value.Database;
|
||||
is96 = PgVersionIs96(conn.Value.ServerVersion);
|
||||
}
|
||||
var dbs = database == null || database.Any() == false ? new[] { olddatabase } : database;
|
||||
var tables = new List<DbTableInfo>();
|
||||
@ -401,7 +403,7 @@ b.relname as index_id,
|
||||
case when a.indisunique then 1 else 0 end IsUnique,
|
||||
case when a.indisprimary then 1 else 0 end IsPrimary,
|
||||
case when a.indisclustered then 0 else 1 end IsClustered,
|
||||
case when pg_index_column_has_property(b.oid, c.attnum, 'desc') = 't' then 1 else 0 end IsDesc,
|
||||
{(is96 ? "case when pg_index_column_has_property(b.oid, c.attnum, 'desc') = 't' then 1 else 0 end" : "0")} IsDesc,
|
||||
a.indkey::text,
|
||||
c.attnum
|
||||
from pg_index a
|
||||
@ -591,5 +593,14 @@ where a.typtype = 'e' and ns.nspname in (SELECT ""schema_name"" FROM information
|
||||
}
|
||||
return ret.Select(a => new DbEnumInfo { Name = a.Key, Labels = a.Value }).ToList();
|
||||
}
|
||||
|
||||
public static bool PgVersionIs96(string serverVersion)
|
||||
{
|
||||
int[] version = serverVersion.Split('.').Select(a => int.TryParse(a, out var tryint) ? tryint : 0).ToArray();
|
||||
if (version?.Any() != true) return true;
|
||||
if (version[0] > 9) return true;
|
||||
if (version[0] == 9 && version.Length > 1 && version[1] >= 6) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user