Skip to content

Commit

Permalink
Merge pull request #175 from orafce/backport_regexp
Browse files Browse the repository at this point in the history
Backport regexp
  • Loading branch information
okbob authored Apr 16, 2022
2 parents 2754b8e + 8b96e44 commit e1c125e
Show file tree
Hide file tree
Showing 9 changed files with 1,350 additions and 456 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.opensdf
*.suo
*.*.user
*.bc
/.deps/
/orafce.sql
/orafce.sql.in
Expand Down
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "orafce",
"abstract": "Oracle's compatibility functions and packages",
"description": "This module allows use a well known Oracle's functions and packages inside PostgreSQL",
"version": "3.20.0",
"version": "3.21.0",
"maintainer": [
"Pavel Stehule <[email protected]>",
"Takahiro Itagaki <[email protected]>"
Expand All @@ -25,7 +25,7 @@
"orafce": {
"file": "sql/orafce.sql",
"docfile": "README.orafce",
"version": "3.20.0",
"version": "3.21.0",
"abstract": "Oracle's compatibility functions and packages"
}
},
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
MODULE_big = orafce
OBJS= parse_keyword.o convert.o file.o datefce.o magic.o others.o plvstr.o plvdate.o shmmc.o plvsubst.o utility.o plvlex.o alert.o pipe.o sqlparse.o putline.o assert.o plunit.o random.o aggregate.o orafce.o varchar2.o nvarchar2.o charpad.o charlen.o replace_empty_string.o
OBJS= regexp.o parse_keyword.o convert.o file.o datefce.o magic.o others.o plvstr.o plvdate.o shmmc.o plvsubst.o utility.o plvlex.o alert.o pipe.o sqlparse.o putline.o assert.o plunit.o random.o aggregate.o orafce.o varchar2.o nvarchar2.o charpad.o charlen.o replace_empty_string.o

EXTENSION = orafce

DATA = orafce--3.20.sql orafce--3.2--3.3.sql orafce--3.3--3.4.sql orafce--3.4--3.5.sql orafce--3.5--3.6.sql orafce--3.6--3.7.sql orafce--3.7--3.8.sql orafce--3.8--3.9.sql orafce--3.9--3.10.sql orafce--3.10--3.11.sql orafce--3.11--3.12.sql orafce--3.12--3.13.sql orafce--3.13--3.14.sql orafce--3.14--3.15.sql orafce--3.15--3.16.sql orafce--3.16--3.17.sql orafce--3.17--3.18.sql orafce--3.18--3.19.sql orafce--3.19--3.20.sql
DATA = orafce--3.21.sql orafce--3.2--3.3.sql orafce--3.3--3.4.sql orafce--3.4--3.5.sql orafce--3.5--3.6.sql orafce--3.6--3.7.sql orafce--3.7--3.8.sql orafce--3.8--3.9.sql orafce--3.9--3.10.sql orafce--3.10--3.11.sql orafce--3.11--3.12.sql orafce--3.12--3.13.sql orafce--3.13--3.14.sql orafce--3.14--3.15.sql orafce--3.15--3.16.sql orafce--3.16--3.17.sql orafce--3.17--3.18.sql orafce--3.18--3.19.sql orafce--3.19--3.20.sql orafce--3.20--3.21.sql
DOCS = README.asciidoc COPYRIGHT.orafce INSTALL.orafce

