Skip to content

Commit 1d09b7f

Browse files
2881028810
authored andcommitted
- 修复 PostgreSQL CodeFirst/DbFirst 系统表的版本兼容问题;
1 parent 90b2418 commit 1d09b7f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLCodeFirst.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ protected override string GetComparisonDDLStatements(params TypeAndName[] object
182182
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
183183
case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end,
184184
case when a.attnotnull then '0' else '1' end as is_nullable,
185-
coalesce((select 1 from pg_sequences where lower(sequencename) = lower({0} || '_' || {1} || '_' || a.attname || '_sequence_name') limit 1),0) is_identity,
186185
--e.adsrc,
186+
(select pg_get_expr(adbin, adrelid) from pg_attrdef where adrelid = e.adrelid) is_identity,
187187
a.attndims,
188188
d.description as comment
189189
from pg_class c
@@ -219,7 +219,7 @@ from pg_class c
219219
sqlType = string.Concat(sqlType),
220220
max_length = long.Parse(string.Concat(a[2])),
221221
is_nullable = string.Concat(a[4]) == "1",
222-
is_identity = string.Concat(a[5]) == "1", //string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
222+
is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
223223
attndims,
224224
comment = string.Concat(a[7])
225225
};

Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLDbFirst.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ where b.nspname not in ('pg_catalog', 'information_schema') and a.relkind in ('m
209209
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
210210
case when t.typelem = 0 then t.typname else t2.typname end,
211211
case when a.attnotnull then 0 else 1 end as is_nullable,
212-
coalesce((select 1 from pg_sequences where lower(sequencename) = lower({0} || '_' || {1} || '_' || a.attname || '_sequence_name') limit 1),0) is_identity,
213-
--e.adsrc as is_identity,
212+
--e.adsrc as is_identity, pg12以下
213+
(select pg_get_expr(adbin, adrelid) from pg_attrdef where adrelid = e.adrelid) is_identity,
214214
d.description as comment,
215215
a.attndims,
216216
case when t.typelem = 0 then t.typtype else t2.typtype end,
@@ -236,7 +236,7 @@ from pg_class c
236236
var max_length = int.Parse(string.Concat(row[3]));
237237
var sqlType = string.Concat(row[4]);
238238
var is_nullable = string.Concat(row[5]) == "1";
239-
var is_identity = string.Concat(row[6]) == "1"; //string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
239+
var is_identity = string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
240240
var comment = string.Concat(row[7]);
241241
int attndims = int.Parse(string.Concat(row[8]));
242242
string typtype = string.Concat(row[9]);

Providers/FreeSql.Provider.PostgreSQL/PostgreSQLCodeFirst.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ protected override string GetComparisonDDLStatements(params TypeAndName[] object
217217
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
218218
case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end,
219219
case when a.attnotnull then '0' else '1' end as is_nullable,
220-
coalesce((select 1 from pg_sequences where lower(sequencename) = lower({0} || '_' || {1} || '_' || a.attname || '_sequence_name') limit 1),0) is_identity,
221220
--e.adsrc,
221+
(select pg_get_expr(adbin, adrelid) from pg_attrdef where adrelid = e.adrelid) is_identity,
222222
a.attndims,
223223
d.description as comment
224224
from pg_class c
@@ -254,7 +254,7 @@ from pg_class c
254254
sqlType = string.Concat(sqlType),
255255
max_length = long.Parse(string.Concat(a[2])),
256256
is_nullable = string.Concat(a[4]) == "1",
257-
is_identity = string.Concat(a[5]) == "1", //string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
257+
is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
258258
attndims,
259259
comment = string.Concat(a[7])
260260
};

Providers/FreeSql.Provider.PostgreSQL/PostgreSQLDbFirst.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ where b.nspname not in ('pg_catalog', 'information_schema') and a.relkind in ('m
319319
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
320320
case when t.typelem = 0 then t.typname else t2.typname end,
321321
case when a.attnotnull then 0 else 1 end as is_nullable,
322-
coalesce((select 1 from pg_sequences where lower(sequencename) = lower({0} || '_' || {1} || '_' || a.attname || '_sequence_name') limit 1),0) is_identity,
323-
--e.adsrc as is_identity,
322+
--e.adsrc as is_identity, pg12以下
323+
(select pg_get_expr(adbin, adrelid) from pg_attrdef where adrelid = e.adrelid) is_identity,
324324
d.description as comment,
325325
a.attndims,
326326
case when t.typelem = 0 then t.typtype else t2.typtype end,
@@ -346,7 +346,7 @@ from pg_class c
346346
var max_length = int.Parse(string.Concat(row[3]));
347347
var sqlType = string.Concat(row[4]);
348348
var is_nullable = string.Concat(row[5]) == "1";
349-
var is_identity = string.Concat(row[6]) == "1"; //string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
349+
var is_identity = string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
350350
var comment = string.Concat(row[7]);
351351
int attndims = int.Parse(string.Concat(row[8]));
352352
string typtype = string.Concat(row[9]);

0 commit comments

Comments
 (0)