From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | strk <strk(at)keybit(dot)net> |
Cc: | pgsql-patches(at)postgresql(dot)org |
Subject: | Re: query output in psql PROMPT |
Date: | 2005-01-14 17:06:32 |
Message-ID: | 24426.1105722392@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
strk <strk(at)keybit(dot)net> writes:
> A simple patch allow query output in psql PROMPT strings:
Why is this a good idea? Having a query implicitly executed during
every prompt will have a ton of bad side effects, for instance
prematurely freezing the query snapshot in SERIALIZABLE transactions.
The syntax you propose is downright bizarre --- what if I needed a dot
in the query text?
> + cmdend = strcspn(cmd, ".");
> + cmd[cmdend] = '\0';
> + if (cmd)
> + {
> + res = PSQLexec(cmd, false);
> + }
What's the if for? cmd can't be NULL (you already dumped core if it
is).
> + if (res && PQntuples(res) )
> + {
> + memcpy(buf, PQgetvalue(res, 0, 0), MAX_PROMPT_SIZE-1);
> + PQclear(res);
> + }
Leaks memory on query failure.
> + if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n')
> + buf[strlen(buf) - 1] = '\0';
Uses undefined contents of buf on query failure.
> + p += cmdend + 1;
Falls off the end of the prompt if there was no terminating dot, causing
subsequent iterations of the loop to continue reading undefined memory.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | strk | 2005-01-14 17:19:38 | Re: query output in psql PROMPT |
Previous Message | strk | 2005-01-14 16:41:50 | query output in psql PROMPT |