tgRecipe.c
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:20k
- /*-------------------------------------------------------------------------
- *
- * tgRecipe.c
- * Tioga recipe-related definitions
- * these functions can be used in both the frontend and the
- * backend
- *
- * this file must be kept current with recipe-schema.sql
- *
- * Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $Header: /usr/local/cvsroot/pgsql/src/backend/tioga/tgRecipe.c,v 1.12 1999/05/10 00:45:49 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
- #include <stdlib.h>
- #include "postgres.h"
- #include "tioga/tgRecipe.h"
- #include "catalog/catalog.h" /* for newoid() */
- static Arr_TgString *TextArray2ArrTgString(char *str);
- #define ARRAY_LEFT_DELIM '{'
- #define ARRAY_RIGHT_DELIM '}'
- #define ARRAY_ELEM_LEFT '"'
- #define ARRAY_ELEM_RIGHT '"'
- #define ARRAY_ELEM_SEPARATOR ','
- /* maximum length of query string */
- #define MAX_QBUF_LENGTH 2048
- /**** the queries being used ********/
- #define Q_RETRIEVE_RECIPE_BYNAME
- "select * from Recipes where Recipes.elemName = '%s';"
- #define Q_RETRIEVE_ELEMENTS_IN_RECIPE
- "select e.* from Element e, Node n where n.belongsTo = '%s' and n.nodeElem = e.elemName;"
- #define Q_RETRIEVE_NODES_IN_RECIPE
- "select * from Node n where n.belongsTo = '%s'"
- #define Q_LOOKUP_EDGES_IN_RECIPE
- "select * from Edge e where e.belongsTo = '%s'"
- /* static functions only used here */
- static void fillTgElement(TgElement * elem, PortalBuffer *pbuf, int tupno);
- static void fillTgNode(TgRecipe * r, TgNode * node, PortalBuffer *pbuf, int tupno);
- static TgRecipe *fillTgRecipe(PortalBuffer *pbuf, int tupno);
- static void lookupEdges(TgRecipe * r, char *name);
- static void fillAllNodes(TgRecipe * r, char *name);
- static void fillAllElements(TgRecipe * r, char *name);
- static TgNode *connectTee(TgRecipe * r, TgNodePtr fromNode, TgNodePtr toNode,
- int fromPort, int toPort);
- /*
- * TextArray2ArrTgString -- take a string of the form:
- * {"fooo", "bar", "xxxxx"} (for postgres)
- * and parse it into a Array of TgString's
- *
- * always returns a valid Arr_TgString. It could be a newly initialized one with
- * zero elements
- */
- Arr_TgString *
- TextArray2ArrTgString(char *str)
- {
- Arr_TgString *result;
- char *beginQuote;
- char *endQuote;
- int nextlen;
- char *word;
- result = newArr_TgString();
- if ((str == NULL) || (str[0] == ' '))
- return result;
- if (*str != ARRAY_LEFT_DELIM)
- {
- elog(NOTICE, "TextArray2ArrTgString: badly formed string, must have %c as
- first charactern", ARRAY_LEFT_DELIM);
- return result;
- }
- str++; /* skip the first { */
- while (*str != '}')
- {
- if (*str == ' ')
- {
- elog(NOTICE, "TextArray2ArrTgString: text string ended prematurelyn");
- return result;
- }
- if ((beginQuote = index(str, ARRAY_ELEM_LEFT)) == NULL)
- {
- elog(NOTICE, "textArray2ArrTgString: missing a begin quoten");
- return result;
- }
- if ((endQuote = index(beginQuote + 1, '"')) == NULL)
- {
- elog(NOTICE, "textArray2ArrTgString: missing an end quoten");
- return result;
- }
- nextlen = endQuote - beginQuote; /* don't subtract one here
- * because we need the
- * extra character for