From 0ba0e321726e02c54c4440282b51f25078fe8d81 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 12 Sep 2000 04:15:58 +0000 Subject: 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 --- src/bin/pg_dump/pg_dump.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/bin/pg_dump/pg_dump.c') diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index d581f13a4af..372ff9be4c8 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.163 2000/08/07 12:32:54 pjw Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.164 2000/09/12 04:15:58 momjian Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -256,12 +256,22 @@ isViewRule(char *relname) { PGresult *res; int ntups; + char rulename[NAMEDATALEN + 5]; PQExpBuffer query = createPQExpBuffer(); appendPQExpBuffer(query, "select relname from pg_class, pg_rewrite "); appendPQExpBuffer(query, "where pg_class.oid = ev_class "); appendPQExpBuffer(query, "and pg_rewrite.ev_type = '1' "); - appendPQExpBuffer(query, "and rulename = '_RET%s'", relname); + snprintf(rulename,NAMEDATALEN + 5,"_RET%s",relname); +#ifdef MULTIBYTE + int len; + len = pg_mbcliplen(rulename,strlen(rulename),NAMEDATALEN-1); + rulename[len] = '\0'; +#else + rulename[NAMEDATALEN-1] = '\0'; +#endif + + appendPQExpBuffer(query, "and rulename = '%s'", rulename); res = PQexec(g_conn, query->data); if (!res || -- cgit v1.2.3