Re: patch to add \watch to psql
От | Daniel Farina |
---|---|
Тема | Re: patch to add \watch to psql |
Дата | |
Msg-id | CAAZKuFaNaKdnkx-dVmAiPn3HdSaNLa7E2FWWvwh6a7FciHDsbA@mail.gmail.com обсуждение исходный текст |
Ответ на | patch to add \watch to psql (Will Leinweber <will@heroku.com>) |
Ответы |
Re: patch to add \watch to psql
Re: patch to add \watch to psql |
Список | pgsql-hackers |
I have adjusted this patch a little bit to take care of the review issues, along with just doing a bit of review myself. On Thu, Oct 25, 2012 at 2:25 AM, Will Leinweber <will@heroku.com> wrote: > Thanks for the reviews and comments. Responses inline: > . > On Sat, Oct 20, 2012 at 9:19 AM, Abhijit Menon-Sen <ams@2ndquadrant.com> wrote: >> Maybe you should call it \repeat or something. I'm sure people would get >> around to using \watch that way eventually. :-) > > > While I agree that clearing the screen would be nicer, I feel that > watching the bottom of the screen instead of the top gets you 95% of > the value of unix watch(1), and having the same name will greatly > enhance discoverability. Perhaps later on if ncurses is linked for > some other reason, this could take advantage of it then. > > That said, I'm not that strongly attached to the name one way or the other. The name \repeat has grown on me, but I haven't bothered renaming it for the time being. I think sameness with the familiar 'watch' program may not be such a big deal as I thought originally, but 'repeat' sounds a lot more like a kind of flow control for scripts, whereas \watch is more clearly for humans, which is the idea. > On Wed, Oct 24, 2012 at 2:55 PM, Peter Eisentraut <peter_e@gmx.net> wrote: >> This doesn't handle multiline queries: >> >> => \watch select 1 + >> ERROR: 42601: syntax error at end of input >> LINE 1: select + >> ^ >> >> I think to make it cooperate better with psql syntax, put the \watch at >> the end, as a replacement for \g, like I have implemented some kind of multi-line support. The rough part is in this part of the patch: + if (query_buf && query_buf->len > 0) + { + /* + * Check that the query in query_buf has been terminated. This + * is mostly consistent with behavior from commands like \g. + * The reason this is here is to prevent terrible things from + * occuring from submitting incomplete input of statements + * like: + * + * DELETE FROM foo + * \watch + * WHERE.... + * + * Wherein \watch will go ahead and send whatever has been + * submitted so far. So instead, insist that the user + * terminate the query with a semicolon to be safe. + */ + if (query_buf->data[query_buf->len - 1] == ';') What I found myself reaching for when giving up and writing this hack was a way to thread through the last lexer state of query_buf, which seems it could stand to be accrue a bit more information than being just a byte buffer. But this is the simplest possible thing, so I'll let others comment... -- fdr
Вложения
В списке pgsql-hackers по дате отправления: