8000 Fix select '1--2'; for PEter. · postgrespro/postgres_cluster@2f131ca · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f131ca

Browse files
committed
Fix select '1--2'; for PEter.
1 parent a164213 commit 2f131ca

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/bin/psql/mainloop.c

Lines changed: 32 additions & 24 deletions
4EBD
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.31 2000/06/29 16:27:57 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.32 2000/06/30 18:03:40 momjian Exp $
77
*/
88
#include "postgres.h"
99
#include "mainloop.h"
@@ -44,7 +44,7 @@ MainLoop(FILE *source)
4444

4545
bool success;
4646
volatile char in_quote; /* == 0 for no in_quote */
47-
volatile bool xcomment; /* in extended comment */
47+
volatile bool in_xcomment; /* in extended comment */
4848
volatile int paren_level;
4949
unsigned int query_start;
5050
volatile int count_eof = 0;
@@ -80,7 +80,7 @@ MainLoop(FILE *source)
8080
exit(EXIT_FAILURE);
8181
}
8282

83-
xcomment = false;
83+
in_xcomment = false;
8484
in_quote = 0;
8585
paren_level = 0;
8686
slashCmdStatus = CMD_UNKNOWN; /* set default */
@@ -123,7 +123,7 @@ MainLoop(FILE *source)
123123
resetPQExpBuffer(query_buf);
124124

125125
/* reset parsing state */
126-
xcomment = false;
126+
in_xcomment = false;
127127
in_quote = 0;
128128
paren_level = 0;
129129
count_eof = 0;
@@ -147,7 +147,7 @@ MainLoop(FILE *source)
147147
line = xstrdup(query_buf->data);
148148
resetPQExpBuffer(query_buf);
149149
/* reset parsing state since we are rescanning whole line */
150-
xcomment = false;
150+
in_xcomment = false;
151151
in_quote = 0;
152152
paren_level = 0;
153153
slashCmdStatus = CMD_UNKNOWN;
@@ -168,7 +168,7 @@ MainLoop(FILE *source)
168168
prompt_status = PROMPT_SINGLEQUOTE;
169169
else if (in_quote && in_quote == '"')
170170
prompt_status = PROMPT_DOUBLEQUOTE;
171-
else if (xcomment)
171+
else if (in_xcomment)
172172
prompt_status = PROMPT_COMMENT;
173173
else if (paren_level)
174174
prompt_status = PROMPT_PAREN;
@@ -296,43 +296,51 @@ MainLoop(FILE *source)
296296
bslash_count = 0;
297297

298298
rescan:
299-
/* start of extended comment? */
300-
if (line[i] == '/' && line[i + thislen] == '*')
299+
/*
300+
* It is important to place the in_* test routines
301+
* before the in_* detection routines.
302+
* i.e. we have to test if we are in a quote before
303+
* testing for comments. bjm 2000-06-30
304+
*/
305+
306+
/* in quote? */
307+
if (in_quote)
301308
{
302-
xcomment = true;
303-
ADVANCE_1;
309+
/* end of quote */
310+
if (line[i] == in_quote && bslash_count % 2 == 0)
311+
in_quote = '\0';
304312
}
305313

306314
/* in extended comment? */
307-
else if (xcomment)
315+
else if (in_xcomment)
308316
{
309317
if (line[i] == '*' && line[i + thislen] == '/')
310318
{
311-
xcomment = false;
319+
in_xcomment = false;
312320
ADVANCE_1;
313321
}
314322
}
315323

316-
/* single-line comment? truncate line */
317-
else if (line[i] == '-' && line[i + thislen] == '-')
318-
{
319-
line[i] = '\0'; /* remove comment */
320-
break;
321-
}
322-
323-
/* in quote? */
324-
else if (in_quote)
324+
/* start of extended comment? */
325+
else if (line[i] == '/' && line[i + thislen] == '*')
325326
{
326-
/* end of quote */
327-
if (line[i] == in_quote && bslash_count % 2 == 0)
328-
in_quote = '\0';
327+
in_xcomment = true;
328+
ADVANCE_1;
329329
}
330330

331331
/* start of quote */
332332
else if (!was_bslash &&
333333
(line[i] == '\'' || line[i] == '"'))
334334
in_quote = line[i];
335335

336+
337+
/* single-line comment? truncate line */
338+
else if (line[i] == '-' && line[i + thislen] == '-')
339+
{
340+
line[i] = '\0'; /* remove comment */
341+
break;
342+
}
343+
336344
/* count nested parentheses */
337345
else if (line[i] == '(')
338346
paren_level++;

0 commit comments

Comments
 (0)
0