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);
225 target =
buf->data +
buf->len;
267 char *stop =
buf->data +
buf->maxlen - 2;
283 buf->len = target -
buf->data;
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";
391 target =
buf->data +
buf->len;
402 *target++ =
hextbl[(
c >> 4) & 0xF];
410 buf->len = target -
buf->data;
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 ==
'\\')
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')
745 if (buffer->
data[buffer->
len - 1] !=
'{')
749 if (
value[0] ==
'\0')
758 for (tmp =
value; *tmp; tmp++)
762 if (ch ==
'"' || ch ==
'\\' ||
763 ch ==
'{' || ch ==
'}' || ch ==
',' ||
765 ch ==
' ' || ch ==
'\t' || ch ==
'\n' ||
766 ch ==
'\r' || ch ==
'\v' || ch ==
'\f')
777 for (tmp =
value; *tmp; tmp++)
781 if (ch ==
'"' || ch ==
'\\')
805 const char *prefix,
int encoding,
bool std_strings)
892 bool have_where,
bool force_escape,
893 const char *schemavar,
const char *namevar,
894 const char *altnamevar,
const char *visibilityrule,
899 bool added_clause =
false;
903 (appendPQExpBufferStr(buf, have_where ? " AND " : "WHERE "), \
904 have_where = true, added_clause = true)
932 (schemavar ? dbnamebuf : NULL),
933 (schemavar ? &schemabuf : NULL),
935 pattern, force_escape,
true, dotcnt);
948 if (namevar && namebuf.
len > 2)
953 if (strcmp(namebuf.
data,
"^(.*)$") != 0)
959 "(%s OPERATOR(pg_catalog.~) ", namevar);
964 "\n OR %s OPERATOR(pg_catalog.~) ",
982 if (schemavar && schemabuf.
len > 2)
987 if (strcmp(schemabuf.
data,
"^(.*)$") != 0 && schemavar)
1010 return added_clause;
1064 PQExpBuffer namebuf,
const char *pattern,
bool force_escape,
1065 bool want_literal_dbname,
int *dotcnt)
1080 Assert(dbnamebuf == NULL || schemabuf != NULL);
1087 if (dbnamebuf != NULL)
1089 else if (schemabuf != NULL)
1095 if (want_literal_dbname)
1110 if (inquotes && cp[1] ==
'"')
1119 inquotes = !inquotes;
1122 else if (!inquotes && isupper((
unsigned char) ch))
1131 else if (!inquotes && ch ==
'*')
1138 else if (!inquotes && ch ==
'?')
1145 else if (!inquotes && ch ==
'.')
1150 if (curbuf < maxbuf)
1190 if ((inquotes || force_escape) &&
1191 strchr(
"|*+?()[]{}.^$\\", ch))
1193 else if (ch ==
'[' && cp[1] ==
']')
1213 if (schemabuf && curbuf >=
buf)
1220 if (dbnamebuf && curbuf >=
buf)
1222 if (want_literal_dbname)
1229 if (want_literal_dbname)
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
#define ESCAPE_STRING_SYNTAX
#define SQL_STR_DOUBLE(ch, escape_backslash)
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
int PQserverVersion(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)
int PQmblen(const char *s, int encoding)
int PQmblenBounded(const char *s, int encoding)
PGDLLIMPORT const ScanKeywordList ScanKeywords
#define UNRESERVED_KEYWORD
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
static rewind_source * source
static const char hextbl[]
int pg_strcasecmp(const char *s1, const char *s2)
unsigned char pg_tolower(unsigned char ch)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
PQExpBufferData * PQExpBuffer
bool appendShellStringNoError(PQExpBuffer buf, const char *str)
void appendShellString(PQExpBuffer buf, const char *str)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
void appendPGArray(PQExpBuffer buffer, const char *value)
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)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
void appendByteaLiteral(PQExpBuffer buf, const unsigned char *str, size_t length, bool std_strings)
const char * fmtId(const char *rawid)
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
void appendStringLiteral(PQExpBuffer buf, const char *str, int encoding, bool std_strings)
void patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf, PQExpBuffer schemabuf, PQExpBuffer namebuf, const char *pattern, bool force_escape, bool want_literal_dbname, int *dotcnt)
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
static PQExpBuffer defaultGetLocalPQExpBuffer(void)
const char * fmtQualifiedId(const char *schema, const char *id)
PQExpBuffer(* getLocalPQExpBuffer)(void)
void appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
void appendConnStrVal(PQExpBuffer buf, const char *str)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
int quote_all_identifiers