| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 069766e commit c8c12c3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1574,6 +1574,40 @@ select * from t_regexp_like where regexp_like(null, null, null); | |||
| 1574 | 1574 | ----+------- | |
| 1575 | 1575 | (0 rows) | |
| 1576 | 1576 | ||
| 1577 | + -- REGEXP_LIKE match_parameter n/m/default (issue #2295) | ||
| 1578 | + select regexp_like('X'||chr(10), 'X.'); | ||
| 1579 | + regexp_like | ||
| 1580 | + ------------- | ||
| 1581 | + f | ||
| 1582 | + (1 row) | ||
| 1583 | + | ||
| 1584 | + select regexp_like('X'||chr(10), 'X.', 'n'); | ||
| 1585 | + regexp_like | ||
| 1586 | + ------------- | ||
| 1587 | + t | ||
| 1588 | + (1 row) | ||
| 1589 | + | ||
| 1590 | + select regexp_like('X'||chr(10), 'X.', 'c'); | ||
| 1591 | + regexp_like | ||
| 1592 | + ------------- | ||
| 1593 | + f | ||
| 1594 | + (1 row) | ||
| 1595 | + | ||
| 1596 | + select regexp_like('x'||chr(10)||'b'||chr(10)||'y', '^b$', 'm'); | ||
| 1597 | + regexp_like | ||
| 1598 | + ------------- | ||
| 1599 | + t | ||
| 1600 | + (1 row) | ||
| 1601 | + | ||
| 1602 | + select regexp_substr('X'||chr(10), 'X.', 1, 1, 'n'); | ||
| 1603 | + regexp_substr | ||
| 1604 | + --------------- | ||
| 1605 | + X | ||
| 1606 | + | ||
| 1607 | + (1 row) | ||
| 1608 | + | ||
| 1609 | + select regexp_like('X'||chr(10), 'X.', 'z'); | ||
| 1610 | + ERROR: invalid regular expression option: "z" | ||
| 1577 | 1611 | DROP table t_regexp_like; | |
| 1578 | 1612 | /* | |
| 1579 | 1613 | * regexp_count | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -796,6 +796,14 @@ select * from t_regexp_like where regexp_like('', null); | |||
| 796 | 796 | select * from t_regexp_like where regexp_like(null, null); | |
| 797 | 797 | select * from t_regexp_like where regexp_like(null, null, null); | |
| 798 | 798 | ||
| 799 | + -- REGEXP_LIKE match_parameter n/m/default (issue #2295) | ||
| 800 | + select regexp_like('X'||chr(10), 'X.'); | ||
| 801 | + select regexp_like('X'||chr(10), 'X.', 'n'); | ||
| 802 | + select regexp_like('X'||chr(10), 'X.', 'c'); | ||
| 803 | + select regexp_like('x'||chr(10)||'b'||chr(10)||'y', '^b$', 'm'); | ||
| 804 | + select regexp_substr('X'||chr(10), 'X.', 1, 1, 'n'); | ||
| 805 | + select regexp_like('X'||chr(10), 'X.', 'z'); | ||
| 806 | + | ||
| 799 | 807 | DROP table t_regexp_like; | |
| 800 | 808 | ||
| 801 | 809 | /* | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -774,9 +774,9 @@ ora_regexp_like(PG_FUNCTION_ARGS) | |||
| 774 | 774 | { | |
| 775 | 775 | text *s = PG_ARGISNULL(0) ? NULL :PG_GETARG_TEXT_P(0); | |
| 776 | 776 | text *p = PG_ARGISNULL(1) ? NULL :PG_GETARG_TEXT_P(1); | |
| 777 | - text *in_flag = PG_ARGISNULL(2) ? PG_STR_GET_TEXT("") : PG_GETARG_TEXT_P(2); | ||
| 778 | - char *in_flag_p = NULL; | ||
| 779 | - int in_flag_len, i, out_flag; | ||
| 777 | + text *in_flag = PG_ARGISNULL(2) ? NULL : PG_GETARG_TEXT_P(2); | ||
| 778 | + char *match_pa_to_str = NULL; | ||
| 779 | + pg_re_flags flags; | ||
| 780 | 780 | bool match; | |
| 781 | 781 | regmatch_t pmatch[2]; | |
| 782 | 782 | ||
@@ -785,36 +785,21 @@ ora_regexp_like(PG_FUNCTION_ARGS) | |||
| 785 | 785 | PG_RETURN_BOOL(false); | |
| 786 | 786 | } | |
| 787 | 787 | ||
| 788 | - in_flag_p = VARDATA(in_flag); | ||
| 789 | - in_flag_len = (VARSIZE(in_flag) - VARHDRSZ); | ||
| 790 | - | ||
| 791 | - /* parse flag options */ | ||
| 792 | - out_flag = REG_ADVANCED; | ||
| 793 | - for (i = 0; i <in_flag_len; i++) | ||
| 788 | + if (in_flag != NULL) | ||
| 794 | 789 | { | |
| 795 | - switch (in_flag_p[i]) | ||
| 790 | + match_pa_to_str = text_to_cstring(in_flag); | ||
| 791 | + for (; *match_pa_to_str != '\0'; match_pa_to_str++) | ||
| 796 | 792 | { | |
| 797 | - case 'i': | ||
| 798 | - out_flag |= REG_ICASE; | ||
| 799 | - break; | ||
| 800 | - case 'n': | ||
| 801 | - out_flag |= REG_NEWLINE; | ||
| 802 | - break; | ||
| 803 | - case 'c': | ||
| 804 | - out_flag &= ~REG_ICASE; | ||
| 805 | - break; | ||
| 806 | - case 'x': | ||
| 807 | - out_flag |= REG_EXPANDED; | ||
| 808 | - break; | ||
| 809 | - default: | ||
| 793 | + if (!MATCHPARAM(*match_pa_to_str)) | ||
| 810 | 794 | ereport(ERROR, | |
| 811 | 795 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), | |
| 812 | 796 | errmsg("invalid option of regexp_like: %c", | |
| 813 | - in_flag_p[i]))); | ||
| 814 | - break; | ||
| 797 | + *match_pa_to_str))); | ||
| 815 | 798 | } | |
| 816 | 799 | } | |
| 817 | 800 | ||
| 801 | + ora_parse_re_flags(&flags, in_flag); | ||
| 802 | + | ||
| 818 | 803 | /* | |
| 819 | 804 | * We pass two regmatch_t structs to get info about the overall match and | |
| 820 | 805 | * the match for the first parenthesized subexpression (if any). If there | |
@@ -824,7 +809,7 @@ ora_regexp_like(PG_FUNCTION_ARGS) | |||
| 824 | 809 | match = RE_compile_and_execute(p, | |
| 825 | 810 | VARDATA(s), | |
| 826 | 811 | VARSIZE(s) - VARHDRSZ, | |
| 827 | - out_flag, | ||
| 812 | + flags.cflags, | ||
| 828 | 813 | PG_GET_COLLATION(), | |
| 829 | 814 | 2, pmatch); | |
| 830 | 815 | ||
@@ -845,16 +830,16 @@ ora_regexp_like_no_flags(PG_FUNCTION_ARGS) | |||
| 845 | 830 | { | |
| 846 | 831 | text *s = PG_ARGISNULL(0) ? NULL :PG_GETARG_TEXT_P(0); | |
| 847 | 832 | text *p = PG_ARGISNULL(1) ? NULL :PG_GETARG_TEXT_P(1); | |
| 848 | - int out_flag; | ||
| 833 | + pg_re_flags flags; | ||
| 849 | 834 | bool match; | |
| 850 | 835 | regmatch_t pmatch[2]; | |
| 851 | 836 | ||
| 852 | 837 | if ((NULL == s) || (NULL == p) ) | |
| 853 | 838 | { | |
| 854 | 839 | PG_RETURN_BOOL(false); | |
| 855 | 840 | } | |
| 856 | - /* parse flag options */ | ||
| 857 | - out_flag = REG_ADVANCED; | ||
| 841 | + | ||
| 842 | + ora_parse_re_flags(&flags, NULL); | ||
| 858 | 843 | ||
| 859 | 844 | /* | |
| 860 | 845 | * We pass two regmatch_t structs to get info about the overall match and | |
@@ -865,7 +850,7 @@ ora_regexp_like_no_flags(PG_FUNCTION_ARGS) | |||
| 865 | 850 | match = RE_compile_and_execute(p, | |
| 866 | 851 | VARDATA(s), | |
| 867 | 852 | VARSIZE(s) - VARHDRSZ, | |
| 868 | - out_flag, | ||
| 853 | + flags.cflags, | ||
| 869 | 854 | PG_GET_COLLATION(), | |
| 870 | 855 | 2, pmatch); | |
| 871 | 856 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments