aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2000-09-12 04:15:58 +0000
committerBruce Momjian <bruce@momjian.us>2000-09-12 04:15:58 +0000
commit0ba0e321726e02c54c4440282b51f25078fe8d81 (patch)
tree43e9199812be014d8e3a03f84612e0a2e1762bf6 /src/backend/utils/adt/ruleutils.c
parentb1777d5f997a4e1c5989c2c7d3be5df447a41614 (diff)
downloadpostgresql-0ba0e321726e02c54c4440282b51f25078fe8d81.tar.gz
postgresql-0ba0e321726e02c54c4440282b51f25078fe8d81.zip
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
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 7d44657429d..571854d446c 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
* out of its tuple
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.59 2000/08/12 04:04:53 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.60 2000/09/12 04:15:58 momjian Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -51,6 +51,7 @@
#include "parser/parse_expr.h"
#include "parser/parsetree.h"
#include "utils/lsyscache.h"
+#include "commands/view.h"
/* ----------
@@ -79,7 +80,7 @@ static char *rulename = NULL;
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 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,7 +139,7 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
int len;
/* ----------
- * We need the rules name somewhere deep down
+ * We need the rules name somewhere deep down: rulename is global
* ----------
*/
rulename = pstrdup(NameStr(*rname));
@@ -226,23 +227,22 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
Datum
pg_get_viewdef(PG_FUNCTION_ARGS)
{
- Name rname = PG_GETARG_NAME(0);
+ Name vname = PG_GETARG_NAME(0);
text *ruledef;
- Datum args[2];
- char nulls[3];
+ Datum args[1];
+ char nulls[2];
int spirc;
HeapTuple ruletup;
TupleDesc rulettc;
StringInfoData buf;
int len;
- char name1[NAMEDATALEN + 5];
- char name2[NAMEDATALEN + 5];
+ char *name;
/* ----------
- * We need the rules name somewhere deep down
+ * We need the view name somewhere deep down
* ----------
*/
- rulename = pstrdup(NameStr(*rname));
+ rulename = pstrdup(NameStr(*vname));
/* ----------
* Connect to SPI manager
@@ -259,28 +259,24 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
*/
if (plan_getview == NULL)
{
- Oid argtypes[2];
+ Oid argtypes[1];
void *plan;
argtypes[0] = NAMEOID;
- argtypes[1] = NAMEOID;
- plan = SPI_prepare(query_getview, 2, argtypes);
+ 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
+ * Get the pg_rewrite tuple for this rule: rulename is actually viewname here
* ----------
*/
- sprintf(name1, "_RET%s", rulename);
- sprintf(name2, "_ret%s", rulename);
- args[0] = PointerGetDatum(name1);
- args[1] = PointerGetDatum(name2);
+ name = MakeRetrieveViewRuleName(rulename);
+ args[0] = PointerGetDatum(name);
nulls[0] = ' ';
- nulls[1] = ' ';
- nulls[2] = '\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,6 +298,7 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
VARATT_SIZEP(ruledef) = len;
memcpy(VARDATA(ruledef), buf.data, buf.len);
pfree(buf.data);
+ pfree(name);
/* ----------
* Disconnect from SPI manager