PG_CONFIG ?= pg_config
Expand Down
13 changes: 13 additions & 0 deletions builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,17 @@ extern PGDLLEXPORT Datum nvarchar2recv(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_replace_empty_strings(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_replace_null_strings(PG_FUNCTION_ARGS);

/* from regexp.c */
extern PGDLLEXPORT Datum orafce_regexp_instr(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_regexp_instr_no_start(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_regexp_instr_no_n(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_regexp_instr_no_endoption(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_regexp_instr_no_flags(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_regexp_instr_no_subexpr(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_textregexreplace_noopt(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_textregexreplace(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_textregexreplace_extended(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_textregexreplace_extended_no_n(PG_FUNCTION_ARGS);
extern PGDLLEXPORT Datum orafce_textregexreplace_extended_no_flags(PG_FUNCTION_ARGS);

#endif
38 changes: 21 additions & 17 deletions expected/regexp_func.out
Original file line number Diff line number Diff line change
Expand Up @@ -575,32 +575,32 @@ SELECT REGEXP_REPLACE('512.123.4567', '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:d

-- ORACLE> SELECT REGEXP_REPLACE('512.123.4567 612.123.4567', '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})', '(\1) \2-\3') FROM DUAL; -> (512) 123-4567 (612) 123-4567
SELECT oracle.REGEXP_REPLACE('512.123.4567 612.123.4567', '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})', '(\1) \2-\3');
regexp_replace
-------------------------------
(512) 123-4567 (612) 123-4567
regexp_replace
-----------------------------
(512) 123-4567 612.123.4567
(1 row)

-- ORACLE> SELECT REGEXP_REPLACE('number your street, zipcode town, FR', '( ){2,}', ' ') FROM DUAL; -> number your street, zipcode town, FR
SELECT oracle.REGEXP_REPLACE('number your street, zipcode town, FR', '( ){2,}', ' ');
regexp_replace
--------------------------------------
number your street, zipcode town, FR
regexp_replace
----------------------------------------------
number your street, zipcode town, FR
(1 row)

-- ORACLE> SELECT REGEXP_REPLACE('number your street,'||CHR(10)||' zipcode town, FR', '( ){2,}', ' ') FROM DUAL; -> number your street,
-- zipcode town, FR
SELECT oracle.REGEXP_REPLACE('number your street,'||CHR(10)||' zipcode town, FR', '( ){2,}', ' ');
regexp_replace
---------------------
number your street,+
zipcode town, FR
regexp_replace
-------------------------
number your street,+
zipcode town, FR
(1 row)

-- ORACLE> SELECT REGEXP_REPLACE('number your street, zipcode town, FR', '( ){2,}', ' ', 9) FROM DUAL; -> number your street, zipcode town, FR
SELECT oracle.REGEXP_REPLACE('number your street, zipcode town, FR', '( ){2,}', ' ', 9);
regexp_replace
----------------------------------------
number your street, zipcode town, FR
regexp_replace
--------------------------------------------
number your street, zipcode town, FR
(1 row)

-- ORACLE> SELECT REGEXP_REPLACE('number your street, zipcode town, FR', '( ){2,}', ' ', 9, 0) FROM DUAL; -> number your street, zipcode town, FR
Expand Down Expand Up @@ -695,7 +695,11 @@ SELECT oracle.REGEXP_REPLACE ('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, -1,
ERROR: argument 'occurrence' must be a positive number
-- ORACLE> SELECT REGEXP_REPLACE ('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 1, 'g') FROM DUAL; -> ORA-01760
SELECT oracle.REGEXP_REPLACE ('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 1, 'g');
ERROR: argument 'flags' has unsupported modifier(s).
regexp_replace
-----------------------
A PXstgreSQL function
(1 row)

--
-- Test NULL input in the regexp_* functions that must returned NULL except for the modifier
-- or regexp flag. There is an exception with regexp_replace(), if the pattern is null (second
Expand Down Expand Up @@ -892,7 +896,7 @@ SELECT oracle.REGEXP_REPLACE('1234', '\d', null);
SELECT oracle.REGEXP_REPLACE('1234', '\d', 'a', null);
regexp_replace
----------------

a234
(1 row)

SELECT oracle.REGEXP_REPLACE('1234', null, 'a', 2);
Expand All @@ -904,7 +908,7 @@ SELECT oracle.REGEXP_REPLACE('1234', null, 'a', 2);
SELECT oracle.REGEXP_REPLACE('1234', null, 'a', null);
regexp_replace
----------------

1234
(1 row)

SELECT oracle.REGEXP_REPLACE('1234', null, 'a', 1);
Expand All @@ -916,7 +920,7 @@ SELECT oracle.REGEXP_REPLACE('1234', null, 'a', 1);
SELECT oracle.REGEXP_REPLACE('1234', null, 'a', 1, null);
regexp_replace
----------------

1234
(1 row)

SELECT oracle.REGEXP_REPLACE('1234', '\d', 'a', 1, null);
Expand Down
64 changes: 64 additions & 0 deletions orafce--3.20--3.21.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- REGEXP_INSTR( string text, pattern text ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr_no_start'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_INSTR( string text, pattern text, position int ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text, integer)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr_no_n'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_INSTR( string text, pattern text, position int, occurence int ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text, integer, integer)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr_no_endoption'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_INSTR( string text, pattern text, position int, occurence int, return_opt int ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text, integer, integer, integer)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr_no_flags'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_INSTR( string text, pattern text, position int, occurence int, return_opt int, flags text ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text, integer, integer, integer, text)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr_no_subexpr'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_INSTR( string text, pattern text, position int, occurence int, return_opt int, flags text, group int ) -> integer
CREATE OR REPLACE FUNCTION oracle.regexp_instr(text, text, integer, integer, integer, text, integer)
RETURNS integer
AS 'MODULE_PATHNAME','orafce_regexp_instr'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_REPLACE( string text, pattern text, replace_string text ) -> text
CREATE OR REPLACE FUNCTION oracle.regexp_replace(text, text, text)
RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace_noopt'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_REPLACE( string text, pattern text, replace_string text, position int ) -> text
CREATE OR REPLACE FUNCTION oracle.regexp_replace(text, text, text, integer)
RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace_extended_no_n'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_REPLACE( string text, pattern text, replace_string text, position int, occurence int ) -> text
CREATE OR REPLACE FUNCTION oracle.regexp_replace(text, text, text, integer, integer)
RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace_extended_no_flags'
LANGUAGE 'c' IMMUTABLE;

-- REGEXP_REPLACE( string text, pattern text, replace_string text, position int, occurence int, flags text ) -> text
CREATE OR REPLACE FUNCTION oracle.regexp_replace(text, text, text, integer, integer, text)
RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace_extended'
LANGUAGE 'c' IMMUTABLE;

CREATE OR REPLACE FUNCTION oracle.regexp_replace(text, text, text, text)
RETURNS text
AS 'MODULE_PATHNAME','orafce_textregexreplace'
LANGUAGE 'c' IMMUTABLE;
Loading

0 comments on commit e1c125e

Please sign in to comment.