Commit 803204bd authored by Bruce Momjian's avatar Bruce Momjian

Playing around with pg_dump for a while resulted in some

    fixes,  enhancements and some found bugs not yet fixed. After
    all I was able to get useful results  when  dumping/reloading
    the regression database.

Jan
parent 57d57d95
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.22 1998/10/02 16:27:46 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.23 1998/10/06 22:14:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -243,6 +243,7 @@ DefineQueryRewrite(RuleStmt *stmt)
Form_pg_attribute attr;
char *attname;
int i;
char expected_name[NAMEDATALEN + 5];
/*
* So there cannot be INSTEAD NOTHING, ...
......@@ -269,7 +270,7 @@ DefineQueryRewrite(RuleStmt *stmt)
/*
* ... the targetlist of the SELECT action must
* exactly match the event relation ...
* exactly match the event relation, ...
*/
event_relation = heap_openr(event_obj->relname);
if (event_relation == NULL)
......@@ -295,8 +296,8 @@ DefineQueryRewrite(RuleStmt *stmt)
}
/*
* ... and final there must not be another ON SELECT
* rule already.
* ... there must not be another ON SELECT
* rule already ...
*/
if (event_relation->rd_rules != NULL) {
for (i = 0; i < event_relation->rd_rules->numLocks; i++) {
......@@ -309,6 +310,15 @@ DefineQueryRewrite(RuleStmt *stmt)
}
heap_close(event_relation);
/*
* ... 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);
}
}
/*
......
......@@ -3,7 +3,7 @@
* out of it's tuple
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.4 1998/10/02 16:27:51 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.5 1998/10/06 22:14:16 momjian Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
......@@ -415,7 +415,7 @@ pg_get_indexdef(Oid indexrelid)
* Start the index definition
* ----------
*/
sprintf(buf, "CREATE %sINDEX %s ON %s USING %s (",
sprintf(buf, "CREATE %sINDEX \"%s\" ON \"%s\" USING %s (",
idxrec->indisunique ? "UNIQUE " : "",
nameout(&(idxrelrec->relname)),
nameout(&(indrelrec->relname)),
......@@ -439,11 +439,13 @@ pg_get_indexdef(Oid indexrelid)
* Add the indexed field name
* ----------
*/
strcat(keybuf, "\"");
if (idxrec->indkey[keyno] == ObjectIdAttributeNumber - 1)
strcat(keybuf, "oid");
else
strcat(keybuf, get_attribute_name(idxrec->indrelid,
idxrec->indkey[keyno]));
strcat(keybuf, "\"");
/* ----------
* If not a functional index, add the operator class name
......@@ -462,8 +464,9 @@ pg_get_indexdef(Oid indexrelid)
spi_tup = SPI_tuptable->vals[0];
spi_ttc = SPI_tuptable->tupdesc;
spi_fno = SPI_fnumber(spi_ttc, "opcname");
strcat(keybuf, " ");
strcat(keybuf, " \"");
strcat(keybuf, SPI_getvalue(spi_tup, spi_ttc, spi_fno));
strcat(keybuf, "\"");
}
}
......@@ -482,8 +485,9 @@ pg_get_indexdef(Oid indexrelid)
elog(ERROR, "cache lookup for proc %d failed", idxrec->indproc);
procStruct = (Form_pg_proc) GETSTRUCT(proctup);
strcat(buf, "\"");
strcat(buf, nameout(&(procStruct->proname)));
strcat(buf, " (");
strcat(buf, "\" (");
strcat(buf, keybuf);
strcat(buf, ") ");
......@@ -498,7 +502,9 @@ pg_get_indexdef(Oid indexrelid)
spi_tup = SPI_tuptable->vals[0];
spi_ttc = SPI_tuptable->tupdesc;
spi_fno = SPI_fnumber(spi_ttc, "opcname");
strcat(buf, "\"");
strcat(buf, SPI_getvalue(spi_tup, spi_ttc, spi_fno));
strcat(buf, "\"");
}
else
/* ----------
......@@ -628,29 +634,29 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc)
* Build the rules definition text
* ----------
*/
strcpy(buf, "CREATE RULE ");
strcpy(buf, "CREATE RULE \"");
/* The rule name */
strcat(buf, rulename);
strcat(buf, " AS ON ");
strcat(buf, "\" AS ON ");
/* The event the rule is fired for */
switch (ev_type)
{
case '1':
strcat(buf, "SELECT TO ");
strcat(buf, "SELECT TO \"");
break;
case '2':
strcat(buf, "UPDATE TO ");
strcat(buf, "UPDATE TO \"");
break;
case '3':
strcat(buf, "INSERT TO ");
strcat(buf, "INSERT TO \"");
break;
case '4':
strcat(buf, "DELETE TO ");
strcat(buf, "DELETE TO \"");
break;
default:
......@@ -661,10 +667,12 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc)
/* The relation the rule is fired on */
strcat(buf, get_relation_name(ev_class));
strcat(buf, "\"");
if (ev_attr > 0)
{
strcat(buf, ".");
strcat(buf, ".\"");
strcat(buf, get_attribute_name(ev_class, ev_attr));
strcat(buf, "\"");
}
/* If the rule has an event qualification, add it */
......@@ -941,8 +949,9 @@ get_select_query_def(Query *query, QryHier *qh)
/* and do if so */
if (tell_as)
{
strcat(buf, " AS ");
strcat(buf, " AS \"");
strcat(buf, tle->resdom->resname);
strcat(buf, "\"");
}
}
......@@ -967,11 +976,14 @@ get_select_query_def(Query *query, QryHier *qh)
strcat(buf, sep);
sep = ", ";
strcat(buf, "\"");
strcat(buf, rte->relname);
strcat(buf, "\"");
if (strcmp(rte->relname, rte->refname) != 0)
{
strcat(buf, " ");
strcat(buf, " \"");
strcat(buf, rte->refname);
strcat(buf, "\"");
}
}
}
......@@ -1071,8 +1083,9 @@ get_insert_query_def(Query *query, QryHier *qh)
* ----------
*/
rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
strcpy(buf, "INSERT INTO ");
strcpy(buf, "INSERT INTO \"");
strcat(buf, rte->relname);
strcat(buf, "\"");
/* Add the target list */
sep = " (";
......@@ -1082,7 +1095,9 @@ get_insert_query_def(Query *query, QryHier *qh)
strcat(buf, sep);
sep = ", ";
strcat(buf, "\"");
strcat(buf, tle->resdom->resname);
strcat(buf, "\"");
}
strcat(buf, ") ");
......@@ -1142,8 +1157,9 @@ get_update_query_def(Query *query, QryHier *qh)
strcat(buf, sep);
sep = ", ";
strcat(buf, "\"");
strcat(buf, tle->resdom->resname);
strcat(buf, " = ");
strcat(buf, "\" = ");
strcat(buf, get_tle_expr(qh, query->resultRelation,
tle, TRUE));
}
......@@ -1179,8 +1195,9 @@ get_delete_query_def(Query *query, QryHier *qh)
* ----------
*/
rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
strcpy(buf, "DELETE FROM ");
strcpy(buf, "DELETE FROM \"");
strcat(buf, rte->relname);
strcat(buf, "\"");
/* Add a WHERE clause if given */
if (query->qual != NULL)
......@@ -1232,8 +1249,9 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
{
Aggreg *agg = (Aggreg *) node;
strcat(buf, "\"");
strcat(buf, agg->aggname);
strcat(buf, "(");
strcat(buf, "\"(");
strcat(buf, get_rule_expr(qh, rt_index,
(Node *) (agg->target), varprefix));
strcat(buf, ")");
......@@ -1328,10 +1346,8 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
int sup = var->varlevelsup;
while(sup-- > 0) qh = qh->parent;
rte = (RangeTblEntry *) nth(var->varno - 1, qh->query->rtable);
if (qh->parent == NULL && var->varlevelsup > 0)
rte = (RangeTblEntry *) nth(var->varno + 1, qh->query->rtable);
rte = (RangeTblEntry *) nth(var->varno - 1, qh->query->rtable);
if (!strcmp(rte->refname, "*NEW*"))
strcat(buf, "new.");
......@@ -1343,12 +1359,15 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
{
if (strcmp(rte->relname, rte->refname) != 0)
{
strcat(buf, "\"");
strcat(buf, rte->refname);
strcat(buf, ".");
strcat(buf, "\".");
}
}
}
strcat(buf, "\"");
strcat(buf, get_attribute_name(rte->relid, var->varattno));
strcat(buf, "\"");
return pstrdup(buf);
}
......@@ -1433,8 +1452,9 @@ get_func_expr(QryHier *qh, int rt_index, Expr *expr, bool varprefix)
* Build a string of proname(args)
* ----------
*/
strcpy(buf, proname);
strcat(buf, "(");
strcpy(buf, "\"");
strcat(buf, proname);
strcat(buf, "\"(");
sep = "";
foreach(l, expr->args)
{
......@@ -1561,7 +1581,7 @@ get_const_expr(Const *constval)
extval = (char *) (*fmgr_faddr(&finfo_output)) (constval->constvalue,
&isnull, -1);
sprintf(namebuf, "::%s", nameout(&(typeStruct->typname)));
sprintf(namebuf, "::\"%s\"", nameout(&(typeStruct->typname)));
if (strcmp(namebuf, "::unknown") == 0)
namebuf[0] = '\0';
sprintf(buf, "'%s'%s", extval, namebuf);
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.26 1998/10/02 16:43:38 thomas Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.27 1998/10/06 22:14:17 momjian Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
......@@ -304,6 +304,14 @@ dumpSchema(FILE *fout,
tinfo, numTypes, tablename, acls);
}
if (!tablename && fout)
{
if (g_verbose)
fprintf(stderr, "%s dumping out user-defined procedural languages %s\n",
g_comment_start, g_comment_end);
dumpProcLangs(fout, finfo, numFuncs, tinfo, numTypes);
}
if (!tablename && fout)
{
if (g_verbose)
......@@ -315,7 +323,7 @@ dumpSchema(FILE *fout,
if (!tablename && fout)
{
if (g_verbose)
fprintf(stderr, "%s dumping out user-defined functions %s\n",
fprintf(stderr, "%s dumping out user-defined aggregates %s\n",
g_comment_start, g_comment_end);
dumpAggs(fout, agginfo, numAggregates, tinfo, numTypes);
}
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.34 1998/10/06 03:09:01 momjian Exp $
* $Id: pg_dump.h,v 1.35 1998/10/06 22:14:21 momjian Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
......@@ -66,7 +66,6 @@ typedef struct _tableInfo
{
char *oid;
char *relname;
char *viewdef;
char *relacl;
bool sequence;
int numatts; /* number of attributes */
......@@ -223,6 +222,8 @@ extern void getTableAttrs(TableInfo *tbinfo, int numTables);
extern IndInfo *getIndices(int *numIndices);
extern void dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes);
extern void dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes);
extern void dumpFuncs(FILE *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes);
extern void dumpAggs(FILE *fout, AggInfo *agginfo, int numAggregates,
......
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