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

Function InteractiveBackend

src/backend/tcop/postgres.c:332–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330 */
331
332static int
333InteractiveBackend(StringInfo inBuf)
334{
335 int c; /* character read from getc() */
336
337 /*
338 * display a prompt and obtain input from the user
339 */
340 printf("backend> ");
341 fflush(stdout);
342
343 resetStringInfo(inBuf);
344
345 /*
346 * Read characters until EOF or the appropriate delimiter is seen.
347 */
348 while ((c = interactive_getc()) != EOF)
349 {
350 if (c == '\n')
351 {
352 if (UseSemiNewlineNewline)
353 {
354 /*
355 * In -j mode, semicolon followed by two newlines ends the
356 * command; otherwise treat newline as regular character.
357 */
358 if (inBuf->len > 1 &&
359 inBuf->data[inBuf->len - 1] == '\n' &&
360 inBuf->data[inBuf->len - 2] == ';')
361 {
362 /* might as well drop the second newline */
363 break;
364 }
365 }
366 else
367 {
368 /*
369 * In plain mode, newline ends the command unless preceded by
370 * backslash.
371 */
372 if (inBuf->len > 0 &&
373 inBuf->data[inBuf->len - 1] == '\\')
374 {
375 /* discard backslash from inBuf */
376 inBuf->data[--inBuf->len] = '\0';
377 /* discard newline too */
378 continue;
379 }
380 else
381 {
382 /* keep the newline character, but end the command */
383 appendStringInfoChar(inBuf, '\n');
384 break;
385 }
386 }
387 }
388
389 /* Not newline, or newline treated as regular character */

Callers 1

ReadCommandFunction · 0.85

Calls 3

resetStringInfoFunction · 0.85
interactive_getcFunction · 0.85
appendStringInfoCharFunction · 0.85

Tested by

no test coverage detected