mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Allow psql to do \p\g. Ingres does it, why not us?
This commit is contained in:
parent
48fd9a2cc2
commit
65decc3402
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.168 1999/02/03 21:17:44 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.169 1999/02/07 02:56:53 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1753,10 +1753,10 @@ do_shell(const char *command)
|
|||||||
/*
|
/*
|
||||||
* HandleSlashCmds:
|
* HandleSlashCmds:
|
||||||
*
|
*
|
||||||
* Handles all the different commands that start with \ db_ptr is a pointer to
|
* Handles all the different commands that start with \
|
||||||
* the TgDb* structure line is the current input line prompt_ptr is a pointer
|
* db_ptr is a pointer to the TgDb* structure line is the current input
|
||||||
* to the prompt string, a pointer is used because the prompt can be used
|
* line prompt_ptr is a pointer to the prompt string, a pointer is used
|
||||||
* with a connection to a new database.
|
* because the prompt can be used with a connection to a new database.
|
||||||
* Returns a status:
|
* Returns a status:
|
||||||
* 0 - send currently constructed query to backend (i.e. we got a \g)
|
* 0 - send currently constructed query to backend (i.e. we got a \g)
|
||||||
* 1 - skip processing of this line, continue building up query
|
* 1 - skip processing of this line, continue building up query
|
||||||
@ -2690,22 +2690,45 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
|
|||||||
|
|
||||||
if (!in_quote && query_start[0] == '\\')
|
if (!in_quote && query_start[0] == '\\')
|
||||||
{
|
{
|
||||||
|
/* handle \p\g and other backslash combinations */
|
||||||
|
while (query_start[0] != '\0')
|
||||||
|
{
|
||||||
|
char hold_char;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
/* I believe \w \dos\system\x would cause a problem */
|
||||||
|
/* do we have '\p\g' or '\p \g' ? */
|
||||||
|
if (strlen(query_start) > 2 &&
|
||||||
|
query_start[2 + strspn(query_start + 2, " \t")] == '\\')
|
||||||
|
{
|
||||||
|
hold_char = query_start[2 + strspn(query_start + 2, " \t")];
|
||||||
|
query_start[2 + strspn(query_start + 2, " \t")] = '\0';
|
||||||
|
}
|
||||||
|
else /* spread over #endif */
|
||||||
|
#endif
|
||||||
|
hold_char = '\0';
|
||||||
|
|
||||||
slashCmdStatus = HandleSlashCmds(pset,
|
slashCmdStatus = HandleSlashCmds(pset,
|
||||||
query_start,
|
query_start,
|
||||||
query);
|
query);
|
||||||
if (slashCmdStatus == CMD_SKIP_LINE)
|
|
||||||
|
if (slashCmdStatus == CMD_SKIP_LINE && !hold_char)
|
||||||
{
|
{
|
||||||
if (query[0] == '\0')
|
if (query[0] == '\0')
|
||||||
paren_level = 0;
|
paren_level = 0;
|
||||||
free(line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (slashCmdStatus == CMD_TERMINATE)
|
|
||||||
{
|
|
||||||
free(line);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (slashCmdStatus == CMD_TERMINATE)
|
||||||
|
break;
|
||||||
|
|
||||||
|
query_start += strlen(query_start);
|
||||||
|
if (hold_char)
|
||||||
|
query_start[0] = hold_char;
|
||||||
|
}
|
||||||
free(line);
|
free(line);
|
||||||
|
/* They did \q, leave the loop */
|
||||||
|
if (slashCmdStatus == CMD_TERMINATE)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (strlen(query) + strlen(query_start) > MAX_QUERY_BUFFER)
|
else if (strlen(query) + strlen(query_start) > MAX_QUERY_BUFFER)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user