mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	O.K. -
Here's the multibyte aware version of my patch to fix the truncation of the rulename autogenerated during a CREATE VIEW. I've modified all the places in the backend that want to construct the rulename to use the MakeRetrieveViewRuleName(), where I put the #ifdef MULTIBYTE, so that's the only place that knows how to construct a view rulename. Except pg_dump, where I replicated the code, since it's a standalone binary. The only effect the enduser will see is that views with names len(name) > NAMEDATALEN-4 will fail to be created, if the derived rulename clases with an existing rule: i.e. the user is trying to create two views with long names whose first difference is past NAMEDATALEN-4 (but before NAMEDATALEN: that'll error out after the viewname truncation.) In no case will the user get left with a table without a view rule, as the current code does. Ross Reedstrom
This commit is contained in:
		@@ -8,7 +8,7 @@
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * IDENTIFICATION
 | 
			
		||||
 *	  $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.49 2000/07/30 22:13:51 tgl Exp $
 | 
			
		||||
 *	  $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.50 2000/09/12 04:15:57 momjian Exp $
 | 
			
		||||
 *
 | 
			
		||||
 *-------------------------------------------------------------------------
 | 
			
		||||
 */
 | 
			
		||||
@@ -23,6 +23,7 @@
 | 
			
		||||
#include "parser/parse_relation.h"
 | 
			
		||||
#include "rewrite/rewriteDefine.h"
 | 
			
		||||
#include "rewrite/rewriteSupport.h"
 | 
			
		||||
#include "commands/view.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -218,7 +219,7 @@ DefineQueryRewrite(RuleStmt *stmt)
 | 
			
		||||
		Form_pg_attribute attr;
 | 
			
		||||
		char	   *attname;
 | 
			
		||||
		int			i;
 | 
			
		||||
		char		expected_name[NAMEDATALEN + 5];
 | 
			
		||||
		char		*expected_name;
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * So there cannot be INSTEAD NOTHING, ...
 | 
			
		||||
@@ -305,12 +306,14 @@ DefineQueryRewrite(RuleStmt *stmt)
 | 
			
		||||
		/*
 | 
			
		||||
		 * ... and finally the rule must be named _RETviewname.
 | 
			
		||||
		 */
 | 
			
		||||
		sprintf(expected_name, "_RET%s", event_obj->relname);
 | 
			
		||||
 | 
			
		||||
		expected_name = MakeRetrieveViewRuleName(event_obj->relname);
 | 
			
		||||
		if (strcmp(expected_name, stmt->rulename) != 0)
 | 
			
		||||
		{
 | 
			
		||||
			elog(ERROR, "view rule for %s must be named %s",
 | 
			
		||||
				 event_obj->relname, expected_name);
 | 
			
		||||
		}
 | 
			
		||||
		pfree(expected_name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user