From 2882e4f2bbcc6dbee93abfe0c5f2aaa8ff821794 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 21 Oct 2014 18:23:35 +0000 Subject: [PATCH] Prefer pg_catalog tables in TDBConnection.GetCreateCode. See http://www.heidisql.com/forum.php?t=16213#p16685 --- source/dbconnection.pas | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 4e1beb6b..6baef716 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -2611,13 +2611,23 @@ begin end; lntView: begin - Result := GetVar('SELECT VIEW_DEFINITION'+ - ' FROM INFORMATION_SCHEMA.VIEWS'+ - ' WHERE TABLE_NAME='+EscapeString(Name)+ - ' AND '+SchemaClauseIS('TABLE') - ); - if FParameters.NetTypeGroup = ngPgSQL then - Result := 'CREATE VIEW ' + QuoteIdent(Name) + ' AS ' + Result; + case FParameters.NetTypeGroup of + ngPgSQL: begin + // Prefer pg_catalog tables. See http://www.heidisql.com/forum.php?t=16213#p16685 + Result := 'CREATE VIEW ' + QuoteIdent(Name) + ' AS ' + GetVar('SELECT '+QuoteIdent('definition')+ + ' FROM '+QuoteIdent('pg_views')+ + ' WHERE '+QuoteIdent('viewname')+'='+EscapeString(Name)+ + ' AND '+QuoteIdent('schemaname')+'='+EscapeString(Schema) + ); + end; + else begin + Result := GetVar('SELECT VIEW_DEFINITION'+ + ' FROM INFORMATION_SCHEMA.VIEWS'+ + ' WHERE TABLE_NAME='+EscapeString(Name)+ + ' AND '+SchemaClauseIS('TABLE') + ); + end; + end; end; lntFunction: begin