summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Conway2004-02-24 05:26:27 +0000
committerJoe Conway2004-02-24 05:26:27 +0000
commit7ce7e3f03699e87517826275a4ed2c2f2c5a177a (patch)
tree7b05914c08cfe7bfc46a174ec9c8ddf252c3d9c9
parentd301dcbe30fe3ad326db877cc1d8cbf970e6f702 (diff)
pply quote_literal to the start_with argument of connectby. Fixes problem
reported by David Garamond when working with bytea parent and child keys.
-rw-r--r--contrib/tablefunc/tablefunc.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 4fd3846820b..cc8fd613a47 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -66,6 +66,7 @@ static Tuplestorestate *build_tuplestore_recursively(char *key_fld,
MemoryContext per_query_ctx,
AttInMetadata *attinmeta,
Tuplestorestate *tupstore);
+static char *quote_literal_cstr(char *rawstr);
typedef struct
{
@@ -779,12 +780,12 @@ build_tuplestore_recursively(char *key_fld,
return tupstore;
/* Build initial sql statement */
- appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL",
+ appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL",
key_fld,
parent_key_fld,
relname,
parent_key_fld,
- start_with,
+ quote_literal_cstr(start_with),
key_fld);
/* Retrieve the desired rows */
@@ -1087,3 +1088,21 @@ make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_catagories)
return tupdesc;
}
+
+/*
+ * Return a properly quoted literal value.
+ * Uses quote_literal in quote.c
+ */
+static char *
+quote_literal_cstr(char *rawstr)
+{
+ text *rawstr_text;
+ text *result_text;
+ char *result;
+
+ rawstr_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(rawstr)));
+ result_text = DatumGetTextP(DirectFunctionCall1(quote_literal, PointerGetDatum(rawstr_text)));
+ result = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(result_text)));
+
+ return result;
+}