mirror of
https://github.com/postgres/postgres.git
synced 2026-02-23 09:52:14 -05:00
psql, pg_dump, and pg_amcheck share code to process object name
patterns like 'foo*.bar*' to match all tables with names starting in
'bar' that are in schemas starting with 'foo'. Before v14, any number
of extra name parts were silently ignored, so a command line '\d
foo.bar.baz.bletch.quux' was interpreted as '\d bletch.quux'. In v14,
as a result of commit 2c8726c4b0, we
instead treated this as a request for table quux in a schema named
'foo.bar.baz.bletch'. That caused problems for people like Justin
Pryzby who were accustomed to copying strings of the form
db.schema.table from messages generated by PostgreSQL itself and using
them as arguments to \d.
Accordingly, revise things so that if an object name pattern contains
more parts than we're expecting, we throw an error, unless there's
exactly one extra part and it matches the current database name.
That way, thisdb.myschema.mytable is accepted as meaning just
myschema.mytable, but otherdb.myschema.mytable is an error, and so
is some.random.garbage.myschema.mytable.
Mark Dilger, per report from Justin Pryzby and discussion among
various people.
Discussion: https://www.postgresql.org/message-id/20211013165426.GD27491%40telsasoft.com
66 lines
2.5 KiB
C
66 lines
2.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* String-processing utility routines for frontend code
|
|
*
|
|
* Utility functions that interpret backend output or quote strings for
|
|
* assorted contexts.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/fe_utils/string_utils.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef STRING_UTILS_H
|
|
#define STRING_UTILS_H
|
|
|
|
#include "libpq-fe.h"
|
|
#include "pqexpbuffer.h"
|
|
|
|
/* Global variables controlling behavior of fmtId() and fmtQualifiedId() */
|
|
extern PGDLLIMPORT int quote_all_identifiers;
|
|
extern PQExpBuffer (*getLocalPQExpBuffer) (void);
|
|
|
|
/* Functions */
|
|
extern const char *fmtId(const char *identifier);
|
|
extern const char *fmtQualifiedId(const char *schema, const char *id);
|
|
|
|
extern char *formatPGVersionNumber(int version_number, bool include_minor,
|
|
char *buf, size_t buflen);
|
|
|
|
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
|
|
int encoding, bool std_strings);
|
|
extern void appendStringLiteralConn(PQExpBuffer buf, const char *str,
|
|
PGconn *conn);
|
|
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
|
|
const char *dqprefix);
|
|
extern void appendByteaLiteral(PQExpBuffer buf,
|
|
const unsigned char *str, size_t length,
|
|
bool std_strings);
|
|
|
|
extern void appendShellString(PQExpBuffer buf, const char *str);
|
|
extern bool appendShellStringNoError(PQExpBuffer buf, const char *str);
|
|
extern void appendConnStrVal(PQExpBuffer buf, const char *str);
|
|
extern void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname);
|
|
|
|
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
|
|
extern void appendPGArray(PQExpBuffer buffer, const char *value);
|
|
|
|
extern bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions,
|
|
const char *prefix, int encoding, bool std_strings);
|
|
|
|
extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
|
|
const char *pattern,
|
|
bool have_where, bool force_escape,
|
|
const char *schemavar, const char *namevar,
|
|
const char *altnamevar, const char *visibilityrule,
|
|
PQExpBuffer dbnamebuf, int *dotcnt);
|
|
|
|
extern void patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf,
|
|
PQExpBuffer schemabuf, PQExpBuffer namebuf,
|
|
const char *pattern, bool force_escape,
|
|
bool want_literal_dbname, int *dotcnt);
|
|
|
|
#endif /* STRING_UTILS_H */
|