MCPcopy Create free account
hub / github.com/apache/cloudberry / appendConnStrVal

Function appendConnStrVal

src/bin/pg_upgrade/util.c:427–465  ·  view source on GitHub ↗

* Append the given string to the buffer, with suitable quoting for passing * the string as a value, in a keyword/pair value in a libpq connection * string */

Source from the content-addressed store, hash-verified

425 * string
426 */
427void
428appendConnStrVal(PQExpBuffer buf, const char *str)
429{
430 const char *s;
431 bool needquotes;
432
433 /*
434 * If the string is one or more plain ASCII characters, no need to quote
435 * it. This is quite conservative, but better safe than sorry.
436 */
437 needquotes = true;
438 for (s = str; *s; s++)
439 {
440 if (!((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
441 (*s >= '0' && *s <= '9') || *s == '_' || *s == '.'))
442 {
443 needquotes = true;
444 break;
445 }
446 needquotes = false;
447 }
448
449 if (needquotes)
450 {
451 appendPQExpBufferChar(buf, '\'');
452 while (*str)
453 {
454 /* ' and \ must be escaped by to \' and \\ */
455 if (*str == '\'' || *str == '\\')
456 appendPQExpBufferChar(buf, '\\');
457
458 appendPQExpBufferChar(buf, *str);
459 str++;
460 }
461 appendPQExpBufferChar(buf, '\'');
462 }
463 else
464 appendPQExpBufferStr(buf, str);
465}
466
467
468/*

Callers 5

generate_old_dumpFunction · 0.70
get_db_connFunction · 0.70
appendPsqlMetaConnectFunction · 0.70
runPgDumpFunction · 0.50
constructConnStrFunction · 0.50

Calls 2

appendPQExpBufferCharFunction · 0.85
appendPQExpBufferStrFunction · 0.85

Tested by

no test coverage detected