mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 22:31:18 +02:00
Remove fixed-size buffers in rule storage routine.
This commit is contained in:
parent
918d9de886
commit
470039332f
@ -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 @@
|
|||||||
|
|
||||||
#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 @@
|
|||||||
|
|
||||||
Oid LastOidProcessed = InvalidOid;
|
Oid LastOidProcessed = InvalidOid;
|
||||||
|
|
||||||
static void
|
|
||||||
strcpyq(char *dest, char *source)
|
|
||||||
{
|
|
||||||
char *current = source,
|
|
||||||
*destp = dest;
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert given string to a suitably quoted string constant,
|
||||||
|
* and append it to the StringInfo buffer.
|
||||||
|
* XXX Any MULTIBYTE considerations here?
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
quoteString(StringInfo buf, char *source)
|
||||||
|
{
|
||||||
|
char *current;
|
||||||
|
|
||||||
|
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,
|
|||||||
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,
|
|||||||
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,
|
|||||||
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);
|
|
||||||
|
|
||||||
template = "INSERT INTO pg_rewrite \
|
initStringInfo(&rulebuf);
|
||||||
(rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES \
|
appendStringInfo(&rulebuf,
|
||||||
('%s', %d::char, %u::oid, %d::int2, '%s'::text, '%s'::text, \
|
"INSERT INTO pg_rewrite (rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES (");
|
||||||
'%s'::bool);";
|
quoteString(&rulebuf, rulname);
|
||||||
if (MAXALIGN(sizeof(FormData_pg_rewrite)) +
|
appendStringInfo(&rulebuf, ", %d::char, %u::oid, %d::int2, ",
|
||||||
MAXALIGN(strlen(actionbuf)) +
|
evtype, eventrel_oid, evslot_index);
|
||||||
MAXALIGN(strlen(qualbuf)) > MaxAttrSize)
|
quoteString(&rulebuf, actiontree);
|
||||||
elog(ERROR, "DefineQueryRewrite: rule plan string too big.");
|
appendStringInfo(&rulebuf, "::text, ");
|
||||||
sprintf(rulebuf, template,
|
quoteString(&rulebuf, evqual);
|
||||||
rulname, evtype, eventrel_oid, evslot_index, actionbuf,
|
appendStringInfo(&rulebuf, "::text, '%s'::bool);",
|
||||||
qualbuf, is_instead);
|
is_instead);
|
||||||
|
|
||||||
pg_exec_query_acl_override(rulebuf);
|
pg_exec_query_acl_override(rulebuf.data);
|
||||||
|
pfree(rulebuf.data);
|
||||||
|
|
||||||
return LastOidProcessed;
|
return LastOidProcessed;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user