85{
86
87 if (plen == 1 && *p == '%')
89
90
92
93
94
95
96
97
98
99
100
101 while (tlen > 0 && plen > 0)
102 {
103 if (*p == '\\')
104 {
105
107
108 if (plen <= 0)
110 (
errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
111 errmsg(
"LIKE pattern must not end with escape character")));
114 }
115 else if (*p == '%')
116 {
117 char firstpat;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
133
134 while (plen > 0)
135 {
136 if (*p == '%')
138 else if (*p == '_')
139 {
140
141 if (tlen <= 0)
145 }
146 else
147 break;
148 }
149
150
151
152
153
154 if (plen <= 0)
156
157
158
159
160
161
162
163
164
165
166
167
168 if (*p == '\\')
169 {
170 if (plen < 2)
172 (
errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
173 errmsg(
"LIKE pattern must not end with escape character")));
175 }
176 else
178
179 while (tlen > 0)
180 {
182 {
184
186 return matched;
187 }
188
190 }
191
192
193
194
195
197 }
198 else if (*p == '_')
199 {
200
203 continue;
204 }
206 {
207
208
209
210
211
212
213
214
215 const char *p1;
216 size_t p1len;
217 const char *t1;
218 size_t t1len;
219 bool found_escape;
220 const char *subpat;
221 size_t subpatlen;
223
224
225
226
227
228
229 p1 = p;
230 p1len = plen;
231 found_escape = false;
232 while (p1len > 0)
233 {
234 if (*p1 == '\\')
235 {
236 found_escape = true;
238 if (p1len == 0)
240 (
errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
241 errmsg(
"LIKE pattern must not end with escape character")));
242 }
243 else if (*p1 == '_' || *p1 == '%')
244 break;
246 }
247
248
249
250
251
252 if (found_escape)
253 {
255
257 for (
const char *
c = p;
c < p1;
c++)
258 {
260 ;
261 else
263 }
264
267 }
268 else
269 {
270 subpat = p;
271 subpatlen = p1 - p;
272 }
273
274
275
276
277
278 if (p1len == 0)
279 {
281
283
288 else
290 }
291
292
293
294
295
296
297 t1 = t;
298 t1len = tlen;
299 for (;;)
300 {
302
304
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
324 {
326
328 {
331 return matched;
332 }
333 }
334
335
336
337
338
339 if (t1len == 0)
340 {
344 }
345 else
347 }
348 }
350 {
351
353 }
354
355
356
357
358
359
360
361
362
363
364
365
366
369 }
370
371 if (tlen > 0)
373
374
375
376
377
378 while (plen > 0 && *p == '%')
380 if (plen <= 0)
382
383
384
385
386
388}
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define NextByte(p, plen)
#define NextChar(p, plen)
static int MatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
void pfree(void *pointer)
#define CHECK_FOR_INTERRUPTS()
int pg_strncoll(const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int cmp(const chr *x, const chr *y, size_t len)
void check_stack_depth(void)