mirror of
https://github.com/postgres/postgres.git
synced 2026-02-20 16:30:40 -05:00
The logic for converting the shell-glob-like syntax supported by utilities like psql and pg_dump to regular expression is extracted into a new function patternToSQLRegex. The existing function processSQLNamePattern now uses this function as a subroutine. patternToSQLRegex is a little more general than what is required by processSQLNamePattern. That function is only interested in patterns that can have up to 2 parts, a schema and a relation; but patternToSQLRegex can limit the maximum number of parts to between 1 and 3, so that patterns can look like either "database.schema.relation", "schema.relation", or "relation" depending on how it's invoked and what the user specifies. processSQLNamePattern only passes two buffers, so works exactly the same as before, always interpreting the pattern as either a "schema.relation" pattern or a "relation" pattern. But, future callers can use this function in other ways. Mark Dilger, reviewed by me. The larger patch series of which this is a part has also had review from Peter Geoghegan, Andres Freund, Álvaro Herrera, Michael Paquier, and Amul Sul, but I don't know whether any of them have reviewed this bit specifically. Discussion: http://postgr.es/m/12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com Discussion: http://postgr.es/m/5F743835-3399-419C-8324-2D424237E999@enterprisedb.com Discussion: http://postgr.es/m/70655DF3-33CE-4527-9A4D-DDEB582B6BA0@enterprisedb.com
63 lines
2.3 KiB
C
63 lines
2.3 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-2021, 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 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 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);
|
|
|
|
extern void patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf,
|
|
PQExpBuffer schemabuf, PQExpBuffer namebuf,
|
|
const char *pattern, bool force_escape);
|
|
|
|
#endif /* STRING_UTILS_H */
|