Commit 47003933 authored by Tom Lane's avatar Tom Lane

Remove fixed-size buffers in rule storage routine.

parent 918d9de8
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.36 1999/09/18 19:07:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.37 1999/10/21 01:46:24 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/pg_rewrite.h" #include "catalog/pg_rewrite.h"
#include "lib/stringinfo.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "rewrite/rewriteDefine.h" #include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
...@@ -24,23 +25,32 @@ ...@@ -24,23 +25,32 @@
Oid LastOidProcessed = InvalidOid; Oid LastOidProcessed = InvalidOid;
/*
* Convert given string to a suitably quoted string constant,
* and append it to the StringInfo buffer.
* XXX Any MULTIBYTE considerations here?
*/
static void static void
strcpyq(char *dest, char *source) quoteString(StringInfo buf, char *source)
{ {
char *current = source, char *current;
*destp = dest;
appendStringInfoChar(buf, '\'');
for (current = source; *current; current++) for (current = source; *current; current++)
{ {
if (*current == '\"') char ch = *current;
if (ch == '\'' || ch == '\\')
{ {
*destp = '\\'; appendStringInfoChar(buf, '\\');
destp++; appendStringInfoChar(buf, ch);
} }
*destp = *current; else if (ch >= 0 && ch < ' ')
destp++; appendStringInfo(buf, "\\%03o", (int) ch);
else
appendStringInfoChar(buf, ch);
} }
*destp = '\0'; appendStringInfoChar(buf, '\'');
} }
/* /*
...@@ -68,15 +78,11 @@ InsertRule(char *rulname, ...@@ -68,15 +78,11 @@ InsertRule(char *rulname,
bool evinstead, bool evinstead,
char *actiontree) char *actiontree)
{ {
static char rulebuf[MaxAttrSize]; StringInfoData rulebuf;
static char actionbuf[MaxAttrSize]; Relation eventrel;
static char qualbuf[MaxAttrSize]; Oid eventrel_oid;
Oid eventrel_oid = InvalidOid; AttrNumber evslot_index;
AttrNumber evslot_index = InvalidAttrNumber;
Relation eventrel = NULL;
char *is_instead = "f"; char *is_instead = "f";
extern void eval_as_new_xact();
char *template;
eventrel = heap_openr(evobj, AccessShareLock); eventrel = heap_openr(evobj, AccessShareLock);
eventrel_oid = RelationGetRelid(eventrel); eventrel_oid = RelationGetRelid(eventrel);
...@@ -87,7 +93,7 @@ InsertRule(char *rulname, ...@@ -87,7 +93,7 @@ InsertRule(char *rulname,
if (evslot == NULL) if (evslot == NULL)
evslot_index = -1; evslot_index = -1;
else else
evslot_index = attnameAttNum(eventrel, (char *) evslot); evslot_index = attnameAttNum(eventrel, evslot);
heap_close(eventrel, AccessShareLock); heap_close(eventrel, AccessShareLock);
if (evinstead) if (evinstead)
...@@ -99,22 +105,21 @@ InsertRule(char *rulname, ...@@ -99,22 +105,21 @@ InsertRule(char *rulname,
if (IsDefinedRewriteRule(rulname)) if (IsDefinedRewriteRule(rulname))
elog(ERROR, "Attempt to insert rule '%s' failed: already exists", elog(ERROR, "Attempt to insert rule '%s' failed: already exists",
rulname); rulname);
strcpyq(actionbuf, actiontree);
strcpyq(qualbuf, evqual); initStringInfo(&rulebuf);
appendStringInfo(&rulebuf,
template = "INSERT INTO pg_rewrite \ "INSERT INTO pg_rewrite (rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES (");
(rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES \ quoteString(&rulebuf, rulname);
('%s', %d::char, %u::oid, %d::int2, '%s'::text, '%s'::text, \ appendStringInfo(&rulebuf, ", %d::char, %u::oid, %d::int2, ",
'%s'::bool);"; evtype, eventrel_oid, evslot_index);
if (MAXALIGN(sizeof(FormData_pg_rewrite)) + quoteString(&rulebuf, actiontree);
MAXALIGN(strlen(actionbuf)) + appendStringInfo(&rulebuf, "::text, ");
MAXALIGN(strlen(qualbuf)) > MaxAttrSize) quoteString(&rulebuf, evqual);
elog(ERROR, "DefineQueryRewrite: rule plan string too big."); appendStringInfo(&rulebuf, "::text, '%s'::bool);",
sprintf(rulebuf, template, is_instead);
rulname, evtype, eventrel_oid, evslot_index, actionbuf,
qualbuf, is_instead); pg_exec_query_acl_override(rulebuf.data);
pfree(rulebuf.data);
pg_exec_query_acl_override(rulebuf);
return LastOidProcessed; return LastOidProcessed;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment