Apply quote_literal to the start_with argument of connectby. Fixes problem
reported by David Garamond when working with bytea parent and child keys.
This commit is contained in:
parent
92bec9a0bc
commit
64a2e1fdef
@ -79,6 +79,7 @@ static Tuplestorestate *build_tuplestore_recursively(char *key_fld,
|
|||||||
MemoryContext per_query_ctx,
|
MemoryContext per_query_ctx,
|
||||||
AttInMetadata *attinmeta,
|
AttInMetadata *attinmeta,
|
||||||
Tuplestorestate *tupstore);
|
Tuplestorestate *tupstore);
|
||||||
|
static char *quote_literal_cstr(char *rawstr);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -1319,23 +1320,23 @@ build_tuplestore_recursively(char *key_fld,
|
|||||||
/* Build initial sql statement */
|
/* Build initial sql statement */
|
||||||
if (!show_serial)
|
if (!show_serial)
|
||||||
{
|
{
|
||||||
appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL AND %s <> %s",
|
appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s",
|
||||||
key_fld,
|
key_fld,
|
||||||
parent_key_fld,
|
parent_key_fld,
|
||||||
relname,
|
relname,
|
||||||
parent_key_fld,
|
parent_key_fld,
|
||||||
start_with,
|
quote_literal_cstr(start_with),
|
||||||
key_fld, key_fld, parent_key_fld);
|
key_fld, key_fld, parent_key_fld);
|
||||||
serial_column = 0;
|
serial_column = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL AND %s <> %s ORDER BY %s",
|
appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s ORDER BY %s",
|
||||||
key_fld,
|
key_fld,
|
||||||
parent_key_fld,
|
parent_key_fld,
|
||||||
relname,
|
relname,
|
||||||
parent_key_fld,
|
parent_key_fld,
|
||||||
start_with,
|
quote_literal_cstr(start_with),
|
||||||
key_fld, key_fld, parent_key_fld,
|
key_fld, key_fld, parent_key_fld,
|
||||||
orderby_fld);
|
orderby_fld);
|
||||||
serial_column = 1;
|
serial_column = 1;
|
||||||
@ -1691,3 +1692,21 @@ make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_categories)
|
|||||||
|
|
||||||
return tupdesc;
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user