|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2000-2006, PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.72 2006/03/0604:45:21 momjian Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.73 2006/03/0615:09:04 momjian Exp $ |
7 | 7 | */
|
8 | 8 | #include"postgres_fe.h"
|
9 | 9 | #include"mainloop.h"
|
@@ -236,23 +236,6 @@ MainLoop(FILE *source)
|
236 | 236 | scan_result=psql_scan(scan_state,query_buf,&prompt_tmp);
|
237 | 237 | prompt_status=prompt_tmp;
|
238 | 238 |
|
239 |
| -/* |
240 |
| - *If we append to history a backslash command that is inside |
241 |
| - *a multi-line query, then when we recall the history, the |
242 |
| - *backslash command will make the query invalid, so we write |
243 |
| - *backslash commands immediately rather than keeping them |
244 |
| - *as part of the current multi-line query. |
245 |
| - */ |
246 |
| -if (first_query_scan&&pset.cur_cmd_interactive) |
247 |
| -{ |
248 |
| -if (scan_result==PSCAN_BACKSLASH&&query_buf->len!=0) |
249 |
| -pg_write_history(line); |
250 |
| -else |
251 |
| -pg_append_history(line,history_buf); |
252 |
| -} |
253 |
| - |
254 |
| -first_query_scan= false; |
255 |
| - |
256 | 239 | /*
|
257 | 240 | * Send command if semicolon found, or if end of line and we're in
|
258 | 241 | * single-line mode.
|
@@ -309,17 +292,35 @@ MainLoop(FILE *source)
|
309 | 292 | /* flush any paren nesting info after forced send */
|
310 | 293 | psql_scan_reset(scan_state);
|
311 | 294 | }
|
| 295 | +} |
312 | 296 |
|
313 |
| -if (slashCmdStatus==PSQL_CMD_TERMINATE) |
314 |
| -break; |
| 297 | +/* |
| 298 | + *If we append to history a backslash command that is inside |
| 299 | + *a multi-line query, then when we recall the history, the |
| 300 | + *backslash command will make the query invalid, so we write |
| 301 | + *backslash commands immediately rather than keeping them |
| 302 | + *as part of the current multi-line query. We do the test |
| 303 | + *down here so we can check for \g and other 'execute' |
| 304 | + *backslash commands, which should be appended. |
| 305 | + */ |
| 306 | +if (first_query_scan&&pset.cur_cmd_interactive) |
| 307 | +{ |
| 308 | +/* Sending a command (PSQL_CMD_SEND) zeros the length */ |
| 309 | +if (scan_result==PSCAN_BACKSLASH&&query_buf->len!=0) |
| 310 | +pg_write_history(line); |
| 311 | +else |
| 312 | +pg_append_history(line,history_buf); |
315 | 313 | }
|
316 | 314 |
|
317 |
| -/* fall out of loop if lexer reached EOL */ |
318 |
| -if (scan_result==PSCAN_INCOMPLETE|| |
| 315 | +first_query_scan= false; |
| 316 | + |
| 317 | +/* fall out of loop on \q or if lexer reached EOL */ |
| 318 | +if (slashCmdStatus==PSQL_CMD_TERMINATE|| |
| 319 | +scan_result==PSCAN_INCOMPLETE|| |
319 | 320 | scan_result==PSCAN_EOL)
|
320 | 321 | break;
|
321 | 322 | }
|
322 |
| -
|
| 323 | + |
323 | 324 | if (pset.cur_cmd_interactive&&prompt_status!=PROMPT_CONTINUE)
|
324 | 325 | {
|
325 | 326 | /*
|
|