|
1 | 1 | /*-------------------------------------------------------------------------
|
2 | 2 | *
|
3 | 3 | * like_match.c
|
4 |
| - * like expression handling internal code. |
| 4 | + * LIKE pattern matching internal code. |
5 | 5 | *
|
6 |
| - * This file is included by like.c four times, to provide natching code for |
7 |
| - * single-byte encodings, UTF8, and for other multi-byte encodings, |
8 |
| - * and case insensitive matches for single byte encodings. |
9 |
| - * UTF8 is a special case because we can use a much more efficient version |
10 |
| - * of NextChar than can be used for other multi-byte encodings. |
| 6 | + * This file is included by like.c four times, to provide matching code for |
| 7 | + * (1) single-byte encodings, (2) UTF8, (3) other multi-byte encodings, |
| 8 | + * and (4) case insensitive matches in single byte encodings. |
| 9 | + * (UTF8 is a special case because we can use a much more efficient version |
| 10 | + * of NextChar than can be used for general multi-byte encodings.) |
11 | 11 | *
|
12 | 12 | * Before the inclusion, we need to define following macros:
|
13 | 13 | *
|
|
19 | 19 | * Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
20 | 20 | *
|
21 | 21 | * IDENTIFICATION
|
22 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.21 2008/03/01 03:26:34 tgl Exp $ |
| 22 | + * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.22 2008/09/26 02:16:40 tgl Exp $ |
23 | 23 | *
|
24 | 24 | *-------------------------------------------------------------------------
|
25 | 25 | */
|
@@ -96,9 +96,14 @@ MatchText(char *t, int tlen, char *p, int plen)
|
96 | 96 | {
|
97 | 97 | if (*p == '\\')
|
98 | 98 | {
|
99 |
| - /* Next byte must match literally, whatever it is */ |
| 99 | + /* Next pattern byte must match literally, whatever it is */ |
100 | 100 | NextByte(p, plen);
|
101 |
| - if ((plen <= 0) || *p != *t) |
| 101 | + /* ... and there had better be one, per SQL standard */ |
| 102 | + if (plen <= 0) |
| 103 | + ereport(ERROR, |
| 104 | + (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE), |
| 105 | + errmsg("LIKE pattern must not end with escape character"))); |
| 106 | + if (*p != *t) |
102 | 107 | return LIKE_FALSE;
|
103 | 108 | }
|
104 | 109 | else if (*p == '%')
|
|
0 commit comments