PostgreSQL Source Code: src/backend/utils/adt/like.c File Reference (original) (raw)
#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <ctype.h>
#include "[catalog/pg_collation.h](pg%5F%5Fcollation%5F8h%5Fsource.html)"
#include "[mb/pg_wchar.h](pg%5F%5Fwchar%5F8h%5Fsource.html)"
#include "[miscadmin.h](miscadmin%5F8h%5Fsource.html)"
#include "utils/fmgrprotos.h"
#include "[utils/pg_locale.h](pg%5F%5Flocale%5F8h%5Fsource.html)"
#include "[varatt.h](varatt%5F8h%5Fsource.html)"
#include "[like_match.c](like%5F%5Fmatch%5F8c%5Fsource.html)"
Go to the source code of this file.
Macros | |
---|---|
#define | LIKE_TRUE 1 |
#define | LIKE_FALSE 0 |
#define | LIKE_ABORT (-1) |
#define | NextByte(p, plen) ((p)++, (plen)--) |
#define | CHAREQ(p1, p2) wchareq((p1), (p2)) |
#define | NextChar(p, plen) do { int __l = pg_mblen(p); (p) +=__l; (plen) -=__l; } while (0) |
#define | CopyAdvChar(dst, src, srclen) |
#define | MatchText MB_MatchText |
#define | do_like_escape MB_do_like_escape |
#define | CHAREQ(p1, p2) (*(p1) == *(p2)) |
#define | NextChar(p, plen) NextByte((p), (plen)) |
#define | CopyAdvChar(dst, src, srclen) (*(dst)++ = *(src)++, (srclen)--) |
#define | MatchText SB_MatchText |
#define | do_like_escape SB_do_like_escape |
#define | MATCH_LOWER(t, locale) SB_lower_char((unsigned char) (t), locale) |
#define | NextChar(p, plen) NextByte((p), (plen)) |
#define | MatchText SB_IMatchText |
#define | NextChar(p, plen) do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 ) |
#define | MatchText UTF8_MatchText |
◆ CHAREQ [1/2]
| #define CHAREQ | ( | | p1, | | -------------- | ----------------------------------------------------------------------- | | --- | | | p2 | | | | | ) | wchareq((p1), (p2)) | | |
Definition at line 124 of file like.c.
◆ CHAREQ [2/2]
| #define CHAREQ | ( | | p1, | | -------------- | ------------------ | | --- | | | p2 | | | | | ) | (*(p1) == *(p2)) | | |
Definition at line 124 of file like.c.
◆ CopyAdvChar [1/2]
| #define CopyAdvChar | ( | | dst, | | ------------------- | - | | ---- | | | src, | | | | | | srclen | | | | | ) | | | |
Value:
(srclen) -= __l; \
while (__l-- > 0) \
*(dst)++ = *(src)++; \
} while (0)
int pg_mblen(const char *mbstr)
Definition at line 126 of file like.c.
◆ CopyAdvChar [2/2]
| #define CopyAdvChar | ( | | dst, | | ------------------- | ----------------------------------- | | ---- | | | src, | | | | | | srclen | | | | | ) | (*(dst)++ = *(src)++, (srclen)--) | | |
Definition at line 126 of file like.c.
◆ do_like_escape [1/2]
◆ do_like_escape [2/2]
◆ LIKE_ABORT
◆ LIKE_FALSE
◆ LIKE_TRUE
◆ MATCH_LOWER
◆ MatchText [1/4]
◆ MatchText [2/4]
◆ MatchText [3/4]
◆ MatchText [4/4]
◆ NextByte
| #define NextByte | ( | | p, | | ---------------- | ----------------- | | -- | | | plen | | | | | ) | ((p)++, (plen)--) | | |
Definition at line 105 of file like.c.
◆ NextChar [1/4]
| #define NextChar | ( | | p, | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -- | | | plen | | | | | ) | do { int __l = pg_mblen(p); (p) +=__l; (plen) -=__l; } while (0) | | |
Definition at line 142 of file like.c.
◆ NextChar [2/4]
| #define NextChar | ( | | p, | | ---------------- | ------------------------------------------------------------------------- | | -- | | | plen | | | | | ) | NextByte((p), (plen)) | | |
Definition at line 142 of file like.c.
◆ NextChar [3/4]
| #define NextChar | ( | | p, | | ---------------- | ------------------------------------------------------------------------- | | -- | | | plen | | | | | ) | NextByte((p), (plen)) | | |
Definition at line 142 of file like.c.
◆ NextChar [4/4]
| #define NextChar | ( | | p, | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | -- | | | plen | | | | | ) | do { (p)++; (plen)--; } while ((plen) > 0 && (*(p) & 0xC0) == 0x80 ) | | |
Definition at line 142 of file like.c.
◆ bytealike()
Definition at line 326 of file like.c.
327{
330 bool result;
331 char *s,
332 *p;
333 int slen,
334 plen;
335
340
342
344}
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BOOL(x)
static int SB_MatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
#define VARSIZE_ANY_EXHDR(PTR)
References LIKE_TRUE, PG_GETARG_BYTEA_PP, PG_RETURN_BOOL, SB_MatchText(), str, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
◆ byteanlike()
◆ Generic_Text_IC_like()
static int Generic_Text_IC_like ( text * str, text * pat, Oid collation ) | inlinestatic |
---|
Definition at line 177 of file like.c.
178{
179 char *s,
180 *p;
181 int slen,
182 plen;
184
186 {
187
188
189
190
192 (errcode(ERRCODE_INDETERMINATE_COLLATION),
193 errmsg("could not determine which collation to use for ILIKE"),
194 errhint("Use the COLLATE clause to set the collation explicitly.")));
195 }
196
198
199 if (->deterministic)
201 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
202 errmsg("nondeterministic collations are not supported for ILIKE")));
203
204
205
206
207
208
209
210
211
213 {
224 else
226 }
227 else
228 {
234 }
235}
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1)
#define DatumGetTextPP(X)
static int UTF8_MatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
static int MB_MatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
static int SB_IMatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
int GetDatabaseEncoding(void)
int pg_database_encoding_max_length(void)
Datum lower(PG_FUNCTION_ARGS)
pg_locale_t pg_newlocale_from_collation(Oid collid)
static Datum PointerGetDatum(const void *X)
References DatumGetTextPP, DirectFunctionCall1Coll(), ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), locale, lower(), MB_MatchText(), OidIsValid, pg_database_encoding_max_length(), pg_newlocale_from_collation(), PG_UTF8, PointerGetDatum(), SB_IMatchText(), str, UTF8_MatchText(), VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by nameiclike(), nameicnlike(), texticlike(), and texticnlike().
◆ GenericMatchText()
static int GenericMatchText ( const char * s, int slen, const char * p, int plen, Oid collation ) | inlinestatic |
---|
Definition at line 150 of file like.c.
151{
153
155 {
156
157
158
159
161 (errcode(ERRCODE_INDETERMINATE_COLLATION),
162 errmsg("could not determine which collation to use for LIKE"),
163 errhint("Use the COLLATE clause to set the collation explicitly.")));
164 }
165
167
172 else
174}
References ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), locale, MB_MatchText(), OidIsValid, pg_database_encoding_max_length(), pg_newlocale_from_collation(), PG_UTF8, SB_MatchText(), and UTF8_MatchText().
Referenced by namelike(), namenlike(), textlike(), and textnlike().
◆ like_escape()
◆ like_escape_bytea()
◆ MB_do_like_escape()
static text * MB_do_like_escape ( text * pat, text * esc ) | static |
---|
◆ MB_MatchText()
static int MB_MatchText ( const char * t, int tlen, const char * p, int plen, pg_locale_t locale ) | static |
---|
◆ nameiclike()
Definition at line 372 of file like.c.
373{
376 bool result;
377 text *strtext;
378
382
384}
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_NAME(n)
#define PG_GET_COLLATION()
static int Generic_Text_IC_like(text *str, text *pat, Oid collation)
static Datum NameGetDatum(const NameData *X)
Datum name_text(PG_FUNCTION_ARGS)
References DatumGetTextPP, DirectFunctionCall1, Generic_Text_IC_like(), LIKE_TRUE, name_text(), NameGetDatum(), PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and str.
◆ nameicnlike()
Definition at line 387 of file like.c.
388{
391 bool result;
392 text *strtext;
393
397
399}
References DatumGetTextPP, DirectFunctionCall1, Generic_Text_IC_like(), LIKE_TRUE, name_text(), NameGetDatum(), PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and str.
◆ namelike()
Definition at line 242 of file like.c.
243{
246 bool result;
247 char *s,
248 *p;
249 int slen,
250 plen;
251
253 slen = strlen(s);
256
258
260}
static int GenericMatchText(const char *s, int slen, const char *p, int plen, Oid collation)
References GenericMatchText(), LIKE_TRUE, NameStr, PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, str, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
◆ namenlike()
Definition at line 263 of file like.c.
264{
267 bool result;
268 char *s,
269 *p;
270 int slen,
271 plen;
272
274 slen = strlen(s);
277
279
281}
References GenericMatchText(), LIKE_TRUE, NameStr, PG_GET_COLLATION, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, str, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
◆ SB_do_like_escape()
static text * SB_do_like_escape ( text * pat, text * esc ) | static |
---|
◆ SB_IMatchText()
static int SB_IMatchText ( const char * t, int tlen, const char * p, int plen, pg_locale_t locale ) | static |
---|
◆ SB_lower_char()
static char SB_lower_char ( unsigned char c, pg_locale_t locale ) | static |
---|
◆ SB_MatchText()
static int SB_MatchText ( const char * t, int tlen, const char * p, int plen, pg_locale_t locale ) | static |
---|
◆ texticlike()
◆ texticnlike()
◆ textlike()
◆ textnlike()
◆ UTF8_MatchText()
static int UTF8_MatchText ( const char * t, int tlen, const char * p, int plen, pg_locale_t locale ) | static |
---|
◆ wchareq()
static int wchareq ( const char * p1, const char * p2 ) | inlinestatic |
---|
Definition at line 58 of file like.c.
59{
60 int p1_len;
61
62
63 if (*p1 != *p2)
64 return 0;
65
68 return 0;
69
70
71 while (p1_len--)
72 {
73 if (*p1++ != *p2++)
74 return 0;
75 }
76 return 1;
77}
References pg_mblen().