FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ora): align REGEXP_LIKE flags with ora_parse_re_flags · IvorySQL/IvorySQL@c8c12c3 · GitHub

Repository navigation

Commit c8c12c3

Browse files
andcommitted
fix(ora): align REGEXP_LIKE flags with ora_parse_re_flags
Use the shared Oracle regexp flag parser for REGEXP_LIKE and the no-flags wrapper. Add regression coverage for n/m/default newline semantics (issue #2295). Fixes #2295. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 069766e commit c8c12c3

3 files changed

Lines changed: 57 additions & 30 deletions

File tree

‎contrib/ivorysql_ora/expected/ora_character_datatype_functions.out‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,40 @@ select * from t_regexp_like where regexp_like(null, null, null);
15741574
----+-------
15751575
(0 rows)
15761576

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"
15771611
DROP table t_regexp_like;
15781612
/*
15791613
* regexp_count

‎contrib/ivorysql_ora/sql/ora_character_datatype_functions.sql‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,14 @@ select * from t_regexp_like where regexp_like('', null);
796796
select * from t_regexp_like where regexp_like(null, null);
797797
select * from t_regexp_like where regexp_like(null, null, null);
798798

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+
799807
DROP table t_regexp_like;
800808

801809
/*

‎contrib/ivorysql_ora/src/builtin_functions/character_datatype_functions.c‎

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ ora_regexp_like(PG_FUNCTION_ARGS)
774774
{
775775
text *s = PG_ARGISNULL(0) ? NULL :PG_GETARG_TEXT_P(0);
776776
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;
780780
bool match;
781781
regmatch_t pmatch[2];
782782

@@ -785,36 +785,21 @@ ora_regexp_like(PG_FUNCTION_ARGS)
785785
PG_RETURN_BOOL(false);
786786
}
787787

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)
794789
{
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++)
796792
{
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))
810794
ereport(ERROR,
811795
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
812796
errmsg("invalid option of regexp_like: %c",
813-
in_flag_p[i])));
814-
break;
797+
*match_pa_to_str)));
815798
}
816799
}
817800

801+
ora_parse_re_flags(&flags, in_flag);
802+
818803
/*
819804
* We pass two regmatch_t structs to get info about the overall match and
820805
* the match for the first parenthesized subexpression (if any). If there
@@ -824,7 +809,7 @@ ora_regexp_like(PG_FUNCTION_ARGS)
824809
match = RE_compile_and_execute(p,
825810
VARDATA(s),
826811
VARSIZE(s) - VARHDRSZ,
827-
out_flag,
812+
flags.cflags,
828813
PG_GET_COLLATION(),
829814
2, pmatch);
830815

@@ -845,16 +830,16 @@ ora_regexp_like_no_flags(PG_FUNCTION_ARGS)
845830
{
846831
text *s = PG_ARGISNULL(0) ? NULL :PG_GETARG_TEXT_P(0);
847832
text *p = PG_ARGISNULL(1) ? NULL :PG_GETARG_TEXT_P(1);
848-
int out_flag;
833+
pg_re_flags flags;
849834
bool match;
850835
regmatch_t pmatch[2];
851836

852837
if ((NULL == s) || (NULL == p) )
853838
{
854839
PG_RETURN_BOOL(false);
855840
}
856-
/* parse flag options */
857-
out_flag = REG_ADVANCED;
841+
842+
ora_parse_re_flags(&flags, NULL);
858843

859844
/*
860845
* 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)
865850
match = RE_compile_and_execute(p,
866851
VARDATA(s),
867852
VARSIZE(s) - VARHDRSZ,
868-
out_flag,
853+
flags.cflags,
869854
PG_GET_COLLATION(),
870855
2, pmatch);
871856

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL