69 bool need_quotes =
false;
78 else if (!((rawid[0] >=
'a' && rawid[0] <=
'z') || rawid[0] ==
'_'))
83 for (cp = rawid; *cp; cp++)
85 if (!((*cp >=
'a' && *cp <=
'z')
86 || (*cp >=
'0' && *cp <=
'9')
119 for (cp = rawid; *cp; cp++)
133 return id_return->
data;
151 if (schema && *schema)
162 return id_return->
data;
178 char *
buf,
size_t buflen)
180 if (version_number >= 100000)
184 snprintf(buf, buflen,
"%d.%d", version_number / 10000,
185 version_number % 10000);
187 snprintf(buf, buflen,
"%d", version_number / 10000);
193 snprintf(buf, buflen,
"%d.%d.%d", version_number / 10000,
194 (version_number / 100) % 100,
195 version_number % 100);
197 snprintf(buf, buflen,
"%d.%d", version_number / 10000,
198 (version_number / 100) % 100);
218 size_t length = strlen(str);
228 while (*source !=
'\0')
247 len =
PQmblen(source, encoding);
250 for (i = 0; i < len; i++)
254 *target++ = *source++;
295 size_t length = strlen(str);
304 if (buf->
len > 0 && buf->
data[buf->
len - 1] !=
' ')
333 static const char suffixes[] =
"_XXXXXXX";
347 while (strstr(str, delimBuf->
data) != NULL)
350 nextchar %=
sizeof(suffixes) - 1;
380 static const char hextbl[] =
"0123456789abcdef";
400 unsigned char c = *source++;
402 *target++ = hextbl[(c >> 4) & 0xF];
403 *target++ = hextbl[c & 0xF];
434 _(
"shell command argument contains a newline or carriage return: \"%s\"\n"),
444 int backslash_run_length = 0;
454 strspn(str,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./:") == strlen(str))
462 for (p = str; *p; p++)
464 if (*p ==
'\n' || *p ==
'\r')
490 for (p = str; *p; p++)
492 if (*p ==
'\n' || *p ==
'\r')
501 while (backslash_run_length)
504 backslash_run_length--;
509 backslash_run_length++;
511 backslash_run_length = 0;
517 if (!((*p >=
'a' && *p <=
'z') ||
518 (*p >=
'A' && *p <=
'Z') ||
519 (*p >=
'0' && *p <=
'9')))
528 while (backslash_run_length)
531 backslash_run_length--;
555 for (s = str; *s; s++)
557 if (!((*s >=
'a' && *s <=
'z') || (*s >=
'A' && *s <=
'Z') ||
558 (*s >=
'0' && *s <=
'9') || *s ==
'_' || *s ==
'.'))
572 if (*str ==
'\'' || *str ==
'\\')
602 for (s = dbname; *s; s++)
604 if (*s ==
'\n' || *s ==
'\r')
607 _(
"database name contains a newline or carriage return: \"%s\"\n"),
612 if (!((*s >=
'a' && *s <=
'z') || (*s >=
'A' && *s <=
'Z') ||
613 (*s >=
'0' && *s <=
'9') || *s ==
'_' || *s ==
'.'))
676 inputlen = strlen(atext);
677 if (inputlen < 2 || atext[0] !=
'{' || atext[inputlen - 1] !=
'}')
679 items = (
char **)
malloc(inputlen * (
sizeof(
char *) +
sizeof(
char)));
683 strings = (
char *) (items + inputlen);
687 while (*atext !=
'}')
691 items[curitem] = strings;
692 while (*atext !=
'}' && *atext !=
',')
697 *strings++ = *atext++;
702 while (*atext !=
'"')
712 *strings++ = *atext++;
722 if (atext[1] !=
'\0')
742 const char *prefix,
int encoding,
bool std_strings)
767 separator = strchr(option,
'=');
771 value = separator + 1;
788 if (strcmp(
fmtId(value), value) == 0)
828 bool have_where,
bool force_escape,
829 const char *schemavar,
const char *namevar,
830 const char *altnamevar,
const char *visibilityrule)
834 bool added_clause =
false;
837 (appendPQExpBufferStr(buf, have_where ? " AND " : "WHERE "), \ 838 have_where = true, added_clause = true) 860 pattern, force_escape);
878 if (strcmp(namebuf.
data,
"^(.*)$") != 0)
884 "(%s OPERATOR(pg_catalog.~) ", namevar);
889 "\n OR %s OPERATOR(pg_catalog.~) ",
907 if (schemabuf.
len > 2)
912 if (strcmp(schemabuf.
data,
"^(.*)$") != 0 && schemavar)
968 PQExpBuffer namebuf,
const char *pattern,
bool force_escape)
981 Assert(dbnamebuf == NULL || schemabuf != NULL);
986 if (dbnamebuf != NULL)
988 else if (schemabuf != NULL)
1002 if (inquotes && cp[1] ==
'"')
1009 inquotes = !inquotes;
1012 else if (!inquotes && isupper((
unsigned char) ch))
1018 else if (!inquotes && ch ==
'*')
1023 else if (!inquotes && ch ==
'?')
1035 else if (!inquotes && ch ==
'.' && curbuf < maxbuf)
1066 if ((inquotes || force_escape) &&
1067 strchr(
"|*+?()[]{}.^$\\", ch))
PQExpBufferData * PQExpBuffer
int quote_all_identifiers
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
const char * fmtId(const char *rawid)
void termPQExpBuffer(PQExpBuffer str)
bool appendShellStringNoError(PQExpBuffer buf, const char *str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void appendConnStrVal(PQExpBuffer buf, const char *str)
unsigned char pg_tolower(unsigned char ch)
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)
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
#define UNRESERVED_KEYWORD
int PQserverVersion(const PGconn *conn)
#define ESCAPE_STRING_SYNTAX
void patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf, PQExpBuffer schemabuf, PQExpBuffer namebuf, const char *pattern, bool force_escape)
int PQclientEncoding(const PGconn *conn)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
PGDLLIMPORT const ScanKeywordList ScanKeywords
void appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
void destroyPQExpBuffer(PQExpBuffer str)
#define IS_HIGHBIT_SET(ch)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendStringLiteral(PQExpBuffer buf, const char *str, int encoding, bool std_strings)
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
static PQExpBuffer defaultGetLocalPQExpBuffer(void)
PQExpBuffer createPQExpBuffer(void)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendShellString(PQExpBuffer buf, const char *str)
#define Assert(condition)
static const char hextbl[]
static rewind_source * source
PQExpBuffer(* getLocalPQExpBuffer)(void)
const char * fmtQualifiedId(const char *schema, const char *id)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
#define SQL_STR_DOUBLE(ch, escape_backslash)
void resetPQExpBuffer(PQExpBuffer str)
int PQmblen(const char *s, int encoding)
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
void initPQExpBuffer(PQExpBuffer str)
void appendByteaLiteral(PQExpBuffer buf, const unsigned char *str, size_t length, bool std_strings)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)