Index: backend/commands/view.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/view.c,v retrieving revision 1.45 diff -c -r1.45 view.c *** backend/commands/view.c 2000/07/04 06:11:30 1.45 --- backend/commands/view.c 2000/08/30 15:58:07 *************** *** 120,125 **** --- 120,133 ---- buf = palloc(strlen(viewName) + 5); snprintf(buf, strlen(viewName) + 5, "_RET%s", viewName); + #ifdef MULTIBYTE + int len; + len = pg_mbcliplen(buf,strlen(buf),NAMEDATALEN-1); + buf[len] = '\0'; + #else + buf[NAMEDATALEN-1] = '\0'; + #endif + return buf; } Index: backend/rewrite/rewriteDefine.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v retrieving revision 1.49 diff -c -r1.49 rewriteDefine.c *** backend/rewrite/rewriteDefine.c 2000/07/30 22:13:51 1.49 --- backend/rewrite/rewriteDefine.c 2000/08/30 15:58:08 *************** *** 23,28 **** --- 23,29 ---- #include "parser/parse_relation.h" #include "rewrite/rewriteDefine.h" #include "rewrite/rewriteSupport.h" + #include "commands/view.h" /* *************** *** 218,224 **** Form_pg_attribute attr; char *attname; int i; ! char expected_name[NAMEDATALEN + 5]; /* * So there cannot be INSTEAD NOTHING, ... --- 219,225 ---- Form_pg_attribute attr; char *attname; int i; ! char *expected_name; /* * So there cannot be INSTEAD NOTHING, ... *************** *** 305,316 **** /* * ... and finally the rule must be named _RETviewname. */ ! sprintf(expected_name, "_RET%s", 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); } } /* --- 306,319 ---- /* * ... and finally the rule must be named _RETviewname. */ ! ! 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); } /* Index: backend/utils/adt/ruleutils.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.59 diff -c -r1.59 ruleutils.c *** backend/utils/adt/ruleutils.c 2000/08/12 04:04:53 1.59 --- backend/utils/adt/ruleutils.c 2000/08/30 15:58:08 *************** *** 51,56 **** --- 51,57 ---- #include "parser/parse_expr.h" #include "parser/parsetree.h" #include "utils/lsyscache.h" + #include "commands/view.h" /* ---------- *************** *** 79,85 **** static void *plan_getrule = NULL; static char *query_getrule = "SELECT * FROM pg_rewrite WHERE rulename = $1"; static void *plan_getview = NULL; ! static char *query_getview = "SELECT * FROM pg_rewrite WHERE rulename = $1 or rulename = $2"; static void *plan_getam = NULL; static char *query_getam = "SELECT * FROM pg_am WHERE oid = $1"; static void *plan_getopclass = NULL; --- 80,86 ---- static void *plan_getrule = NULL; static char *query_getrule = "SELECT * FROM pg_rewrite WHERE rulename = $1"; static void *plan_getview = NULL; ! static char *query_getview = "SELECT * FROM pg_rewrite WHERE rulename = $1"; static void *plan_getam = NULL; static char *query_getam = "SELECT * FROM pg_am WHERE oid = $1"; static void *plan_getopclass = NULL; *************** *** 138,144 **** int len; /* ---------- ! * We need the rules name somewhere deep down * ---------- */ rulename = pstrdup(NameStr(*rname)); --- 139,145 ---- int len; /* ---------- ! * We need the rules name somewhere deep down: rulename is global * ---------- */ rulename = pstrdup(NameStr(*rname)); *************** *** 226,248 **** Datum pg_get_viewdef(PG_FUNCTION_ARGS) { ! Name rname = PG_GETARG_NAME(0); text *ruledef; ! Datum args[2]; ! char nulls[3]; int spirc; HeapTuple ruletup; TupleDesc rulettc; StringInfoData buf; int len; ! char name1[NAMEDATALEN + 5]; ! char name2[NAMEDATALEN + 5]; /* ---------- ! * We need the rules name somewhere deep down * ---------- */ ! rulename = pstrdup(NameStr(*rname)); /* ---------- * Connect to SPI manager --- 227,248 ---- Datum pg_get_viewdef(PG_FUNCTION_ARGS) { ! Name vname = PG_GETARG_NAME(0); text *ruledef; ! Datum args[1]; ! char nulls[2]; int spirc; HeapTuple ruletup; TupleDesc rulettc; StringInfoData buf; int len; ! char *name; /* ---------- ! * We need the view name somewhere deep down * ---------- */ ! rulename = pstrdup(NameStr(*vname)); /* ---------- * Connect to SPI manager *************** *** 259,286 **** */ if (plan_getview == NULL) { ! Oid argtypes[2]; void *plan; argtypes[0] = NAMEOID; ! argtypes[1] = NAMEOID; ! plan = SPI_prepare(query_getview, 2, argtypes); if (plan == NULL) elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getview); plan_getview = SPI_saveplan(plan); } /* ---------- ! * Get the pg_rewrite tuple for this rule * ---------- */ ! sprintf(name1, "_RET%s", rulename); ! sprintf(name2, "_ret%s", rulename); ! args[0] = PointerGetDatum(name1); ! args[1] = PointerGetDatum(name2); nulls[0] = ' '; ! nulls[1] = ' '; ! nulls[2] = '\0'; spirc = SPI_execp(plan_getview, args, nulls, 1); if (spirc != SPI_OK_SELECT) elog(ERROR, "failed to get pg_rewrite tuple for view %s", rulename); --- 259,282 ---- */ if (plan_getview == NULL) { ! Oid argtypes[1]; void *plan; argtypes[0] = NAMEOID; ! plan = SPI_prepare(query_getview, 1, argtypes); if (plan == NULL) elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getview); plan_getview = SPI_saveplan(plan); } /* ---------- ! * Get the pg_rewrite tuple for this rule: rulename is actually viewname here * ---------- */ ! name = MakeRetrieveViewRuleName(rulename); ! args[0] = PointerGetDatum(name); nulls[0] = ' '; ! nulls[1] = '\0'; spirc = SPI_execp(plan_getview, args, nulls, 1); if (spirc != SPI_OK_SELECT) elog(ERROR, "failed to get pg_rewrite tuple for view %s", rulename); *************** *** 302,307 **** --- 298,304 ---- VARATT_SIZEP(ruledef) = len; memcpy(VARDATA(ruledef), buf.data, buf.len); pfree(buf.data); + pfree(name); /* ---------- * Disconnect from SPI manager Index: bin/pg_dump/pg_dump.c =================================================================== RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v retrieving revision 1.163 diff -c -r1.163 pg_dump.c *** bin/pg_dump/pg_dump.c 2000/08/07 12:32:54 1.163 --- bin/pg_dump/pg_dump.c 2000/08/30 15:58:09 *************** *** 256,267 **** { PGresult *res; int ntups; 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); res = PQexec(g_conn, query->data); if (!res || --- 256,277 ---- { 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' "); ! 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 ||