|
3 | 3 | * |
4 | 4 | * Copyright (c) 2000-2006, PostgreSQL Global Development Group |
5 | 5 | * |
6 | | - * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.75 2006/06/04 04:35:55 momjian Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.76 2006/06/05 03:55:00 momjian Exp $ |
7 | 7 | */ |
8 | 8 | #include"postgres_fe.h" |
9 | 9 | #include"mainloop.h" |
@@ -41,7 +41,7 @@ MainLoop(FILE *source) |
41 | 41 | char*line;/* current line of input */ |
42 | 42 | intadded_nl_pos; |
43 | 43 | boolsuccess; |
44 | | -boolfirst_query_scan; |
| 44 | +boolline_saved_in_history; |
45 | 45 |
|
46 | 46 | volatileintsuccessResult=EXIT_SUCCESS; |
47 | 47 | volatilebackslashResultslashCmdStatus=PSQL_CMD_UNKNOWN; |
@@ -80,6 +80,8 @@ MainLoop(FILE *source) |
80 | 80 | /* main loop to get queries and execute them */ |
81 | 81 | while (successResult==EXIT_SUCCESS) |
82 | 82 | { |
| 83 | +line_saved_in_history= false; |
| 84 | + |
83 | 85 | /* |
84 | 86 | * Welcome code for Control-C |
85 | 87 | */ |
@@ -154,6 +156,8 @@ MainLoop(FILE *source) |
154 | 156 | */ |
155 | 157 | pg_write_history(history_buf->data); |
156 | 158 | pg_clear_history(history_buf); |
| 159 | +pg_write_history(line); |
| 160 | +line_saved_in_history= true; |
157 | 161 | } |
158 | 162 | } |
159 | 163 | /* otherwise, get another line */ |
@@ -226,7 +230,6 @@ MainLoop(FILE *source) |
226 | 230 | */ |
227 | 231 | psql_scan_setup(scan_state,line,strlen(line)); |
228 | 232 | success= true; |
229 | | -first_query_scan= true; |
230 | 233 |
|
231 | 234 | while (success|| !die_on_error) |
232 | 235 | { |
@@ -303,17 +306,16 @@ MainLoop(FILE *source) |
303 | 306 | *down here so we can check for \g and other 'execute' |
304 | 307 | *backslash commands, which should be appended. |
305 | 308 | */ |
306 | | -if (first_query_scan&&pset.cur_cmd_interactive) |
| 309 | +if (!line_saved_in_history&&pset.cur_cmd_interactive) |
307 | 310 | { |
308 | 311 | /* Sending a command (PSQL_CMD_SEND) zeros the length */ |
309 | 312 | if (scan_result==PSCAN_BACKSLASH&&history_buf->len!=0) |
310 | 313 | pg_write_history(line); |
311 | 314 | else |
312 | 315 | pg_append_history(line,history_buf); |
| 316 | +line_saved_in_history= true; |
313 | 317 | } |
314 | 318 |
|
315 | | -first_query_scan= false; |
316 | | - |
317 | 319 | /* fall out of loop on \q or if lexer reached EOL */ |
318 | 320 | if (slashCmdStatus==PSQL_CMD_TERMINATE|| |
319 | 321 | scan_result==PSCAN_INCOMPLETE|| |
|