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

Function appendStringLiteralDQ

src/fe_utils/string_utils.c:504–536  ·  view source on GitHub ↗

* Convert a string value to a dollar quoted literal and append it to * the given buffer. If the dqprefix parameter is not NULL then the * dollar quote delimiter will begin with that (after the opening $). * * No escaping is done at all on str, in compliance with the rules * for parsing dollar quoted strings. Also, we need not worry about * encoding issues. */

Source from the content-addressed store, hash-verified

502 * encoding issues.
503 */
504void
505appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
506{
507 static const char suffixes[] = "_XXXXXXX";
508 int nextchar = 0;
509 PQExpBuffer delimBuf = createPQExpBuffer();
510
511 /* start with $ + dqprefix if not NULL */
512 appendPQExpBufferChar(delimBuf, '$');
513 if (dqprefix)
514 appendPQExpBufferStr(delimBuf, dqprefix);
515
516 /*
517 * Make sure we choose a delimiter which (without the trailing $) is not
518 * present in the string being quoted. We don't check with the trailing $
519 * because a string ending in $foo must not be quoted with $foo$.
520 */
521 while (strstr(str, delimBuf->data) != NULL)
522 {
523 appendPQExpBufferChar(delimBuf, suffixes[nextchar++]);
524 nextchar %= sizeof(suffixes) - 1;
525 }
526
527 /* add trailing $ */
528 appendPQExpBufferChar(delimBuf, '$');
529
530 /* quote it and we are all done */
531 appendPQExpBufferStr(buf, delimBuf->data);
532 appendPQExpBufferStr(buf, str);
533 appendPQExpBufferStr(buf, delimBuf->data);
534
535 destroyPQExpBuffer(delimBuf);
536}
537
538
539/*

Callers 1

dumpFuncFunction · 0.85

Calls 4

createPQExpBufferFunction · 0.85
appendPQExpBufferCharFunction · 0.85
appendPQExpBufferStrFunction · 0.85
destroyPQExpBufferFunction · 0.85

Tested by

no test coverage detected