Fix ancient oversight in psql's \d pattern processing code: when seeing two
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 7 Oct 2006 22:21:44 +0000 (22:21 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 7 Oct 2006 22:21:44 +0000 (22:21 +0000)
quote chars inside quote marks, should emit one quote *and stay in inquotes
mode*.  No doubt the lack of reports of this have something to do with the
poor documentation of the feature ...

src/bin/psql/describe.c

index 8529cab68110f3b48ca4d9b07cdf035772322994..109a022ce97b4bd324d87e4a8503879320e5eaae 100644 (file)
@@ -1803,34 +1803,37 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
 
        while (*cp)
        {
-               if (*cp == '"')
+               char    ch = *cp;
+
+               if (ch == '"')
                {
                        if (inquotes && cp[1] == '"')
                        {
-                               /* emit one quote */
+                               /* emit one quote, stay in inquotes mode */
                                appendPQExpBufferChar(&namebuf, '"');
                                cp++;
                        }
-                       inquotes = !inquotes;
+                       else
+                               inquotes = !inquotes;
                        cp++;
                }
-               else if (!inquotes && isupper((unsigned char) *cp))
+               else if (!inquotes && isupper((unsigned char) ch))
                {
                        appendPQExpBufferChar(&namebuf,
-                                                                 pg_tolower((unsigned char) *cp));
+                                                                 pg_tolower((unsigned char) ch));
                        cp++;
                }
-               else if (!inquotes && *cp == '*')
+               else if (!inquotes && ch == '*')
                {
                        appendPQExpBuffer(&namebuf, ".*");
                        cp++;
                }
-               else if (!inquotes && *cp == '?')
+               else if (!inquotes && ch == '?')
                {
                        appendPQExpBufferChar(&namebuf, '.');
                        cp++;
                }
-               else if (!inquotes && *cp == '.')
+               else if (!inquotes && ch == '.')
                {
                        /* Found schema/name separator, move current pattern to schema */
                        resetPQExpBuffer(&schemabuf);