Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cad3e70

Browse files
committed
Fix for backslash quote.
1 parent 38d2ca5 commit cad3e70

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/bin/psql/psql.c

+22-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.97 1997/09/19 03:42:39 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.98 1997/09/23 19:47:59 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1185,7 +1185,7 @@ do_help(PsqlSettings *pset, const char *topic)
11851185
printf("%-25s\n", QL_HELP[i].cmd);
11861186
left_center_right = 'L';
11871187
break;
1188-
};
1188+
}
11891189
i++;
11901190
}
11911191
if (left_center_right != 'L')
@@ -1649,6 +1649,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
16491649
/* We've reached the end of our command input. */
16501650
bool success;
16511651
bool in_quote;
1652+
bool was_bslash; /* backslash */
16521653
int paren_level;
16531654
char *query_start;
16541655

@@ -1737,7 +1738,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
17371738
{
17381739
query_start = line;
17391740
xcomment = line;
1740-
};
1741+
}
17411742

17421743
if (line == NULL)
17431744
{ /* No more input. Time to quit */
@@ -1774,9 +1775,11 @@ MainLoop(PsqlSettings *pset, FILE *source)
17741775
{
17751776
int i;
17761777

1778+
was_bslash = false;
1779+
17771780
for (i = 0; i < len; i++)
17781781
{
1779-
if (line[i] == '\\')
1782+
if (line[i] == '\\' && !in_quote)
17801783
{
17811784
char hold_char = line[i];
17821785

@@ -1791,7 +1794,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
17911794
else
17921795
{
17931796
strcpy(query, query_start);
1794-
};
1797+
}
17951798
}
17961799
line[i] = hold_char;
17971800
query_start = line + i;
@@ -1806,32 +1809,32 @@ MainLoop(PsqlSettings *pset, FILE *source)
18061809
querySent = false;
18071810
}
18081811

1812+
if (was_bslash)
1813+
was_bslash = false;
1814+
else if (i > 0 && line[i-1] == '\\')
1815+
was_bslash = true;
1816+
18091817
/* inside a quote? */
1810-
if (in_quote && (line[i] != '\''))
1818+
if (in_quote && (line[i] != '\'' || was_bslash))
18111819
{
1812-
continue;
1813-
1814-
/* inside an extended comment? */
1820+
/* do nothing */;
18151821
}
1816-
else if (xcomment != NULL)
1822+
else if (xcomment != NULL) /*inside an extended comment?*/
18171823
{
18181824
if (line[i] == '*' && line[i + 1] == '/')
18191825
{
18201826
xcomment = NULL;
18211827
i++;
1822-
};
1823-
continue;
1824-
1825-
/* possible backslash command? */
1828+
}
18261829
}
1830+
/* possible backslash command? */
18271831
else if (line[i] == '/' && line[i + 1] == '*')
18281832
{
18291833
xcomment = line + i;
18301834
i++;
1831-
continue;
18321835

1833-
/* single-line comment? truncate line */
18341836
}
1837+
/* single-line comment? truncate line */
18351838
else if ((line[i] == '-' && line[i + 1] == '-') ||
18361839
(line[i] == '/' && line[i + 1] == '/'))
18371840
{
@@ -1840,14 +1843,12 @@ MainLoop(PsqlSettings *pset, FILE *source)
18401843
fprintf(stdout, "%s\n", line + i);
18411844
line[i] = '\0'; /* remove comment */
18421845
break;
1843-
18441846
}
18451847
else if (line[i] == '\'')
18461848
{
18471849
in_quote ^= 1;
1848-
1849-
/* semi-colon? then send query now */
18501850
}
1851+
/* semi-colon? then send query now */
18511852
else if (!paren_level && line[i] == ';')
18521853
{
18531854
char hold_char = line[i + 1];
@@ -1878,10 +1879,10 @@ MainLoop(PsqlSettings *pset, FILE *source)
18781879
else if (paren_level && line[i] == ')')
18791880
{
18801881
paren_level--;
1881-
};
1882+
}
18821883
}
18831884
}
1884-
1885+
puts(line);
18851886
/* nothing on line after trimming? then ignore */
18861887
if (line[0] == '\0')
18871888
{

0 commit comments

Comments
 (0)