pax_global_header00006660000000000000000000000064122130043600014501gustar00rootroot0000000000000052 comment=25fdcd38a48af444c27b7eb8dc00190eb06d8c5e orafce-VERSION_3_0_6/000077500000000000000000000000001221300436000143155ustar00rootroot00000000000000orafce-VERSION_3_0_6/.gitignore000066400000000000000000000001411221300436000163010ustar00rootroot00000000000000*.o *.so *.so.* /.deps/ /orafunc.sql /orafunc.sql.in /sqlparse.c /sqlparse.h /sqlscan.c /results orafce-VERSION_3_0_6/COPYRIGHT.orafunc000066400000000000000000000017331221300436000172500ustar00rootroot00000000000000Orafce, Oracle API support Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. orafce-VERSION_3_0_6/INSTALL.orafunc000066400000000000000000000016011221300436000170000ustar00rootroot00000000000000Installation ============ This module is normally distributed as a PostgreSQL 'contrib' module. To install it from a pre-configured source tree run the following commands as a user with appropriate privileges from the orafce source directory: make make install Alternatively, if you have no source tree you can install using PGXS. Simply run the following commands the adminpack source directory: make USE_PGXS=1 make USE_PGXS=1 install To install Orafce functions in the database, either run the orafce.sql script using the pgAdmin SQL tool (and then close and reopen the connection to the freshly instrumented server), or run the script using psql, eg: psql -U postgres postgres < orafunc.sql Other administration tools that use this module may have different requirements, please consult the tool's documentation for further details. This package requires PostgreSQL 8.2 or later. orafce-VERSION_3_0_6/META.json000066400000000000000000000026651221300436000157470ustar00rootroot00000000000000{ "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.0.6", "maintainer": [ "Pavel Stehule ", "Takahiro Itagaki " ], "license": { "PostgreSQL": "http://www.postgresql.org/about/licence" }, "prereqs": { "runtime": { "requires": { "plpgsql": 0, "PostgreSQL": "8.1.0" }, "recommends": { "PostgreSQL": "9.2.0" } } }, "provides": { "pgtap": { "file": "sql/orafce.sql", "docfile": "README.orafce", "version": "3.0.6", "abstract": "Oracle's compatibility functions and packages" }, }, "resources": { "homepage": "http://www.pgsql.cz/index.php/Oracle_functionality_%28en%29", "repository": { "url": "https://github.com/orafce/orafce", "web": "https://github.com/orafce/orafce", "type": "git" } }, "generated_by": "Pavel Stehule", "meta-spec": { "version": "1.0.0", "url": "http://pgxn.org/meta/spec.txt" }, "tags": [ "oracle", "compatibility", "user function", "custom function", "intrerprocess communication", "read from file", "write to file", "bussiness calendar" ] } orafce-VERSION_3_0_6/Makefile000066400000000000000000000053131221300436000157570ustar00rootroot00000000000000MODULE_big = orafunc OBJS= 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 EXTENSION = orafce DATA_built = orafunc.sql DATA = uninstall_orafunc.sql orafce--3.0.6.sql orafce--unpackaged--3.0.6.sql DOCS = README.asciidoc COPYRIGHT.orafunc INSTALL.orafunc PG_CONFIG ?= pg_config # version as a number, e.g. 9.1.4 -> 901 VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}') INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)\.\([[:digit:]]\{1,\}\).*/\1*100+\2/' )))) REGRESS = orafunc dbms_output dbms_utility files ifeq ($(shell echo $$(($(INTVERSION) >= 804))),1) REGRESS += aggregates nlssort dbms_random endif REGRESS_OPTS = --load-language=plpgsql --schedule=parallel_schedule REGRESSION_EXPECTED = expected/orafunc.out expected/dbms_pipe_session_B.out ifeq ($(shell echo $$(($(INTVERSION) <= 802))),1) $(REGRESSION_EXPECTED): %.out: %1.out cp $< $@ else $(REGRESSION_EXPECTED): %.out: %2.out cp $< $@ endif installcheck: $(REGRESSION_EXPECTED) EXTRA_CLEAN = sqlparse.c sqlparse.h sqlscan.c y.tab.c y.tab.h orafunc.sql.in expected/orafunc.out expected/dbms_pipe_session_B.out ifndef USE_PGXS top_builddir = ../.. makefile_global = $(top_builddir)/src/Makefile.global ifeq "$(wildcard $(makefile_global))" "" USE_PGXS = 1 # use pgxs if not in contrib directory endif endif ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) else subdir = contrib/$(MODULE_big) include $(makefile_global) include $(top_srcdir)/contrib/contrib-global.mk endif ifeq ($(enable_nls), yes) ifeq ($(PORTNAME),win32) SHLIB_LINK += -lintl else SHLIB_LINK += -L$(libdir)/gettextlib endif endif # remove dependency to libxml2 and libxslt LIBS := $(filter-out -lxml2, $(LIBS)) LIBS := $(filter-out -lxslt, $(LIBS)) plvlex.o: sqlparse.o sqlparse.o: $(srcdir)/sqlscan.c $(srcdir)/sqlparse.h: $(srcdir)/sqlparse.c ; $(srcdir)/sqlparse.c: sqlparse.y ifdef BISON $(BISON) -d $(BISONFLAGS) -o $@ $< else ifdef YACC $(YACC) -d $(YFLAGS) -p cube_yy $< mv -f y.tab.c sqlparse.c mv -f y.tab.h sqlparse.h else bison -d $(BISONFLAGS) -o $@ $< endif endif $(srcdir)/sqlscan.c: sqlscan.l ifdef FLEX $(FLEX) $(FLEXFLAGS) -o'$@' $< else flex $(FLEXFLAGS) -o'$@' $< endif distprep: $(srcdir)/sqlparse.c $(srcdir)/sqlscan.c maintainer-clean: rm -f $(srcdir)/sqlparse.c $(srcdir)/sqlscan.c ifndef MAJORVERSION MAJORVERSION := $(basename $(VERSION)) endif orafunc.sql.in: if [ -f orafunc-$(MAJORVERSION).sql ] ; \ then \ cat orafunc-common.sql orafunc-$(MAJORVERSION).sql > orafunc.sql.in; \ else \ cat orafunc-common.sql orafunc-common-2.sql > orafunc.sql.in; \ fi orafce-VERSION_3_0_6/NEWS000066400000000000000000000004371221300436000150200ustar00rootroot00000000000000Orafce News - History of user-visible changes Copyright (C) 2008-2012 Orafce Global Development Group Version 3.0.6 - 8. Sep 2013 * PostgreSQL 9.3 compilation * some cleaning, fixes, much more regress tests Version 3.0.5 - X Dec 2012 * PostgreSQL 9.1/9.2 compilation * ... TODO ... orafce-VERSION_3_0_6/README.asciidoc000066400000000000000000000523471221300436000167650ustar00rootroot00000000000000= Orafce - Oracle's compatibility functions and packages Functions and operators that emulate a subset of functions and packages from the Oracle RDBMS. == Oracle functions and Oracle packages This module contains some useful function which can help with porting Oracle application to PostgreSQL or can be useful generally. Built-in Oracle date functions have been tested against Oracle 10 for comformance. Date ranges from 1960 to 2070 work correctly. Dates before 1100-03-01 cannot be verified due to a bug in Oracle. All functions are fully compatible with Oracle and respect all known format strings. Detailed description you can find on internet. Find keywords oracle round trunc date iyyy. == List of format strings for trunc, round functions ---- Y,YY,YYY,YYYY,SYYY,SYEAR year I,IY,IYY,IYYY iso year Q, quarter WW week, day as first day of year IW week, beginning Monday W week, day as first day of month DAY,DY,D first day of week, sunday MONTH,MON,MM,RM month CC,SCC century DDD,DD,J day HH,HH12,HH24 hour MI minute ---- Functions round up. That is, a date of July 1st will be rounded to the next year. The 16th of July will be rounded to August. == Date Functions * add_months(date, integer) date - Returns date plus n months + ----- add_months(date '2005-05-31',1) -> 2005-06-30 ----- * last_date(date) date - Returns last day of the month based on a date value + ---- last_day(date '2005-05-24') -> 2005-05-31 ---- * next_day(date, text) date - Returns the first weekday that is greater than a date value + ---- next_day(date '2005-05-24', 'monday') -> 2005-05-30 ---- * next_day(date, integer) date - Same as above. The second argument should be 1..7 and interpreted as Sunday..Satday. + ---- next_day(date '2005-05-24', 1) -> 2005-05-30 ---- * months_between(date, date) float8 - Returns the number of months between date1 and date2. If a fractional month is calculated, the months_between function calculates the fraction based on a 31-day month. + ---- months_between(date '1995-02-02', date '1995-01-01') -> 1.0322580645161 ---- * trunc(date, text) date - truncate date according to the specified format + ---- trunc(date '2005-07-12', 'iw') -> 2005-07-11 ---- * round(date, text) date - will round dates according to the specified format + ---- round(date '2005-07-12', 'yyyy') -> 2006-01-01 ---- == Table dual PostgreSQL does not need Oracle's table 'dual', but since it is intensively used by Oracle users, we create it. == Package dbms_output PostgreSQL sends information to the client via RAISE NOTICE. Oracle uses dbms_output.put_line(). This works differently to RAISE NOTICE. Oracle has a session queue, put_line() adds a line to the queue and the function get_line() reads from queue. If flag 'serveroutput' is set, then client over all sql statements reads queue. You can use: ---- select dbms_output.enable(); select dbms_output.put_line('first_line'); select dbms_output.put_line('next_line'); select * from dbms_output.get_lines(0); ---- or ---- select dbms_output.enable(); select dbms_output.serveroutput('t'); select dbms_output.put_line('first_line'); ---- This package contains the following functions: enable(), disable(), serveroutput(), put(), put_line(), new_line(), get_line(), get_lines(). The package queue is implemented in the session's local memory. == Package utl_file This package allows PL/pgSQL prgrams read from and write to any files that are accessible from server. Every session can open maximaly ten files and max line size is 32K. This package contains functions: * utl_file.fclose(file utl_file.file_type) - close file * utl_file.fclose_all() - close all files * utl_file.fcopy(src_location, src_filename, dest_location, dest_filename[, start_line][, end_line]) - copy text file * utl_file.fflush(file utl_file.file_type) - flushes all data from buffers * utl_file.fgetattr(location, filename) - get file attributes * utl_file.fopen(location text, filename text, file_mode text [, maxlinesize int] [, encoding name]) utl_file.file_type - open file * utl_file.fremove(location, filename) - remove file * utl_file.frename(location, filename, dest_dir, dest_file[, overwrite]) - rename file * utl_file.get_line(file utl_file.file_type) text - read one line from file * utl_file.get_nextline(file utl_file.file_type) text - read one line from file or returns NULL * utl_file.is_open(file utl_file.file_type) bool - returns true, if file is opened * utl_file.new_line(file utl_file.file_type [,rows int]) - puts some new line chars to file * utl_file.put(file utl_file.file_type, buffer text) - puts buffer to file * utl_file.put_line(file utl_file.file_type, buffer text) - puts line to file * utl_file.putf(file utl_file.file_type, format buffer [,arg1 text][,arg2 text][..][,arg5 text]) - put formated text into file * utl_file.tmpdir() - get path of temp directory Because PostgreSQL doesn't support call by reference, some function's are gently different: fclose and get_line. ---- declare f utl_file.file_type; begin f := utl_file.fopen('/tmp', 'sample.txt', 'r'); <> loop begin raise notice '%', utl_file.get_line(f); exception when no_data_found then exit readl; end; end loop; f := fclose(f); end; ---- or second (with PostgreSQL specific function get_nextline) ---- declare f utl_file.file_type; line text; begin f := utl_file.fopen('/tmp', 'sample.txt', 'r'); loop line := utl_file.get_nextline(f); exit when line is NULL; raise notice '%', line; exception when others then utl_file.fclose_all(); end; ---- Before using package you have to set table utl_file.utl_file_dir. This contains all allowed directories without ending symbol ('/' or '\'). On WinNT platform you have to put locality parametr with ending symbol '\' everytime. == Package dbms_pipe This package is an emulation of Oracle's package dbms_pipe. It provides inter-session comunication. You can send and read any message with or without waiting; list active pipes; set a pipe as private or public; and, use explicit or implicit pipes. The maximum number of pipes is 50. Shared memory is used to send messages. An example follows: ---- -- Session A select dbms_pipe.create_pipe('my_pipe',10,true); -- explicit pipe creating select dbms_pipe.pack_message('neco je jinak'); select dbms_pipe.pack_message('anything is else'); select dbms_pipe.send_message('my_pipe',20,0); -- change limit and send without waiting select * from dbms_pipe.db_pipes; -- list of current pipes -- Session B select dbms_pipe.receive_message('my_pipe',1); -- wait max 1 sec for message select dbms_pipe.next_item_type(); -- -> 11, text select dbms_pipe.unpack_message_text(); select dbms_pipe.next_item_type(); -- -> 11, text select dbms_pipe.unpack_message_text(); select dbms_pipe.next_item_type(); -- -> 0, no more items select dbms_pipe.remove_pipe('my_pipe'); ---- There are some differences compared to Oracle, however: * limit for pipes isn't in bytes but in elements in pipe * you can send message without waiting * you can send empty messages * next_item_type knows about TIMESTAMP (type 13) * PostgreSQL don't know about the RAW type, use bytea instead == Package dbms_alert Another means of inter-process communication. ---- -- Session A select dbms_alert.register('boo'); select * from dbms_alert.waitany(10); -- Session B select dbms_alert.register('boo'); select * from dbms_alert.waitany(10); -- Session C select dbms_alert.signal('boo','Nice day'); ---- == Package PLVdate This module contains some function for working with bussines days from package PLVdate. Detailed documentation can be found in PLVision library. This package is multicultural, but default configurations are only for european countries (see source code). You should define your own non-business days (max 50 days) and own holidays (max 30 days). A holiday is any non-business day, which is same every year. For example, Christmas day in Western countries. === Functions * plvdate.add_bizdays(day date, days int) date - Get the date created by adding business days to a date * plvdate.nearest_bizday(day date) date - Get the nearest business date to a given date, user defined * plvdate.next_bizday(day date) date - Get the next business date from a given date, user defined * plvdate.bizdays_between(day1 date, day2 date) int - Get the number of business days between two dates * plvdate.prev_bizday(day date) date - Get the previous business date from a given date * plvdate_isbizday(date) bool - Call this function to determine if a date is a business day * plvdate.set_nonbizday(dow varchar) - Set day of week as non bussines day * plvdate.unset_nonbizday(dow varchar) - Unset day of week as non bussines day * plvdate.set_nonbizday(day date) - Set day as non bussines day * plvdate.unset_nonbizday(day date) - Unset day as non bussines day * plvdate.set_nonbizday(day date, repeat bool) - Set day as non bussines day, if 'repeat' is true, then day is nonbiz every year * plvdate.unset_nonbizday(day date, repeat bool) - Unset day as non bussines day, if 'repeat' is true, then day is nonbiz every year * plvdate.use_easter() - Easter Sunday and easter monday will be holiday * plvdate.unuse_easter(); * plvdate.use_easter(useit boolean); * plvdate.using_easter() bool - If we use easter then returns true * plvdate.include_start() - Include starting date in bizdays_between calculation * plvdate.noinclude_start(); * plvdate.include_start(include boolean); * plvdate.including_start() bool; * plvdate.default_holidays(varchar) - load default configurations. You can use the following configurations: Czech, German, Austria, Poland, Slovakia, Russia, GB and USA at this moment. * configuration contains only common holidays for all regions. You can add your own regional holiday with plvdate.set_nonbizday(nonbizday, true) Example: ---- postgres=# select plvdate.default_holidays('czech'); default_holidays ----------------- (1 row) postgres=# select to_char(current_date, 'day'), plvdate.next_bizday(current_date), to_char(plvdate.next_bizday(current_date),'day'); to_char | next_bizday | to_char ----------+-------------+----------- saturday | 2006-03-13 | monday (1 row) ---- Change for non-European environment: ---- select plvdate.unset_nonbizday('saturday'); select plvdate.unset_nonbizday('sunday'); select plvdate.set_nonbizday('friday'); select plvdate.set_nonbizday('2006-05-19', true); select plvdate.unuse_easter(); ---- == Package PLVstr and PLVchr This package contains some useful string and character functions. Each function supports positive and negative offsets -- i.e., offset from the end of the string. For example: ---- plvstr.left('abcdef',2) -> ab plvstr.left('abcdef',-2) -> abcd plvstr.substr('abcdef',1,1) -> a plvstr.substr('abcdef',-1,1) -> f plvstr.substr('abcde',-2,1) -> d ---- List of functions: * plvstr.normalize(str text) - Normalize string - Replace white chars by space, replace spaces by space * plvstr.is_prefix(str text, prefix text, cs bool) - Returns true, if prefix is prefix of str * plvstr.is_prefix(str text, prefix text) - Returns true, if prefix is prefix of str * plvstr.is_prefix(str int, prefix int) - Returns true, if prefix is prefix of str * plvstr.is_prefix(str bigint, prefix bigint) - Returns true, if prefix is prefix of str * plvstr.substr(str text, start int, len int) - Returns substring started on start_in to end * plvstr.substr(str text, start int) - Returns substring started on start_in to end * plvstr.instr(str text, patt text, start int, nth int) - Search pattern in string * plvstr.instr(str text, patt text, start int) - Search pattern in string * plvstr.instr(str text, patt text) - Search pattern in string * plvstr.lpart(str text, div text, start int, nth int, all_if_notfound bool) - Call this function to return the left part of a string * plvstr.lpart(str text, div text, start int, nth int) - Call this function to return the left part of a string * plvstr.lpart(str text, div text, start int) - Call this function to return the left part of a string * plvstr.lpart(str text, div text) - Call this function to return the left part of a string * plvstr.rpart(str text, div text, start int, nth int, all_if_notfound bool) - Call this function to return the right part of a string * plvstr.rpart(str text, div text, start int, nth int) - Call this function to return the right part of a string * plvstr.rpart(str text, div text, start int) - Call this function to return the right part of a string * plvstr.rpart(str text, div text) - Call this function to return the right part of a string * plvstr.lstrip(str text, substr text, num int) - Call this function to remove characters from the beginning * plvstr.lstrip(str text, substr text) - Call this function to remove characters from the beginning * plvstr.rstrip(str text, substr text, num int) - Call this function to remove characters from the end * plvstr.rstrip(str text, substr text) - Call this function to remove characters from the end * plvstr.rvrs(str text, start int, _end int) - Reverse string or part of string * plvstr.rvrs(str text, start int) - Reverse string or part of string * plvstr.rvrs(str text) - Reverse string or part of string * plvstr.left(str text, n int) - Returns firs num_in charaters. You can use negative num_in * plvstr.right(str text, n int) - Returns last num_in charaters. You can use negative num_ni * plvstr.swap(str text, replace text, start int, lengh int) - Replace a substring in a string with a specified string * plvstr.swap(str text, replace text) - Replace a substring in a string with a specified string * plvstr.betwn(str text, start int, _end int, inclusive bool) - Find the Substring Between Start and End Locations * plvstr.betwn(str text, start text, _end text, startnth int, endnth int, inclusive bool, gotoend bool) - Find the Substring Between Start and End Locations * plvstr.betwn(str text, start text, _end text) - Find the Substring Between Start and End Locations * plvstr.betwn(str text, start text, _end text, startnth int, endnth int) - Find the Substring Between Start and End Locations * plvchr.nth(str text, n int) - Call this function to return the Nth character in a string * plvchr.first(str text) - Call this function to return the first character in a string * plvchr.last(str text) - Call this function to return the last character in a string * plvchr.is_blank(c int) - Is blank * plvchr.is_blank(c text) - Is blank * plvchr.is_digit(c int) - Is digit * plvchr.is_digit(c text) - Is digit * plvchr.is_quote(c int) - Is quote * plvchr.is_quote(c text) - Is quote * plvchr.is_other(c int) - Is other * plvchr.is_other(c text) - Is other * plvchr.is_letter(c int) - Is letter * plvchr.is_letter(c text) - Is letter * plvchr.char_name(c text) - Returns the name of the character to ascii code as a VARCHAR. * plvchr.quoted1(str text) - Quoted text between ''' * plvchr.quoted2(str text) - Quoted text between '"' * plvchr.stripped(str text, char_in text) - Strips a string of all instances of the specified characters == Package PLVsubst The PLVsubst package performs string substitutions based on a substitution keyword. * plvsubst.string(template_in text, vals_in text[]) - Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list * plvsubst.string(template_in text, vals_in text[], subst_in text) * plvsubst.string(template_in text, vals_in text, delim_in text) * plvsubst.string(template_in text, vals_in text, delim_in text, subst_in text) * plvsubst.setsubst(str text) - Set substitution keyword to default '%s' * plvsubst.subst() - Retrieve substitution keyword Examples: ---- select plvsubst.string('My name is %s %s.', ARRAY['Pavel','Stěhule']); string -------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s %s.', 'Pavel,Stěhule'); string -------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is $$ $$.', 'Pavel|Stěhule','|','$$'); string -------------------------- My name is Pavel Stěhule. (1 row) ---- == Package DBMS_utility * dms_utility.format_call_stack() -- return a formatted string with content of call stack ---- postgres=# select foo2(); foo2 --------------------------------- ----- Call Stack ----- line object number statement name 1 return function foo 1 return function foo1 1 return function foo2 (1 row) ---- == Package PLVlex This package isn't compatible with original PLVlex. ---- postgres=# select * from plvlex.tokens('select * from a.b.c join d ON x=y', true, true); pos | token | code | class | separator | mod ----+--------+------+---------+-----------+------ 0 | select | 527 | KEYWORD | | 7 | * | 42 | OTHERS | | self 9 | from | 377 | KEYWORD | | 25 | a.b.c | | IDENT | | 20 | join | 418 | KEYWORD | | 25 | d | | IDENT | | 27 | on | 473 | KEYWORD | | 30 | x | | IDENT | | 31 | = | 61 | OTHERS | | self 32 | y | | IDENT | | (10 rows) ---- Warning: Keyword's codes can be changed between PostgreSQL versions! o plvlex.tokens(str text, skip_spaces bool, qualified_names bool) - Returns table of lexical elements in str. == DBMS_ASSERT This package protect user input against SQL injection. * dbms_assert.enquote_literal(varchar) varchar - Add leading and trailing quotes, verify that all single quotes are paired with adjacent single quotes. * dbms_assert.enquote_name(varchar [, boolean]) varchar - Enclose name in double quotes. Optional second parameter ensure loweralize of name. Attention - On Oracle is second parameter capitalize! * dbms_assert.noop(varchar) varchar - Returns value without any checking. * dbms_assert.qualified_sql_name(varchar) varchar - This function verifies that the input string is qualified SQL name. * dbms_assert.schema_name(varchar) varchar - Function verifies that input string is an existing schema name. * dbms_assert.simple_sql_name(varchar) varchar -This function verifies that the input string is simple SQL name. * dbms_assert.object_name(varchar) varchar - Verifies that input string is qualified SQL identifier of an existing SQL object. == PLUnit This unit contains some assert functions. * plunit.assert_true(bool [, varchar]) - Asserts that the condition is true. * plunit.assert_false(bool [, varchar]) - Asserts that the condition is false. * plunit.assert_null(anyelement [, varchar]) - Asserts that the actual is null. * plunit.assert_not_null(anyelement [, varchar]) - Asserts that the actual isn't null. * plunit.assert_equals(anyelement, anyelement [, double precision] [, varchar]) - Asserts that expected and actual are equal. * plunit.assert_not_equals(anyelement, anyelement [, double precision] [, varchar]) - Asserts that expected and actual are equal. * plunit.fail([varchar]) - Fail can be used to cause a test procedure to fail immediately using the supplied message. == Package DBMS_random * dbms_random.initialize(int) - Initialize package with a seed value. * dbms_random.normal() - Returns random numbers in a standard normal distribution. * dbms_random.random() - Returns random number from -2^31 .. 2^31. * dbms_random.seed(int) * dbms_random.seed(text) - Reset seed value. * dbms_random.string(opt text(1), len int) - Create random string * dbms_random.terminate() - Terminate package (do nothing in Pg) * dbms_random.value() - Returns a random number from [0.0 - 1.0) * dbms_random.value(low double precision, high double precision) - Returns a random number from [low - high) == Others functions This module contains implementation of functions: concat, nvl, nvl2, lnnvl, decode, bitand, nanvl, sinh, cosh, tanh and oracle.substr. * oracle.substr(str text, start int, len int) - Oracle compatible substring * oracle.substr(str text, start int) - Oracle compatible substring * pg_catalog.listagg(str text [, separator text]) - aggregate values to list * pg_catalog.median(float4) - calculate a median * pg_catalog.median(float8) - calculate a median You might need to set search_path to 'oracle, pg_catalog, "$user", public' because oracle.substr is installed side-by-side with pg_catalog.substr. == TODO * better documentation * better seralization in dbms_pipe (via _send and _recv functions) * alter shared memory structures by temporary tables: only locks are in shmem, (bitmaps), data in tmp tbl == License This module is released under BSD licence. == Contributors The project was founded in 2008 by Pavel Stehule . Other contributors: * Peter Eisentraut (petere) * Gavin Sherry (swm) * Pavel Stehule (okbob) * Heikki Linnakangas (hlinnaka) * Gabriele Bartolini (gbartolini) * Zdenek Kotala (hlipa) * Takahiro Itagaki (itagaki) * Marco Nenciarini (mnencia) * Pavan Deolasee (pavanvd) * Jeffrey Cohen (jcohen) * Amit Langote (amitlan) * Rahila Syed (rahila) * Beena Emerson (b-emerson) orafce-VERSION_3_0_6/aggregate.c000066400000000000000000000241561221300436000164170ustar00rootroot00000000000000#include "postgres.h" #include "funcapi.h" #include "orafunc.h" #if PG_VERSION_NUM >= 80400 #include "utils/builtins.h" #endif #include "builtins.h" #include "lib/stringinfo.h" PG_FUNCTION_INFO_V1(orafce_listagg1_transfn); PG_FUNCTION_INFO_V1(orafce_listagg2_transfn); PG_FUNCTION_INFO_V1(orafce_listagg_finalfn); PG_FUNCTION_INFO_V1(orafce_median4_transfn); PG_FUNCTION_INFO_V1(orafce_median4_finalfn); PG_FUNCTION_INFO_V1(orafce_median8_transfn); PG_FUNCTION_INFO_V1(orafce_median8_finalfn); typedef struct { int alen; /* allocated length */ int nextlen; /* next allocated length */ int nelems; /* number of valid entries */ union { float4 *float4_values; float8 *float8_values; } d; } MedianState; int orafce_float4_cmp(const void *a, const void *b); int orafce_float8_cmp(const void *a, const void *b); #if PG_VERSION_NUM >= 80400 && PG_VERSION_NUM < 90000 static int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext) { if (fcinfo->context && IsA(fcinfo->context, AggState)) { if (aggcontext) *aggcontext = ((AggState *) fcinfo->context)->aggcontext; return 1; } else if (fcinfo->context && IsA(fcinfo->context, WindowAggState)) { if (aggcontext) *aggcontext = ((WindowAggState *) fcinfo->context)->wincontext; return 2; } /* this is just to prevent "uninitialized variable" warnings */ if (aggcontext) *aggcontext = NULL; return 0; } #endif /**************************************************************** * listagg * * Concates values and returns string. * * Syntax: * FUNCTION listagg(string varchar, delimiter varchar = '') * RETURNS varchar; * * Note: any NULL value is ignored. * ****************************************************************/ #if PG_VERSION_NUM >= 80400 /* subroutine to initialize state */ static StringInfo makeStringAggState(FunctionCallInfo fcinfo) { StringInfo state; MemoryContext aggcontext; MemoryContext oldcontext; if (!AggCheckCallContext(fcinfo, &aggcontext)) { /* cannot be called directly because of internal-type argument */ elog(ERROR, "listagg_transfn called in non-aggregate context"); } /* * Create state in aggregate context. It'll stay there across subsequent * calls. */ oldcontext = MemoryContextSwitchTo(aggcontext); state = makeStringInfo(); MemoryContextSwitchTo(oldcontext); return state; } static void appendStringInfoText(StringInfo str, const text *t) { appendBinaryStringInfo(str, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)); } #endif Datum orafce_listagg1_transfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 80400 StringInfo state; state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0); /* Append the element unless null. */ if (!PG_ARGISNULL(1)) { if (state == NULL) state = makeStringAggState(fcinfo); appendStringInfoText(state, PG_GETARG_TEXT_PP(1)); /* value */ } /* * The transition type for string_agg() is declared to be "internal", * which is a pass-by-value type the same size as a pointer. */ PG_RETURN_POINTER(state); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } Datum orafce_listagg2_transfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 90000 return string_agg_transfn(fcinfo); #elif PG_VERSION_NUM >= 80400 StringInfo state; state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0); /* Append the value unless null. */ if (!PG_ARGISNULL(1)) { /* On the first time through, we ignore the delimiter. */ if (state == NULL) state = makeStringAggState(fcinfo); else if (!PG_ARGISNULL(2)) appendStringInfoText(state, PG_GETARG_TEXT_PP(2)); /* delimiter */ appendStringInfoText(state, PG_GETARG_TEXT_PP(1)); /* value */ } /* * The transition type for string_agg() is declared to be "internal", * which is a pass-by-value type the same size as a pointer. */ PG_RETURN_POINTER(state); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } Datum orafce_listagg_finalfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 90000 return string_agg_finalfn(fcinfo); #elif PG_VERSION_NUM >= 80400 StringInfo state; /* cannot be called directly because of internal-type argument */ Assert(AggCheckCallContext(fcinfo, NULL)); state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0); if (state != NULL) PG_RETURN_TEXT_P(cstring_to_text(state->data)); else PG_RETURN_NULL(); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } #if PG_VERSION_NUM >= 80400 static MedianState * accumFloat4(MedianState *mstate, float4 value, MemoryContext aggcontext) { MemoryContext oldcontext; if (mstate == NULL) { /* First call - initialize */ oldcontext = MemoryContextSwitchTo(aggcontext); mstate = palloc(sizeof(MedianState)); mstate->alen = 1024; mstate->nextlen = 2 * 1024; mstate->nelems = 0; mstate->d.float4_values = palloc(mstate->alen * sizeof(float4)); MemoryContextSwitchTo(oldcontext); } else { /* enlarge float4_values if needed */ if (mstate->nelems >= mstate->alen) { int newlen = mstate->nextlen; oldcontext = MemoryContextSwitchTo(aggcontext); mstate->nextlen += mstate->alen; mstate->alen = newlen; mstate->d.float4_values = repalloc(mstate->d.float4_values, mstate->alen * sizeof(float4)); MemoryContextSwitchTo(oldcontext); } } mstate->d.float4_values[mstate->nelems++] = value; return mstate; } static MedianState * accumFloat8(MedianState *mstate, float8 value, MemoryContext aggcontext) { MemoryContext oldcontext; if (mstate == NULL) { /* First call - initialize */ oldcontext = MemoryContextSwitchTo(aggcontext); mstate = palloc(sizeof(MedianState)); mstate->alen = 1024; mstate->nextlen = 2 * 1024; mstate->nelems = 0; mstate->d.float8_values = palloc(mstate->alen * sizeof(float8)); MemoryContextSwitchTo(oldcontext); } else { /* enlarge float4_values if needed */ if (mstate->nelems >= mstate->alen) { int newlen = mstate->nextlen; oldcontext = MemoryContextSwitchTo(aggcontext); mstate->nextlen += mstate->alen; mstate->alen = newlen; mstate->d.float8_values = repalloc(mstate->d.float8_values, mstate->alen * sizeof(float8)); MemoryContextSwitchTo(oldcontext); } } mstate->d.float8_values[mstate->nelems++] = value; return mstate; } #endif Datum orafce_median4_transfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 80400 MemoryContext aggcontext; MedianState *state = NULL; float4 elem; if (!AggCheckCallContext(fcinfo, &aggcontext)) { /* cannot be called directly because of internal-type argument */ elog(ERROR, "median4_transfn called in non-aggregate context"); } state = PG_ARGISNULL(0) ? NULL : (MedianState *) PG_GETARG_POINTER(0); if (PG_ARGISNULL(1)) PG_RETURN_POINTER(state); elem = PG_GETARG_FLOAT4(1); state = accumFloat4(state, elem, aggcontext); PG_RETURN_POINTER(state); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } int orafce_float4_cmp(const void *a, const void *b) { return (int) (*((float4 *) a) - *((float4*) b)); } Datum orafce_median4_finalfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 80400 MedianState *state = NULL; int lidx; int hidx; float4 result; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); state = (MedianState *) PG_GETARG_POINTER(0); if (state == NULL) PG_RETURN_NULL(); qsort(state->d.float4_values, state->nelems, sizeof(float4), orafce_float4_cmp); lidx = state->nelems / 2 + 1 - 1; hidx = (state->nelems + 1) / 2 - 1; if (lidx == hidx) result = state->d.float4_values[lidx]; else result = (state->d.float4_values[lidx] + state->d.float4_values[hidx]) / 2.0f; PG_RETURN_FLOAT4(result); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } Datum orafce_median8_transfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 80400 MemoryContext aggcontext; MedianState *state = NULL; float8 elem; if (!AggCheckCallContext(fcinfo, &aggcontext)) { /* cannot be called directly because of internal-type argument */ elog(ERROR, "median4_transfn called in non-aggregate context"); } state = PG_ARGISNULL(0) ? NULL : (MedianState *) PG_GETARG_POINTER(0); if (PG_ARGISNULL(1)) PG_RETURN_POINTER(state); elem = PG_GETARG_FLOAT8(1); state = accumFloat8(state, elem, aggcontext); PG_RETURN_POINTER(state); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } int orafce_float8_cmp(const void *a, const void *b) { return (int) (*((float8 *) a) - *((float8*) b)); } Datum orafce_median8_finalfn(PG_FUNCTION_ARGS) { #if PG_VERSION_NUM >= 80400 MedianState *state = NULL; int lidx; int hidx; float8 result; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); state = (MedianState *) PG_GETARG_POINTER(0); if (state == NULL) PG_RETURN_NULL(); qsort(state->d.float8_values, state->nelems, sizeof(float8), orafce_float8_cmp); lidx = state->nelems / 2 + 1 - 1; hidx = (state->nelems + 1) / 2 - 1; if (lidx == hidx) result = state->d.float8_values[lidx]; else result = (state->d.float8_values[lidx] + state->d.float8_values[hidx]) / 2.0; PG_RETURN_FLOAT8(result); #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not suppported"), errdetail("This functions is blocked on PostgreSQL 8.3 and older (from security reasons)."))); PG_RETURN_NULL(); #endif } orafce-VERSION_3_0_6/alert.c000066400000000000000000000526201221300436000155750ustar00rootroot00000000000000#include "postgres.h" #include "executor/spi.h" #if PG_VERSION_NUM >= 90300 #include "access/htup_details.h" #endif #include "catalog/pg_type.h" #include "commands/trigger.h" #include "funcapi.h" #include "miscadmin.h" #include "string.h" #include "storage/lwlock.h" #include "utils/timestamp.h" #include "orafunc.h" #include "builtins.h" #include "pipe.h" #include "shmmc.h" #include "utils/rel.h" PG_FUNCTION_INFO_V1(dbms_alert_register); PG_FUNCTION_INFO_V1(dbms_alert_remove); PG_FUNCTION_INFO_V1(dbms_alert_removeall); PG_FUNCTION_INFO_V1(dbms_alert_set_defaults); PG_FUNCTION_INFO_V1(dbms_alert_signal); PG_FUNCTION_INFO_V1(dbms_alert_waitany); PG_FUNCTION_INFO_V1(dbms_alert_waitone); PG_FUNCTION_INFO_V1(dbms_alert_defered_signal); extern unsigned int sid; float8 sensitivity = 250.0; extern LWLockId shmem_lock; #ifndef _GetCurrentTimestamp #define _GetCurrentTimestamp() GetCurrentTimestamp() #endif #ifndef GetNowFloat #ifdef HAVE_INT64_TIMESTAMP #define GetNowFloat() ((float8) _GetCurrentTimestamp() / 1000000.0) #else #define GetNowFloat() _GetCurrentTimestamp() #endif #endif #define TDAYS (1000*24*3600) /* * There are maximum 30 events and 255 collaborating sessions * */ alert_event *events; alert_lock *locks; alert_lock *session_lock = NULL; #define NOT_FOUND -1 #define NOT_USED -1 /* * Compare text and cstr */ static int textcmpm(text *txt, char *str) { int retval; char *p; int len; len = VARSIZE(txt) - VARHDRSZ; p = VARDATA(txt); while (len-- && *p != '\0') { if (0 != (retval = *p++ - *str++)) return retval; } if (len > 0) return 1; if (*str != '\0') return -1; return 0; } /* * find or create event rec * */ static alert_lock* find_lock(int sid, bool create) { int i; int first_free = NOT_FOUND; if (session_lock != NULL) return session_lock; for (i = 0; i < MAX_LOCKS; i++) { if (locks[i].sid == sid) return &locks[i]; else if (locks[i].sid == NOT_USED && first_free == NOT_FOUND) first_free = i; } if (create) { if (first_free != NOT_FOUND) { locks[first_free].sid = sid; locks[first_free].echo = NULL; session_lock = &locks[first_free]; return &locks[first_free]; } else ereport(ERROR, (errcode(ERRCODE_ORA_PACKAGES_LOCK_REQUEST_ERROR), errmsg("lock request error"), errdetail("Failed to create session lock."), errhint("There are too many collaborating sessions. Increase MAX_LOCKS in 'pipe.h'."))); } return NULL; } static alert_event* find_event(text *event_name, bool create, int *event_id) { int i; for (i = 0; i < MAX_EVENTS;i++) { if (events[i].event_name != NULL && textcmpm(event_name,events[i].event_name) == 0) { if (event_id != NULL) *event_id = i; return &events[i]; } } if (create) { for (i=0; i < MAX_EVENTS; i++) { if (events[i].event_name == NULL) { events[i].event_name = ora_scstring(event_name); events[i].max_receivers = 0; events[i].receivers = NULL; events[i].messages = NULL; events[i].receivers_number = 0; if (event_id != NULL) *event_id = i; return &events[i]; } } ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("event registeration error"), errdetail("Too many registered events."), errhint("There are too many collaborating sessions. Increase MAX_EVENTS in 'pipe.h'."))); } return NULL; } static void register_event(text *event_name) { alert_event *ev; int *new_receivers; int first_free; int i; find_lock(sid, true); ev = find_event(event_name, true, NULL); first_free = NOT_FOUND; for (i = 0; i < ev->max_receivers; i++) { if (ev->receivers[i] == sid) return; /* event is registered */ if (ev->receivers[i] == NOT_USED && first_free == NOT_FOUND) first_free = i; } /* * I can have a maximum of MAX_LOCKS receivers for one event. * Array receivers is increased for 16 fields */ if (first_free == NOT_FOUND) { if (ev->max_receivers + 16 > MAX_LOCKS) ereport(ERROR, (errcode(ERRCODE_ORA_PACKAGES_LOCK_REQUEST_ERROR), errmsg("lock request error"), errdetail("Failed to create session lock."), errhint("There are too many collaborating sessions. Increase MAX_LOCKS in 'pipe.h'."))); /* increase receiver's array */ new_receivers = (int*)salloc((ev->max_receivers + 16)*sizeof(int)); for (i = 0; i < ev->max_receivers + 16; i++) { if (i < ev->max_receivers) new_receivers[i] = ev->receivers[i]; else new_receivers[i] = NOT_USED; } ev->max_receivers += 16; if (ev->receivers) ora_sfree(ev->receivers); ev->receivers = new_receivers; first_free = ev->max_receivers - 16; } ev->receivers_number += 1; ev->receivers[first_free] = sid; } /* * Remove receiver from default receivers of message, * I expect clean all message_items */ static void unregister_event(int event_id, int sid) { alert_event *ev; int i; ev = &events[event_id]; if (ev->receivers_number > 0) { for (i = 0; i < ev->max_receivers; i++) { if (ev->receivers[i] == sid) { ev->receivers[i] = NOT_USED; ev->receivers_number -= 1; break; } } if (ev->receivers_number == 0) { ora_sfree(ev->receivers); ora_sfree(ev->event_name); ev->receivers = NULL; ev->event_name = NULL; } } } /* * remove receiver from list of receivers. * Message has always minimal one receiver * Return true, if exist other receiver */ static bool remove_receiver(message_item *msg, int sid) { int i; bool find_other = false; bool found = false; for (i = 0; i < msg->receivers_number; i++) { if (msg->receivers[i] == sid) { msg->receivers[i] = NOT_USED; found = true; } else if (msg->receivers[i] != NOT_USED) { find_other = true; } if (found && find_other) break; } return find_other; } /* * * Reads message message_id for user sid. If arg:all is true, * then get any message. If arg:remove_all then remove all * signaled messages for sid. If arg:filter_message then * skip other messages than message_id, else read and remove * all others messages than message_id. * */ static char* find_and_remove_message_item(int message_id, int sid, bool all, bool remove_all, bool filter_message, int *sleep, char **event_name) { alert_lock *alck; int _message_id; char *result = NULL; if (sleep != NULL) *sleep = 0; alck = find_lock(sid, false); if (event_name) *event_name = NULL; if (alck != NULL && alck->echo != NULL) { /* if I have registered and created item */ struct _message_echo *echo, *last_echo; echo = alck->echo; last_echo = NULL; while (echo != NULL) { char *message_text; bool destroy_msg_item = false; if (filter_message && echo->message_id != message_id) { last_echo = echo; echo = echo->next_echo; continue; } message_text = echo->message->message; _message_id = echo->message_id; if (!remove_receiver(echo->message, sid)) { destroy_msg_item = true; if (echo->message->prev_message != NULL) echo->message->prev_message->next_message = echo->message->next_message; else events[echo->message_id].messages = echo->message->next_message; if (echo->message->next_message != NULL) echo->message->next_message->prev_message = echo->message->prev_message; ora_sfree(echo->message->receivers); ora_sfree(echo->message); } if (last_echo == NULL) { alck->echo = echo->next_echo; ora_sfree(echo); echo = alck->echo; } else { last_echo->next_echo = echo->next_echo; ora_sfree(echo); echo = last_echo; } if (remove_all) { if (message_text != NULL && destroy_msg_item) ora_sfree(message_text); continue; } else if (_message_id == message_id || all) { /* I have to do local copy */ if (message_text) { result = pstrdup(message_text); if (destroy_msg_item) ora_sfree(message_text); } if (event_name != NULL) *event_name = pstrdup(events[_message_id].event_name); break; } } } return result; } /* * Queue mustn't to contain duplicate messages */ static void create_message(text *event_name, text *message) { int event_id; alert_event *ev; message_item *msg_item = NULL; int i,j,k; find_event(event_name, false, &event_id); /* process event only when any recipient exitsts */ if (NULL != (ev = find_event(event_name, false, &event_id))) { if (ev->receivers_number > 0) { msg_item = ev->messages; while (msg_item != NULL) { if (msg_item->message == NULL && message == NULL) return; if (msg_item->message != NULL && message != NULL) if (0 == textcmpm(message,msg_item->message)) return; msg_item = msg_item->next_message; } msg_item = salloc(sizeof(message_item)); msg_item->receivers = salloc( ev->receivers_number*sizeof(int)); msg_item->receivers_number = ev->receivers_number; if (message != NULL) msg_item->message = ora_scstring(message); else msg_item->message = NULL; msg_item->message_id = event_id; for (i = j = 0; j < ev->max_receivers; j++) { if (ev->receivers[j] != NOT_USED) { msg_item->receivers[i++] = ev->receivers[j]; for (k = 0; k < MAX_LOCKS; k++) if (locks[k].sid == ev->receivers[j]) { /* create echo */ message_echo *echo = salloc(sizeof(message_echo)); echo->message = msg_item; echo->message_id = event_id; echo->next_echo = NULL; if (locks[k].echo == NULL) locks[k].echo = echo; else { message_echo *p; p = locks[k].echo; while (p->next_echo != NULL) p = p->next_echo; p->next_echo = echo; } } } } msg_item->next_message = NULL; if (ev->messages == NULL) { msg_item->prev_message = NULL; ev->messages = msg_item; } else { message_item *p; p = ev->messages; while (p->next_message != NULL) p = p->next_message; p->next_message = msg_item; msg_item->prev_message = p; } } } } #define WATCH_PRE(t, et, c) \ et = GetNowFloat() + (float8)t; c = 0; \ do \ { \ #define WATCH_POST(t,et,c) \ if (GetNowFloat() >= et) \ break; \ if (cycle++ % 100 == 0) \ CHECK_FOR_INTERRUPTS(); \ pg_usleep(10000L); \ } while(t != 0); /* * * PROCEDURE DBMS_ALERT.REGISTER (name IN VARCHAR2); * * Registers the calling session to receive notification of alert name. * */ Datum dbms_alert_register(PG_FUNCTION_ARGS) { text *name = PG_GETARG_TEXT_P(0); int cycle = 0; float8 endtime; float8 timeout = 2; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { register_event(name); LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * * PROCEDURE DBMS_ALERT.REMOVE(name IN VARCHAR2); * * Unregisters the calling session from receiving notification of alert name. * Don't raise any exceptions. * */ Datum dbms_alert_remove(PG_FUNCTION_ARGS) { text *name = PG_GETARG_TEXT_P(0); alert_event *ev; int ev_id; int cycle = 0; float8 endtime; float8 timeout = 2; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { ev = find_event(name, false, &ev_id); if (NULL != ev) { find_and_remove_message_item(ev_id, sid, false, true, true, NULL, NULL); unregister_event(ev_id, sid); } LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * * PROCEDURE DBMS_ALERT.REMOVEALL; * * Unregisters the calling session from notification of all alerts. * */ Datum dbms_alert_removeall(PG_FUNCTION_ARGS) { int i; int cycle = 0; float8 endtime; float8 timeout = 2; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { for (i = 0; i < MAX_EVENTS; i++) if (events[i].event_name != NULL) { find_and_remove_message_item(i, sid, false, true, true, NULL, NULL); unregister_event(i, sid); } LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * * PROCEDURE DBMS_ALERT.WAITANY(name OUT VARCHAR2 ,message OUT VARCHAR2 * ,status OUT INTEGER * ,timeout IN NUMBER DEFAULT MAXWAIT); * * Waits for up to timeout seconds to be notified of any alerts for which * the session is registered. If status = 0 then name and message contain * alert information. If status = 1 then timeout seconds elapsed without * notification of any alert. * */ Datum dbms_alert_waitany(PG_FUNCTION_ARGS) { float8 timeout; TupleDesc tupdesc; AttInMetadata *attinmeta; HeapTuple tuple; Datum result; char *str[3] = {NULL, NULL, "1"}; int cycle = 0; float8 endtime; TupleDesc btupdesc; if (PG_ARGISNULL(0)) timeout = TDAYS; else timeout = PG_GETARG_FLOAT8(0); WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { str[1] = find_and_remove_message_item(-1, sid, true, false, false, NULL, &str[0]); if (str[0]) { str[2] = "0"; LWLockRelease(shmem_lock); break; } LWLockRelease(shmem_lock); } WATCH_POST(timeout, endtime, cycle); get_call_result_type(fcinfo, NULL, &tupdesc); btupdesc = BlessTupleDesc(tupdesc); attinmeta = TupleDescGetAttInMetadata(btupdesc); tuple = BuildTupleFromCStrings(attinmeta, str); result = HeapTupleGetDatum(tuple); if (str[0]) pfree(str[0]); if (str[1]) pfree(str[1]); return result; } /* * * PROCEDURE DBMS_ALERT.WAITONE(name IN VARCHAR2, message OUT VARCHAR2 * ,status OUT INTEGER * ,timeout IN NUMBER DEFAULT MAXWAIT); * * Waits for up to timeout seconds for notification of alert name. If status = 0 * then message contains alert information. If status = 1 then timeout * seconds elapsed without notification. * */ Datum dbms_alert_waitone(PG_FUNCTION_ARGS) { text *name; float8 timeout; TupleDesc tupdesc; AttInMetadata *attinmeta; HeapTuple tuple; Datum result; int message_id; char *str[2] = {NULL,"1"}; char *event_name; int cycle = 0; float8 endtime; TupleDesc btupdesc; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("event name is NULL"), errdetail("Eventname may not be NULL."))); if (PG_ARGISNULL(1)) timeout = TDAYS; else timeout = PG_GETARG_FLOAT8(1); name = PG_GETARG_TEXT_P(0); WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { if (NULL != find_event(name, false, &message_id)) { str[0] = find_and_remove_message_item(message_id, sid, false, false, false, NULL, &event_name); if (event_name != NULL) { str[1] = "0"; pfree(event_name); LWLockRelease(shmem_lock); break; } } LWLockRelease(shmem_lock); } WATCH_POST(timeout, endtime, cycle); get_call_result_type(fcinfo, NULL, &tupdesc); btupdesc = BlessTupleDesc(tupdesc); attinmeta = TupleDescGetAttInMetadata(btupdesc); tuple = BuildTupleFromCStrings(attinmeta, str); result = HeapTupleGetDatum(tuple); if (str[0]) pfree(str[0]); return result; } /* * * PROCEDURE DBMS_ALERT.SET_DEFAULTS(sensitivity IN NUMBER); * * The SET_DEFAULTS procedure is used to set session configurable settings * used by the DBMS_ALERT package. Currently, the polling loop interval sleep time * is the only session setting that can be modified using this procedure. The * header for this procedure is, * */ Datum dbms_alert_set_defaults(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("feature not supported"), errdetail("Sensitivity isn't supported."))); PG_RETURN_VOID(); } /* * This code was originally in plpgsql * */ /* CREATE OR REPLACE FUNCTION dbms_alert._defered_signal() RETURNS trigger AS $$ BEGIN PERFORM dbms_alert._signal(NEW.event, NEW.message); DELETE FROM ora_alerts WHERE oid=NEW.oid; RETURN NEW; END; $$ LANGUAGE plpgsql SECURITY DEFINER VOLATILE; */ #define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X)) #define ItemPointerGetDatum(X) PointerGetDatum(X) Datum dbms_alert_defered_signal(PG_FUNCTION_ARGS) { TriggerData *trigdata = (TriggerData *) fcinfo->context; TupleDesc tupdesc; HeapTuple rettuple; char *relname; text *name; text *message; int event_col; int message_col; Datum datum; bool isnull; int cycle = 0; float8 endtime; float8 timeout = 2; if (!CALLED_AS_TRIGGER(fcinfo)) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("not called by trigger manager"))); if (!TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("not called on valid event"))); if (SPI_connect() < 0) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("SPI_connect failed"))); if (strcmp((relname = SPI_getrelname(trigdata->tg_relation)), "ora_alerts") != 0) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("not called with valid relation"))); rettuple = trigdata->tg_trigtuple; tupdesc = trigdata->tg_relation->rd_att; if (SPI_ERROR_NOATTRIBUTE == (event_col = SPI_fnumber(tupdesc, "event"))) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("attribute event not found"))); if (SPI_ERROR_NOATTRIBUTE == (message_col = SPI_fnumber(tupdesc, "message"))) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("attribute message not found"))); datum = SPI_getbinval(rettuple, tupdesc, event_col, &isnull); if (isnull) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("event name is NULL"), errdetail("Eventname may not be NULL."))); name = DatumGetTextP(datum); datum = SPI_getbinval(rettuple, tupdesc, message_col, &isnull); if (isnull) message = NULL; else message = DatumGetTextP(datum); WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { ItemPointer tid; Oid argtypes[1] = {TIDOID}; char nulls[1] = {' '}; Datum values[1]; void *plan; create_message(name, message); LWLockRelease(shmem_lock); tid = &rettuple->t_data->t_ctid; if (!(plan = SPI_prepare("DELETE FROM ora_alerts WHERE ctid = $1", 1, argtypes))) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("SPI_prepare failed"))); values[0] = ItemPointerGetDatum(tid); if (SPI_OK_DELETE != SPI_execute_plan(plan, values, nulls, false, 1)) ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION), errmsg("can't execute sql"))); SPI_finish(); return PointerGetDatum(rettuple); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_NULL(); } /* * * PROCEDURE DBMS_ALERT.SIGNAL(name IN VARCHAR2,message IN VARCHAR2); * * Signals the occurrence of alert name and attaches message. (Sessions * registered for alert name are notified only when the signaling transaction * commits.) * */ /* CREATE OR REPLACE FUNCTION dbms_alert.signal(_event text, _message text) RETURNS void AS $$ BEGIN PERFORM 1 FROM pg_catalog.pg_class c WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind='r' AND c.relname = 'ora_alerts'; IF NOT FOUND THEN CREATE TEMP TABLE ora_alerts(event text, message text) WITH OIDS; REVOKE ALL ON TABLE ora_alerts FROM PUBLIC; CREATE CONSTRAINT TRIGGER ora_alert_signal AFTER INSERT ON ora_alerts INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE dbms_alert._defered_signal(); END IF; INSERT INTO ora_alerts(event, message) VALUES(_event, _message); END; $$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER; */ #define SPI_EXEC(cmd,_type_) \ if (SPI_OK_##_type_ != SPI_exec(cmd, 1)) \ ereport(ERROR, \ (errcode(ERRCODE_INTERNAL_ERROR), \ errmsg("SPI execute error"), \ errdetail("Can't execute %s.", cmd))); Datum dbms_alert_signal(PG_FUNCTION_ARGS) { void *plan; Oid argtypes[] = {TEXTOID, TEXTOID}; Datum values[2]; char nulls[2] = {' ',' '}; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("event name is NULL"), errdetail("Eventname may not be NULL."))); if (PG_ARGISNULL(1)) nulls[1] = 'n'; values[0] = PG_GETARG_DATUM(0); values[1] = PG_GETARG_DATUM(1); if (SPI_connect() < 0) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_connect failed"))); SPI_EXEC("SELECT 1 FROM pg_catalog.pg_class c " "WHERE pg_catalog.pg_table_is_visible(c.oid) " "AND c.relkind='r' AND c.relname = 'ora_alerts'", SELECT); if (0 == SPI_processed) { SPI_EXEC("CREATE TEMP TABLE ora_alerts(event text, message text)", UTILITY); SPI_EXEC("REVOKE ALL ON TABLE ora_alerts FROM PUBLIC", UTILITY); SPI_EXEC("CREATE CONSTRAINT TRIGGER ora_alert_signal AFTER INSERT ON ora_alerts " "INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE dbms_alert.defered_signal()", UTILITY); } if (!(plan = SPI_prepare( "INSERT INTO ora_alerts(event,message) VALUES($1, $2)", 2, argtypes))) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_prepare failed"))); if (SPI_OK_INSERT != SPI_execute_plan(plan, values, nulls, false, 1)) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("can't execute sql"))); SPI_finish(); PG_RETURN_VOID(); } orafce-VERSION_3_0_6/assert.c000066400000000000000000000217071221300436000157710ustar00rootroot00000000000000#include "postgres.h" #include "funcapi.h" #include "assert.h" #include "miscadmin.h" #include "utils/acl.h" #include "utils/builtins.h" #include "utils/syscache.h" #include "catalog/namespace.h" #include "ctype.h" #include "string.h" #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(dbms_assert_enquote_literal); PG_FUNCTION_INFO_V1(dbms_assert_enquote_name); PG_FUNCTION_INFO_V1(dbms_assert_noop); PG_FUNCTION_INFO_V1(dbms_assert_qualified_sql_name); PG_FUNCTION_INFO_V1(dbms_assert_schema_name); PG_FUNCTION_INFO_V1(dbms_assert_simple_sql_name); PG_FUNCTION_INFO_V1(dbms_assert_object_name); #define CUSTOM_EXCEPTION(code, msg) \ ereport(ERROR, \ (errcode(ERRCODE_ORA_PACKAGES_##code), \ errmsg(msg))) #define INVALID_SCHEMA_NAME_EXCEPTION() \ CUSTOM_EXCEPTION(INVALID_SCHEMA_NAME, "invalid schema name") #define INVALID_OBJECT_NAME_EXCEPTION() \ CUSTOM_EXCEPTION(INVALID_OBJECT_NAME, "invalid object name") #define ISNOT_SIMPLE_SQL_NAME_EXCEPTION() \ CUSTOM_EXCEPTION(ISNOT_SIMPLE_SQL_NAME, "string is not simple SQL name") #define ISNOT_QUALIFIED_SQL_NAME_EXCEPTION() \ CUSTOM_EXCEPTION(ISNOT_QUALIFIED_SQL_NAME, "string is not qualified SQL name") #define EMPTY_STR(str) ((VARSIZE(str) - VARHDRSZ) == 0) static bool check_sql_name(char *cp, int len); static bool ParseIdentifierString(char *rawstring); /* * Procedure ParseIdentifierString is based on SplitIdentifierString * from varlena.c. We need different behave of quote symbol evaluation. */ bool ParseIdentifierString(char *rawstring) { char *nextp = rawstring; bool done = false; while (isspace((unsigned char) *nextp)) nextp++; /* skip leading whitespace */ if (*nextp == '\0') return true; /* allow empty string */ /* At the top of the loop, we are at start of a new identifier. */ do { char *curname; char *endp; if (*nextp == '\"') { /* Quoted name --- collapse quote-quote pairs, no downcasing */ curname = nextp + 1; for (;;) { endp = strchr(nextp + 1, '\"'); if (endp == NULL) return false; /* mismatched quotes */ if (endp[1] != '\"') break; /* found end of quoted name */ /* Collapse adjacent quotes into one quote, and look again */ memmove(endp, endp + 1, strlen(endp)); nextp = endp; } /* endp now points at the terminating quote */ nextp = endp + 1; } else { /* Unquoted name --- extends to separator or whitespace */ curname = nextp; while (*nextp && *nextp != '.' && !isspace((unsigned char) *nextp)) { if (!isalnum(*nextp) && *nextp != '_') return false; nextp++; } endp = nextp; if (curname == nextp) return false; /* empty unquoted name not allowed */ } while (isspace((unsigned char) *nextp)) nextp++; /* skip trailing whitespace */ if (*nextp == '.') { nextp++; while (isspace((unsigned char) *nextp)) nextp++; /* skip leading whitespace for next */ /* we expect another name, so done remains false */ } else if (*nextp == '\0') done = true; else return false; /* invalid syntax */ /* Loop back if we didn't reach end of string */ } while (!done); return true; } /**************************************************************** * DBMS_ASSERT.ENQUOTE_LITERAL * * Syntax: * FUNCTION ENQUOTE_LITERAL(str varchar) RETURNS varchar; * * Purpouse: * Add leading and trailing quotes, verify that all single quotes * are paired with adjacent single quotes. * ****************************************************************/ Datum dbms_assert_enquote_literal(PG_FUNCTION_ARGS) { PG_RETURN_DATUM(DirectFunctionCall1(quote_literal, PG_GETARG_DATUM(0))); } /**************************************************************** * DBMS_ASSERT.ENQUOTE_NAME * * Syntax: * FUNCTION ENQUOTE_NAME(str varchar) RETURNS varchar; * FUNCTION ENQUOTE_NAME(str varchar, loweralize boolean := true) * RETURNS varchar; * Purpouse: * Enclose name in double quotes. * Atention!: * On Oracle is second parameter capitalize! * ****************************************************************/ Datum dbms_assert_enquote_name(PG_FUNCTION_ARGS) { Datum name = PG_GETARG_DATUM(0); bool loweralize = PG_GETARG_BOOL(1); #if PG_VERSION_NUM >= 90100 Oid collation = PG_GET_COLLATION(); #endif name = DirectFunctionCall1(quote_ident, name); #if PG_VERSION_NUM >= 90100 if (loweralize) name = DirectFunctionCall1Coll(lower, collation, name); #else if (loweralize) name = DirectFunctionCall1(lower, name); #endif PG_RETURN_DATUM(name); } /**************************************************************** * DBMS_ASSERT.NOOP * * Syntax: * FUNCTION NOOP(str varchar) RETURNS varchar; * * Purpouse: * Returns value without any checking. * ****************************************************************/ Datum dbms_assert_noop(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_P(0); PG_RETURN_TEXT_P(TextPCopy(str)); } /**************************************************************** * DBMS_ASSERT.QUALIFIED_SQL_NAME * * Syntax: * FUNCTION QUALIFIED_SQL_NAME(str varchar) RETURNS varchar; * * Purpouse: * This function verifies that the input string is qualified SQL * name. * Exception: 44004 string is not a qualified SQL name * ****************************************************************/ Datum dbms_assert_qualified_sql_name(PG_FUNCTION_ARGS) { text *qname; if (PG_ARGISNULL(0)) ISNOT_QUALIFIED_SQL_NAME_EXCEPTION(); qname = PG_GETARG_TEXT_P(0); if (EMPTY_STR(qname)) ISNOT_QUALIFIED_SQL_NAME_EXCEPTION(); if (!ParseIdentifierString(text_to_cstring(qname))) ISNOT_QUALIFIED_SQL_NAME_EXCEPTION(); PG_RETURN_TEXT_P(qname); } /**************************************************************** * DBMS_ASSERT.SCHEMA_NAME * * Syntax: * FUNCTION SCHEMA_NAME(str varchar) RETURNS varchar; * * Purpouse: * Function verifies that input string is an existing schema * name. * Exception: 44001 Invalid schema name * ****************************************************************/ Datum dbms_assert_schema_name(PG_FUNCTION_ARGS) { Oid namespaceId; AclResult aclresult; text *sname; char *nspname; List *names; if (PG_ARGISNULL(0)) INVALID_SCHEMA_NAME_EXCEPTION(); sname = PG_GETARG_TEXT_P(0); if (EMPTY_STR(sname)) INVALID_SCHEMA_NAME_EXCEPTION(); nspname = text_to_cstring(sname); names = stringToQualifiedNameList(nspname); if (list_length(names) != 1) INVALID_SCHEMA_NAME_EXCEPTION(); namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(strVal(linitial(names))), 0, 0, 0); if (!OidIsValid(namespaceId)) INVALID_SCHEMA_NAME_EXCEPTION(); aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE); if (aclresult != ACLCHECK_OK) INVALID_SCHEMA_NAME_EXCEPTION(); PG_RETURN_TEXT_P(sname); } /**************************************************************** * DBMS_ASSERT.SIMPLE_SQL_NAME * * Syntax: * FUNCTION SIMPLE_SQL_NAME(str varchar) RETURNS varchar; * * Purpouse: * This function verifies that the input string is simple SQL * name. * Exception: 44003 String is not a simple SQL name * ****************************************************************/ static bool check_sql_name(char *cp, int len) { if (*cp == '"') { for (cp++, len -= 2; len-- > 0; cp++) { /* all double quotes have to be paired */ if (*cp == '"') { if (len-- == 0) return false; /* next char has to be quote */ if (*cp != '"') return false; } } if (*cp != '"') return false; } else { /* Doesn't allow national characters in sql name :( */ for (; len-- > 0; cp++) if (!isalnum(*cp) && *cp != '_') return false; } return true; } Datum dbms_assert_simple_sql_name(PG_FUNCTION_ARGS) { text *sname; int len; char *cp; if (PG_ARGISNULL(0)) ISNOT_SIMPLE_SQL_NAME_EXCEPTION(); sname = PG_GETARG_TEXT_P(0); if (EMPTY_STR(sname)) ISNOT_SIMPLE_SQL_NAME_EXCEPTION(); len = VARSIZE(sname) - VARHDRSZ; cp = VARDATA(sname); if (!check_sql_name(cp, len)) ISNOT_SIMPLE_SQL_NAME_EXCEPTION(); PG_RETURN_TEXT_P(sname); } /**************************************************************** * DBMS_ASSERT.OBJECT_NAME * * Syntax: * FUNCTION OBJECT_NAME(str varchar) RETURNS varchar; * * Purpouse: * Verifies that input string is qualified SQL identifier of * an existing SQL object. * Exception: 44002 Invalid object name * ****************************************************************/ Datum dbms_assert_object_name(PG_FUNCTION_ARGS) { List *names; text *str; char *object_name; Oid classId; if (PG_ARGISNULL(0)) INVALID_OBJECT_NAME_EXCEPTION(); str = PG_GETARG_TEXT_P(0); if (EMPTY_STR(str)) INVALID_OBJECT_NAME_EXCEPTION(); object_name = text_to_cstring(str); names = stringToQualifiedNameList(object_name); #if PG_VERSION_NUM >= 90200 classId = RangeVarGetRelid(makeRangeVarFromNameList(names), NoLock, true); #else classId = RangeVarGetRelid(makeRangeVarFromNameList(names), true); #endif if (!OidIsValid(classId)) INVALID_OBJECT_NAME_EXCEPTION(); PG_RETURN_TEXT_P(str); } orafce-VERSION_3_0_6/assert.h000066400000000000000000000006061221300436000157710ustar00rootroot00000000000000#ifndef __ASSERT__ #define __ASSERT__ #define ERRCODE_ORA_PACKAGES_INVALID_SCHEMA_NAME MAKE_SQLSTATE('4','4','0','0','1') #define ERRCODE_ORA_PACKAGES_INVALID_OBJECT_NAME MAKE_SQLSTATE('4','4','0','0','2') #define ERRCODE_ORA_PACKAGES_ISNOT_SIMPLE_SQL_NAME MAKE_SQLSTATE('4','4','0','0','3') #define ERRCODE_ORA_PACKAGES_ISNOT_QUALIFIED_SQL_NAME MAKE_SQLSTATE('4','4','0','0','4') #endif orafce-VERSION_3_0_6/builtins.h000066400000000000000000000306071221300436000163250ustar00rootroot00000000000000 #ifndef ORAFCE_BUILTINS #define ORAFCE_BUILTINS #ifndef PGDLLEXPORT #ifdef _MSC_VER #define PGDLLEXPORT __declspec(dllexport) /* * PG_MODULE_MAGIC and PG_FUNCTION_INFO_V1 macros are broken for MSVC. * So, we redefine them. */ #undef PG_MODULE_MAGIC #define PG_MODULE_MAGIC \ extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \ const Pg_magic_struct * \ PG_MAGIC_FUNCTION_NAME(void) \ { \ static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \ return &Pg_magic_data; \ } \ extern int no_such_variable #undef PG_FUNCTION_INFO_V1 #define PG_FUNCTION_INFO_V1(funcname) \ extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \ const Pg_finfo_record * \ CppConcat(pg_finfo_,funcname) (void) \ { \ static const Pg_finfo_record my_finfo = { 1 }; \ return &my_finfo; \ } \ extern int no_such_variable #else #define PGDLLEXPORT PGDLLIMPORT #endif #endif /* from aggregate.c */ extern PGDLLEXPORT Datum orafce_listagg1_transfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_listagg2_transfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_listagg_finalfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_median4_transfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_median4_finalfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_median8_transfn(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_median8_finalfn(PG_FUNCTION_ARGS); /* from alert.c */ extern PGDLLEXPORT Datum dbms_alert_register(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_remove(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_removeall(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_set_defaults(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_signal(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_waitany(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_waitone(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_alert_defered_signal(PG_FUNCTION_ARGS); /* from assert.c */ extern PGDLLEXPORT Datum dbms_assert_enquote_literal(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_enquote_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_noop(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_qualified_sql_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_schema_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_simple_sql_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_assert_object_name(PG_FUNCTION_ARGS); /* from convert.c */ extern PGDLLEXPORT Datum orafce_to_char_int4(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_char_int8(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_char_float4(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_char_float8(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_char_numeric(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_number(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_to_multi_byte(PG_FUNCTION_ARGS); /* from datefce.c */ extern PGDLLEXPORT Datum next_day(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum next_day_by_index(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum last_day(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum months_between(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum add_months(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_date_trunc(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_date_round(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_timestamptz_trunc(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_timestamptz_round(PG_FUNCTION_ARGS); /* from file.c */ extern PGDLLEXPORT Datum utl_file_fopen(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_is_open(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_get_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_get_nextline(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_put(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_put_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_new_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_putf(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fflush(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fclose(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fclose_all(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fremove(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_frename(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fcopy(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_fgetattr(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum utl_file_tmpdir(PG_FUNCTION_ARGS); /* from others.c */ extern PGDLLEXPORT Datum ora_nvl(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_nvl2(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_concat(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_nlssort(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_set_nls_sort(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_lnnvl(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum ora_decode(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum orafce_dump(PG_FUNCTION_ARGS); /* from pipe.c */ extern PGDLLEXPORT Datum dbms_pipe_pack_message_text(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_text(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_send_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_receive_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unique_session_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_list_pipes(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_next_item_type(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_create_pipe(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_create_pipe_2(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_create_pipe_1(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_reset_buffer(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_purge(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_remove_pipe(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_date(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_date(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_timestamp(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_timestamp(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_number(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_number(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_bytea(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_bytea(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_record(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_unpack_message_record(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_integer(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_pipe_pack_message_bigint(PG_FUNCTION_ARGS); /* from plunit.c */ extern PGDLLEXPORT Datum plunit_assert_true(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_true_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_false(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_false_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_null(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_null_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_null(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_null_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_equals(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_equals_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_equals_range(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_equals_range_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_equals(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_equals_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_equals_range(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_assert_not_equals_range_message(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_fail(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plunit_fail_message(PG_FUNCTION_ARGS); /* from plvdate.c */ extern PGDLLEXPORT Datum plvdate_add_bizdays(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_nearest_bizday(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_next_bizday(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_bizdays_between(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_prev_bizday(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_isbizday(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_set_nonbizday_dow(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_unset_nonbizday_dow(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_set_nonbizday_day(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_unset_nonbizday_day(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_use_easter(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_using_easter(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_include_start(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_including_start(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_default_holidays(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_version(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_days_inmonth(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvdate_isleapyear(PG_FUNCTION_ARGS); /* from plvlec.c */ extern PGDLLEXPORT Datum plvlex_tokens(PG_FUNCTION_ARGS); /* from plvstr.c */ extern PGDLLEXPORT Datum plvstr_rvrs(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_normalize(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_is_prefix_text(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_is_prefix_int(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_is_prefix_int64(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_lpart(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_rpart(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_lstrip(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_rstrip(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_left(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_right(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_substr2(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_substr3(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_instr2(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_instr3(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_instr4(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_betwn_i(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_betwn_c(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvstr_swap(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_nth(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_first(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_last(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_is_kind_i(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_is_kind_a(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvchr_char_name(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum oracle_substr2(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum oracle_substr3(PG_FUNCTION_ARGS); /* from plvsubst.c */ extern PGDLLEXPORT Datum plvsubst_string_array(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvsubst_string_string(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvsubst_setsubst(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvsubst_setsubst_default(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum plvsubst_subst(PG_FUNCTION_ARGS); /* from putline.c */ extern PGDLLEXPORT Datum dbms_output_enable(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_enable_default(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_disable(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_serveroutput(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_put(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_put_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_new_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_get_line(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_output_get_lines(PG_FUNCTION_ARGS); /* from random.c */ extern PGDLLEXPORT Datum dbms_random_initialize(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_normal(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_random(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_seed_int(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_seed_varchar(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_string(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_terminate(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_value(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_random_value_range(PG_FUNCTION_ARGS); /* from utility.c */ extern PGDLLEXPORT Datum dbms_utility_format_call_stack0(PG_FUNCTION_ARGS); extern PGDLLEXPORT Datum dbms_utility_format_call_stack1(PG_FUNCTION_ARGS); #endif orafce-VERSION_3_0_6/convert.c000066400000000000000000000163531221300436000161510ustar00rootroot00000000000000#include "postgres.h" #include "fmgr.h" #include "lib/stringinfo.h" #include "mb/pg_wchar.h" #include "utils/builtins.h" #include "utils/numeric.h" #include "utils/pg_locale.h" #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(orafce_to_char_int4); PG_FUNCTION_INFO_V1(orafce_to_char_int8); PG_FUNCTION_INFO_V1(orafce_to_char_float4); PG_FUNCTION_INFO_V1(orafce_to_char_float8); PG_FUNCTION_INFO_V1(orafce_to_char_numeric); PG_FUNCTION_INFO_V1(orafce_to_number); PG_FUNCTION_INFO_V1(orafce_to_multi_byte); Datum orafce_to_char_int4(PG_FUNCTION_ARGS) { int32 arg0 = PG_GETARG_INT32(0); StringInfo buf = makeStringInfo(); appendStringInfo(buf, "%d", arg0); PG_RETURN_TEXT_P(cstring_to_text(buf->data)); } Datum orafce_to_char_int8(PG_FUNCTION_ARGS) { int64 arg0 = PG_GETARG_INT64(0); StringInfo buf = makeStringInfo(); appendStringInfo(buf, INT64_FORMAT, arg0); PG_RETURN_TEXT_P(cstring_to_text(buf->data)); } Datum orafce_to_char_float4(PG_FUNCTION_ARGS) { float4 arg0 = PG_GETARG_FLOAT4(0); StringInfo buf = makeStringInfo(); struct lconv *lconv = PGLC_localeconv(); char *p; appendStringInfo(buf, "%f", arg0); for (p = buf->data; *p; p++) if (*p == '.') *p = lconv->decimal_point[0]; PG_RETURN_TEXT_P(cstring_to_text(buf->data)); } Datum orafce_to_char_float8(PG_FUNCTION_ARGS) { float8 arg0 = PG_GETARG_FLOAT8(0); StringInfo buf = makeStringInfo(); struct lconv *lconv = PGLC_localeconv(); char *p; appendStringInfo(buf, "%f", arg0); for (p = buf->data; *p; p++) if (*p == '.') *p = lconv->decimal_point[0]; PG_RETURN_TEXT_P(cstring_to_text(buf->data)); } Datum orafce_to_char_numeric(PG_FUNCTION_ARGS) { Numeric arg0 = PG_GETARG_NUMERIC(0); StringInfo buf = makeStringInfo(); struct lconv *lconv = PGLC_localeconv(); char *p; char *decimal = NULL; appendStringInfoString(buf, DatumGetCString(DirectFunctionCall1(numeric_out, NumericGetDatum(arg0)))); for (p = buf->data; *p; p++) if (*p == '.') { *p = lconv->decimal_point[0]; decimal = p; /* save decimal point position for the next loop */ } /* Simulate the default Oracle to_char template (TM9 - Text Minimum) by removing unneeded digits after the decimal point; if no digits are left, then remove the decimal point too */ for (p = buf->data + buf->len - 1; decimal && p >= decimal; p--) { if (*p == '0' || *p == lconv->decimal_point[0]) *p = 0; else break; /* non-zero digit found, exit the loop */ } PG_RETURN_TEXT_P(cstring_to_text(buf->data)); } Datum orafce_to_number(PG_FUNCTION_ARGS) { text *arg0 = PG_GETARG_TEXT_PP(0); char *buf; struct lconv *lconv = PGLC_localeconv(); Numeric res; char *p; buf = text_to_cstring(arg0); for (p = buf; *p; p++) if (*p == lconv->decimal_point[0] && lconv->decimal_point[0]) *p = '.'; else if (*p == lconv->thousands_sep[0] && lconv->thousands_sep[0]) *p = ','; res = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(buf), 0, -1)); PG_RETURN_NUMERIC(res); } /* 3 is enough, but it is defined as 4 in backend code. */ #ifndef MAX_CONVERSION_GROWTH #define MAX_CONVERSION_GROWTH 4 #endif /* * Convert a tilde (~) to ... * 1: a full width tilde. (same as JA16EUCTILDE in oracle) * 0: a full width overline. (same as JA16EUC in oracle) */ #define JA_TO_FULL_WIDTH_TILDE 1 static const char * TO_MULTI_BYTE_UTF8[95] = { "\343\200\200", "\357\274\201", "\342\200\235", "\357\274\203", "\357\274\204", "\357\274\205", "\357\274\206", "\342\200\231", "\357\274\210", "\357\274\211", "\357\274\212", "\357\274\213", "\357\274\214", "\357\274\215", "\357\274\216", "\357\274\217", "\357\274\220", "\357\274\221", "\357\274\222", "\357\274\223", "\357\274\224", "\357\274\225", "\357\274\226", "\357\274\227", "\357\274\230", "\357\274\231", "\357\274\232", "\357\274\233", "\357\274\234", "\357\274\235", "\357\274\236", "\357\274\237", "\357\274\240", "\357\274\241", "\357\274\242", "\357\274\243", "\357\274\244", "\357\274\245", "\357\274\246", "\357\274\247", "\357\274\250", "\357\274\251", "\357\274\252", "\357\274\253", "\357\274\254", "\357\274\255", "\357\274\256", "\357\274\257", "\357\274\260", "\357\274\261", "\357\274\262", "\357\274\263", "\357\274\264", "\357\274\265", "\357\274\266", "\357\274\267", "\357\274\270", "\357\274\271", "\357\274\272", "\357\274\273", "\357\277\245", "\357\274\275", "\357\274\276", "\357\274\277", "\342\200\230", "\357\275\201", "\357\275\202", "\357\275\203", "\357\275\204", "\357\275\205", "\357\275\206", "\357\275\207", "\357\275\210", "\357\275\211", "\357\275\212", "\357\275\213", "\357\275\214", "\357\275\215", "\357\275\216", "\357\275\217", "\357\275\220", "\357\275\221", "\357\275\222", "\357\275\223", "\357\275\224", "\357\275\225", "\357\275\226", "\357\275\227", "\357\275\230", "\357\275\231", "\357\275\232", "\357\275\233", "\357\275\234", "\357\275\235", #if JA_TO_FULL_WIDTH_TILDE "\357\275\236" #else "\357\277\243" #endif }; static const char * TO_MULTI_BYTE_EUCJP[95] = { "\241\241", "\241\252", "\241\311", "\241\364", "\241\360", "\241\363", "\241\365", "\241\307", "\241\312", "\241\313", "\241\366", "\241\334", "\241\244", "\241\335", "\241\245", "\241\277", "\243\260", "\243\261", "\243\262", "\243\263", "\243\264", "\243\265", "\243\266", "\243\267", "\243\270", "\243\271", "\241\247", "\241\250", "\241\343", "\241\341", "\241\344", "\241\251", "\241\367", "\243\301", "\243\302", "\243\303", "\243\304", "\243\305", "\243\306", "\243\307", "\243\310", "\243\311", "\243\312", "\243\313", "\243\314", "\243\315", "\243\316", "\243\317", "\243\320", "\243\321", "\243\322", "\243\323", "\243\324", "\243\325", "\243\326", "\243\327", "\243\330", "\243\331", "\243\332", "\241\316", "\241\357", "\241\317", "\241\260", "\241\262", "\241\306", "\243\341", "\243\342", "\243\343", "\243\344", "\243\345", "\243\346", "\243\347", "\243\350", "\243\351", "\243\352", "\243\353", "\243\354", "\243\355", "\243\356", "\243\357", "\243\360", "\243\361", "\243\362", "\243\363", "\243\364", "\243\365", "\243\366", "\243\367", "\243\370", "\243\371", "\243\372", "\241\320", "\241\303", "\241\321", #if JA_TO_FULL_WIDTH_TILDE "\241\301" #else "\241\261" #endif }; Datum orafce_to_multi_byte(PG_FUNCTION_ARGS) { text *src; text *dst; const char *s; char *d; int srclen; int dstlen; int i; const char **map; switch (GetDatabaseEncoding()) { case PG_UTF8: map = TO_MULTI_BYTE_UTF8; break; case PG_EUC_JP: #if PG_VERSION_NUM >= 80300 case PG_EUC_JIS_2004: #endif map = TO_MULTI_BYTE_EUCJP; break; /* * TODO: Add converter for encodings. */ default: /* no need to convert */ PG_RETURN_DATUM(PG_GETARG_DATUM(0)); } src = PG_GETARG_TEXT_PP(0); s = VARDATA_ANY(src); srclen = VARSIZE_ANY_EXHDR(src); dst = (text *) palloc(VARHDRSZ + srclen * MAX_CONVERSION_GROWTH); d = VARDATA(dst); for (i = 0; i < srclen; i++) { unsigned char u = (unsigned char) s[i]; if (0x20 <= u && u <= 0x7e) { const char *m = map[u - 0x20]; while (*m) { *d++ = *m++; } } else { *d++ = s[i]; } } dstlen = d - VARDATA(dst); SET_VARSIZE(dst, VARHDRSZ + dstlen); PG_RETURN_TEXT_P(dst); } orafce-VERSION_3_0_6/datefce.c000066400000000000000000000425261221300436000160650ustar00rootroot00000000000000#include "postgres.h" #include "mb/pg_wchar.h" #include "utils/date.h" #include "utils/builtins.h" #include "utils/nabstime.h" #include "utils/numeric.h" #include #include "orafunc.h" #include "builtins.h" #define ENABLE_INTERNATIONALIZED_WEEKDAY #ifdef ENABLE_INTERNATIONALIZED_WEEKDAY typedef struct WeekDays { int encoding; const char *names[7]; } WeekDays; /* * { encoding, { "sun", "mon", "tue", "wed", "thu", "fri", "sat" } }, */ static const WeekDays WEEKDAYS[] = { /* Japanese, UTF8 */ { PG_UTF8, { "\346\227\245", "\346\234\210", "\347\201\253", "\346\260\264", "\346\234\250", "\351\207\221", "\345\234\237" } }, /* Japanese, EUC_JP */ { PG_EUC_JP, { "\306\374", "\267\356", "\262\320", "\277\345", "\314\332", "\266\342", "\305\332" } }, #if PG_VERSION_NUM >= 80300 /* Japanese, EUC_JIS_2004 (same as EUC_JP) */ { PG_EUC_JIS_2004, { "\306\374", "\267\356", "\262\320", "\277\345", "\314\332", "\266\342", "\305\332" } }, #endif }; static const WeekDays *mru_weekdays = NULL; static int weekday_search(const WeekDays *weekdays, const char *str, int len) { int i; for (i = 0; i < 7; i++) { int n = strlen(weekdays->names[i]); if (n > len) continue; /* too short */ if (pg_strncasecmp(weekdays->names[i], str, n) == 0) return i; } return -1; /* not found */ } #endif /* ENABLE_INTERNATIONALIZED_WEEKDAY */ /* * External (defined in PgSQL datetime.c (timestamp utils)) */ extern PGDLLIMPORT char *days[]; extern PGDLLIMPORT pg_tz *session_timezone; #define CASE_fmt_YYYY case 0: case 1: case 2: case 3: case 4: case 5: case 6: #define CASE_fmt_IYYY case 7: case 8: case 9: case 10: #define CASE_fmt_Q case 11: #define CASE_fmt_WW case 12: #define CASE_fmt_IW case 13: #define CASE_fmt_W case 14: #define CASE_fmt_DAY case 15: case 16: case 17: #define CASE_fmt_MON case 18: case 19: case 20: case 21: #define CASE_fmt_CC case 22: case 23: #define CASE_fmt_DDD case 24: case 25: case 26: #define CASE_fmt_HH case 27: case 28: case 29: #define CASE_fmt_MI case 30: char *date_fmt[] = { "Y", "Yy", "Yyy", "Yyyy", "Year", "Syyyy", "syear", "I", "Iy", "Iyy", "Iyyy", "Q", "Ww", "Iw", "W", "Day", "Dy", "D", "Month", "Mon", "Mm", "Rm", "Cc", "Scc", "Ddd", "Dd", "J", "Hh", "Hh12", "Hh24", "Mi", NULL }; #define CHECK_SEQ_SEARCH(_l, _s) \ do { \ if ((_l) < 0) { \ ereport(ERROR, \ (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \ errmsg("invalid value for %s", (_s)))); \ } \ } while (0) PG_FUNCTION_INFO_V1(next_day); PG_FUNCTION_INFO_V1(next_day_by_index); PG_FUNCTION_INFO_V1(last_day); PG_FUNCTION_INFO_V1(months_between); PG_FUNCTION_INFO_V1(add_months); PG_FUNCTION_INFO_V1(ora_date_trunc); PG_FUNCTION_INFO_V1(ora_date_round); PG_FUNCTION_INFO_V1(ora_timestamptz_trunc); PG_FUNCTION_INFO_V1(ora_timestamptz_round); /* * Search const value in char array * */ int ora_seq_search(const char *name, /*const*/ char **array, int max); int ora_seq_search(const char *name, /*const*/ char **array, int max) { int i; if (!*name) return -1; for (i = 0; array[i]; i++) { if (strlen(array[i]) == max && pg_strncasecmp(name, array[i], max) == 0) return i; } return -1; /* not found */ } static int ora_seq_prefix_search(const char *name, /*const*/ char **array, int max) { int i; if (!*name) return -1; for (i = 0; array[i]; i++) { if (pg_strncasecmp(name, array[i], max) == 0) return i; } return -1; /* not found */ } /******************************************************************** * * next_day * * Syntax: * * date next_day(date value, text weekday) * * Purpose: * * Returns the first weekday that is greater than a date value. * ********************************************************************/ Datum next_day(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); text *day_txt = PG_GETARG_TEXT_PP(1); const char *str = VARDATA_ANY(day_txt); int len = VARSIZE_ANY_EXHDR(day_txt); int off; int d = -1; #ifdef ENABLE_INTERNATIONALIZED_WEEKDAY /* Check mru_weekdays first for performance. */ if (mru_weekdays) { if ((d = weekday_search(mru_weekdays, str, len)) >= 0) goto found; else mru_weekdays = NULL; } #endif /* * Oracle uses only 3 heading characters of the input. * Ignore all trailing characters. */ if (len >= 3 && (d = ora_seq_prefix_search(str, days, 3)) >= 0) goto found; #ifdef ENABLE_INTERNATIONALIZED_WEEKDAY do { int i; int encoding = GetDatabaseEncoding(); for (i = 0; i < lengthof(WEEKDAYS); i++) { if (encoding == WEEKDAYS[i].encoding) { if ((d = weekday_search(&WEEKDAYS[i], str, len)) >= 0) { mru_weekdays = &WEEKDAYS[i]; goto found; } } } } while(0); #endif CHECK_SEQ_SEARCH(-1, "DAY/Day/day"); found: off = d - j2day(day+POSTGRES_EPOCH_JDATE); PG_RETURN_DATEADT((off <= 0) ? day+off+7 : day + off); } /* next_day(date, integer) is not documented in Oracle manual, but ... */ Datum next_day_by_index(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int idx = PG_GETARG_INT32(1); int off; /* * off is 1..7 (Sun..Sat). * * TODO: It should be affected by NLS_TERRITORY. For example, * 1..7 should be interpreted as Mon..Sun in GERMAN. */ CHECK_SEQ_SEARCH((idx < 1 || 7 < idx) ? -1 : 0, "DAY/Day/day"); /* j2day returns 0..6 as Sun..Sat */ off = (idx - 1) - j2day(day+POSTGRES_EPOCH_JDATE); PG_RETURN_DATEADT((off <= 0) ? day+off+7 : day + off); } /******************************************************************** * * last_day * * Syntax: * * date last_day(date value) * * Purpose: * * Returns last day of the month based on a date value * ********************************************************************/ Datum last_day(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); DateADT result; int y, m, d; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); result = date2j(y, m+1, 1) - POSTGRES_EPOCH_JDATE; PG_RETURN_DATEADT(result - 1); } static const int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static int days_of_month(int y, int m) { int days; if (m < 0 || 12 < m) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("date out of range"))); days = month_days[m - 1]; if (m == 2 && (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))) days += 1; /* February 29 in leap year */ return days; } /******************************************************************** * * months_between * * Syntax: * * float8 months_between(date date1, date date2) * * Purpose: * * Returns the number of months between date1 and date2. If * a fractional month is calculated, the months_between function * calculates the fraction based on a 31-day month. * ********************************************************************/ Datum months_between(PG_FUNCTION_ARGS) { DateADT date1 = PG_GETARG_DATEADT(0); DateADT date2 = PG_GETARG_DATEADT(1); int y1, m1, d1; int y2, m2, d2; float8 result; j2date(date1 + POSTGRES_EPOCH_JDATE, &y1, &m1, &d1); j2date(date2 + POSTGRES_EPOCH_JDATE, &y2, &m2, &d2); /* Ignore day components for last days, or based on a 31-day month. */ if (d1 == days_of_month(y1, m1) && d2 == days_of_month(y2, m2)) result = (y1 - y2) * 12 + (m1 - m2); else result = (y1 - y2) * 12 + (m1 - m2) + (d1 - d2) / 31.0; PG_RETURN_NUMERIC( DirectFunctionCall1(float8_numeric, Float8GetDatumFast(result))); } /******************************************************************** * * add_months * * Syntax: * * date add_months(date day, int val) * * Purpose: * * Returns a date plus n months. * ********************************************************************/ Datum add_months(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int n = PG_GETARG_INT32(1); int y, m, d; int days; DateADT result; div_t v; bool last_day; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); last_day = (d == days_of_month(y, m)); v = div(y * 12 + m - 1 + n, 12); y = v.quot; if (y < 0) y += 1; /* offset because of year 0 */ m = v.rem + 1; days = days_of_month(y, m); if (last_day || d > days) d = days; result = date2j(y, m, d) - POSTGRES_EPOCH_JDATE; PG_RETURN_DATEADT (result); } /* * ISO year * */ #define DATE2J(y,m,d) (date2j((y),(m),(d)) - POSTGRES_EPOCH_JDATE) #define J2DAY(date) (j2day(date + POSTGRES_EPOCH_JDATE)) static DateADT iso_year (int y, int m, int d) { DateADT result, result2, day; int off; result = DATE2J(y,1,1); day = DATE2J(y,m,d); off = 4 - J2DAY(result); result += off + ((off >= 0) ? - 3: + 4); /* to monday */ if (result > day) { result = DATE2J(y-1,1,1); off = 4 - J2DAY(result); result += off + ((off >= 0) ? - 3: + 4); /* to monday */ } if (((day - result) / 7 + 1) > 52) { result2 = DATE2J(y+1,1,1); off = 4 - J2DAY(result2); result2 += off + ((off >= 0) ? - 3: + 4); /* to monday */ if (day >= result2) return result2; } return result; } static DateADT _ora_date_trunc(DateADT day, int f) { int y, m, d; DateADT result; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); switch (f) { CASE_fmt_CC if (y > 0) result = DATE2J((y/100)*100+1,1,1); else result = DATE2J(-((99 - (y - 1)) / 100) * 100 + 1,1,1); break; CASE_fmt_YYYY result = DATE2J(y,1,1); break; CASE_fmt_IYYY result = iso_year(y,m,d); break; CASE_fmt_MON result = DATE2J(y,m,1); break; CASE_fmt_WW result = day - (day - DATE2J(y,1,1)) % 7; break; CASE_fmt_IW result = day - (day - iso_year(y,m,d)) % 7; break; CASE_fmt_W result = day - (day - DATE2J(y,m,1)) % 7; break; CASE_fmt_DAY result = day - J2DAY(day); break; CASE_fmt_Q result = DATE2J(y,((m-1)/3)*3+1,1); break; default: result = day; } return result; } static DateADT _ora_date_round(DateADT day, int f) { int y, m, d, z; DateADT result; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); switch (f) { CASE_fmt_CC if (y > 0) result = DATE2J((y/100)*100+(day < DATE2J((y/100)*100+50,1,1) ?1:101),1,1); else result = DATE2J((y/100)*100+(day < DATE2J((y/100)*100-50+1,1,1) ?-99:1),1,1); break; CASE_fmt_YYYY result = DATE2J(y+(day= 52) { bool overl = ((date2j(y+2,1,1)-date2j(y+1,1,1)) == 366); bool isSaturday = (J2DAY(day) == 6); DateADT iy2 = iso_year(y+2, 1, 8); DateADT day1 = DATE2J(y+1,1,1); /* exception saturdays */ if (iy1 >= (day1) && day >= day1 - 2 && isSaturday) { result = overl?iy2:iy1; } /* iso year stars in last year and day >= iso year */ else if (iy1 <= (day1) && day >= iy1 - 3) { DateADT cmp = iy1 - (iy1 < day1?0:1); int d = J2DAY(day1); /* some exceptions */ if ((day >= cmp - 2) && (!(d == 3 && overl))) { /* if year don't starts in thursday */ if ((d < 4 && J2DAY(day) != 5 && !isSaturday) ||(d == 2 && isSaturday && overl)) { result = iy2; } } } } } break; } CASE_fmt_MON result = DATE2J(y,m+(day= 52) { /* only for last iso week */ DateADT isoyear = iso_year(y+1, 1, 8); if (isoyear > (DATE2J(y+1,1,1)-1)) if (day > isoyear - 7) { int d = J2DAY(day); result -= (d == 0 || d > 4?7:0); } } break; } CASE_fmt_W z = (day - DATE2J(y,m,1)) % 7; result = day - z + (z < 4?0:7); break; CASE_fmt_DAY z = J2DAY(day); if (y > 0) result = day - z + (z < 4?0:7); else result = day + (5 - (z>0?(z>1?z:z+7):7)); break; CASE_fmt_Q result = DATE2J(y,((m-1)/3)*3+(day<(DATE2J(y,((m-1)/3)*3+2,16))?1:4),1); break; default: result = day; } return result; } /******************************************************************** * * ora_date_trunc|ora_timestamptz_trunc .. trunc * * Syntax: * * date trunc(date date1, text format) * * Purpose: * * Returns d with the time portion of the day truncated to the unit * specified by the format fmt. * ********************************************************************/ Datum ora_date_trunc(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); text *fmt = PG_GETARG_TEXT_PP(1); DateADT result; int f = ora_seq_search(VARDATA_ANY(fmt), date_fmt, VARSIZE_ANY_EXHDR(fmt)); CHECK_SEQ_SEARCH(f, "round/trunc format string"); result = _ora_date_trunc(day, f); PG_RETURN_DATEADT(result); } Datum ora_timestamptz_trunc(PG_FUNCTION_ARGS) { TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0); TimestampTz result; text *fmt = PG_GETARG_TEXT_PP(1); int tz; fsec_t fsec; struct pg_tm tt, *tm = &tt; const char *tzn; bool redotz = false; int f; if (TIMESTAMP_NOT_FINITE(timestamp)) PG_RETURN_TIMESTAMPTZ(timestamp); f = ora_seq_search(VARDATA_ANY(fmt), date_fmt, VARSIZE_ANY_EXHDR(fmt)); CHECK_SEQ_SEARCH(f, "round/trunc format string"); if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); tm->tm_sec = 0; fsec = 0; switch (f) { CASE_fmt_IYYY CASE_fmt_WW CASE_fmt_W CASE_fmt_IW CASE_fmt_DAY CASE_fmt_CC j2date(_ora_date_trunc(DATE2J(tm->tm_year, tm->tm_mon, tm->tm_mday), f) + POSTGRES_EPOCH_JDATE, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); tm->tm_hour = 0; tm->tm_min = 0; redotz = true; break; CASE_fmt_YYYY tm->tm_mon = 1; CASE_fmt_Q tm->tm_mon = (3*((tm->tm_mon - 1)/3)) + 1; CASE_fmt_MON tm->tm_mday = 1; CASE_fmt_DDD tm->tm_hour = 0; redotz = true; /* for all cases >= DAY */ CASE_fmt_HH tm->tm_min = 0; } if (redotz) tz = DetermineTimeZoneOffset(tm, session_timezone); if (tm2timestamp(tm, fsec, &tz, &result) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); PG_RETURN_TIMESTAMPTZ(result); } /******************************************************************** * * ora_date_round|ora_timestamptz_round .. round * * Syntax: * * date round(date date1, text format) * * Purpose: * * Returns d with the time portion of the day roundeded to the unit * specified by the format fmt. * ********************************************************************/ Datum ora_date_round(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); text *fmt = PG_GETARG_TEXT_PP(1); DateADT result; int f = ora_seq_search(VARDATA_ANY(fmt), date_fmt, VARSIZE_ANY_EXHDR(fmt)); CHECK_SEQ_SEARCH(f, "round/trunc format string"); result = _ora_date_round(day, f); PG_RETURN_DATEADT(result); } #define NOT_ROUND_MDAY(_p_) \ do { if (_p_) rounded = false; } while(0) #define ROUND_MDAY(_tm_) \ do { if (rounded) _tm_->tm_mday += _tm_->tm_hour >= 12?1:0; } while(0) Datum ora_timestamptz_round(PG_FUNCTION_ARGS) { TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0); TimestampTz result; text *fmt = PG_GETARG_TEXT_PP(1); int tz; fsec_t fsec; struct pg_tm tt, *tm = &tt; const char *tzn; bool redotz = false; bool rounded = true; int f; if (TIMESTAMP_NOT_FINITE(timestamp)) PG_RETURN_TIMESTAMPTZ(timestamp); f = ora_seq_search(VARDATA_ANY(fmt), date_fmt, VARSIZE_ANY_EXHDR(fmt)); CHECK_SEQ_SEARCH(f, "round/trunc format string"); if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); /* tm->tm_sec = 0; */ fsec = 0; /* set rounding rule */ switch (f) { CASE_fmt_IYYY NOT_ROUND_MDAY(tm->tm_mday < 8 && tm->tm_mon == 1); NOT_ROUND_MDAY(tm->tm_mday == 30 && tm->tm_mon == 6); if (tm->tm_mday >= 28 && tm->tm_mon == 12 && tm->tm_hour >= 12) { DateADT isoyear = iso_year(tm->tm_year+1, 1, 8); DateADT day0 = DATE2J(tm->tm_year+1,1,1); DateADT dayc = DATE2J(tm->tm_year, tm->tm_mon, tm->tm_mday); if ((isoyear <= day0) || (day0 <= dayc + 2)) { rounded = false; } } break; CASE_fmt_YYYY NOT_ROUND_MDAY(tm->tm_mday == 30 && tm->tm_mon == 6); break; CASE_fmt_MON NOT_ROUND_MDAY(tm->tm_mday == 15); break; CASE_fmt_Q NOT_ROUND_MDAY(tm->tm_mday == 15 && tm->tm_mon == ((tm->tm_mon-1)/3)*3+2); break; CASE_fmt_WW CASE_fmt_IW /* last day in year */ NOT_ROUND_MDAY(DATE2J(tm->tm_year, tm->tm_mon, tm->tm_mday) == (DATE2J(tm->tm_year+1, 1,1) - 1)); break; CASE_fmt_W /* last day in month */ NOT_ROUND_MDAY(DATE2J(tm->tm_year, tm->tm_mon, tm->tm_mday) == (DATE2J(tm->tm_year, tm->tm_mon+1,1) - 1)); break; } switch (f) { /* easier convert to date */ CASE_fmt_IW CASE_fmt_DAY CASE_fmt_IYYY CASE_fmt_WW CASE_fmt_W CASE_fmt_CC CASE_fmt_MON CASE_fmt_YYYY CASE_fmt_Q ROUND_MDAY(tm); j2date(_ora_date_round(DATE2J(tm->tm_year, tm->tm_mon, tm->tm_mday), f) + POSTGRES_EPOCH_JDATE, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); tm->tm_hour = 0; tm->tm_min = 0; redotz = true; break; CASE_fmt_DDD tm->tm_mday += (tm->tm_hour >= 12)?1:0; tm->tm_hour = 0; tm->tm_min = 0; redotz = true; break; CASE_fmt_MI tm->tm_min += (tm->tm_sec >= 30)?1:0; break; CASE_fmt_HH tm->tm_hour += (tm->tm_min >= 30)?1:0; tm->tm_min = 0; break; } tm->tm_sec = 0; if (redotz) tz = DetermineTimeZoneOffset(tm, session_timezone); if (tm2timestamp(tm, fsec, &tz, &result) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); PG_RETURN_TIMESTAMPTZ(result); } orafce-VERSION_3_0_6/expected/000077500000000000000000000000001221300436000161165ustar00rootroot00000000000000orafce-VERSION_3_0_6/expected/aggregates.out000066400000000000000000000062541221300436000207670ustar00rootroot00000000000000-- Tests for the aggregate listagg SELECT listagg(i::text) from generate_series(1,3) g(i); listagg --------- 123 (1 row) SELECT listagg(i::text, ',') from generate_series(1,3) g(i); listagg --------- 1,2,3 (1 row) SELECT coalesce(listagg(i::text), '') from (SELECT ''::text) g(i); coalesce ---------- (1 row) SELECT coalesce(listagg(i::text), '') from generate_series(1,0) g(i); coalesce ---------- (1 row) -- Tests for the aggregate median( real | double ) CREATE FUNCTION checkMedianRealOdd() RETURNS real AS $$ DECLARE med real; BEGIN CREATE TABLE median_test (salary real); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (NULL); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); SELECT into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianRealEven() RETURNS real AS $$ DECLARE med real; BEGIN CREATE TABLE median_test (salary real); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (1000); INSERT INTO median_test VALUES (4000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianDoubleOdd() RETURNS double precision AS $$ DECLARE med double precision; BEGIN CREATE TABLE median_test (salary double precision); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianDoubleEven() RETURNS double precision AS $$ DECLARE med double precision; BEGIN CREATE TABLE median_test (salary double precision); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); INSERT INTO median_test VALUES (1000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; SELECT checkMedianRealOdd(); checkmedianrealodd -------------------- 3800 (1 row) SELECT checkMedianRealEven(); checkmedianrealeven --------------------- 2850 (1 row) SELECT checkMedianDoubleOdd(); checkmediandoubleodd ---------------------- 3600 (1 row) SELECT checkMedianDoubleEven(); checkmediandoubleeven ----------------------- 2850 (1 row) DROP FUNCTION checkMedianRealOdd(); DROP FUNCTION checkMedianRealEven(); DROP FUNCTION checkMedianDoubleOdd(); DROP FUNCTION checkMedianDoubleEven(); orafce-VERSION_3_0_6/expected/dbms_alert_session_A.out000066400000000000000000000062571221300436000230000ustar00rootroot00000000000000\set ECHO all /* * DBMS_ALERT is used for one-way communication of one session to other. * * This session mainly sends signals for testing the alert functionality in * session B and C. * * The following alerts are used to ensure that signals are sent at correct * times to session B for testing. These signals are sent from session B * indicating completion of an event. * After the signal is received, the next required signal for testing is sent * from this session. */ SELECT dbms_alert.register('b1'); register ---------- (1 row) SELECT dbms_alert.register('b2'); register ---------- (1 row) SELECT dbms_alert.register('b3'); register ---------- (1 row) SELECT dbms_alert.register('b4'); register ---------- (1 row) SELECT dbms_alert.register('b5'); register ---------- (1 row) SELECT dbms_alert.signal('a1','Msg1 for a1'); signal -------- (1 row) SELECT dbms_alert.signal('a2','Msg1 for a2'); signal -------- (1 row) /* * Test: defered_signal * The signal is received only when the signalling transaction commits. * To test this, an explict BEGIN-COMMIT block is used. */ SELECT dbms_alert.signal('tds','Begin defered_signal test'); signal -------- (1 row) BEGIN; SELECT dbms_alert.signal('tds','Testing defered_signal'); signal -------- (1 row) /* The signal is received while transaction is running */ SELECT dbms_alert.waitone('b1',15); waitone --------------------------------- ("Transaction still running",0) (1 row) COMMIT; /* The signal is received after transaction completed. * After this the tds signal is received in session B indicating that the * signal is received only after commit. */ SELECT dbms_alert.waitone('b1',15); waitone ----------------------------- ("Transaction committed",0) (1 row) SELECT dbms_alert.waitone('b2',15); waitone ---------------------------------------- ("to check unregistered alert wait",0) (1 row) /* This signals a3 which is not registered in Session B */ SELECT dbms_alert.signal('a3','Msg1 for a3'); signal -------- (1 row) /* alert a4 is signalled soon after a3 */ SELECT dbms_alert.signal('a4','Test- Register after signal'); signal -------- (1 row) /* This signal indicates at remove() is called */ SELECT dbms_alert.waitone('b3',15); waitone ------------------------- ("remove(a1) called",0) (1 row) /* Send signal which is removed in session B */ SELECT dbms_alert.signal('a1','Msg2 for a1'); signal -------- (1 row) SELECT dbms_alert.waitone('b4',15); waitone -------------------------------- ("to check unremoved alert",0) (1 row) /* Send signal which is registered in B and not removed */ SELECT dbms_alert.signal('a4','Msg1 for a4'); signal -------- (1 row) /* This signal inidcates that removeall() is called */ SELECT dbms_alert.waitone('b5',15); waitone ------------------------ ("removeall called",0) (1 row) /* Send a signal to test if session B receives it after removeall() */ SELECT dbms_alert.signal('a2','Msg2 for a2'); signal -------- (1 row) /* cleanup */ SELECT dbms_alert.removeall(); removeall ----------- (1 row) orafce-VERSION_3_0_6/expected/dbms_alert_session_B.out000066400000000000000000000051311221300436000227670ustar00rootroot00000000000000\set ECHO all /* Register alerts */ SELECT dbms_alert.register('a1'); register ---------- (1 row) SELECT dbms_alert.register('a2'); register ---------- (1 row) SELECT dbms_alert.register('tds'); register ---------- (1 row) /* Test: multisession waitone */ SELECT dbms_alert.waitone('a1',10); waitone ------------------- ("Msg1 for a1",0) (1 row) /* Test: multisession waitany */ SELECT dbms_alert.waitany(2); waitany ---------------------- (a2,"Msg1 for a2",0) (1 row) /* Test defered_signal */ /* This indicated that the transaction has begun */ SELECT dbms_alert.waitone('tds',2); waitone --------------------------------- ("Begin defered_signal test",0) (1 row) /* The signal will not be received because the transaction is running */ SELECT dbms_alert.waitone('tds',2); waitone --------- (,1) (1 row) SELECT dbms_alert.signal('b1','Transaction still running'); signal -------- (1 row) SELECT dbms_alert.signal('b1','Transaction committed'); signal -------- (1 row) /* Since the transaction has commited, the signal will be received */ SELECT dbms_alert.waitone('tds',2); waitone ------------------------------ ("Testing defered_signal",0) (1 row) /* Signal session A to send msg1 for a3 */ SELECT dbms_alert.signal('b2','to check unregistered alert wait'); signal -------- (1 row) /* Test: wait for unregistered alert which is signaled*/ SELECT dbms_alert.waitone('a3',2); waitone --------- (,1) (1 row) /* Test: Register after alert is signaled and wait */ SELECT dbms_alert.register('a4'); register ---------- (1 row) SELECT dbms_alert.waitone('a4',2); waitone --------- (,1) (1 row) /* Test: remove one */ SELECT dbms_alert.remove('a1'); remove -------- (1 row) /* Signal session A to send msg2 for a1 */ SELECT dbms_alert.signal('b3','remove(a1) called'); signal -------- (1 row) /* Test: wait for removed alert */ SELECT dbms_alert.waitone('a1',2); waitone --------- (,1) (1 row) /* Signal session A to send msg1 for a4 */ SELECT dbms_alert.signal('b4','to check unremoved alert'); signal -------- (1 row) /* Test: Check if unremoved alert is received */ SELECT dbms_alert.waitone('a4',2); waitone ------------------- ("Msg1 for a4",0) (1 row) /* Test removeall */ SELECT dbms_alert.removeall(); removeall ----------- (1 row) /* Signal session A to send msg2 for a2 */ SELECT dbms_alert.signal('b5','removeall called'); signal -------- (1 row) /* Test: Use waitany to see if any alert is received */ SELECT dbms_alert.waitany(2); waitany --------- (,,1) (1 row) orafce-VERSION_3_0_6/expected/dbms_alert_session_C.out000066400000000000000000000010161221300436000227660ustar00rootroot00000000000000\set ECHO all /* Register alerts */ SELECT dbms_alert.register('a1'); register ---------- (1 row) SELECT dbms_alert.register('a2'); register ---------- (1 row) /* Test: multisession waitone */ SELECT dbms_alert.waitone('a1',2); waitone ------------------- ("Msg1 for a1",0) (1 row) /* Test: multisession waitany */ SELECT dbms_alert.waitany(2); waitany ---------------------- (a2,"Msg1 for a2",0) (1 row) /* cleanup */ SELECT dbms_alert.removeall(); removeall ----------- (1 row) orafce-VERSION_3_0_6/expected/dbms_output.out000066400000000000000000001063121221300436000212170ustar00rootroot00000000000000\set ECHO none DROP FUNCTION dbms_output_test(); ERROR: function dbms_output_test() does not exist DROP TABLE dbms_output_test; ERROR: table "dbms_output_test" does not exist -- DBMS_OUTPUT.DISABLE [0] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status --------+-------- | 1 (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT_LINE [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20) := 'orafce'; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE'); PERFORM DBMS_OUTPUT.PUT_LINE (buff1); PERFORM DBMS_OUTPUT.PUT ('ABC'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE orafce ABC dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT_LINE [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORA F CE dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20) := 'ora'; buff2 VARCHAR(20) := 'f'; buff3 VARCHAR(20) := 'ce'; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.PUT ('F'); PERFORM DBMS_OUTPUT.PUT ('CE'); PERFORM DBMS_OUTPUT.PUT_LINE (''); PERFORM DBMS_OUTPUT.PUT ('ABC'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE ABC dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORA F CE'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORA F CE dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 ORAFCE TEST 2 | 0 (2 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 ORAFCE TEST 3 | 0 | 1 | 1 (4 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORA'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 ORA | 0 | 1 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [4] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 | 0 | 1 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1 '); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT REPLACE(buff, ' ', '') FROM dbms_output_test; replace ------------------- ORAFCE TEST 1 ORAFCE TEST 2 (2 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT regexp_replace(buff, E'\n', '', 'g') FROM dbms_output_test limit 1; regexp_replace ---------------- ORAFCE (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); buff1 VARCHAR(20); buff2 VARCHAR(20); buff3 VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff1,buff2,buff3,stts lines[1],lines[2],lines[3],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); INSERT INTO dbms_output_test VALUES (buff3, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 3 ORAFCE TEST 2 | 3 ORAFCE TEST 3 | 3 | 0 (4 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); buff1 VARCHAR(20); buff2 VARCHAR(20); stts INTEGER := 2; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff1,buff2,stts lines[1],lines[2],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 2 ORAFCE TEST 2 | 2 ORAFCE TEST 3 | 1 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 1 ORAFCE TEST 3 | 1 | 0 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [4] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORA'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 1 ORA | 1 | 0 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 1 | 1 | 0 (3 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT regexp_replace(buff, E'\n', '', 'g') FROM dbms_output_test limit 1; regexp_replace ---------------- ORAFCE (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.NEW_LINE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20); buff2 VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.PUT ('FCE'); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff1,buff2,stts lines[1],lines[2],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ------+-------- ORA | 2 FCE | 2 (2 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.NEW_LINE [2] CREATE TABLE dbms_output_test (buff VARCHAR(3000), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(3000); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.ENABLE(2000); FOR j IN 1..1999 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); END LOOP; PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff1,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT buff FROM dbms_output_test; buff --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.DISABLE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); PERFORM DBMS_OUTPUT.DISABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 4'); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 5'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status --------+-------- | 1 | 1 | 1 | 0 | 1 (5 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.DISABLE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status --------+-------- | 0 (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); status INTEGER; num INTEGER := 2000; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.ENABLE(2000); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE TEST 1 dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ------+-------- (0 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 ORAFCE TEST 2 | 0 (2 rows) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 1 (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [4] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); FOR j IN 1..2000 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); END LOOP; PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(NULL); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) SELECT * FROM dbms_output_test; buff | status ---------------+-------- ORAFCE TEST 1 | 0 (1 row) DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIn PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE TEST 2 dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE TEST 2 dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [3] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); ORAFCE TEST 1 dbms_output_test ------------------ (1 row) DROP FUNCTION dbms_output_test(); orafce-VERSION_3_0_6/expected/dbms_pipe_session_A.out000066400000000000000000000013011221300436000226070ustar00rootroot00000000000000\set ECHO none pack_message -------------- (1 row) send_message -------------- 0 (1 row) createimplicitpipe -------------------- (1 row) bulksend ---------- (1 row) notify -------- (1 row) createexplicitpipe -------------------- (1 row) notify -------- (1 row) createexplicitpipe -------------------- (1 row) notify -------- (1 row) createexplicitpipe -------------------- (1 row) notify -------- (1 row) createexplicitpipe -------------------- (1 row) checksend1 ------------ (1 row) checksend2 ------------ (1 row) notifydroptemp ---------------- (1 row) checkuniquesessionnamea ------------------------- (1 row) orafce-VERSION_3_0_6/expected/dbms_pipe_session_B1.out000066400000000000000000000066361221300436000227110ustar00rootroot00000000000000\set ECHO none receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: NOTICE: RECEIVE 24: (2,rob) bulkreceive ------------- (1 row) receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: role "pipe_test_other" does not exist, skipping receive_message ----------------- 0 (1 row) ERROR: insufficient privilege receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: RECEIVE checking one-argument send_message() checkreceive1 --------------- (1 row) NOTICE: RECEIVE checking two-argument send_message() checkreceive1 --------------- (1 row) name | items | limit | private | owner ----------------+-------+-------+---------+----------------- private_pipe_1 | 0 | 10 | t | pipe_test_owner private_pipe_2 | 9 | 10 | t | pipe_test_owner (2 rows) name | items | limit | private | owner ----------------+-------+-------+---------+----------------- pipe_name_3 | 1 | | f | private_pipe_1 | 0 | 10 | t | pipe_test_owner private_pipe_2 | 9 | 10 | t | pipe_test_owner public_pipe_3 | 0 | 10 | f | public_pipe_4 | 0 | 10 | f | (5 rows) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) purge ------- (1 row) purge ------- (1 row) droptemptable --------------- (1 row) purge ------- (1 row) checkuniquesessionnameb ------------------------- f (1 row) purge ------- (1 row) receive_message ----------------- 1 (1 row) purge ------- (1 row) orafce-VERSION_3_0_6/expected/dbms_pipe_session_B2.out000066400000000000000000000066551221300436000227130ustar00rootroot00000000000000\set ECHO none receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: \201 NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: \201 NOTICE: RECEIVE 24: (2,rob) bulkreceive ------------- (1 row) receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: \201 NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: role "pipe_test_other" does not exist, skipping receive_message ----------------- 0 (1 row) ERROR: insufficient privilege receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: \201 NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) receive_message ----------------- 0 (1 row) NOTICE: RECEIVE 11: Message From Session A NOTICE: RECEIVE 12: 01-01-2013 NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 13: Tue Jan 01 09:00:00 2013 PST NOTICE: RECEIVE 9: 12345.6789 NOTICE: RECEIVE 9: 12345 NOTICE: RECEIVE 9: 99999999999 NOTICE: RECEIVE 23: \201 NOTICE: RECEIVE 24: (2,rob) receivefrom ------------- (1 row) NOTICE: RECEIVE checking one-argument send_message() checkreceive1 --------------- (1 row) NOTICE: RECEIVE checking two-argument send_message() checkreceive1 --------------- (1 row) name | items | limit | private | owner ----------------+-------+-------+---------+----------------- private_pipe_1 | 0 | 10 | t | pipe_test_owner private_pipe_2 | 9 | 10 | t | pipe_test_owner (2 rows) name | items | limit | private | owner ----------------+-------+-------+---------+----------------- pipe_name_3 | 1 | | f | private_pipe_1 | 0 | 10 | t | pipe_test_owner private_pipe_2 | 9 | 10 | t | pipe_test_owner public_pipe_3 | 0 | 10 | f | public_pipe_4 | 0 | 10 | f | (5 rows) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) remove_pipe ------------- (1 row) purge ------- (1 row) purge ------- (1 row) droptemptable --------------- (1 row) purge ------- (1 row) checkuniquesessionnameb ------------------------- f (1 row) purge ------- (1 row) receive_message ----------------- 1 (1 row) purge ------- (1 row) orafce-VERSION_3_0_6/expected/dbms_random.out000066400000000000000000000021551221300436000211370ustar00rootroot00000000000000-- Tests for package DBMS_RANDOM SELECT dbms_random.initialize(8); initialize ------------ (1 row) SELECT dbms_random.normal(); normal -------------------- -0.377877688597918 (1 row) SELECT dbms_random.normal(); normal ------------------- 0.804998041043833 (1 row) SELECT dbms_random.seed(8); seed ------ (1 row) SELECT dbms_random.random(); random ------------ -632387854 (1 row) SELECT dbms_random.seed('test'); seed ------ (1 row) SELECT dbms_random.string('U',5); string -------- XEJGE (1 row) SELECT dbms_random.string('P',2); string -------- T9 (1 row) SELECT dbms_random.string('x',4); string -------- FVGL (1 row) SELECT dbms_random.string('a',2); string -------- AZ (1 row) SELECT dbms_random.string('l',3); string -------- hmo (1 row) SELECT dbms_random.seed(5); seed ------ (1 row) SELECT dbms_random.value(); value ------------------- 0.274745596107095 (1 row) SELECT dbms_random.value(10,15); value ------------------ 10.2323388238437 (1 row) SELECT dbms_random.terminate(); terminate ----------- (1 row) orafce-VERSION_3_0_6/expected/dbms_utility.out000066400000000000000000000006341221300436000213620ustar00rootroot00000000000000\set ECHO none checkhexcallstack ----- PL/pgSQL Call Stack ----- object line object handle number name 0 function anonymous object 0 function checkhexcallstack (1 row) checkintcallstack 0 function anonymous object 0 function checkintcallstack (1 row) checkintunpaddedcallstack 0,,anonymous object 0,,checkintunpaddedcallstack (1 row) orafce-VERSION_3_0_6/expected/files.out000066400000000000000000000127701221300436000177600ustar00rootroot00000000000000SET client_min_messages = NOTICE; \set VERBOSITY terse \set ECHO all CREATE OR REPLACE FUNCTION gen_file(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; BEGIN f := utl_file.fopen(dir, 'regress_orafce.txt', 'w'); PERFORM utl_file.put_line(f, 'ABC'); PERFORM utl_file.put_line(f, '123'::numeric); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f, 0); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f, 2); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.put(f, 'A'); PERFORM utl_file.put(f, 'B'); PERFORM utl_file.new_line(f); PERFORM utl_file.putf(f, '[1=%s, 2=%s, 3=%s, 4=%s, 5=%s]', '1', '2', '3', '4', '5'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '1234567890'); f := utl_file.fclose(f); END; $$ LANGUAGE plpgsql; /* Test functions utl_file.fflush(utl_file.file_type) and * utl_file.get_nextline(utl_file.file_type) * This function tests the positive test case of fflush by reading from the * file after flushing the contents to the file. */ CREATE OR REPLACE FUNCTION checkFlushFile(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; f1 utl_file.file_type; ret_val text; i integer; BEGIN f := utl_file.fopen(dir, 'regressflush_orafce.txt', 'a'); PERFORM utl_file.put_line(f, 'ABC'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '123'::numeric); PERFORM utl_file.new_line(f); PERFORM utl_file.putf(f, '[1=%s, 2=%s, 3=%s, 4=%s, 5=%s]', '1', '2', '3', '4', '5'); PERFORM utl_file.fflush(f); f1 := utl_file.fopen(dir, 'regressflush_orafce.txt', 'r'); ret_val=utl_file.get_nextline(f1); i:=1; WHILE ret_val IS NOT NULL LOOP RAISE NOTICE '[%] >>%<<', i,ret_val; ret_val := utl_file.get_nextline(f1); i:=i+1; END LOOP; RAISE NOTICE '>>%<<', ret_val; f1 := utl_file.fclose(f1); f := utl_file.fclose(f); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION read_file(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; BEGIN f := utl_file.fopen(dir, 'regress_orafce.txt', 'r'); FOR i IN 1..11 LOOP RAISE NOTICE '[%] >>%<<', i, utl_file.get_line(f); END LOOP; RAISE NOTICE '>>%<<', utl_file.get_line(f, 4); RAISE NOTICE '>>%<<', utl_file.get_line(f, 4); RAISE NOTICE '>>%<<', utl_file.get_line(f); RAISE NOTICE '>>%<<', utl_file.get_line(f); EXCEPTION -- WHEN no_data_found THEN, 8.1 plpgsql doesn't know no_data_found WHEN others THEN RAISE NOTICE 'finish % ', sqlerrm; RAISE NOTICE 'is_open = %', utl_file.is_open(f); PERFORM utl_file.fclose_all(); RAISE NOTICE 'is_open = %', utl_file.is_open(f); END; $$ LANGUAGE plpgsql; SELECT EXISTS(SELECT * FROM pg_catalog.pg_class where relname='utl_file_dir') AS exists; exists -------- t (1 row) SELECT EXISTS(SELECT * FROM pg_catalog.pg_type where typname='file_type') AS exists; exists -------- t (1 row) -- Trying to access a file in path not registered SELECT utl_file.fopen(utl_file.tmpdir(),'sample.txt','r'); ERROR: UTL_FILE_INVALID_PATH -- Trying to access file in a non-existent directory INSERT INTO utl_file.utl_file_dir(dir) VALUES('test_tmp_dir'); SELECT utl_file.fopen('test_tmp_dir','file.txt.','w'); ERROR: UTL_FILE_INVALID_PATH DELETE FROM utl_file.utl_file_dir WHERE dir LIKE 'test_tmp_dir'; -- Add tmpdir() to utl_file_dir table INSERT INTO utl_file.utl_file_dir(dir) VALUES(utl_file.tmpdir()); SELECT * from utl_file.utl_file_dir; dir ------ /tmp (1 row) -- Trying to access non-existent file SELECT utl_file.fopen(utl_file.tmpdir(),'non_existent_file.txt','r'); ERROR: UTL_FILE_INVALID_PATH --Other test cases SELECT gen_file(utl_file.tmpdir()); gen_file ---------- (1 row) SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); fexists --------- t (1 row) SELECT utl_file.fcopy(utl_file.tmpdir(), 'regress_orafce.txt', utl_file.tmpdir(), 'regress_orafce2.txt'); fcopy ------- (1 row) SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt'); fexists --------- t (1 row) SELECT utl_file.frename(utl_file.tmpdir(), 'regress_orafce2.txt', utl_file.tmpdir(), 'regress_orafce.txt', true); frename --------- (1 row) SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); fexists --------- t (1 row) SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt'); fexists --------- f (1 row) SELECT read_file(utl_file.tmpdir()); NOTICE: [1] >>ABC<< NOTICE: [2] >>123<< NOTICE: [3] >>-----<< NOTICE: [4] >><< NOTICE: [5] >>-----<< NOTICE: [6] >>-----<< NOTICE: [7] >><< NOTICE: [8] >><< NOTICE: [9] >>-----<< NOTICE: [10] >>AB<< NOTICE: [11] >>[1=1, 2=2, 3=3, 4=4, 5=5]<< NOTICE: >>1234<< NOTICE: >>5678<< NOTICE: >>90<< NOTICE: finish no data found NOTICE: is_open = t NOTICE: is_open = f read_file ----------- (1 row) SELECT utl_file.fremove(utl_file.tmpdir(), 'regress_orafce.txt'); fremove --------- (1 row) SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); fexists --------- f (1 row) DROP FUNCTION gen_file(text); DROP FUNCTION read_file(text); SELECT checkFlushFile(utl_file.tmpdir()); NOTICE: [1] >>ABC<< NOTICE: [2] >><< NOTICE: [3] >>123<< NOTICE: [4] >><< NOTICE: [5] >>[1=1, 2=2, 3=3, 4=4, 5=5]<< NOTICE: >><< checkflushfile ---------------- (1 row) SELECT utl_file.fremove(utl_file.tmpdir(), 'regressflush_orafce.txt'); fremove --------- (1 row) DROP FUNCTION checkFlushFile(text); DELETE FROM utl_file.utl_file_dir; orafce-VERSION_3_0_6/expected/init.out000066400000000000000000000000171221300436000176100ustar00rootroot00000000000000\set ECHO none orafce-VERSION_3_0_6/expected/nlssort.out000066400000000000000000000010451221300436000203530ustar00rootroot00000000000000-- Tests for nlssort \set ECHO none name -------- brown Purple red yellow (4 rows) name -------- Purple brown red yellow (4 rows) set_nls_sort -------------- (1 row) ERROR: failed to set the requested LC_COLLATE value [invalid] CONTEXT: SQL function "nlssort" statement 1 set_nls_sort -------------- (1 row) name -------- Purple brown red yellow (4 rows) set_nls_sort -------------- (1 row) name -------- brown Purple red yellow (4 rows) name -------- brown Purple red yellow (5 rows) orafce-VERSION_3_0_6/expected/orafunc1.out000066400000000000000000001431321221300436000203710ustar00rootroot00000000000000\set ECHO none -- -- test built-in date type oracle compatibility functions -- SELECT add_months ('2003-08-01', 3); add_months ------------ 2003-11-01 (1 row) SELECT add_months ('2003-08-01', -3); add_months ------------ 2003-05-01 (1 row) SELECT add_months ('2003-08-21', -3); add_months ------------ 2003-05-21 (1 row) SELECT add_months ('2003-01-31', 1); add_months ------------ 2003-02-28 (1 row) SELECT add_months ('2008-02-28', 1); add_months ------------ 2008-03-28 (1 row) SELECT add_months ('2008-02-29', 1); add_months ------------ 2008-03-31 (1 row) SELECT add_months ('2008-01-31', 12); add_months ------------ 2009-01-31 (1 row) SELECT add_months ('2008-01-31', -12); add_months ------------ 2007-01-31 (1 row) SELECT add_months ('2008-01-31', 95903); add_months ------------ 9999-12-31 (1 row) SELECT add_months ('2008-01-31', -80640); add_months --------------- 4712-01-31 BC (1 row) SELECT add_months ('03-21-2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('21-MAR-2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('21-MAR-08',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('2008-MAR-21',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('March 21,2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('03/21/2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('20080321',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('080321',3); add_months ------------ 2008-06-21 (1 row) SELECT last_day(to_date('2003/03/15', 'yyyy/mm/dd')); last_day ------------ 2003-03-31 (1 row) SELECT last_day(to_date('2003/02/03', 'yyyy/mm/dd')); last_day ------------ 2003-02-28 (1 row) SELECT last_day(to_date('2004/02/03', 'yyyy/mm/dd')); last_day ------------ 2004-02-29 (1 row) SELECT last_day('1900-02-01'); last_day ------------ 1900-02-28 (1 row) SELECT last_day('2000-02-01'); last_day ------------ 2000-02-29 (1 row) SELECT last_day('2007-02-01'); last_day ------------ 2007-02-28 (1 row) SELECT last_day('2008-02-01'); last_day ------------ 2008-02-29 (1 row) SELECT next_day ('2003-08-01', 'TUESDAY'); next_day ------------ 2003-08-05 (1 row) SELECT next_day ('2003-08-06', 'WEDNESDAY'); next_day ------------ 2003-08-13 (1 row) SELECT next_day ('2003-08-06', 'SUNDAY'); next_day ------------ 2003-08-10 (1 row) SELECT next_day ('2008-01-01', 'sun'); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 'sunAAA'); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 1); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 7); next_day ------------ 2008-01-05 (1 row) SELECT months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); months_between ------------------- -2.41935483870968 (1 row) SELECT months_between (to_date ('2003/07/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); months_between ------------------ 3.58064516129032 (1 row) SELECT months_between (to_date ('2003/07/02', 'yyyy/mm/dd'), to_date ('2003/07/02', 'yyyy/mm/dd')); months_between ---------------- 0 (1 row) SELECT months_between (to_date ('2003/08/02', 'yyyy/mm/dd'), to_date ('2003/06/02', 'yyyy/mm/dd')); months_between ---------------- 2 (1 row) SELECT months_between ('2007-02-28', '2007-04-30'); months_between ---------------- -2 (1 row) SELECT months_between ('2008-01-31', '2008-02-29'); months_between ---------------- -1 (1 row) SELECT months_between ('2008-02-29', '2008-03-31'); months_between ---------------- -1 (1 row) SELECT months_between ('2008-02-29', '2008-04-30'); months_between ---------------- -2 (1 row) SELECT trunc(months_between('21-feb-2008', '2008-02-29')); trunc ------- 0 (1 row) select length('jmenuji se Pavel Stehule'),dbms_pipe.pack_message('jmenuji se Pavel Stehule'); length | pack_message --------+-------------- 24 | (1 row) select length('a bydlim ve Skalici'),dbms_pipe.pack_message('a bydlim ve Skalici'); length | pack_message --------+-------------- 19 | (1 row) select dbms_pipe.send_message('pavel',0,1); send_message -------------- 0 (1 row) select dbms_pipe.send_message('pavel',0,2); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('pavel',0); receive_message ----------------- 0 (1 row) select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; ?column? ---------------------------------- >>>>jmenuji se Pavel Stehule<<<< (1 row) select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; ?column? ----------------------------- >>>>a bydlim ve Skalici<<<< (1 row) select dbms_pipe.receive_message('pavel',0); receive_message ----------------- 0 (1 row) select dbms_pipe.purge('bob'); purge ------- (1 row) select dbms_pipe.reset_buffer(); reset_buffer -------------- (1 row) select dbms_pipe.pack_message('012345678901234+1'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.pack_message('012345678901234+2'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.pack_message('012345678901234+3'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) -------------------------------------------- select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+1 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+2 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+3 (1 row) select dbms_pipe.unique_session_name() LIKE 'PG$PIPE$%'; ?column? ---------- t (1 row) select dbms_pipe.pack_message('012345678901234-1'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234-1 (1 row) select dbms_pipe.pack_message('012345678901234-2'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234-2 (1 row) select dbms_pipe.pack_message(TO_DATE('2006-10-11', 'YYYY-MM-DD')); pack_message -------------- (1 row) select dbms_pipe.send_message('test_date'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_date'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 12 (1 row) select dbms_pipe.unpack_message_date(); unpack_message_date --------------------- 2006-10-11 (1 row) select dbms_pipe.pack_message(to_timestamp('2008-10-30 01:23:45', 'YYYY-MM-DD HH24:MI:SS')); pack_message -------------- (1 row) select dbms_pipe.send_message('test_timestamp'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_timestamp'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 13 (1 row) select to_char(dbms_pipe.unpack_message_timestamp(), 'YYYY-MM-DD HH24:MI:SS'); to_char --------------------- 2008-10-30 01:23:45 (1 row) select dbms_pipe.pack_message(6262626262::numeric); pack_message -------------- (1 row) select dbms_pipe.send_message('test_int'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_int'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 9 (1 row) select dbms_pipe.unpack_message_number(); unpack_message_number ----------------------- 6262626262 (1 row) select dbms_pipe.purge('bob'); purge ------- (1 row) select name, items, "limit", private, owner from dbms_pipe.db_pipes where name = 'bob'; name | items | limit | private | owner ------+-------+-------+---------+------- (0 rows) select PLVstr.betwn('Harry and Sally are very happy', 7, 9); betwn ------- and (1 row) select PLVstr.betwn('Harry and Sally are very happy', 7, 9, FALSE); betwn ------- n (1 row) select PLVstr.betwn('Harry and Sally are very happy', -3, -1); betwn ------- ppy (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry'); betwn ------- arry (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 1,1,FALSE,FALSE); betwn ------- r (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 2,1,TRUE,FALSE); betwn -------------------- and Sally are very (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'y', 2,1); betwn ----------- and Sally (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 2); betwn ------------- and Sally a (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 3, FALSE,FALSE); betwn --------------------- nd Sally are very h (1 row) select plvsubst.string('My name is %s %s.', ARRAY['Pavel','Stěhule']); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is % %.', ARRAY['Pavel','Stěhule'], '%'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s.', ARRAY['Stěhule']); string --------------------- My name is Stěhule. (1 row) select plvsubst.string('My name is %s %s.', 'Pavel,Stěhule'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s %s.', 'Pavel|Stěhule','|'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s.', 'Stěhule'); string --------------------- My name is Stěhule. (1 row) select plvsubst.string('My name is %s.', ''); ERROR: too few parameters specified for template string select plvsubst.string('My name is empty.', ''); string ------------------- My name is empty. (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'YEAR') = to_date ('01-JAN-04', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'Q') = to_date ('01-OCT-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'MONTH') = to_date ('01-SEP-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DAY') = to_date ('24-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'YEAR') = to_date ('01-JAN-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'Q') = to_date ('01-JUL-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'MONTH') = to_date ('01-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DAY') = to_date ('17-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','YEAR') = '2004-01-01 00:00:00-08'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','Q') = '2004-10-01 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MONTH') = '2004-10-01 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DDD') = '2004-10-19 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DAY') = '2004-10-17 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','HH') = '2004-10-19 01:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MI') = '2004-10-19 01:23:00-07'; ?column? ---------- t (1 row) select next_day(to_date('01-Aug-03', 'DD-MON-YY'), 'TUESDAY') = to_date ('05-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'WEDNESDAY') = to_date ('13-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'SUNDAY') = to_date ('10-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select instr('Tech on the net', 'e') =2; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 1) = 2; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 2) = 11; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 3) = 14; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', -3, 2) = 2; ?column? ---------- t (1 row) select instr('abc', NULL) IS NULL; ?column? ---------- t (1 row) select 1 = instr('abc', ''); ?column? ---------- t (1 row) select 1 = instr('abc', 'a'); ?column? ---------- t (1 row) select 3 = instr('abc', 'c'); ?column? ---------- t (1 row) select 0 = instr('abc', 'z'); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', 1); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', 2); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 7); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 9); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', -1); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', -8); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', -9); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', -10); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', 1, 1); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', 1, 2); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 1, 3); ?column? ---------- t (1 row) select oracle.substr('This is a test', 6, 2) = 'is'; ?column? ---------- t (1 row) select oracle.substr('This is a test', 6) = 'is a test'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', 1, 4) = 'Tech'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -3, 3) = 'Net'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -6, 3) = 'The'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, 2) = 'On'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, 0) = ''; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, -1) = ''; ?column? ---------- (1 row) select concat('Tech on', ' the Net') = 'Tech on the Net'; ?column? ---------- t (1 row) select concat('a', 'b') = 'ab'; ?column? ---------- t (1 row) select concat('a', NULL) = 'a'; ?column? ---------- t (1 row) select concat(NULL, 'b') = 'b'; ?column? ---------- t (1 row) select concat('a', 2) = 'a2'; ?column? ---------- t (1 row) select concat(1, 'b') = '1b'; ?column? ---------- t (1 row) select concat(1, 2) = '12'; ?column? ---------- t (1 row) select concat(1, NULL) = '1'; ?column? ---------- t (1 row) select concat(NULL, 2) = '2'; ?column? ---------- t (1 row) select nvl('A'::text, 'B'); nvl ----- A (1 row) select nvl(NULL::text, 'B'); nvl ----- B (1 row) select nvl(NULL::text, NULL); nvl ----- (1 row) select nvl(1, 2); nvl ----- 1 (1 row) select nvl(NULL, 2); nvl ----- 2 (1 row) select nvl2('A'::text, 'B', 'C'); nvl2 ------ B (1 row) select nvl2(NULL::text, 'B', 'C'); nvl2 ------ C (1 row) select nvl2('A'::text, NULL, 'C'); nvl2 ------ (1 row) select nvl2(NULL::text, 'B', NULL); nvl2 ------ (1 row) select nvl2(1, 2, 3); nvl2 ------ 2 (1 row) select nvl2(NULL, 2, 3); nvl2 ------ 3 (1 row) select lnnvl(true); lnnvl ------- f (1 row) select lnnvl(false); lnnvl ------- t (1 row) select lnnvl(NULL); lnnvl ------- t (1 row) select decode(1, 1, 100, 2, 200); decode -------- 100 (1 row) select decode(2, 1, 100, 2, 200); decode -------- 200 (1 row) select decode(3, 1, 100, 2, 200); decode -------- (1 row) select decode(3, 1, 100, 2, 200, 300); decode -------- 300 (1 row) select decode(NULL, 1, 100, NULL, 200, 300); decode -------- 200 (1 row) select decode('1'::text, '1', 100, '2', 200); decode -------- 100 (1 row) select decode(2, 1, 'ABC', 2, 'DEF'); decode -------- DEF (1 row) select decode('2009-02-05'::date, '2009-02-05', 'ok'); decode -------- ok (1 row) select decode('2009-02-05 01:02:03'::timestamp, '2009-02-05 01:02:03', 'ok'); decode -------- ok (1 row) -- For type 'bpchar' select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar); decode ---------- postgres (1 row) select decode('c'::bpchar, 'a'::bpchar,'postgres'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('c', 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar); decode ---------- database (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar); decode -------- (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar,'default value'::bpchar); decode ---------- database (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) -- For type 'bigint' select decode(2147483651::bigint, 2147483650::bigint,2147483650::bigint); decode -------- (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint); decode -------- (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); decode -------- (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); decode -------- (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint); decode ------------ 2147483651 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint); decode -------- (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint,9999999999::bigint); decode ------------ 2147483651 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) -- For type 'numeric' select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4)); decode ------------- 214748.3651 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4)); decode -------- (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3651 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) --For type 'date' select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); decode ------------ 2012-12-21 (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-31 (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); decode ------------ 2013-01-01 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date); decode ------------ 2012-12-21 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date); decode -------- (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-21 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-31 (1 row) -- For type 'time' select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:01'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time); decode ---------- 12:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time); decode -------- (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time,'00:00:00'::time); decode ---------- 12:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) -- For type 'timestamp' select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp); decode --------------------- 2012-12-20 12:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode -------- (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 12:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) -- For type 'timestamptz' select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode(4, 1,'2012-12-20 09:00:00-08'::timestamptz,2,'2012-12-20 12:00:00-08'::timestamptz, 3, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 12:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode -------- (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 12:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) --Test case to check if decode accepts other expressions as a key CREATE OR REPLACE FUNCTION five() RETURNS integer AS $$ BEGIN RETURN 5; END; $$ LANGUAGE plpgsql; select decode(five(), 1, 'one', 2, 'two', 5, 'five'); decode -------- five (1 row) DROP FUNCTION five(); -- Test case to check duplicate keys in search list select decode(1, 1, 'one', 2, 'two', 1, 'one-again') = 'one'; ?column? ---------- t (1 row) /* Test case to check explicit type casting of keys in search list in * case of ambiguous key (1st argument) provided. */ -- 1) succeed and return 'result-1' select decode('2012-01-01', '2012-01-01'::date,'result-1','2012-01-02', 'result-2'); decode ---------- result-1 (1 row) select decode('2012-01-01', '2012-01-01', 'result-1', '2012-02-01'::date, 'result-2'); decode ---------- result-1 (1 row) -- 2) fails and throws error: 'ERROR: could not determine polymorphic type -- because input has type "unknown"' select decode('2012-01-01', '2012-01-01', 23, '2012-01-02', 24); ERROR: could not determine anyarray/anyelement type because input has type "unknown" select PLVstr.rvrs ('Jumping Jack Flash') ='hsalF kcaJ gnipmuJ'; ?column? ---------- t (1 row) select PLVstr.rvrs ('Jumping Jack Flash', 9) = 'hsalF kcaJ'; ?column? ---------- t (1 row) select PLVstr.rvrs ('Jumping Jack Flash', 4, 6) = 'nip'; ?column? ---------- t (1 row) select PLVstr.lstrip ('*val1|val2|val3|*', '*') = 'val1|val2|val3|*'; ?column? ---------- t (1 row) select PLVstr.lstrip (',,,val1,val2,val3,', ',', 3)= 'val1,val2,val3,'; ?column? ---------- t (1 row) select PLVstr.lstrip ('WHERE WHITE = ''FRONT'' AND COMP# = 1500', 'WHERE ') = 'WHITE = ''FRONT'' AND COMP# = 1500'; ?column? ---------- t (1 row) select plvstr.left('Příliš žluťoučký kůň',4) = pg_catalog.substr('Příl', 1, 4); ?column? ---------- t (1 row) select pos,token from plvlex.tokens('select * from a.b.c join d ON x=y', true, true); pos | token -----+-------- 0 | select 7 | * 9 | from 14 | a.b.c 20 | join 25 | d 27 | on 30 | x 31 | = 32 | y (10 rows) SET lc_numeric TO 'C'; select to_char(22); to_char --------- 22 (1 row) select to_char(-44444); to_char --------- -44444 (1 row) select to_char(1234567890123456::bigint); to_char ------------------ 1234567890123456 (1 row) select to_char(123.456::real); to_char ------------ 123.456001 (1 row) select to_char(1234.5678::double precision); to_char ------------- 1234.567800 (1 row) select to_char(12345678901234567890::numeric); to_char ---------------------- 12345678901234567890 (1 row) select to_char(1234567890.12345); to_char ------------------ 1234567890.12345 (1 row) select to_char('4.00'::numeric); to_char --------- 4 (1 row) select to_char('4.0010'::numeric); to_char --------- 4.001 (1 row) SELECT to_number('123'::text); to_number ----------- 123 (1 row) SELECT to_number('123.456'::text); to_number ----------- 123.456 (1 row) SELECT to_date('2009-01-02'); to_date ------------ 2009-01-02 (1 row) SELECT bitand(5,1), bitand(5,2), bitand(5,4); bitand | bitand | bitand --------+--------+-------- 1 | 0 | 4 (1 row) SELECT sinh(1.570796), cosh(1.570796), tanh(4); sinh | cosh | tanh -----------------+------------------+------------------- 2.3012980823207 | 2.50917772660545 | 0.999329299739067 (1 row) SELECT nanvl(12345, 1), nanvl('NaN', 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::float4, 1), nanvl('NaN'::float4, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::float8, 1), nanvl('NaN'::float8, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::numeric, 1), nanvl('NaN'::numeric, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) select dbms_assert.enquote_literal('some text '' some text'); enquote_literal -------------------------- 'some text '' some text' (1 row) select dbms_assert.enquote_name('''"AAA'); enquote_name -------------- "'""aaa" (1 row) select dbms_assert.enquote_name('''"AAA', false); enquote_name -------------- "'""AAA" (1 row) select dbms_assert.noop('some string'); noop ------------- some string (1 row) select dbms_assert.qualified_sql_name('aaa.bbb.ccc."aaaa""aaa"'); qualified_sql_name ------------------------- aaa.bbb.ccc."aaaa""aaa" (1 row) select dbms_assert.qualified_sql_name('aaa.bbb.cc%c."aaaa""aaa"'); ERROR: string is not qualified SQL name select dbms_assert.schema_name('dbms_assert'); schema_name ------------- dbms_assert (1 row) select dbms_assert.schema_name('jabadabado'); ERROR: invalid schema name select dbms_assert.simple_sql_name('"Aaa dghh shsh"'); simple_sql_name ----------------- "Aaa dghh shsh" (1 row) select dbms_assert.simple_sql_name('ajajaj -- ajaj'); ERROR: string is not simple SQL name select dbms_assert.object_name('pg_catalog.pg_class'); object_name --------------------- pg_catalog.pg_class (1 row) select dbms_assert.object_name('dbms_assert.fooo'); ERROR: invalid object name select plunit.assert_true(NULL); ERROR: plunit.assert_true exception DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 2); ERROR: plunit.assert_true exception DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 2, 'one is not two'); ERROR: one is not two DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 1); assert_true ------------- (1 row) select plunit.assert_false(1 = 1); ERROR: plunit.assert_false exception DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_false(1 = 1, 'trap is open'); ERROR: trap is open DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_false(NULL); ERROR: plunit.assert_false exception DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_null(current_date); ERROR: plunit.assert_null exception DETAIL: Plunit.assertation fails (assert_null). select plunit.assert_null(NULL::date); assert_null ------------- (1 row) select plunit.assert_not_null(current_date); assert_not_null ----------------- (1 row) select plunit.assert_not_null(NULL::date); ERROR: plunit.assert_not_null exception DETAIL: Plunit.assertation fails (assert_not_null). select plunit.assert_equals('Pavel','Pa'||'vel'); assert_equals --------------- (1 row) select plunit.assert_equals(current_date, current_date + 1, 'diff dates'); ERROR: diff dates DETAIL: Plunit.assertation fails (assert_equals). select plunit.assert_equals(10.2, 10.3, 0.5); assert_equals --------------- (1 row) select plunit.assert_equals(10.2, 10.3, 0.01, 'attention some diff'); ERROR: attention some diff DETAIL: Plunit.assertation fails (assert_equals). select plunit.assert_not_equals(current_date, current_date + 1, 'yestarday is today'); assert_not_equals ------------------- (1 row) select plunit.fail(); ERROR: plunit.assert_fail exception DETAIL: Plunit.assertation (assert_fail). select plunit.fail('custom exception'); ERROR: custom exception DETAIL: Plunit.assertation (assert_fail). SELECT dump('Yellow dog'::text) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('Yellow dog'::text, 10) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('Yellow dog'::text, 17) ~ E'^Typ=25 Len=(\\d+): .(,.)*$' AS t; t --- t (1 row) SELECT dump(10::int2) ~ E'^Typ=21 Len=2: \\d+(,\\d+){1}$' AS t; t --- t (1 row) SELECT dump(10::int4) ~ E'^Typ=23 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump(10::int8) ~ E'^Typ=20 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump(10.23::float4) ~ E'^Typ=700 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump(10.23::float8) ~ E'^Typ=701 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump(10.23::numeric) ~ E'^Typ=1700 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('2008-10-10'::date) ~ E'^Typ=1082 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump('2008-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump('2009-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) -- Tests for to_multi_byte SELECT to_multi_byte('123$test'); to_multi_byte ------------------ 123$test (1 row) -- Check internal representation difference SELECT octet_length('abc'); octet_length -------------- 3 (1 row) SELECT octet_length(to_multi_byte('abc')); octet_length -------------- 9 (1 row) -- Tests for round(TIMESTAMP WITH TIME ZONE) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','YEAR') = '1991-01-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'05/08/1990 05:35:25','Q') = '1990-04-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','MONTH') = '1990-12-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DDD') = '1990-12-08 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DAY') = '1990-12-09 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','hh') = '1990-12-08 06:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','mi') = '1990-12-08 05:35:00'; ?column? ---------- t (1 row) -- Tests for to_date SET DATESTYLE TO SQL, MDY; SELECT to_date('2009-01-02'); to_date ------------ 01/02/2009 (1 row) select to_date('January 8,1999'); to_date ------------ 01/08/1999 (1 row) SET DATESTYLE TO POSTGRES, MDY; select to_date('1999-01-08'); to_date ------------ 01-08-1999 (1 row) select to_date('1/12/1999'); to_date ------------ 01-12-1999 (1 row) SET DATESTYLE TO SQL, DMY; select to_date('01/02/03'); to_date ------------ 01/02/2003 (1 row) select to_date('1999-Jan-08'); to_date ------------ 08/01/1999 (1 row) select to_date('Jan-08-1999'); to_date ------------ 08/01/1999 (1 row) select to_date('08-Jan-1999'); to_date ------------ 08/01/1999 (1 row) SET DATESTYLE TO ISO, YMD; select to_date('99-Jan-08'); to_date ------------ 1999-01-08 (1 row) SET DATESTYLE TO ISO, DMY; select to_date('08-Jan-99'); to_date ------------ 1999-01-08 (1 row) select to_date('Jan-08-99'); to_date ------------ 1999-01-08 (1 row) select to_date('19990108'); to_date ------------ 1999-01-08 (1 row) select to_date('990108'); to_date ------------ 1999-01-08 (1 row) select to_date('J2451187'); to_date ------------ 1999-01-08 (1 row) orafce-VERSION_3_0_6/expected/orafunc2.out000066400000000000000000001431221221300436000203710ustar00rootroot00000000000000\set ECHO none -- -- test built-in date type oracle compatibility functions -- SELECT add_months ('2003-08-01', 3); add_months ------------ 2003-11-01 (1 row) SELECT add_months ('2003-08-01', -3); add_months ------------ 2003-05-01 (1 row) SELECT add_months ('2003-08-21', -3); add_months ------------ 2003-05-21 (1 row) SELECT add_months ('2003-01-31', 1); add_months ------------ 2003-02-28 (1 row) SELECT add_months ('2008-02-28', 1); add_months ------------ 2008-03-28 (1 row) SELECT add_months ('2008-02-29', 1); add_months ------------ 2008-03-31 (1 row) SELECT add_months ('2008-01-31', 12); add_months ------------ 2009-01-31 (1 row) SELECT add_months ('2008-01-31', -12); add_months ------------ 2007-01-31 (1 row) SELECT add_months ('2008-01-31', 95903); add_months ------------ 9999-12-31 (1 row) SELECT add_months ('2008-01-31', -80640); add_months --------------- 4712-01-31 BC (1 row) SELECT add_months ('03-21-2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('21-MAR-2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('21-MAR-08',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('2008-MAR-21',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months ('March 21,2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('03/21/2008',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('20080321',3); add_months ------------ 2008-06-21 (1 row) SELECT add_months('080321',3); add_months ------------ 2008-06-21 (1 row) SELECT last_day(to_date('2003/03/15', 'yyyy/mm/dd')); last_day ------------ 2003-03-31 (1 row) SELECT last_day(to_date('2003/02/03', 'yyyy/mm/dd')); last_day ------------ 2003-02-28 (1 row) SELECT last_day(to_date('2004/02/03', 'yyyy/mm/dd')); last_day ------------ 2004-02-29 (1 row) SELECT last_day('1900-02-01'); last_day ------------ 1900-02-28 (1 row) SELECT last_day('2000-02-01'); last_day ------------ 2000-02-29 (1 row) SELECT last_day('2007-02-01'); last_day ------------ 2007-02-28 (1 row) SELECT last_day('2008-02-01'); last_day ------------ 2008-02-29 (1 row) SELECT next_day ('2003-08-01', 'TUESDAY'); next_day ------------ 2003-08-05 (1 row) SELECT next_day ('2003-08-06', 'WEDNESDAY'); next_day ------------ 2003-08-13 (1 row) SELECT next_day ('2003-08-06', 'SUNDAY'); next_day ------------ 2003-08-10 (1 row) SELECT next_day ('2008-01-01', 'sun'); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 'sunAAA'); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 1); next_day ------------ 2008-01-06 (1 row) SELECT next_day ('2008-01-01', 7); next_day ------------ 2008-01-05 (1 row) SELECT months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); months_between ------------------- -2.41935483870968 (1 row) SELECT months_between (to_date ('2003/07/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); months_between ------------------ 3.58064516129032 (1 row) SELECT months_between (to_date ('2003/07/02', 'yyyy/mm/dd'), to_date ('2003/07/02', 'yyyy/mm/dd')); months_between ---------------- 0 (1 row) SELECT months_between (to_date ('2003/08/02', 'yyyy/mm/dd'), to_date ('2003/06/02', 'yyyy/mm/dd')); months_between ---------------- 2 (1 row) SELECT months_between ('2007-02-28', '2007-04-30'); months_between ---------------- -2 (1 row) SELECT months_between ('2008-01-31', '2008-02-29'); months_between ---------------- -1 (1 row) SELECT months_between ('2008-02-29', '2008-03-31'); months_between ---------------- -1 (1 row) SELECT months_between ('2008-02-29', '2008-04-30'); months_between ---------------- -2 (1 row) SELECT trunc(months_between('21-feb-2008', '2008-02-29')); trunc ------- 0 (1 row) select length('jmenuji se Pavel Stehule'),dbms_pipe.pack_message('jmenuji se Pavel Stehule'); length | pack_message --------+-------------- 24 | (1 row) select length('a bydlim ve Skalici'),dbms_pipe.pack_message('a bydlim ve Skalici'); length | pack_message --------+-------------- 19 | (1 row) select dbms_pipe.send_message('pavel',0,1); send_message -------------- 0 (1 row) select dbms_pipe.send_message('pavel',0,2); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('pavel',0); receive_message ----------------- 0 (1 row) select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; ?column? ---------------------------------- >>>>jmenuji se Pavel Stehule<<<< (1 row) select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; ?column? ----------------------------- >>>>a bydlim ve Skalici<<<< (1 row) select dbms_pipe.receive_message('pavel',0); receive_message ----------------- 0 (1 row) select dbms_pipe.purge('bob'); purge ------- (1 row) select dbms_pipe.reset_buffer(); reset_buffer -------------- (1 row) select dbms_pipe.pack_message('012345678901234+1'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.pack_message('012345678901234+2'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.pack_message('012345678901234+3'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) -------------------------------------------- select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+1 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+2 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234+3 (1 row) select dbms_pipe.unique_session_name() LIKE 'PG$PIPE$%'; ?column? ---------- t (1 row) select dbms_pipe.pack_message('012345678901234-1'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234-1 (1 row) select dbms_pipe.pack_message('012345678901234-2'); pack_message -------------- (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.send_message('bob',0,10); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('bob',0); receive_message ----------------- 0 (1 row) select dbms_pipe.unpack_message_text(); unpack_message_text --------------------- 012345678901234-2 (1 row) select dbms_pipe.pack_message(TO_DATE('2006-10-11', 'YYYY-MM-DD')); pack_message -------------- (1 row) select dbms_pipe.send_message('test_date'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_date'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 12 (1 row) select dbms_pipe.unpack_message_date(); unpack_message_date --------------------- 2006-10-11 (1 row) select dbms_pipe.pack_message(to_timestamp('2008-10-30 01:23:45', 'YYYY-MM-DD HH24:MI:SS')); pack_message -------------- (1 row) select dbms_pipe.send_message('test_timestamp'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_timestamp'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 13 (1 row) select to_char(dbms_pipe.unpack_message_timestamp(), 'YYYY-MM-DD HH24:MI:SS'); to_char --------------------- 2008-10-30 01:23:45 (1 row) select dbms_pipe.pack_message(6262626262::numeric); pack_message -------------- (1 row) select dbms_pipe.send_message('test_int'); send_message -------------- 0 (1 row) select dbms_pipe.receive_message('test_int'); receive_message ----------------- 0 (1 row) select dbms_pipe.next_item_type(); next_item_type ---------------- 9 (1 row) select dbms_pipe.unpack_message_number(); unpack_message_number ----------------------- 6262626262 (1 row) select dbms_pipe.purge('bob'); purge ------- (1 row) select name, items, "limit", private, owner from dbms_pipe.db_pipes where name = 'bob'; name | items | limit | private | owner ------+-------+-------+---------+------- (0 rows) select PLVstr.betwn('Harry and Sally are very happy', 7, 9); betwn ------- and (1 row) select PLVstr.betwn('Harry and Sally are very happy', 7, 9, FALSE); betwn ------- n (1 row) select PLVstr.betwn('Harry and Sally are very happy', -3, -1); betwn ------- ppy (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry'); betwn ------- arry (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 1,1,FALSE,FALSE); betwn ------- r (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 2,1,TRUE,FALSE); betwn -------------------- and Sally are very (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'y', 2,1); betwn ----------- and Sally (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 2); betwn ------------- and Sally a (1 row) select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 3, FALSE,FALSE); betwn --------------------- nd Sally are very h (1 row) select plvsubst.string('My name is %s %s.', ARRAY['Pavel','Stěhule']); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is % %.', ARRAY['Pavel','Stěhule'], '%'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s.', ARRAY['Stěhule']); string --------------------- My name is Stěhule. (1 row) select plvsubst.string('My name is %s %s.', 'Pavel,Stěhule'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s %s.', 'Pavel|Stěhule','|'); string --------------------------- My name is Pavel Stěhule. (1 row) select plvsubst.string('My name is %s.', 'Stěhule'); string --------------------- My name is Stěhule. (1 row) select plvsubst.string('My name is %s.', ''); ERROR: too few parameters specified for template string select plvsubst.string('My name is empty.', ''); string ------------------- My name is empty. (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'YEAR') = to_date ('01-JAN-04', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'Q') = to_date ('01-OCT-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'MONTH') = to_date ('01-SEP-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DAY') = to_date ('24-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'YEAR') = to_date ('01-JAN-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'Q') = to_date ('01-JUL-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'MONTH') = to_date ('01-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DAY') = to_date ('17-AUG-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','YEAR') = '2004-01-01 00:00:00-08'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','Q') = '2004-10-01 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MONTH') = '2004-10-01 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DDD') = '2004-10-19 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DAY') = '2004-10-17 00:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','HH') = '2004-10-19 01:00:00-07'; ?column? ---------- t (1 row) select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MI') = '2004-10-19 01:23:00-07'; ?column? ---------- t (1 row) select next_day(to_date('01-Aug-03', 'DD-MON-YY'), 'TUESDAY') = to_date ('05-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'WEDNESDAY') = to_date ('13-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'SUNDAY') = to_date ('10-Aug-03', 'DD-MON-YY'); ?column? ---------- t (1 row) select instr('Tech on the net', 'e') =2; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 1) = 2; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 2) = 11; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', 1, 3) = 14; ?column? ---------- t (1 row) select instr('Tech on the net', 'e', -3, 2) = 2; ?column? ---------- t (1 row) select instr('abc', NULL) IS NULL; ?column? ---------- t (1 row) select 1 = instr('abc', ''); ?column? ---------- t (1 row) select 1 = instr('abc', 'a'); ?column? ---------- t (1 row) select 3 = instr('abc', 'c'); ?column? ---------- t (1 row) select 0 = instr('abc', 'z'); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', 1); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', 2); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 7); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 9); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', -1); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', -8); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', -9); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', -10); ?column? ---------- t (1 row) select 1 = instr('abcabcabc', 'abca', 1, 1); ?column? ---------- t (1 row) select 4 = instr('abcabcabc', 'abca', 1, 2); ?column? ---------- t (1 row) select 0 = instr('abcabcabc', 'abca', 1, 3); ?column? ---------- t (1 row) select oracle.substr('This is a test', 6, 2) = 'is'; ?column? ---------- t (1 row) select oracle.substr('This is a test', 6) = 'is a test'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', 1, 4) = 'Tech'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -3, 3) = 'Net'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -6, 3) = 'The'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, 2) = 'On'; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, 0) = ''; ?column? ---------- t (1 row) select oracle.substr('TechOnTheNet', -8, -1) = ''; ?column? ---------- (1 row) select concat('Tech on', ' the Net') = 'Tech on the Net'; ?column? ---------- t (1 row) select concat('a', 'b') = 'ab'; ?column? ---------- t (1 row) select concat('a', NULL) = 'a'; ?column? ---------- t (1 row) select concat(NULL, 'b') = 'b'; ?column? ---------- t (1 row) select concat('a', 2) = 'a2'; ?column? ---------- t (1 row) select concat(1, 'b') = '1b'; ?column? ---------- t (1 row) select concat(1, 2) = '12'; ?column? ---------- t (1 row) select concat(1, NULL) = '1'; ?column? ---------- t (1 row) select concat(NULL, 2) = '2'; ?column? ---------- t (1 row) select nvl('A'::text, 'B'); nvl ----- A (1 row) select nvl(NULL::text, 'B'); nvl ----- B (1 row) select nvl(NULL::text, NULL); nvl ----- (1 row) select nvl(1, 2); nvl ----- 1 (1 row) select nvl(NULL, 2); nvl ----- 2 (1 row) select nvl2('A'::text, 'B', 'C'); nvl2 ------ B (1 row) select nvl2(NULL::text, 'B', 'C'); nvl2 ------ C (1 row) select nvl2('A'::text, NULL, 'C'); nvl2 ------ (1 row) select nvl2(NULL::text, 'B', NULL); nvl2 ------ (1 row) select nvl2(1, 2, 3); nvl2 ------ 2 (1 row) select nvl2(NULL, 2, 3); nvl2 ------ 3 (1 row) select lnnvl(true); lnnvl ------- f (1 row) select lnnvl(false); lnnvl ------- t (1 row) select lnnvl(NULL); lnnvl ------- t (1 row) select decode(1, 1, 100, 2, 200); decode -------- 100 (1 row) select decode(2, 1, 100, 2, 200); decode -------- 200 (1 row) select decode(3, 1, 100, 2, 200); decode -------- (1 row) select decode(3, 1, 100, 2, 200, 300); decode -------- 300 (1 row) select decode(NULL, 1, 100, NULL, 200, 300); decode -------- 200 (1 row) select decode('1'::text, '1', 100, '2', 200); decode -------- 100 (1 row) select decode(2, 1, 'ABC', 2, 'DEF'); decode -------- DEF (1 row) select decode('2009-02-05'::date, '2009-02-05', 'ok'); decode -------- ok (1 row) select decode('2009-02-05 01:02:03'::timestamp, '2009-02-05 01:02:03', 'ok'); decode -------- ok (1 row) -- For type 'bpchar' select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar); decode ---------- postgres (1 row) select decode('c'::bpchar, 'a'::bpchar,'postgres'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('c', 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); decode -------- (1 row) select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); decode ---------- postgres (1 row) select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar); decode ---------- database (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar); decode -------- (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar,'default value'::bpchar); decode ---------- database (1 row) select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar,'default value'::bpchar); decode --------------- default value (1 row) -- For type 'bigint' select decode(2147483651::bigint, 2147483650::bigint,2147483650::bigint); decode -------- (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint); decode -------- (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); decode -------- (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); decode -------- (1 row) select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); decode ------------ 2147483650 (1 row) select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint); decode ------------ 2147483651 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint); decode -------- (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint,9999999999::bigint); decode ------------ 2147483651 (1 row) select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint,9999999999::bigint); decode ------------ 9999999999 (1 row) -- For type 'numeric' select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); decode -------- (1 row) select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3650 (1 row) select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4)); decode ------------- 214748.3651 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4)); decode -------- (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 214748.3651 (1 row) select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); decode ------------- 999999.9999 (1 row) --For type 'date' select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); decode ------------ 2012-12-21 (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-31 (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); decode -------- (1 row) select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); decode ------------ 2012-12-20 (1 row) select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); decode ------------ 2013-01-01 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date); decode ------------ 2012-12-21 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date); decode -------- (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-21 (1 row) select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); decode ------------ 2012-12-31 (1 row) -- For type 'time' select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:01'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); decode -------- (1 row) select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); decode ---------- 09:00:00 (1 row) select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time); decode ---------- 12:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time); decode -------- (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time,'00:00:00'::time); decode ---------- 12:00:00 (1 row) select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time,'00:00:00'::time); decode ---------- 00:00:00 (1 row) -- For type 'timestamp' select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); decode -------- (1 row) select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 09:00:00 (1 row) select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp); decode --------------------- 2012-12-20 12:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); decode -------- (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 12:00:00 (1 row) select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); decode --------------------- 2012-12-20 00:00:00 (1 row) -- For type 'timestamptz' select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); decode -------- (1 row) select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 09:00:00-08 (1 row) select decode(4, 1,'2012-12-20 09:00:00-08'::timestamptz,2,'2012-12-20 12:00:00-08'::timestamptz, 3, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 12:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); decode -------- (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 12:00:00-08 (1 row) select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); decode ------------------------ 2012-12-20 00:00:00-08 (1 row) --Test case to check if decode accepts other expressions as a key CREATE OR REPLACE FUNCTION five() RETURNS integer AS $$ BEGIN RETURN 5; END; $$ LANGUAGE plpgsql; select decode(five(), 1, 'one', 2, 'two', 5, 'five'); decode -------- five (1 row) DROP FUNCTION five(); -- Test case to check duplicate keys in search list select decode(1, 1, 'one', 2, 'two', 1, 'one-again') = 'one'; ?column? ---------- t (1 row) /* Test case to check explicit type casting of keys in search list in * case of ambiguous key (1st argument) provided. */ -- 1) succeed and return 'result-1' select decode('2012-01-01', '2012-01-01'::date,'result-1','2012-01-02', 'result-2'); decode ---------- result-1 (1 row) select decode('2012-01-01', '2012-01-01', 'result-1', '2012-02-01'::date, 'result-2'); decode ---------- result-1 (1 row) -- 2) fails and throws error: 'ERROR: could not determine polymorphic type -- because input has type "unknown"' select decode('2012-01-01', '2012-01-01', 23, '2012-01-02', 24); ERROR: could not determine polymorphic type because input has type "unknown" select PLVstr.rvrs ('Jumping Jack Flash') ='hsalF kcaJ gnipmuJ'; ?column? ---------- t (1 row) select PLVstr.rvrs ('Jumping Jack Flash', 9) = 'hsalF kcaJ'; ?column? ---------- t (1 row) select PLVstr.rvrs ('Jumping Jack Flash', 4, 6) = 'nip'; ?column? ---------- t (1 row) select PLVstr.lstrip ('*val1|val2|val3|*', '*') = 'val1|val2|val3|*'; ?column? ---------- t (1 row) select PLVstr.lstrip (',,,val1,val2,val3,', ',', 3)= 'val1,val2,val3,'; ?column? ---------- t (1 row) select PLVstr.lstrip ('WHERE WHITE = ''FRONT'' AND COMP# = 1500', 'WHERE ') = 'WHITE = ''FRONT'' AND COMP# = 1500'; ?column? ---------- t (1 row) select plvstr.left('Příliš žluťoučký kůň',4) = pg_catalog.substr('Příl', 1, 4); ?column? ---------- t (1 row) select pos,token from plvlex.tokens('select * from a.b.c join d ON x=y', true, true); pos | token -----+-------- 0 | select 7 | * 9 | from 14 | a.b.c 20 | join 25 | d 27 | on 30 | x 31 | = 32 | y (10 rows) SET lc_numeric TO 'C'; select to_char(22); to_char --------- 22 (1 row) select to_char(-44444); to_char --------- -44444 (1 row) select to_char(1234567890123456::bigint); to_char ------------------ 1234567890123456 (1 row) select to_char(123.456::real); to_char ------------ 123.456001 (1 row) select to_char(1234.5678::double precision); to_char ------------- 1234.567800 (1 row) select to_char(12345678901234567890::numeric); to_char ---------------------- 12345678901234567890 (1 row) select to_char(1234567890.12345); to_char ------------------ 1234567890.12345 (1 row) select to_char('4.00'::numeric); to_char --------- 4 (1 row) select to_char('4.0010'::numeric); to_char --------- 4.001 (1 row) SELECT to_number('123'::text); to_number ----------- 123 (1 row) SELECT to_number('123.456'::text); to_number ----------- 123.456 (1 row) SELECT to_date('2009-01-02'); to_date ------------ 2009-01-02 (1 row) SELECT bitand(5,1), bitand(5,2), bitand(5,4); bitand | bitand | bitand --------+--------+-------- 1 | 0 | 4 (1 row) SELECT sinh(1.570796), cosh(1.570796), tanh(4); sinh | cosh | tanh -----------------+------------------+------------------- 2.3012980823207 | 2.50917772660545 | 0.999329299739067 (1 row) SELECT nanvl(12345, 1), nanvl('NaN', 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::float4, 1), nanvl('NaN'::float4, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::float8, 1), nanvl('NaN'::float8, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) SELECT nanvl(12345::numeric, 1), nanvl('NaN'::numeric, 1); nanvl | nanvl -------+------- 12345 | 1 (1 row) select dbms_assert.enquote_literal('some text '' some text'); enquote_literal -------------------------- 'some text '' some text' (1 row) select dbms_assert.enquote_name('''"AAA'); enquote_name -------------- "'""aaa" (1 row) select dbms_assert.enquote_name('''"AAA', false); enquote_name -------------- "'""AAA" (1 row) select dbms_assert.noop('some string'); noop ------------- some string (1 row) select dbms_assert.qualified_sql_name('aaa.bbb.ccc."aaaa""aaa"'); qualified_sql_name ------------------------- aaa.bbb.ccc."aaaa""aaa" (1 row) select dbms_assert.qualified_sql_name('aaa.bbb.cc%c."aaaa""aaa"'); ERROR: string is not qualified SQL name select dbms_assert.schema_name('dbms_assert'); schema_name ------------- dbms_assert (1 row) select dbms_assert.schema_name('jabadabado'); ERROR: invalid schema name select dbms_assert.simple_sql_name('"Aaa dghh shsh"'); simple_sql_name ----------------- "Aaa dghh shsh" (1 row) select dbms_assert.simple_sql_name('ajajaj -- ajaj'); ERROR: string is not simple SQL name select dbms_assert.object_name('pg_catalog.pg_class'); object_name --------------------- pg_catalog.pg_class (1 row) select dbms_assert.object_name('dbms_assert.fooo'); ERROR: invalid object name select plunit.assert_true(NULL); ERROR: plunit.assert_true exception DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 2); ERROR: plunit.assert_true exception DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 2, 'one is not two'); ERROR: one is not two DETAIL: Plunit.assertation fails (assert_true). select plunit.assert_true(1 = 1); assert_true ------------- (1 row) select plunit.assert_false(1 = 1); ERROR: plunit.assert_false exception DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_false(1 = 1, 'trap is open'); ERROR: trap is open DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_false(NULL); ERROR: plunit.assert_false exception DETAIL: Plunit.assertation fails (assert_false). select plunit.assert_null(current_date); ERROR: plunit.assert_null exception DETAIL: Plunit.assertation fails (assert_null). select plunit.assert_null(NULL::date); assert_null ------------- (1 row) select plunit.assert_not_null(current_date); assert_not_null ----------------- (1 row) select plunit.assert_not_null(NULL::date); ERROR: plunit.assert_not_null exception DETAIL: Plunit.assertation fails (assert_not_null). select plunit.assert_equals('Pavel','Pa'||'vel'); assert_equals --------------- (1 row) select plunit.assert_equals(current_date, current_date + 1, 'diff dates'); ERROR: diff dates DETAIL: Plunit.assertation fails (assert_equals). select plunit.assert_equals(10.2, 10.3, 0.5); assert_equals --------------- (1 row) select plunit.assert_equals(10.2, 10.3, 0.01, 'attention some diff'); ERROR: attention some diff DETAIL: Plunit.assertation fails (assert_equals). select plunit.assert_not_equals(current_date, current_date + 1, 'yestarday is today'); assert_not_equals ------------------- (1 row) select plunit.fail(); ERROR: plunit.assert_fail exception DETAIL: Plunit.assertation (assert_fail). select plunit.fail('custom exception'); ERROR: custom exception DETAIL: Plunit.assertation (assert_fail). SELECT dump('Yellow dog'::text) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('Yellow dog'::text, 10) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('Yellow dog'::text, 17) ~ E'^Typ=25 Len=(\\d+): .(,.)*$' AS t; t --- t (1 row) SELECT dump(10::int2) ~ E'^Typ=21 Len=2: \\d+(,\\d+){1}$' AS t; t --- t (1 row) SELECT dump(10::int4) ~ E'^Typ=23 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump(10::int8) ~ E'^Typ=20 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump(10.23::float4) ~ E'^Typ=700 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump(10.23::float8) ~ E'^Typ=701 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump(10.23::numeric) ~ E'^Typ=1700 Len=(\\d+): \\d+(,\\d+)*$' AS t; t --- t (1 row) SELECT dump('2008-10-10'::date) ~ E'^Typ=1082 Len=4: \\d+(,\\d+){3}$' AS t; t --- t (1 row) SELECT dump('2008-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) SELECT dump('2009-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; t --- t (1 row) -- Tests for to_multi_byte SELECT to_multi_byte('123$test'); to_multi_byte ------------------ 123$test (1 row) -- Check internal representation difference SELECT octet_length('abc'); octet_length -------------- 3 (1 row) SELECT octet_length(to_multi_byte('abc')); octet_length -------------- 9 (1 row) -- Tests for round(TIMESTAMP WITH TIME ZONE) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','YEAR') = '1991-01-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'05/08/1990 05:35:25','Q') = '1990-04-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','MONTH') = '1990-12-01 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DDD') = '1990-12-08 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DAY') = '1990-12-09 00:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','hh') = '1990-12-08 06:00:00'; ?column? ---------- t (1 row) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','mi') = '1990-12-08 05:35:00'; ?column? ---------- t (1 row) -- Tests for to_date SET DATESTYLE TO SQL, MDY; SELECT to_date('2009-01-02'); to_date ------------ 01/02/2009 (1 row) select to_date('January 8,1999'); to_date ------------ 01/08/1999 (1 row) SET DATESTYLE TO POSTGRES, MDY; select to_date('1999-01-08'); to_date ------------ 01-08-1999 (1 row) select to_date('1/12/1999'); to_date ------------ 01-12-1999 (1 row) SET DATESTYLE TO SQL, DMY; select to_date('01/02/03'); to_date ------------ 01/02/2003 (1 row) select to_date('1999-Jan-08'); to_date ------------ 08/01/1999 (1 row) select to_date('Jan-08-1999'); to_date ------------ 08/01/1999 (1 row) select to_date('08-Jan-1999'); to_date ------------ 08/01/1999 (1 row) SET DATESTYLE TO ISO, YMD; select to_date('99-Jan-08'); to_date ------------ 1999-01-08 (1 row) SET DATESTYLE TO ISO, DMY; select to_date('08-Jan-99'); to_date ------------ 1999-01-08 (1 row) select to_date('Jan-08-99'); to_date ------------ 1999-01-08 (1 row) select to_date('19990108'); to_date ------------ 1999-01-08 (1 row) select to_date('990108'); to_date ------------ 1999-01-08 (1 row) select to_date('J2451187'); to_date ------------ 1999-01-08 (1 row) orafce-VERSION_3_0_6/file.c000066400000000000000000000546001221300436000154050ustar00rootroot00000000000000#include "postgres.h" #include #include #include "executor/spi.h" #if PG_VERSION_NUM >= 90300 #include "access/htup_details.h" #endif #include "catalog/pg_type.h" #include "fmgr.h" #include "funcapi.h" #include "mb/pg_wchar.h" #include "miscadmin.h" #include "port.h" #include "storage/fd.h" #include "utils/builtins.h" #include "utils/memutils.h" #include "orafunc.h" #include "builtins.h" #ifndef ERRCODE_NO_DATA_FOUND #define ERRCODE_NO_DATA_FOUND MAKE_SQLSTATE('P','0', '0','0','2') #endif #define INVALID_OPERATION "UTL_FILE_INVALID_OPERATION" #define WRITE_ERROR "UTL_FILE_WRITE_ERROR" #define READ_ERROR "UTL_FILE_READ_ERROR" #define INVALID_FILEHANDLE "UTL_FILE_INVALID_FILEHANDLE" #define INVALID_MAXLINESIZE "UTL_FILE_INVALID_MAXLINESIZE" #define INVALID_MODE "UTL_FILE_INVALID_MODE" #define INVALID_PATH "UTL_FILE_INVALID_PATH" #define VALUE_ERROR "UTL_FILE_VALUE_ERROR" PG_FUNCTION_INFO_V1(utl_file_fopen); PG_FUNCTION_INFO_V1(utl_file_is_open); PG_FUNCTION_INFO_V1(utl_file_get_line); PG_FUNCTION_INFO_V1(utl_file_get_nextline); PG_FUNCTION_INFO_V1(utl_file_put); PG_FUNCTION_INFO_V1(utl_file_put_line); PG_FUNCTION_INFO_V1(utl_file_new_line); PG_FUNCTION_INFO_V1(utl_file_putf); PG_FUNCTION_INFO_V1(utl_file_fflush); PG_FUNCTION_INFO_V1(utl_file_fclose); PG_FUNCTION_INFO_V1(utl_file_fclose_all); PG_FUNCTION_INFO_V1(utl_file_fremove); PG_FUNCTION_INFO_V1(utl_file_frename); PG_FUNCTION_INFO_V1(utl_file_fcopy); PG_FUNCTION_INFO_V1(utl_file_fgetattr); PG_FUNCTION_INFO_V1(utl_file_tmpdir); #define CUSTOM_EXCEPTION(msg, detail) \ ereport(ERROR, \ (errcode(ERRCODE_RAISE_EXCEPTION), \ errmsg("%s", msg), \ errdetail("%s", detail))) #define INVALID_FILEHANDLE_EXCEPTION() CUSTOM_EXCEPTION(INVALID_FILEHANDLE, "Used file handle isn't valid.") #define CHECK_FILE_HANDLE() \ if (PG_ARGISNULL(0)) \ CUSTOM_EXCEPTION(INVALID_FILEHANDLE, "Used file handle isn't valid.") #define NON_EMPTY_TEXT(dat) \ if (VARSIZE(dat) - VARHDRSZ == 0) \ ereport(ERROR, \ (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ errmsg("invalid parameter"), \ errdetail("Empty string isn't allowed."))); #define NOT_NULL_ARG(n) \ if (PG_ARGISNULL(n)) \ ereport(ERROR, \ (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \ errmsg("null value not allowed"), \ errhint("%dth argument is NULL.", n))); #define MAX_LINESIZE 32767 #define CHECK_LINESIZE(max_linesize) \ do { \ if ((max_linesize) < 1 || (max_linesize) > MAX_LINESIZE) \ CUSTOM_EXCEPTION(INVALID_MAXLINESIZE, "maxlinesize is out of range"); \ } while(0) typedef struct FileSlot { FILE *file; int max_linesize; int encoding; int32 id; } FileSlot; #define MAX_SLOTS 50 /* Oracle 10g supports 50 files */ #define INVALID_SLOTID 0 /* invalid slot id */ static FileSlot slots[MAX_SLOTS]; /* initilaized with zeros */ static int32 slotid = 0; /* next slot id */ static void check_secure_locality(const char *path); static char *get_safe_path(text *location, text *filename); static int copy_text_file(FILE *srcfile, FILE *dstfile, int start_line, int end_line); /* * get_descriptor(FILE *file) find any free slot for FILE pointer. * If isn't realloc array slots and add 32 new free slots. * */ static int get_descriptor(FILE *file, int max_linesize, int encoding) { int i; for (i = 0; i < MAX_SLOTS; i++) { if (slots[i].id == INVALID_SLOTID) { slots[i].id = ++slotid; if (slots[i].id == INVALID_SLOTID) slots[i].id = ++slotid; /* skip INVALID_SLOTID */ slots[i].file = file; slots[i].max_linesize = max_linesize; slots[i].encoding = encoding; return slots[i].id; } } return INVALID_SLOTID; } /* return stored pointer to FILE */ static FILE * get_stream(int d, int *max_linesize, int *encoding) { int i; if (d == INVALID_SLOTID) INVALID_FILEHANDLE_EXCEPTION(); for (i = 0; i < MAX_SLOTS; i++) { if (slots[i].id == d) { if (max_linesize) *max_linesize = slots[i].max_linesize; if (encoding) *encoding = slots[i].encoding; return slots[i].file; } } INVALID_FILEHANDLE_EXCEPTION(); return NULL; /* keep compiler quiet */ } static void IO_EXCEPTION(void) { switch (errno) { case EACCES: case ENAMETOOLONG: case ENOENT: case ENOTDIR: CUSTOM_EXCEPTION(INVALID_PATH, strerror(errno)); break; default: CUSTOM_EXCEPTION(INVALID_OPERATION, strerror(errno)); } } /* * FUNCTION UTL_FILE.FOPEN(location text, * filename text, * open_mode text, * max_linesize integer) * RETURNS UTL_FILE.FILE_TYPE; * * The FOPEN function opens specified file and returns file handle. * open_mode: ['R', 'W', 'A'] * max_linesize: [1 .. 32767] * * Exceptions: * INVALID_MODE, INVALID_OPERATION, INVALID_PATH, INVALID_MAXLINESIZE */ Datum utl_file_fopen(PG_FUNCTION_ARGS) { text *open_mode; int max_linesize; int encoding; const char *mode = NULL; FILE *file; char *fullname; int d; NOT_NULL_ARG(0); NOT_NULL_ARG(1); NOT_NULL_ARG(2); NOT_NULL_ARG(3); open_mode = PG_GETARG_TEXT_P(2); NON_EMPTY_TEXT(open_mode); max_linesize = PG_GETARG_INT32(3); CHECK_LINESIZE(max_linesize); if (PG_NARGS() > 4 && !PG_ARGISNULL(4)) { const char *encname = NameStr(*PG_GETARG_NAME(4)); encoding = pg_char_to_encoding(encname); if (encoding < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid encoding name \"%s\"", encname))); } else encoding = GetDatabaseEncoding(); if (VARSIZE(open_mode) - VARHDRSZ != 1) CUSTOM_EXCEPTION(INVALID_MODE, "open mode is different than [R,W,A]"); switch (*((char*)VARDATA(open_mode))) { case 'a': case 'A': mode = "a"; break; case 'r': case 'R': mode = "r"; break; case 'w': case 'W': mode = "w"; break; default: CUSTOM_EXCEPTION(INVALID_MODE, "open mode is different than [R,W,A]"); } /* open file */ fullname = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); /* * We cannot use AllocateFile here because those files are automatically * closed at the end of (sub)transactions, but we want to keep them open * for oracle compatibility. */ #if NOT_USED fullname = convert_encoding_server_to_platform(fullname); #endif file = fopen(fullname, mode); if (!file) IO_EXCEPTION(); d = get_descriptor(file, max_linesize, encoding); if (d == INVALID_SLOTID) { fclose(file); ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("program limit exceeded"), errdetail("Too much concurent opened files"), errhint("You can only open a maximum of ten files for each session"))); } PG_RETURN_INT32(d); } Datum utl_file_is_open(PG_FUNCTION_ARGS) { if (!PG_ARGISNULL(0)) { int i; int d = PG_GETARG_INT32(0); for (i = 0; i < MAX_SLOTS; i++) { if (slots[i].id == d) PG_RETURN_BOOL(slots[i].file != NULL); } } PG_RETURN_BOOL(false); } #define CHECK_LENGTH(l) \ if (l > max_linesize) \ CUSTOM_EXCEPTION(VALUE_ERROR, "buffer is too short"); /* read line from file. set eof if is EOF */ static text * get_line(FILE *f, int max_linesize, int encoding, bool *iseof) { int c; char *buffer = NULL; char *bpt; int csize = 0; text *result = NULL; bool eof = true; buffer = palloc(max_linesize + 2); bpt = buffer; errno = 0; while (csize < max_linesize && (c = fgetc(f)) != EOF) { eof = false; /* I was able read one char */ if (c == '\r') /* lookin ahead \n */ { c = fgetc(f); if (c == EOF) break; /* last char */ if (c != '\n') ungetc(c, f); /* skip \r\n */ break; } else if (c == '\n') break; ++csize; *bpt++ = c; } if (!eof) { char *decoded; int len; pg_verify_mbstr(encoding, buffer, csize, false); decoded = (char *) pg_do_encoding_conversion((unsigned char *) buffer, csize, encoding, GetDatabaseEncoding()); len = (decoded == buffer ? csize : strlen(decoded)); result = palloc(len + VARHDRSZ); memcpy(VARDATA(result), decoded, len); SET_VARSIZE(result, len + VARHDRSZ); if (decoded != buffer) pfree(decoded); *iseof = false; } else { switch (errno) { case 0: break; case EBADF: CUSTOM_EXCEPTION(INVALID_OPERATION, "file descriptor isn't valid for reading"); break; default: CUSTOM_EXCEPTION(READ_ERROR, strerror(errno)); break; } *iseof = true; } pfree(buffer); return result; } /* * FUNCTION UTL_FILE.GET_LINE(file UTL_TYPE.FILE_TYPE, line int DEFAULT NULL) * RETURNS text; * * Reads one line from file. * * Exceptions: * NO_DATA_FOUND, INVALID_FILEHANDLE, INVALID_OPERATION, READ_ERROR */ Datum utl_file_get_line(PG_FUNCTION_ARGS) { int max_linesize; int encoding; FILE *f; text *result; bool iseof; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); /* 'len' overwrites max_linesize, but must be smaller than max_linesize */ if (PG_NARGS() > 1 && !PG_ARGISNULL(1)) { int len = PG_GETARG_INT32(1); CHECK_LINESIZE(len); if (max_linesize > len) max_linesize = len; } result = get_line(f, max_linesize, encoding, &iseof); if (iseof) ereport(ERROR, (errcode(ERRCODE_NO_DATA_FOUND), errmsg("no data found"))); PG_RETURN_TEXT_P(result); } /* * FUNCTION UTL_FILE.GET_NEXTLINE(file UTL_TYPE.FILE_TYPE) * RETURNS text; * * Reads one line from file or retutns NULL * by Steven Feuerstein. * * Exceptions: * INVALID_FILEHANDLE, INVALID_OPERATION, READ_ERROR */ Datum utl_file_get_nextline(PG_FUNCTION_ARGS) { int max_linesize; int encoding; FILE *f; text *result; bool iseof; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); result = get_line(f, max_linesize, encoding, &iseof); if (iseof) PG_RETURN_NULL(); PG_RETURN_TEXT_P(result); } static void do_flush(FILE *f) { if (fflush(f) != 0) { if (errno == EBADF) CUSTOM_EXCEPTION(INVALID_OPERATION, "File is not an opened, or is not open for writing"); else CUSTOM_EXCEPTION(WRITE_ERROR, strerror(errno)); } } /* * FUNCTION UTL_FILE.PUT(file UTL_FILE.FILE_TYPE, buffer text) * RETURNS bool; * * The PUT function puts data out to specified file. Buffer length allowed is * 32K or 1024 (max_linesize); * * Exceptions: * INVALID_FILEHANDLE, INVALID_OPERATION, WRITE_ERROR, VALUE_ERROR * * Note: returns bool because I cannot do envelope over void function */ #define CHECK_ERRNO_PUT() \ switch (errno) \ { \ case EBADF: \ CUSTOM_EXCEPTION(INVALID_OPERATION, "file descriptor isn't valid for writing"); \ break; \ default: \ CUSTOM_EXCEPTION(WRITE_ERROR, strerror(errno)); \ } /* encode(t, encoding) */ static char * encode_text(int encoding, text *t, int *length) { char *src = VARDATA_ANY(t); char *encoded; encoded = (char *) pg_do_encoding_conversion((unsigned char *) src, VARSIZE_ANY_EXHDR(t), GetDatabaseEncoding(), encoding); *length = (src == encoded ? VARSIZE_ANY_EXHDR(t) : strlen(encoded)); return encoded; } /* fwrite(encode(args[n], encoding), f) */ static int do_write(PG_FUNCTION_ARGS, int n, FILE *f, int max_linesize, int encoding) { text *arg = PG_GETARG_TEXT_P(n); char *str; int len; str = encode_text(encoding, arg, &len); CHECK_LENGTH(len); if (fwrite(str, 1, len, f) != len) CHECK_ERRNO_PUT(); if (VARDATA(arg) != str) pfree(str); PG_FREE_IF_COPY(arg, n); return len; } static FILE * do_put(PG_FUNCTION_ARGS) { FILE *f; int max_linesize; int encoding; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); NOT_NULL_ARG(1); do_write(fcinfo, 1, f, max_linesize, encoding); return f; } Datum utl_file_put(PG_FUNCTION_ARGS) { do_put(fcinfo); PG_RETURN_BOOL(true); } static void do_new_line(FILE *f, int lines) { int i; for (i = 0; i < lines; i++) { #ifndef WIN32 if (fputc('\n', f) == EOF) CHECK_ERRNO_PUT(); #else if (fputs("\r\n", f) == EOF) CHECK_ERRNO_PUT(); #endif } } Datum utl_file_put_line(PG_FUNCTION_ARGS) { FILE *f; bool autoflush; f = do_put(fcinfo); autoflush = PG_GETARG_IF_EXISTS(2, BOOL, false); do_new_line(f, 1); if (autoflush) do_flush(f); PG_RETURN_BOOL(true); } Datum utl_file_new_line(PG_FUNCTION_ARGS) { FILE *f; int lines; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), NULL, NULL); lines = PG_GETARG_IF_EXISTS(1, INT32, 1); do_new_line(f, lines); PG_RETURN_BOOL(true); } /* * FUNCTION UTL_FILE.PUTF(file UTL_FILE.FILE_TYPE, * format text, * arg1 text, * arg2 text, * arg3 text, * arg4 text, * arg5 text) * RETURNS bool; * * Puts formated data to file. Allows %s like subst symbol. * * Exception: * INVALID_FILEHANDLE, INVALID_OPERATION, WRITE_ERROR */ Datum utl_file_putf(PG_FUNCTION_ARGS) { FILE *f; char *format; int max_linesize; int encoding; int format_length; char *fpt; int cur_par = 0; int cur_len = 0; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); NOT_NULL_ARG(1); format = encode_text(encoding, PG_GETARG_TEXT_P(1), &format_length); for (fpt = format; format_length > 0; fpt++, format_length--) { if (format_length == 1) { /* last char */ CHECK_LENGTH(++cur_len); if (fputc(*fpt, f) == EOF) CHECK_ERRNO_PUT(); continue; } /* ansi compatible string */ if (fpt[0] == '\\' && fpt[1] == 'n') { CHECK_LENGTH(++cur_len); if (fputc('\n', f) == EOF) CHECK_ERRNO_PUT(); fpt++; format_length--; continue; } if (fpt[0] == '%') { if (fpt[1] == '%') { CHECK_LENGTH(++cur_len); if (fputc('%', f) == EOF) CHECK_ERRNO_PUT(); } else if (fpt[1] == 's' && ++cur_par <= 5 && !PG_ARGISNULL(cur_par + 1)) { cur_len += do_write(fcinfo, cur_par + 1, f, max_linesize - cur_len, encoding); } fpt++; format_length--; continue; } CHECK_LENGTH(++cur_len); if (fputc(fpt[0], f) == EOF) CHECK_ERRNO_PUT(); } PG_RETURN_BOOL(true); } /* * FUNCTION UTL_FILE.FFLUSH(file UTL_FILE.FILE_TYPE) * RETURNS void; * * This function makes sure that all pending data for the specified file is written * physically out to file. * * Exceptions: * INVALID_FILEHANDLE, INVALID_OPERATION, WRITE_ERROR */ Datum utl_file_fflush(PG_FUNCTION_ARGS) { FILE *f; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), NULL, NULL); do_flush(f); PG_RETURN_VOID(); } /* * FUNCTION UTL_FILE.FCLOSE(file UTL_FILE.FILE_TYPE) * RETURNS NULL * * Close an open file. This function reset file handle to NULL on Oracle platform. * It isn't possible in PostgreSQL, and then you have to call fclose function * like: * file := utl_file.fclose(file); * * Exception: * INVALID_FILEHANDLE, WRITE_ERROR */ Datum utl_file_fclose(PG_FUNCTION_ARGS) { int i; int d = PG_GETARG_INT32(0); for (i = 0; i < MAX_SLOTS; i++) { if (slots[i].id == d) { if (slots[i].file && fclose(slots[i].file) != 0) { if (errno == EBADF) CUSTOM_EXCEPTION(INVALID_FILEHANDLE, "File is not an opened"); else CUSTOM_EXCEPTION(WRITE_ERROR, strerror(errno)); } slots[i].file = NULL; slots[i].id = INVALID_SLOTID; PG_RETURN_NULL(); } } INVALID_FILEHANDLE_EXCEPTION(); PG_RETURN_NULL(); } /* * FUNCTION UTL_FILE.FCLOSE_ALL() * RETURNS void * * Close all opened files. * * Exceptions: WRITE_ERROR */ Datum utl_file_fclose_all(PG_FUNCTION_ARGS) { int i; for (i = 0; i < MAX_SLOTS; i++) { if (slots[i].id != INVALID_SLOTID) { if (slots[i].file && fclose(slots[i].file) != 0) { if (errno == EBADF) CUSTOM_EXCEPTION(INVALID_FILEHANDLE, "File is not an opened"); else CUSTOM_EXCEPTION(WRITE_ERROR, strerror(errno)); } slots[i].file = NULL; slots[i].id = INVALID_SLOTID; } } PG_RETURN_VOID(); } /* * utl_file_dir security .. is solved with aux. table. * * Raise exception if don't find string in table. */ static void check_secure_locality(const char *path) { static SPIPlanPtr plan = NULL; Oid argtypes[] = {TEXTOID}; Datum values[1]; char nulls[1] = {' '}; values[0] = CStringGetTextDatum(path); /* * SELECT 1 FROM utl_file.utl_file_dir * WHERE CASE WHEN substring(dir from '.$') = '/' THEN * substring($1, 1, length(dir)) = dir * ELSE * substring($1, 1, length(dir) + 1) = dir || '/' * END */ if (SPI_connect() < 0) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_connect failed"))); if (!plan) { /* Don't use LIKE not to escape '_' and '%' */ SPIPlanPtr p = SPI_prepare( "SELECT 1 FROM utl_file.utl_file_dir" " WHERE CASE WHEN substring(dir from '.$') = '/' THEN" " substring($1, 1, length(dir)) = dir" " ELSE" " substring($1, 1, length(dir) + 1) = dir || '/'" " END", 1, argtypes); if (p == NULL || (plan = SPI_saveplan(p)) == NULL) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_prepare_failed"))); } if (SPI_OK_SELECT != SPI_execute_plan(plan, values, nulls, false, 1)) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("can't execute sql"))); if (SPI_processed == 0) ereport(ERROR, (errcode(ERRCODE_RAISE_EXCEPTION), errmsg(INVALID_PATH), errdetail("you cannot access locality"), errhint("locality is not found in utl_file_dir table"))); SPI_finish(); } /* * get_safe_path - make a fullpath and check security. */ static char * get_safe_path(text *location, text *filename) { char *fullname; int aux_pos; int aux_len; NON_EMPTY_TEXT(location); NON_EMPTY_TEXT(filename); aux_pos = VARSIZE_ANY_EXHDR(location); aux_len = VARSIZE_ANY_EXHDR(filename); fullname = palloc(aux_pos + 1 + aux_len + 1); memcpy(fullname, VARDATA(location), aux_pos); fullname[aux_pos] = '/'; memcpy(fullname + aux_pos + 1, VARDATA(filename), aux_len); fullname[aux_pos + aux_len + 1] = '\0'; /* check locality in canonizalized form of path */ canonicalize_path(fullname); check_secure_locality(fullname); return fullname; } /* * CREATE FUNCTION utl_file.fremove( * location text, * filename text) */ Datum utl_file_fremove(PG_FUNCTION_ARGS) { char *fullname; NOT_NULL_ARG(0); NOT_NULL_ARG(1); fullname = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); if (unlink(fullname) != 0) IO_EXCEPTION(); PG_RETURN_VOID(); } /* * CREATE FUNCTION utl_file.frename( * location text, * filename text, * dest_dir text, * dest_file text, * overwrite boolean DEFAULT false) */ Datum utl_file_frename(PG_FUNCTION_ARGS) { char *srcpath; char *dstpath; bool overwrite; NOT_NULL_ARG(0); NOT_NULL_ARG(1); NOT_NULL_ARG(2); NOT_NULL_ARG(3); overwrite = PG_GETARG_IF_EXISTS(4, BOOL, false); srcpath = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); dstpath = get_safe_path(PG_GETARG_TEXT_P(2), PG_GETARG_TEXT_P(3)); if (!overwrite) { struct stat st; if (stat(dstpath, &st) == 0) CUSTOM_EXCEPTION(WRITE_ERROR, "File exists"); else if (errno != ENOENT) IO_EXCEPTION(); } /* rename() overwrites existing files. */ if (rename(srcpath, dstpath) != 0) IO_EXCEPTION(); PG_RETURN_VOID(); } /* * CREATE FUNCTION utl_file.fcopy( * src_location text, * src_filename text, * dest_location text, * dest_filename text, * start_line integer DEFAULT NULL * end_line integer DEFAULT NULL) */ Datum utl_file_fcopy(PG_FUNCTION_ARGS) { char *srcpath; char *dstpath; int start_line; int end_line; FILE *srcfile; FILE *dstfile; NOT_NULL_ARG(0); NOT_NULL_ARG(1); NOT_NULL_ARG(2); NOT_NULL_ARG(3); srcpath = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); dstpath = get_safe_path(PG_GETARG_TEXT_P(2), PG_GETARG_TEXT_P(3)); start_line = PG_GETARG_IF_EXISTS(4, INT32, 1); if (start_line <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("start_line must be positive (%d passed)", start_line))); end_line = PG_GETARG_IF_EXISTS(5, INT32, INT_MAX); if (end_line <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("end_line must be positive (%d passed)", end_line))); srcfile = AllocateFile(srcpath, "rt"); if (srcfile == NULL) { /* failed to open src file. */ IO_EXCEPTION(); } dstfile = AllocateFile(dstpath, "wt"); if (dstfile == NULL) { /* failed to open dst file. */ fclose(srcfile); IO_EXCEPTION(); } if (copy_text_file(srcfile, dstfile, start_line, end_line)) IO_EXCEPTION(); FreeFile(srcfile); FreeFile(dstfile); PG_RETURN_VOID(); } /* * Copy srcfile to dstfile. Return 0 if succeeded, or non-0 if error. */ static int copy_text_file(FILE *srcfile, FILE *dstfile, int start_line, int end_line) { char buffer[MAX_LINESIZE]; size_t len; int i; errno = 0; /* skip first start_line. */ for (i = 1; i < start_line; i++) { CHECK_FOR_INTERRUPTS(); do { if (fgets(buffer, lengthof(buffer), srcfile) == NULL) return errno; len = strlen(buffer); } while(buffer[len - 1] != '\n'); } /* copy until end_line. */ for (; i <= end_line; i++) { CHECK_FOR_INTERRUPTS(); do { if (fgets(buffer, lengthof(buffer), srcfile) == NULL) return errno; len = strlen(buffer); if (fwrite(buffer, 1, len, dstfile) != len) return errno; } while(buffer[len - 1] != '\n'); } return 0; } /* * CREATE FUNCTION utl_file.fgetattr( * location text, * filename text * ) RETURNS ( * fexists boolean, * file_length bigint, * blocksize integer) */ Datum utl_file_fgetattr(PG_FUNCTION_ARGS) { char *fullname; struct stat st; TupleDesc tupdesc; Datum result; HeapTuple tuple; Datum values[3]; bool nulls[3] = { 0 }; NOT_NULL_ARG(0); NOT_NULL_ARG(1); /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); fullname = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); if (stat(fullname, &st) == 0) { values[0] = BoolGetDatum(true); values[1] = Int64GetDatum(st.st_size); #ifndef WIN32 values[2] = Int32GetDatum(st.st_blksize); #else values[2] = 512; /* NTFS block size */ #endif } else { values[0] = BoolGetDatum(false); nulls[1] = true; nulls[2] = true; } tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); PG_RETURN_DATUM(result); } Datum utl_file_tmpdir(PG_FUNCTION_ARGS) { #ifndef WIN32 const char *tmpdir = getenv("TMPDIR"); if (!tmpdir) tmpdir = "/tmp"; #else char tmpdir[MAXPGPATH]; int ret; ret = GetTempPathA(MAXPGPATH, tmpdir); if (ret == 0 || ret > MAXPGPATH) CUSTOM_EXCEPTION(INVALID_PATH, strerror(errno)); canonicalize_path(tmpdir); #endif PG_RETURN_TEXT_P(cstring_to_text(tmpdir)); } orafce-VERSION_3_0_6/magic.c000066400000000000000000000001301221300436000155330ustar00rootroot00000000000000#include "postgres.h" #include "fmgr.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif orafce-VERSION_3_0_6/msvc/000077500000000000000000000000001221300436000152655ustar00rootroot00000000000000orafce-VERSION_3_0_6/msvc/orafce.2010.sln000066400000000000000000000027411221300436000176270ustar00rootroot00000000000000 Microsoft Visual Studio Solution File, Format Version 11.00 # Visual C++ Express 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "orafce.2010", "orafce.2010.vcxproj", "{B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 8.3|Win32 = 8.3|Win32 8.3|x64 = 8.3|x64 8.4|Win32 = 8.4|Win32 8.4|x64 = 8.4|x64 9.0|Win32 = 9.0|Win32 9.0|x64 = 9.0|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.3|Win32.ActiveCfg = 8.3|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.3|Win32.Build.0 = 8.3|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.3|x64.ActiveCfg = 8.3|x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.3|x64.Build.0 = 8.3|x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.4|Win32.ActiveCfg = 8.4|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.4|Win32.Build.0 = 8.4|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.4|x64.ActiveCfg = 8.4|x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.8.4|x64.Build.0 = 8.4|x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.9.0|Win32.ActiveCfg = 9.0|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.9.0|Win32.Build.0 = 9.0|Win32 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.9.0|x64.ActiveCfg = 9.0|x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2}.9.0|x64.Build.0 = 9.0|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal orafce-VERSION_3_0_6/msvc/orafce.2010.vcxproj000066400000000000000000000503221221300436000205240ustar00rootroot00000000000000 8.3 Win32 8.3 x64 8.4 Win32 8.4 x64 9.0 Win32 9.0 x64 {B6B37F22-9E44-4240-AAA0-650D4AC2C2E2} lib Win32Proj orafunc DynamicLibrary Unicode true Windows7.1SDK DynamicLibrary Unicode true Windows7.1SDK DynamicLibrary Unicode true Windows7.1SDK DynamicLibrary Unicode true Windows7.1SDK DynamicLibrary Unicode true Windows7.1SDK DynamicLibrary Unicode true Windows7.1SDK <_ProjectFileVersion>10.0.30319.1 $(SolutionDir)/bin/x86/$(Configuration)/lib/ $(SolutionDir)/bin/$(Platform)/$(Configuration)/lib/ $(SolutionDir)/bin/x86/$(Configuration)/lib/ $(SolutionDir)/bin/$(Platform)/$(Configuration)/lib/ $(SolutionDir)/bin/x86/$(Configuration)/lib/ $(SolutionDir)/bin/$(Platform)/$(Configuration)/lib/ $(SolutionDir)/obj/x86/$(Configuration)/$(ProjectName)/ $(SolutionDir)/obj/$(Platform)/$(Configuration)/$(ProjectName)/ $(SolutionDir)/obj/x86/$(Configuration)/$(ProjectName)/ $(SolutionDir)/obj/$(Platform)/$(Configuration)/$(ProjectName)/ $(SolutionDir)/obj/x86/$(Configuration)/$(ProjectName)/ $(SolutionDir)/obj/$(Platform)/$(Configuration)/$(ProjectName)/ false false false false false false C:\Program Files %28x86%29\PostgreSQL\9.0\include\server\port\win32_msvc;C:\Program Files %28x86%29\PostgreSQL\9.0\include\server\port\win32;C:\Program Files %28x86%29\PostgreSQL\9.0\include\server;C:\Program Files %28x86%29\PostgreSQL\9.0\include;$(IncludePath) C:\Program Files\PostgreSQL\9.0\include\server\port\win32_msvc;C:\Program Files\PostgreSQL\9.0\include\server\port\win32;C:\Program Files\PostgreSQL\9.0\include\server;C:\Program Files\PostgreSQL\9.0\include;$(IncludePath) C:\Program Files %28x86%29\PostgreSQL\8.4\include\server\port\win32_msvc;C:\Program Files %28x86%29\PostgreSQL\8.4\include\server\port\win32;C:\Program Files %28x86%29\PostgreSQL\8.4\include\server;C:\Program Files %28x86%29\PostgreSQL\8.4\include;$(IncludePath) C:\Program Files %28x86%29\PostgreSQL\8.4\include\server\port\win32_msvc;C:\Program Files %28x86%29\PostgreSQL\8.4\include\server\port\win32;C:\Program Files %28x86%29\PostgreSQL\8.4\include\server;C:\Program Files %28x86%29\PostgreSQL\8.4\include;$(IncludePath) C:\Program Files %28x86%29\PostgreSQL\8.3\include\server\port\win32_msvc;C:\Program Files %28x86%29\PostgreSQL\8.3\include\server\port\win32;C:\Program Files %28x86%29\PostgreSQL\8.3\include\server;C:\Program Files %28x86%29\PostgreSQL\8.3\include;$(IncludePath) C:\Program Files %28x86%29\PostgreSQL\8.3\include\server\port\win32_msvc;C:\Program Files %28x86%29\PostgreSQL\8.3\include\server\port\win32;C:\Program Files %28x86%29\PostgreSQL\8.3\include\server;C:\Program Files %28x86%29\PostgreSQL\8.3\include;$(IncludePath) C:\Program Files %28x86%29\PostgreSQL\9.0\lib;$(LibraryPath) C:\Program Files\PostgreSQL\9.0\lib;$(LibraryPath) C:\Program Files %28x86%29\PostgreSQL\8.4\lib;$(LibraryPath) C:\Program Files %28x86%29\PostgreSQL\8.4\lib;$(LibraryPath) C:\Program Files %28x86%29\PostgreSQL\8.3\lib;$(LibraryPath) C:\Program Files %28x86%29\PostgreSQL\8.3\lib;$(LibraryPath) orafunc orafunc orafunc orafunc orafunc orafunc ../include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true MachineX86 ../include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true ../include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true MachineX86 ../include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true ../include;%(AdditionalIncludeDirectories) _USE_32BIT_TIME_T;WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true MachineX86 ../include;%(AdditionalIncludeDirectories) _USE_32BIT_TIME_T;WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 false CompileAsC 4005;4996;4018;%(DisableSpecificWarnings) postgres.lib $(OutDir)/$(TargetFileName) false Console true true orafce-VERSION_3_0_6/msvc/orafce.2010.vcxproj.filters000066400000000000000000000107371221300436000222010ustar00rootroot00000000000000 {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx {c12fa9ac-05f6-45cb-bb38-f575a3a78f47} {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd {bc5d92fe-cfa8-4220-b3cf-c63aede7db41} src src regress regress regress regress regress regress regress script script script script script script script script src src src src src src src src src src src src src src src src src src include include include include include include orafce-VERSION_3_0_6/orafce--3.0.6.sql000066400000000000000000002073301221300436000170210ustar00rootroot00000000000000/* contrib/orafce--3.0.sql */ CREATE FUNCTION pg_catalog.trunc(value date, fmt text) RETURNS date AS 'MODULE_PATHNAME','ora_date_trunc' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(date,text) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.round(value date, fmt text) RETURNS date AS 'MODULE_PATHNAME','ora_date_round' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(date, text) IS 'round dates according to the specified format'; CREATE FUNCTION pg_catalog.next_day(value date, weekday text) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.next_day (date, text) IS 'returns the first weekday that is greather than a date value'; CREATE FUNCTION pg_catalog.next_day(value date, weekday integer) RETURNS date AS 'MODULE_PATHNAME', 'next_day_by_index' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.next_day (date, integer) IS 'returns the first weekday that is greather than a date value'; CREATE FUNCTION pg_catalog.last_day(value date) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.last_day(date) IS 'returns last day of the month based on a date value'; CREATE FUNCTION pg_catalog.months_between(date1 date, date2 date) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.months_between(date, date) IS 'returns the number of months between date1 and date2'; CREATE FUNCTION pg_catalog.add_months(day date, value int) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.add_months(date, int) IS 'returns date plus n months'; CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone, fmt text) RETURNS timestamp with time zone AS 'MODULE_PATHNAME', 'ora_timestamptz_trunc' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone, text) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.round(value timestamp with time zone, fmt text) RETURNS timestamp with time zone AS 'MODULE_PATHNAME','ora_timestamptz_round' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone, text) IS 'round dates according to the specified format'; CREATE FUNCTION pg_catalog.round(value timestamp with time zone) RETURNS timestamp with time zone AS $$ SELECT pg_catalog.round($1, 'DDD'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone) IS 'will round dates according to the specified format'; CREATE FUNCTION pg_catalog.round(value date) RETURNS date AS $$ SELECT $1; $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(value date)IS 'will round dates according to the specified format'; CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone) RETURNS timestamp with time zone AS $$ SELECT pg_catalog.trunc($1, 'DDD'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.trunc(value date) RETURNS date AS $$ SELECT $1; $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(date) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.nlssort(text, text) RETURNS bytea AS 'MODULE_PATHNAME', 'ora_nlssort' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION pg_catalog.nlssort(text, text) IS ''; CREATE FUNCTION pg_catalog.nlssort(text) RETURNS bytea AS $$ SELECT pg_catalog.nlssort($1, null); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.nlssort(text)IS ''; CREATE FUNCTION pg_catalog.set_nls_sort(text) RETURNS void AS 'MODULE_PATHNAME', 'ora_set_nls_sort' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.set_nls_sort(text) IS ''; CREATE FUNCTION pg_catalog.instr(str text, patt text, start int, nth int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text, int, int) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.instr(str text, patt text, start int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text, int) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.instr(str text, patt text) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.to_char(num int) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_int4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(int) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num bigint) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_int8' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(bigint) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num real) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_float4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(real) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num double precision) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_float8' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(double precision) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num numeric) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_numeric' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(numeric) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_number(str text) RETURNS numeric AS 'MODULE_PATHNAME','orafce_to_number' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_number(text) IS 'Convert string to number'; CREATE FUNCTION pg_catalog.to_date(str text) RETURNS date AS $$ SELECT $1::date; $$ LANGUAGE sql IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_date(text) IS 'Convert string to date'; CREATE FUNCTION to_multi_byte(str text) RETURNS text AS 'MODULE_PATHNAME','orafce_to_multi_byte' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION to_multi_byte(text) IS 'Convert all single-byte characters to their corresponding multibyte characters'; CREATE FUNCTION bitand(bigint, bigint) RETURNS bigint AS $$ SELECT $1 & $2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION sinh(float8) RETURNS float8 AS $$ SELECT (exp($1) - exp(-$1)) / 2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION cosh(float8) RETURNS float8 AS $$ SELECT (exp($1) + exp(-$1)) / 2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION tanh(float8) RETURNS float8 AS $$ SELECT sinh($1) / cosh($1); $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(float4, float4) RETURNS float4 AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(float8, float8) RETURNS float8 AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(numeric, numeric) RETURNS numeric AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION dump("any") RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump("any", integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE SCHEMA plvstr; CREATE FUNCTION plvstr.rvrs(str text, start int, _end int) RETURNS text AS 'MODULE_PATHNAME','plvstr_rvrs' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.rvrs(text, int, int) IS 'Reverse string or part of string'; CREATE FUNCTION plvstr.rvrs(str text, start int) RETURNS text AS $$ SELECT plvstr.rvrs($1,$2,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rvrs(text, int) IS 'Reverse string or part of string'; CREATE FUNCTION plvstr.rvrs(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rvrs(text) IS 'Reverse string or part of string'; CREATE FUNCTION pg_catalog.lnnvl(bool) RETURNS bool AS 'MODULE_PATHNAME','ora_lnnvl' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION pg_catalog.lnnvl(bool) IS ''; -- can't overwrite PostgreSQL functions!!!! CREATE SCHEMA oracle; CREATE FUNCTION oracle.substr(str text, start int) RETURNS text AS 'MODULE_PATHNAME','oracle_substr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION oracle.substr(text, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION oracle.substr(str text, start int, len int) RETURNS text AS 'MODULE_PATHNAME','oracle_substr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION oracle.substr(text, int, int) IS 'Returns substring started on start_in len chars'; -- emulation of dual table CREATE VIEW public.dual AS SELECT 'X'::varchar AS dummy; REVOKE ALL ON public.dual FROM PUBLIC; GRANT SELECT, REFERENCES ON public.dual TO PUBLIC; -- this packege is emulation of dbms_output Oracle packege -- CREATE SCHEMA dbms_output; CREATE FUNCTION dbms_output.enable(IN buffer_size int4) RETURNS void AS 'MODULE_PATHNAME','dbms_output_enable' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_output.enable(IN int4) IS 'Enable package functionality'; CREATE FUNCTION dbms_output.enable() RETURNS void AS 'MODULE_PATHNAME','dbms_output_enable_default' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.enable() IS 'Enable package functionality'; CREATE FUNCTION dbms_output.disable() RETURNS void AS 'MODULE_PATHNAME','dbms_output_disable' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.disable() IS 'Disable package functionality'; CREATE FUNCTION dbms_output.serveroutput(IN bool) RETURNS void AS 'MODULE_PATHNAME','dbms_output_serveroutput' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.serveroutput(IN bool) IS 'Set drowing output'; CREATE FUNCTION dbms_output.put(IN a text) RETURNS void AS 'MODULE_PATHNAME','dbms_output_put' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.put(IN text) IS 'Put some text to output'; CREATE FUNCTION dbms_output.put_line(IN a text) RETURNS void AS 'MODULE_PATHNAME','dbms_output_put_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.put_line(IN text) IS 'Put line to output'; CREATE FUNCTION dbms_output.new_line() RETURNS void AS 'MODULE_PATHNAME','dbms_output_new_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.new_line() IS 'Put new line char to output'; CREATE FUNCTION dbms_output.get_line(OUT line text, OUT status int4) AS 'MODULE_PATHNAME','dbms_output_get_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.get_line(OUT text, OUT int4) IS 'Get line from output buffer'; CREATE FUNCTION dbms_output.get_lines(OUT lines text[], INOUT numlines int4) AS 'MODULE_PATHNAME','dbms_output_get_lines' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.get_lines(OUT text[], INOUT int4) IS 'Get lines from output buffer'; -- others functions CREATE FUNCTION nvl(anyelement, anyelement) RETURNS anyelement AS 'MODULE_PATHNAME','ora_nvl' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION nvl(anyelement, anyelement) IS ''; CREATE FUNCTION nvl2(anyelement, anyelement, anyelement) RETURNS anyelement AS 'MODULE_PATHNAME','ora_nvl2' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION nvl2(anyelement, anyelement, anyelement) IS ''; CREATE FUNCTION decode(anyelement, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE SCHEMA dbms_pipe; CREATE FUNCTION dbms_pipe.pack_message(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_text' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(text) IS 'Add text field to message'; CREATE FUNCTION dbms_pipe.unpack_message_text() RETURNS text AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_text' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.unpack_message_text() IS 'Get text fiedl from message'; CREATE FUNCTION dbms_pipe.receive_message(text, int) RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_receive_message' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.receive_message(text, int) IS 'Receive message from pipe'; CREATE FUNCTION dbms_pipe.receive_message(text) RETURNS int AS $$SELECT dbms_pipe.receive_message($1,NULL::int);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.receive_message(text) IS 'Receive message from pipe'; CREATE FUNCTION dbms_pipe.send_message(text, int, int) RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_send_message' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text, int, int) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.send_message(text, int) RETURNS int AS $$SELECT dbms_pipe.send_message($1,$2,NULL);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text, int) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.send_message(text) RETURNS int AS $$SELECT dbms_pipe.send_message($1,NULL,NULL);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.unique_session_name() RETURNS varchar AS 'MODULE_PATHNAME','dbms_pipe_unique_session_name' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unique_session_name() IS 'Returns unique session name'; CREATE FUNCTION dbms_pipe.__list_pipes() RETURNS SETOF RECORD AS 'MODULE_PATHNAME','dbms_pipe_list_pipes' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.__list_pipes() IS ''; CREATE VIEW dbms_pipe.db_pipes AS SELECT * FROM dbms_pipe.__list_pipes() AS (Name varchar, Items int, Size int, "limit" int, "private" bool, "owner" varchar); CREATE FUNCTION dbms_pipe.next_item_type() RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_next_item_type' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.next_item_type() IS 'Returns type of next field in message'; CREATE FUNCTION dbms_pipe.create_pipe(text, int, bool) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text, int, bool) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.create_pipe(text, int) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe_2' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text, int) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.create_pipe(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe_1' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.reset_buffer() RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_reset_buffer' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.reset_buffer() IS 'Clean input buffer'; CREATE FUNCTION dbms_pipe.purge(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_purge' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.purge(text) IS 'Clean pipe'; CREATE FUNCTION dbms_pipe.remove_pipe(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_remove_pipe' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.remove_pipe(text) IS 'Destroy pipe'; CREATE FUNCTION dbms_pipe.pack_message(date) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_date' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(date) IS 'Add date field to message'; CREATE FUNCTION dbms_pipe.unpack_message_date() RETURNS date AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_date' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_date() IS 'Get date field from message'; CREATE FUNCTION dbms_pipe.pack_message(timestamp with time zone) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_timestamp' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(timestamp with time zone) IS 'Add timestamp field to message'; CREATE FUNCTION dbms_pipe.unpack_message_timestamp() RETURNS timestamp with time zone AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_timestamp' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_timestamp() IS 'Get timestamp field from message'; CREATE FUNCTION dbms_pipe.pack_message(numeric) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_number' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(numeric) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.unpack_message_number() RETURNS numeric AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_number' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_number() IS 'Get numeric field from message'; CREATE FUNCTION dbms_pipe.pack_message(integer) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_integer' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(integer) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.pack_message(bigint) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_bigint' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(bigint) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.pack_message(bytea) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_bytea' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(bytea) IS 'Add bytea field to message'; CREATE FUNCTION dbms_pipe.unpack_message_bytea() RETURNS bytea AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_bytea' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_bytea() IS 'Get bytea field from message'; CREATE FUNCTION dbms_pipe.pack_message(record) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_record' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(record) IS 'Add record field to message'; CREATE FUNCTION dbms_pipe.unpack_message_record() RETURNS record AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_record' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_record() IS 'Get record field from message'; -- follow package PLVdate emulation CREATE SCHEMA plvdate; CREATE FUNCTION plvdate.add_bizdays(date, int) RETURNS date AS 'MODULE_PATHNAME','plvdate_add_bizdays' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.add_bizdays(date, int) IS 'Get the date created by adding business days to a date'; CREATE FUNCTION plvdate.nearest_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_nearest_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.nearest_bizday(date) IS 'Get the nearest business date to a given date, user defined'; CREATE FUNCTION plvdate.next_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_next_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.next_bizday(date) IS 'Get the next business date from a given date, user defined'; CREATE FUNCTION plvdate.bizdays_between(date, date) RETURNS int AS 'MODULE_PATHNAME','plvdate_bizdays_between' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.bizdays_between(date, date) IS 'Get the number of business days between two dates'; CREATE FUNCTION plvdate.prev_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_prev_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.prev_bizday(date) IS 'Get the previous business date from a given date'; CREATE FUNCTION plvdate.isbizday(date) RETURNS bool AS 'MODULE_PATHNAME','plvdate_isbizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.isbizday(date) IS 'Call this function to determine if a date is a business day'; CREATE FUNCTION plvdate.set_nonbizday(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_set_nonbizday_dow' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(text) IS 'Set day of week as non bussines day'; CREATE FUNCTION plvdate.unset_nonbizday(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_dow' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(text) IS 'Unset day of week as non bussines day'; CREATE FUNCTION plvdate.set_nonbizday(date, bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_set_nonbizday_day' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(date, bool) IS 'Set day as non bussines day, if repeat is true, then day is nonbiz every year'; CREATE FUNCTION plvdate.unset_nonbizday(date, bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_day' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(date, bool) IS 'Unset day as non bussines day, if repeat is true, then day is nonbiz every year'; CREATE FUNCTION plvdate.set_nonbizday(date) RETURNS bool AS $$SELECT plvdate.set_nonbizday($1, false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(date) IS 'Set day as non bussines day'; CREATE FUNCTION plvdate.unset_nonbizday(date) RETURNS bool AS $$SELECT plvdate.unset_nonbizday($1, false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(date) IS 'Unset day as non bussines day'; CREATE FUNCTION plvdate.use_easter(bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_use_easter' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.use_easter(bool) IS 'Easter Sunday and easter monday will be holiday'; CREATE FUNCTION plvdate.use_easter() RETURNS bool AS $$SELECT plvdate.use_easter(true); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.use_easter() IS 'Easter Sunday and easter monday will be holiday'; CREATE FUNCTION plvdate.unuse_easter() RETURNS bool AS $$SELECT plvdate.use_easter(false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unuse_easter() IS 'Easter Sunday and easter monday will not be holiday'; CREATE FUNCTION plvdate.using_easter() RETURNS bool AS 'MODULE_PATHNAME','plvdate_using_easter' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.using_easter() IS 'Use easter?'; CREATE FUNCTION plvdate.include_start(bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_include_start' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.include_start(bool) IS 'Include starting date in bizdays_between calculation'; CREATE FUNCTION plvdate.include_start() RETURNS bool AS $$SELECT plvdate.include_start(true); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.include_start() IS ''; CREATE FUNCTION plvdate.noinclude_start() RETURNS bool AS $$SELECT plvdate.include_start(false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.noinclude_start() IS ''; CREATE FUNCTION plvdate.including_start() RETURNS bool AS 'MODULE_PATHNAME','plvdate_including_start' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.including_start() IS ''; CREATE FUNCTION plvdate.version() RETURNS cstring AS 'MODULE_PATHNAME','plvdate_version' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.version() IS ''; CREATE FUNCTION plvdate.default_holidays(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_default_holidays' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.default_holidays(text) IS 'Load calendar for some nations'; CREATE FUNCTION plvdate.days_inmonth(date) RETURNS integer AS 'MODULE_PATHNAME','plvdate_days_inmonth' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.days_inmonth(date) IS 'Returns number of days in month'; CREATE FUNCTION plvdate.isleapyear(date) RETURNS bool AS 'MODULE_PATHNAME','plvdate_isleapyear' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.isleapyear(date) IS 'Is leap year'; -- PLVstr package CREATE FUNCTION plvstr.normalize(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_normalize' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.normalize(text) IS 'Replace white chars by space, replace spaces by space'; CREATE FUNCTION plvstr.is_prefix(str text, prefix text, cs bool) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_text' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(text, text, bool) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str text, prefix text) RETURNS bool AS $$ SELECT plvstr.is_prefix($1,$2,true);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(text, text) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str int, prefix int) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_int' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(int, int) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str bigint, prefix bigint) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_int64' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(bigint, bigint) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.substr(str text, start int, len int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_substr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.substr(text, int, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION plvstr.substr(str text, start int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_substr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.substr(text, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION plvstr.instr(str text, patt text, start int, nth int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text, int, int) IS 'Search pattern in string'; CREATE FUNCTION plvstr.instr(str text, patt text, start int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text, int) IS 'Search pattern in string'; CREATE FUNCTION plvstr.instr(str text, patt text) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text) IS 'Search pattern in string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int, all_if_notfound bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_lpart' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int, int, bool) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, $3, $4, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int, int) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, $3, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, 1, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int, all_if_notfound bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_rpart' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int, int, bool) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, $3, $4, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int, int) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, $3, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, 1, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.lstrip(str text, substr text, num int) RETURNS text AS 'MODULE_PATHNAME','plvstr_lstrip' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lstrip(text, text, int) IS 'Call this function to remove characters from the beginning '; CREATE FUNCTION plvstr.lstrip(str text, substr text) RETURNS text AS $$ SELECT plvstr.lstrip($1, $2, 1); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lstrip(text, text) IS 'Call this function to remove characters from the beginning '; CREATE FUNCTION plvstr.rstrip(str text, substr text, num int) RETURNS text AS 'MODULE_PATHNAME','plvstr_rstrip' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rstrip(text, text, int) IS 'Call this function to remove characters from the end'; CREATE FUNCTION plvstr.rstrip(str text, substr text) RETURNS text AS $$ SELECT plvstr.rstrip($1, $2, 1); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rstrip(text, text) IS 'Call this function to remove characters from the end'; CREATE FUNCTION plvstr.swap(str text, replace text, start int, length int) RETURNS text AS 'MODULE_PATHNAME','plvstr_swap' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.swap(text,text, int, int) IS 'Replace a substring in a string with a specified string'; CREATE FUNCTION plvstr.swap(str text, replace text) RETURNS text AS $$ SELECT plvstr.swap($1,$2,1, NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.swap(text,text) IS 'Replace a substring in a string with a specified string'; CREATE FUNCTION plvstr.betwn(str text, start int, _end int, inclusive bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_betwn_i' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.betwn(text, int, int, bool) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start int, _end int) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,true);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.betwn(text, int, int) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int, inclusive bool, gotoend bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_betwn_c' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int, bool, bool) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,1,1,true,false);$$ LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,$4,$5,true,false);$$ LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int) IS 'Find the Substring Between Start and End Locations'; CREATE SCHEMA plvchr; CREATE FUNCTION plvchr.nth(str text, n int) RETURNS text AS 'MODULE_PATHNAME','plvchr_nth' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.nth(text, int) IS 'Call this function to return the Nth character in a string'; CREATE FUNCTION plvchr.first(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_first' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.first(text) IS 'Call this function to return the first character in a string'; CREATE FUNCTION plvchr.last(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_last' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.last(text) IS 'Call this function to return the last character in a string'; CREATE FUNCTION plvchr._is_kind(str text, kind int) RETURNS bool AS 'MODULE_PATHNAME','plvchr_is_kind_a' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr._is_kind(text, int) IS ''; CREATE FUNCTION plvchr._is_kind(c int, kind int) RETURNS bool AS 'MODULE_PATHNAME','plvchr_is_kind_i' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr._is_kind(int, int) IS ''; CREATE FUNCTION plvchr.is_blank(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 1);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_blank(int) IS ''; CREATE FUNCTION plvchr.is_blank(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 1);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_blank(text) IS ''; CREATE FUNCTION plvchr.is_digit(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 2);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_digit(int) IS ''; CREATE FUNCTION plvchr.is_digit(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 2);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_digit(text) IS ''; CREATE FUNCTION plvchr.is_quote(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 3);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_quote(int) IS ''; CREATE FUNCTION plvchr.is_quote(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 3);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_quote(text) IS ''; CREATE FUNCTION plvchr.is_other(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 4);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_other(int) IS ''; CREATE FUNCTION plvchr.is_other(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 4);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_other(text) IS ''; CREATE FUNCTION plvchr.is_letter(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 5);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_letter(int) IS ''; CREATE FUNCTION plvchr.is_letter(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 5);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_letter(text) IS ''; CREATE FUNCTION plvchr.char_name(c text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_char_name' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.char_name(text) IS ''; CREATE FUNCTION plvstr.left(str text, n int) RETURNS varchar AS 'MODULE_PATHNAME', 'plvstr_left' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.left(text, int) IS 'Returns firs num_in charaters. You can use negative num_in'; CREATE FUNCTION plvstr.right(str text, n int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_right' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.right(text, int) IS 'Returns last num_in charaters. You can use negative num_ni'; CREATE FUNCTION plvchr.quoted1(str text) RETURNS varchar AS $$SELECT ''''||$1||'''';$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.quoted1(text) IS E'Quoted text between '''; CREATE FUNCTION plvchr.quoted2(str text) RETURNS varchar AS $$SELECT '"'||$1||'"';$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.quoted2(text) IS 'Quoted text between "'; CREATE FUNCTION plvchr.stripped(str text, char_in text) RETURNS varchar AS $$ SELECT TRANSLATE($1, 'A'||$2, 'A'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.stripped(text, text) IS 'Strips a string of all instances of the specified characters'; -- dbms_alert CREATE SCHEMA dbms_alert; CREATE FUNCTION dbms_alert.register(name text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_register' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_alert.register(text) IS 'Register session as recipient of alert name'; CREATE FUNCTION dbms_alert.remove(name text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_remove' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_alert.remove(text) IS 'Remove session as recipient of alert name'; CREATE FUNCTION dbms_alert.removeall() RETURNS void AS 'MODULE_PATHNAME','dbms_alert_removeall' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.removeall() IS 'Remove registration for all alerts'; CREATE FUNCTION dbms_alert._signal(name text, message text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_signal' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert._signal(text, text) IS ''; CREATE FUNCTION dbms_alert.waitany(OUT name text, OUT message text, OUT status integer, timeout float8) RETURNS record AS 'MODULE_PATHNAME','dbms_alert_waitany' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.waitany(OUT text, OUT text, OUT integer, float8) IS 'Wait for any signal'; CREATE FUNCTION dbms_alert.waitone(name text, OUT message text, OUT status integer, timeout float8) RETURNS record AS 'MODULE_PATHNAME','dbms_alert_waitone' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.waitone(text, OUT text, OUT integer, float8) IS 'Wait for specific signal'; CREATE FUNCTION dbms_alert.set_defaults(sensitivity float8) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_set_defaults' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.set_defaults(float8) IS ''; CREATE FUNCTION dbms_alert.defered_signal() RETURNS trigger AS 'MODULE_PATHNAME','dbms_alert_defered_signal' LANGUAGE C SECURITY DEFINER; REVOKE ALL ON FUNCTION dbms_alert.defered_signal() FROM PUBLIC; CREATE FUNCTION dbms_alert.signal(_event text, _message text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_signal' LANGUAGE C SECURITY DEFINER; COMMENT ON FUNCTION dbms_alert.signal(text, text) IS 'Emit signal to all recipients'; CREATE SCHEMA plvsubst; CREATE FUNCTION plvsubst.string(template_in text, values_in text[], subst text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_array' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text[], text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, values_in text[]) RETURNS text AS $$SELECT plvsubst.string($1,$2, NULL);$$ LANGUAGE SQL STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.string(text, text[]) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text, subst_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.setsubst(str text) RETURNS void AS 'MODULE_PATHNAME','plvsubst_setsubst' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.setsubst(text) IS 'Change the substitution keyword'; CREATE FUNCTION plvsubst.setsubst() RETURNS void AS 'MODULE_PATHNAME','plvsubst_setsubst_default' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.setsubst() IS 'Change the substitution keyword to default %s'; CREATE FUNCTION plvsubst.subst() RETURNS text AS 'MODULE_PATHNAME','plvsubst_subst' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.subst() IS 'Retrieve the current substitution keyword'; CREATE SCHEMA dbms_utility; CREATE FUNCTION dbms_utility.format_call_stack(text) RETURNS text AS 'MODULE_PATHNAME','dbms_utility_format_call_stack1' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION dbms_utility.format_call_stack(text) IS 'Return formated call stack'; CREATE FUNCTION dbms_utility.format_call_stack() RETURNS text AS 'MODULE_PATHNAME','dbms_utility_format_call_stack0' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_utility.format_call_stack() IS 'Return formated call stack'; CREATE SCHEMA plvlex; CREATE FUNCTION plvlex.tokens(IN str text, IN skip_spaces bool, IN qualified_names bool, OUT pos int, OUT token text, OUT code int, OUT class text, OUT separator text, OUT mod text) RETURNS SETOF RECORD AS 'MODULE_PATHNAME','plvlex_tokens' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvlex.tokens(text,bool,bool) IS 'Parse SQL string'; CREATE SCHEMA utl_file; CREATE DOMAIN utl_file.file_type integer; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text, max_linesize integer, encoding name) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fopen' LANGUAGE C VOLATILE SECURITY DEFINER; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer,name) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text, max_linesize integer) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fopen' LANGUAGE C VOLATILE SECURITY DEFINER; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text) RETURNS utl_file.file_type AS $$SELECT utl_file.fopen($1, $2, $3, 1024); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.is_open(file utl_file.file_type) RETURNS bool AS 'MODULE_PATHNAME','utl_file_is_open' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.is_open(utl_file.file_type) IS 'Functions returns true if handle points to file that is open'; CREATE FUNCTION utl_file.get_line(file utl_file.file_type, OUT buffer text) AS 'MODULE_PATHNAME','utl_file_get_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_line(utl_file.file_type) IS 'Returns one line from file'; CREATE FUNCTION utl_file.get_line(file utl_file.file_type, OUT buffer text, len integer) AS 'MODULE_PATHNAME','utl_file_get_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_line(utl_file.file_type, len integer) IS 'Returns one line from file'; CREATE FUNCTION utl_file.get_nextline(file utl_file.file_type, OUT buffer text) AS 'MODULE_PATHNAME','utl_file_get_nextline' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_nextline(utl_file.file_type) IS 'Returns one line from file or returns NULL'; CREATE FUNCTION utl_file.put(file utl_file.file_type, buffer text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put(utl_file.file_type, text) IS 'Puts data to specified file'; CREATE FUNCTION utl_file.put(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put(utl_file.file_type, anyelement) IS 'Puts data to specified file'; CREATE FUNCTION utl_file.new_line(file utl_file.file_type) RETURNS bool AS 'MODULE_PATHNAME','utl_file_new_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.new_line(file utl_file.file_type) IS 'Function inserts one ore more newline characters in specified file'; CREATE FUNCTION utl_file.new_line(file utl_file.file_type, lines int) RETURNS bool AS 'MODULE_PATHNAME','utl_file_new_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.new_line(file utl_file.file_type) IS 'Function inserts one ore more newline characters in specified file'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, text) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer text, autoflush bool) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, text, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text, arg5 text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_putf' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, $5, $6, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, $5, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, NULL, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, NULL, NULL, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.fflush(file utl_file.file_type) RETURNS void AS 'MODULE_PATHNAME','utl_file_fflush' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fflush(file utl_file.file_type) IS 'This procedure makes sure that all pending data for specified file is written physically out to a file'; CREATE FUNCTION utl_file.fclose(file utl_file.file_type) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fclose' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fclose(utl_file.file_type) IS 'Close file'; CREATE FUNCTION utl_file.fclose_all() RETURNS void AS 'MODULE_PATHNAME','utl_file_fclose_all' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fclose_all() IS 'Close all open files.'; CREATE FUNCTION utl_file.fremove(location text, filename text) RETURNS void AS 'MODULE_PATHNAME','utl_file_fremove' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fremove(text, text) IS 'Remove file.'; CREATE FUNCTION utl_file.frename(location text, filename text, dest_dir text, dest_file text, overwrite boolean) RETURNS void AS 'MODULE_PATHNAME','utl_file_frename' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.frename(text, text, text, text, boolean) IS 'Rename file.'; CREATE FUNCTION utl_file.frename(location text, filename text, dest_dir text, dest_file text) RETURNS void AS $$SELECT utl_file.frename($1, $2, $3, $4, false);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.frename(text, text, text, text) IS 'Rename file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text, integer) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer, end_line integer) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text, integer, integer) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fgetattr(location text, filename text, OUT fexists boolean, OUT file_length bigint, OUT blocksize integer) AS 'MODULE_PATHNAME','utl_file_fgetattr' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fgetattr(text, text) IS 'Get file attributes.'; CREATE FUNCTION utl_file.tmpdir() RETURNS text AS 'MODULE_PATHNAME','utl_file_tmpdir' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.tmpdir() IS 'Get temp directory path.'; /* carry all safe directories */ CREATE TABLE utl_file.utl_file_dir(dir text); REVOKE ALL ON utl_file.utl_file_dir FROM PUBLIC; REVOKE ALL ON FUNCTION utl_file.tmpdir() FROM PUBLIC; -- dbms_assert CREATE SCHEMA dbms_assert; CREATE FUNCTION dbms_assert.enquote_literal(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_enquote_literal' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_assert.enquote_literal(varchar) IS 'Add leading and trailing quotes, verify that all single quotes are paired with adjacent single quotes'; CREATE FUNCTION dbms_assert.enquote_name(str varchar, loweralize boolean) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_enquote_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.enquote_name(varchar, boolean) IS 'Enclose name in double quotes'; CREATE FUNCTION dbms_assert.enquote_name(str varchar) RETURNS varchar AS 'SELECT dbms_assert.enquote_name($1, true)' LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION dbms_assert.enquote_name(varchar) IS 'Enclose name in double quotes'; CREATE FUNCTION dbms_assert.noop(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_noop' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.noop(varchar) IS 'Returns value without any checking.'; CREATE FUNCTION dbms_assert.schema_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_schema_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.schema_name(varchar) IS 'Verify input string is an existing schema name.'; CREATE FUNCTION dbms_assert.object_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_object_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an existing object name.'; CREATE FUNCTION dbms_assert.simple_sql_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_simple_sql_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an sql name.'; CREATE FUNCTION dbms_assert.qualified_sql_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_qualified_sql_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an qualified sql name.'; CREATE SCHEMA plunit; CREATE FUNCTION plunit.assert_true(condition boolean) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_true' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_true(condition boolean) IS 'Asserts that the condition is true'; CREATE FUNCTION plunit.assert_true(condition boolean, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_true_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_true(condition boolean, message varchar) IS 'Asserts that the condition is true'; CREATE FUNCTION plunit.assert_false(condition boolean) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_false' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_false(condition boolean) IS 'Asserts that the condition is false'; CREATE FUNCTION plunit.assert_false(condition boolean, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_false_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_false(condition boolean, message varchar) IS 'Asserts that the condition is false'; CREATE FUNCTION plunit.assert_null(actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_null' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_null(actual anyelement) IS 'Asserts that the actual is null'; CREATE FUNCTION plunit.assert_null(actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_null_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_null(actual anyelement, message varchar) IS 'Asserts that the condition is null'; CREATE FUNCTION plunit.assert_not_null(actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_null' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement) IS 'Asserts that the actual is not null'; CREATE FUNCTION plunit.assert_not_null(actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_null_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement, message varchar) IS 'Asserts that the condition is not null'; CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_range' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_range_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_range' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_range_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.fail() RETURNS void AS 'MODULE_PATHNAME','plunit_fail' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.fail() IS 'Immediately fail.'; CREATE FUNCTION plunit.fail(message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_fail_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.fail(message varchar) IS 'Immediately fail.'; -- dbms_random CREATE SCHEMA dbms_random; CREATE FUNCTION dbms_random.initialize(int) RETURNS void AS 'MODULE_PATHNAME','dbms_random_initialize' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.initialize(int) IS 'Initialize package with a seed value'; CREATE FUNCTION dbms_random.normal() RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_normal' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.normal() IS 'Returns random numbers in a standard normal distribution'; CREATE FUNCTION dbms_random.random() RETURNS integer AS 'MODULE_PATHNAME','dbms_random_random' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.random() IS 'Generate Random Numeric Values'; CREATE FUNCTION dbms_random.seed(integer) RETURNS void AS 'MODULE_PATHNAME','dbms_random_seed_int' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.seed(int) IS 'Reset the seed value'; CREATE FUNCTION dbms_random.seed(text) RETURNS void AS 'MODULE_PATHNAME','dbms_random_seed_varchar' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.seed(text) IS 'Reset the seed value'; CREATE FUNCTION dbms_random.string(opt text, len int) RETURNS text AS 'MODULE_PATHNAME','dbms_random_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_random.string(text,int) IS 'Create Random Strings'; CREATE FUNCTION dbms_random.terminate() RETURNS void AS 'MODULE_PATHNAME','dbms_random_terminate' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_random.terminate() IS 'Terminate use of the Package'; CREATE FUNCTION dbms_random.value(low double precision, high double precision) RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_value_range' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION dbms_random.value(double precision, double precision) IS 'Generate Random number x, where x is greather or equal to low and less then high'; CREATE FUNCTION dbms_random.value() RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_value' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.value() IS 'Generate Random number x, where x is greather or equal to 0 and less then 1'; CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION pg_catalog.listagg1_transfn(internal, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg1_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg2_transfn(internal, text, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg2_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg_finalfn(internal) RETURNS text AS 'MODULE_PATHNAME','orafce_listagg_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.listagg(text) ( SFUNC=pg_catalog.listagg1_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE AGGREGATE pg_catalog.listagg(text, text) ( SFUNC=pg_catalog.listagg2_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE FUNCTION pg_catalog.median4_transfn(internal, real) RETURNS internal AS 'MODULE_PATHNAME','orafce_median4_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median4_finalfn(internal) RETURNS real AS 'MODULE_PATHNAME','orafce_median4_finalfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_transfn(internal, double precision) RETURNS internal AS 'MODULE_PATHNAME','orafce_median8_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_finalfn(internal) RETURNS double precision AS 'MODULE_PATHNAME','orafce_median8_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.median(real) ( SFUNC=pg_catalog.median4_transfn, STYPE=internal, FINALFUNC=pg_catalog.median4_finalfn ); CREATE AGGREGATE pg_catalog.median(double precision) ( SFUNC=pg_catalog.median8_transfn, STYPE=internal, FINALFUNC=pg_catalog.median8_finalfn ); GRANT USAGE ON SCHEMA dbms_pipe TO PUBLIC; GRANT USAGE ON SCHEMA dbms_alert TO PUBLIC; GRANT USAGE ON SCHEMA plvdate TO PUBLIC; GRANT USAGE ON SCHEMA plvstr TO PUBLIC; GRANT USAGE ON SCHEMA plvchr TO PUBLIC; GRANT USAGE ON SCHEMA dbms_output TO PUBLIC; GRANT USAGE ON SCHEMA plvsubst TO PUBLIC; GRANT SELECT ON dbms_pipe.db_pipes to PUBLIC; GRANT USAGE ON SCHEMA dbms_utility TO PUBLIC; GRANT USAGE ON SCHEMA plvlex TO PUBLIC; GRANT USAGE ON SCHEMA utl_file TO PUBLIC; GRANT USAGE ON SCHEMA dbms_assert TO PUBLIC; GRANT USAGE ON SCHEMA dbms_random TO PUBLIC; orafce-VERSION_3_0_6/orafce--unpackaged--3.0.6.sql000066400000000000000000000643751221300436000212100ustar00rootroot00000000000000/* contrib/orafce/orafce--unpackaged--3.0.sql */ ALTER EXTENSION orafce ADD function pg_catalog.trunc(value date, fmt text); ALTER EXTENSION orafce ADD function pg_catalog.round(value date, fmt text); ALTER EXTENSION orafce ADD function pg_catalog.next_day(value date, weekday text); ALTER EXTENSION orafce ADD function pg_catalog.next_day(value date, weekday integer); ALTER EXTENSION orafce ADD function pg_catalog.last_day(value date); ALTER EXTENSION orafce ADD function pg_catalog.months_between(date1 date, date2 date); ALTER EXTENSION orafce ADD function pg_catalog.add_months(day date, value int); ALTER EXTENSION orafce ADD function pg_catalog.trunc(value timestamp with time zone, fmt text); ALTER EXTENSION orafce ADD function pg_catalog.round(value timestamp with time zone, fmt text); ALTER EXTENSION orafce ADD function pg_catalog.round(value timestamp with time zone); ALTER EXTENSION orafce ADD function pg_catalog.round(value date); ALTER EXTENSION orafce ADD function pg_catalog.trunc(value timestamp with time zone); ALTER EXTENSION orafce ADD function pg_catalog.trunc(value date); ALTER EXTENSION orafce ADD function pg_catalog.nlssort(text, text); ALTER EXTENSION orafce ADD function pg_catalog.nlssort(text); ALTER EXTENSION orafce ADD function pg_catalog.set_nls_sort(text); ALTER EXTENSION orafce ADD function pg_catalog.instr(str text, patt text, start int, nth int); ALTER EXTENSION orafce ADD function pg_catalog.instr(str text, patt text, start int); ALTER EXTENSION orafce ADD function pg_catalog.instr(str text, patt text); ALTER EXTENSION orafce ADD function pg_catalog.to_char(num int); ALTER EXTENSION orafce ADD function pg_catalog.to_char(num bigint); ALTER EXTENSION orafce ADD function pg_catalog.to_char(num real); ALTER EXTENSION orafce ADD function pg_catalog.to_char(num double precision); ALTER EXTENSION orafce ADD function pg_catalog.to_char(num numeric); ALTER EXTENSION orafce ADD function pg_catalog.to_number(str text); ALTER EXTENSION orafce ADD function pg_catalog.to_date(str text); ALTER EXTENSION orafce ADD function to_multi_byte(str text); ALTER EXTENSION orafce ADD function bitand(bigint, bigint); ALTER EXTENSION orafce ADD function sinh(float8); ALTER EXTENSION orafce ADD function cosh(float8); ALTER EXTENSION orafce ADD function tanh(float8); ALTER EXTENSION orafce ADD function nanvl(float4, float4); ALTER EXTENSION orafce ADD function nanvl(float8, float8); ALTER EXTENSION orafce ADD function nanvl(numeric, numeric); ALTER EXTENSION orafce ADD function dump("any"); ALTER EXTENSION orafce ADD function dump("any", integer); ALTER EXTENSION orafce ADD schema plvstr; ALTER EXTENSION orafce ADD function plvstr.rvrs(str text, start int, _end int); ALTER EXTENSION orafce ADD function plvstr.rvrs(str text, start int); ALTER EXTENSION orafce ADD function plvstr.rvrs(str text); ALTER EXTENSION orafce ADD function pg_catalog.lnnvl(bool); -- can't overwrite PostgreSQL functions!!!! ALTER EXTENSION orafce ADD schema oracle; ALTER EXTENSION orafce ADD function oracle.substr(str text, start int); ALTER EXTENSION orafce ADD function oracle.substr(str text, start int, len int); -- emulation of dual table ALTER EXTENSION orafce ADD view public.dual; -- this packege is emulation of dbms_output Oracle packege -- ALTER EXTENSION orafce ADD schema dbms_output; ALTER EXTENSION orafce ADD function dbms_output.enable(IN buffer_size int4); ALTER EXTENSION orafce ADD function dbms_output.enable(); ALTER EXTENSION orafce ADD function dbms_output.disable(); ALTER EXTENSION orafce ADD function dbms_output.serveroutput(IN bool); ALTER EXTENSION orafce ADD function dbms_output.put(IN a text); ALTER EXTENSION orafce ADD function dbms_output.put_line(IN a text); ALTER EXTENSION orafce ADD function dbms_output.new_line(); ALTER EXTENSION orafce ADD function dbms_output.get_line(OUT line text, OUT status int4); ALTER EXTENSION orafce ADD function dbms_output.get_lines(OUT lines text[], INOUT numlines int4); -- others functions ALTER EXTENSION orafce ADD function nvl(anyelement, anyelement); ALTER EXTENSION orafce ADD function nvl2(anyelement, anyelement, anyelement); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text, anyelement, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text, anyelement, text, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text, anyelement, text, anyelement, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar, anyelement, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer, anyelement, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer, anyelement, integer, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint, anyelement, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint, anyelement, bigint, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric, anyelement, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric, anyelement, numeric, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date, anyelement, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date, anyelement, date, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date, anyelement, date, anyelement, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time, anyelement, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time, anyelement, time, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time, anyelement, time, anyelement, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp, anyelement, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz, timestamptz); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz, anyelement, timestamptz); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz); ALTER EXTENSION orafce ADD function decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz); ALTER EXTENSION orafce ADD schema dbms_pipe; ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(text); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_text(); ALTER EXTENSION orafce ADD function dbms_pipe.receive_message(text, int); ALTER EXTENSION orafce ADD function dbms_pipe.receive_message(text); ALTER EXTENSION orafce ADD function dbms_pipe.send_message(text, int, int); ALTER EXTENSION orafce ADD function dbms_pipe.send_message(text, int); ALTER EXTENSION orafce ADD function dbms_pipe.send_message(text); ALTER EXTENSION orafce ADD function dbms_pipe.unique_session_name(); ALTER EXTENSION orafce ADD function dbms_pipe.__list_pipes(); ALTER EXTENSION orafce ADD VIEW dbms_pipe.db_pipes; ALTER EXTENSION orafce ADD function dbms_pipe.next_item_type(); ALTER EXTENSION orafce ADD function dbms_pipe.create_pipe(text, int, bool); ALTER EXTENSION orafce ADD function dbms_pipe.create_pipe(text, int); ALTER EXTENSION orafce ADD function dbms_pipe.create_pipe(text); ALTER EXTENSION orafce ADD function dbms_pipe.reset_buffer(); ALTER EXTENSION orafce ADD function dbms_pipe.purge(text); ALTER EXTENSION orafce ADD function dbms_pipe.remove_pipe(text); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(date); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_date(); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(timestamp with time zone); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_timestamp(); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(numeric); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_number(); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(integer); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(bigint); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(bytea); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_bytea(); ALTER EXTENSION orafce ADD function dbms_pipe.pack_message(record); ALTER EXTENSION orafce ADD function dbms_pipe.unpack_message_record(); -- follow package PLVdate emulation ALTER EXTENSION orafce ADD schema plvdate; ALTER EXTENSION orafce ADD function plvdate.add_bizdays(date, int); ALTER EXTENSION orafce ADD function plvdate.nearest_bizday(date); ALTER EXTENSION orafce ADD function plvdate.next_bizday(date); ALTER EXTENSION orafce ADD function plvdate.bizdays_between(date, date); ALTER EXTENSION orafce ADD function plvdate.prev_bizday(date); ALTER EXTENSION orafce ADD function plvdate.isbizday(date); ALTER EXTENSION orafce ADD function plvdate.set_nonbizday(text); ALTER EXTENSION orafce ADD function plvdate.unset_nonbizday(text); ALTER EXTENSION orafce ADD function plvdate.set_nonbizday(date, bool); ALTER EXTENSION orafce ADD function plvdate.unset_nonbizday(date, bool); ALTER EXTENSION orafce ADD function plvdate.set_nonbizday(date); ALTER EXTENSION orafce ADD function plvdate.unset_nonbizday(date); ALTER EXTENSION orafce ADD function plvdate.use_easter(bool); ALTER EXTENSION orafce ADD function plvdate.use_easter(); ALTER EXTENSION orafce ADD function plvdate.unuse_easter(); ALTER EXTENSION orafce ADD function plvdate.using_easter(); ALTER EXTENSION orafce ADD function plvdate.include_start(bool); ALTER EXTENSION orafce ADD function plvdate.include_start(); ALTER EXTENSION orafce ADD function plvdate.noinclude_start(); ALTER EXTENSION orafce ADD function plvdate.including_start(); ALTER EXTENSION orafce ADD function plvdate.version(); ALTER EXTENSION orafce ADD function plvdate.default_holidays(text); ALTER EXTENSION orafce ADD function plvdate.days_inmonth(date); ALTER EXTENSION orafce ADD function plvdate.isleapyear(date); -- PLVstr package ALTER EXTENSION orafce ADD schema plvstr; ALTER EXTENSION orafce ADD function plvstr.normalize(str text); ALTER EXTENSION orafce ADD function plvstr.is_prefix(str text, prefix text, cs bool); ALTER EXTENSION orafce ADD function plvstr.is_prefix(str text, prefix text); ALTER EXTENSION orafce ADD function plvstr.is_prefix(str int, prefix int); ALTER EXTENSION orafce ADD function plvstr.is_prefix(str bigint, prefix bigint); ALTER EXTENSION orafce ADD function plvstr.substr(str text, start int, len int); ALTER EXTENSION orafce ADD function plvstr.substr(str text, start int); ALTER EXTENSION orafce ADD function plvstr.instr(str text, patt text, start int, nth int); ALTER EXTENSION orafce ADD function plvstr.instr(str text, patt text, start int); ALTER EXTENSION orafce ADD function plvstr.instr(str text, patt text); ALTER EXTENSION orafce ADD function plvstr.lpart(str text, div text, start int, nth int, all_if_notfound bool); ALTER EXTENSION orafce ADD function plvstr.lpart(str text, div text, start int, nth int); ALTER EXTENSION orafce ADD function plvstr.lpart(str text, div text, start int); ALTER EXTENSION orafce ADD function plvstr.lpart(str text, div text); ALTER EXTENSION orafce ADD function plvstr.rpart(str text, div text, start int, nth int, all_if_notfound bool); ALTER EXTENSION orafce ADD function plvstr.rpart(str text, div text, start int, nth int); ALTER EXTENSION orafce ADD function plvstr.rpart(str text, div text, start int); ALTER EXTENSION orafce ADD function plvstr.rpart(str text, div text); ALTER EXTENSION orafce ADD function plvstr.lstrip(str text, substr text, num int); ALTER EXTENSION orafce ADD function plvstr.lstrip(str text, substr text); ALTER EXTENSION orafce ADD function plvstr.rstrip(str text, substr text, num int); ALTER EXTENSION orafce ADD function plvstr.rstrip(str text, substr text); ALTER EXTENSION orafce ADD function plvstr.swap(str text, replace text, start int, length int); ALTER EXTENSION orafce ADD function plvstr.swap(str text, replace text); ALTER EXTENSION orafce ADD function plvstr.betwn(str text, start int, _end int, inclusive bool); ALTER EXTENSION orafce ADD function plvstr.betwn(str text, start int, _end int); ALTER EXTENSION orafce ADD function plvstr.betwn(str text, start text, _end text, startnth int, endnth int, inclusive bool, gotoend bool); ALTER EXTENSION orafce ADD function plvstr.betwn(str text, start text, _end text); ALTER EXTENSION orafce ADD function plvstr.betwn(str text, start text, _end text, startnth int, endnth int); ALTER EXTENSION orafce ADD schema plvchr; ALTER EXTENSION orafce ADD function plvchr.nth(str text, n int); ALTER EXTENSION orafce ADD function plvchr.first(str text); ALTER EXTENSION orafce ADD function plvchr.last(str text); ALTER EXTENSION orafce ADD function plvchr._is_kind(str text, kind int); ALTER EXTENSION orafce ADD function plvchr._is_kind(c int, kind int); ALTER EXTENSION orafce ADD function plvchr.is_blank(c int); ALTER EXTENSION orafce ADD function plvchr.is_blank(c text); ALTER EXTENSION orafce ADD function plvchr.is_digit(c int); ALTER EXTENSION orafce ADD function plvchr.is_digit(c text); ALTER EXTENSION orafce ADD function plvchr.is_quote(c int); ALTER EXTENSION orafce ADD function plvchr.is_quote(c text); ALTER EXTENSION orafce ADD function plvchr.is_other(c int); ALTER EXTENSION orafce ADD function plvchr.is_other(c text); ALTER EXTENSION orafce ADD function plvchr.is_letter(c int); ALTER EXTENSION orafce ADD function plvchr.is_letter(c text); ALTER EXTENSION orafce ADD function plvchr.char_name(c text); ALTER EXTENSION orafce ADD function plvstr.left(str text, n int); ALTER EXTENSION orafce ADD function plvstr.right(str text, n int); ALTER EXTENSION orafce ADD function plvchr.quoted1(str text); ALTER EXTENSION orafce ADD function plvchr.quoted2(str text); ALTER EXTENSION orafce ADD function plvchr.stripped(str text, char_in text); -- dbms_alert ALTER EXTENSION orafce ADD schema dbms_alert; ALTER EXTENSION orafce ADD function dbms_alert.register(name text); ALTER EXTENSION orafce ADD function dbms_alert.remove(name text); ALTER EXTENSION orafce ADD function dbms_alert.removeall(); ALTER EXTENSION orafce ADD function dbms_alert._signal(name text, message text); ALTER EXTENSION orafce ADD function dbms_alert.waitany(OUT name text, OUT message text, OUT status integer, timeout float8); ALTER EXTENSION orafce ADD function dbms_alert.waitone(name text, OUT message text, OUT status integer, timeout float8); ALTER EXTENSION orafce ADD function dbms_alert.set_defaults(sensitivity float8); ALTER EXTENSION orafce ADD function dbms_alert.defered_signal(); ALTER EXTENSION orafce ADD function dbms_alert.signal(_event text, _message text); ALTER EXTENSION orafce ADD schema plvsubst; ALTER EXTENSION orafce ADD function plvsubst.string(template_in text, values_in text[], subst text); ALTER EXTENSION orafce ADD function plvsubst.string(template_in text, values_in text[]); ALTER EXTENSION orafce ADD function plvsubst.string(template_in text, vals_in text, delim_in text, subst_in text); ALTER EXTENSION orafce ADD function plvsubst.string(template_in text, vals_in text); ALTER EXTENSION orafce ADD function plvsubst.string(template_in text, vals_in text, delim_in text); ALTER EXTENSION orafce ADD function plvsubst.setsubst(str text); ALTER EXTENSION orafce ADD function plvsubst.setsubst(); ALTER EXTENSION orafce ADD function plvsubst.subst(); ALTER EXTENSION orafce ADD schema dbms_utility; ALTER EXTENSION orafce ADD function dbms_utility.format_call_stack(text); ALTER EXTENSION orafce ADD function dbms_utility.format_call_stack(); ALTER EXTENSION orafce ADD schema plvlex; ALTER EXTENSION orafce ADD function plvlex.tokens(IN str text, IN skip_spaces bool, IN qualified_names bool, OUT pos int, OUT token text, OUT code int, OUT class text, OUT separator text, OUT mod text); ALTER EXTENSION orafce ADD schema utl_file; ALTER EXTENSION orafce ADD domain utl_file.file_type; ALTER EXTENSION orafce ADD function utl_file.fopen(location text, filename text, open_mode text, max_linesize integer, encoding name); ALTER EXTENSION orafce ADD function utl_file.fopen(location text, filename text, open_mode text, max_linesize integer); ALTER EXTENSION orafce ADD function utl_file.fopen(location text, filename text, open_mode text); ALTER EXTENSION orafce ADD function utl_file.is_open(file utl_file.file_type); ALTER EXTENSION orafce ADD function utl_file.get_line(file utl_file.file_type, OUT buffer text); ALTER EXTENSION orafce ADD function utl_file.get_line(file utl_file.file_type, OUT buffer text, len integer); ALTER EXTENSION orafce ADD function utl_file.get_nextline(file utl_file.file_type, OUT buffer text); ALTER EXTENSION orafce ADD function utl_file.put(file utl_file.file_type, buffer text); ALTER EXTENSION orafce ADD function utl_file.put(file utl_file.file_type, buffer anyelement); ALTER EXTENSION orafce ADD function utl_file.new_line(file utl_file.file_type); ALTER EXTENSION orafce ADD function utl_file.new_line(file utl_file.file_type, lines int); ALTER EXTENSION orafce ADD function utl_file.put_line(file utl_file.file_type, buffer text); ALTER EXTENSION orafce ADD function utl_file.put_line(file utl_file.file_type, buffer text, autoflush bool); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text, arg5 text); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text, arg1 text); ALTER EXTENSION orafce ADD function utl_file.putf(file utl_file.file_type, format text); ALTER EXTENSION orafce ADD function utl_file.fflush(file utl_file.file_type); ALTER EXTENSION orafce ADD function utl_file.fclose(file utl_file.file_type); ALTER EXTENSION orafce ADD function utl_file.fclose_all(); ALTER EXTENSION orafce ADD function utl_file.fremove(location text, filename text); ALTER EXTENSION orafce ADD function utl_file.frename(location text, filename text, dest_dir text, dest_file text, overwrite boolean); ALTER EXTENSION orafce ADD function utl_file.frename(location text, filename text, dest_dir text, dest_file text); ALTER EXTENSION orafce ADD function utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text); ALTER EXTENSION orafce ADD function utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer); ALTER EXTENSION orafce ADD function utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer, end_line integer); ALTER EXTENSION orafce ADD function utl_file.fgetattr(location text, filename text, OUT fexists boolean, OUT file_length bigint, OUT blocksize integer); ALTER EXTENSION orafce ADD function utl_file.tmpdir(); /* carry all safe directories */ ALTER EXTENSION orafce ADD table utl_file.utl_file_dir; -- dbms_assert ALTER EXTENSION orafce ADD schema dbms_assert; ALTER EXTENSION orafce ADD function dbms_assert.enquote_literal(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.enquote_name(str varchar, loweralize boolean); ALTER EXTENSION orafce ADD function dbms_assert.enquote_name(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.noop(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.schema_name(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.object_name(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.simple_sql_name(str varchar); ALTER EXTENSION orafce ADD function dbms_assert.qualified_sql_name(str varchar); ALTER EXTENSION orafce ADD schema plunit; ALTER EXTENSION orafce ADD function plunit.assert_true(condition boolean); ALTER EXTENSION orafce ADD function plunit.assert_true(condition boolean, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_false(condition boolean); ALTER EXTENSION orafce ADD function plunit.assert_false(condition boolean, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_null(actual anyelement); ALTER EXTENSION orafce ADD function plunit.assert_null(actual anyelement, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_not_null(actual anyelement); ALTER EXTENSION orafce ADD function plunit.assert_not_null(actual anyelement, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_equals(expected anyelement, actual anyelement); ALTER EXTENSION orafce ADD function plunit.assert_equals(expected anyelement, actual anyelement, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_equals(expected double precision, actual double precision, "range" double precision); ALTER EXTENSION orafce ADD function plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_not_equals(expected anyelement, actual anyelement); ALTER EXTENSION orafce ADD function plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar); ALTER EXTENSION orafce ADD function plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision); ALTER EXTENSION orafce ADD function plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar); ALTER EXTENSION orafce ADD function plunit.fail(); ALTER EXTENSION orafce ADD function plunit.fail(message varchar); -- dbms_random ALTER EXTENSION orafce ADD schema dbms_random; ALTER EXTENSION orafce ADD function dbms_random.initialize(int); ALTER EXTENSION orafce ADD function dbms_random.normal(); ALTER EXTENSION orafce ADD function dbms_random.random(); ALTER EXTENSION orafce ADD function dbms_random.seed(integer); ALTER EXTENSION orafce ADD function dbms_random.seed(text); ALTER EXTENSION orafce ADD function dbms_random.string(opt text, len int); ALTER EXTENSION orafce ADD function dbms_random.terminate(); ALTER EXTENSION orafce ADD function dbms_random.value(low double precision, high double precision); ALTER EXTENSION orafce ADD function dbms_random.value(); ALTER EXTENSION orafce ADD function dump(text); ALTER EXTENSION orafce ADD function dump(text, integer); ALTER EXTENSION orafce ADD function utl_file.put_line(file utl_file.file_type, buffer anyelement); ALTER EXTENSION orafce ADD function utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool); ALTER EXTENSION orafce ADD function pg_catalog.listagg1_transfn(internal, text); ALTER EXTENSION orafce ADD function pg_catalog.listagg2_transfn(internal, text, text); ALTER EXTENSION orafce ADD function pg_catalog.listagg_finalfn(internal); ALTER EXTENSION orafce ADD aggregate pg_catalog.listagg(text); ALTER EXTENSION orafce ADD aggregate pg_catalog.listagg(text, text); ALTER EXTENSION orafce ADD function pg_catalog.median4_transfn(internal, real); ALTER EXTENSION orafce ADD function pg_catalog.median4_finalfn(internal); ALTER EXTENSION orafce ADD function pg_catalog.median8_transfn(internal, double precision); ALTER EXTENSION orafce ADD function pg_catalog.median8_finalfn(internal); ALTER EXTENSION orafce ADD aggregate pg_catalog.median(real); ALTER EXTENSION orafce ADD aggregate pg_catalog.median(double precision); orafce-VERSION_3_0_6/orafce.control000066400000000000000000000003211221300436000171520ustar00rootroot00000000000000# intarray extension comment = 'Functions and operators that emulate a subset of functions and packages from the Oracle RDBMS' default_version = '3.0.6' module_pathname = '$libdir/orafunc' relocatable = false orafce-VERSION_3_0_6/orafunc-8.1.sql000077500000000000000000000006061221300436000170040ustar00rootroot00000000000000CREATE FUNCTION pg_catalog.reverse(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.reverse(text) IS 'Reverse string or part of string'; CREATE FUNCTION concat(text, text) RETURNS text AS 'MODULE_PATHNAME','ora_concat' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings'; COMMIT; orafce-VERSION_3_0_6/orafunc-8.2.sql000077500000000000000000000006061221300436000170050ustar00rootroot00000000000000CREATE FUNCTION pg_catalog.reverse(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.reverse(text) IS 'Reverse string or part of string'; CREATE FUNCTION concat(text, text) RETURNS text AS 'MODULE_PATHNAME','ora_concat' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings'; COMMIT; orafce-VERSION_3_0_6/orafunc-8.3.sql000077500000000000000000000035511221300436000170100ustar00rootroot00000000000000CREATE FUNCTION pg_catalog.reverse(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.reverse(text) IS 'Reverse string or part of string'; CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION concat(text, text) RETURNS text AS 'MODULE_PATHNAME','ora_concat' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings'; CREATE FUNCTION concat(text, anyarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, anyarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(text, anynonarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, anynonarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; COMMIT; orafce-VERSION_3_0_6/orafunc-8.4.sql000077500000000000000000000066641221300436000170210ustar00rootroot00000000000000CREATE FUNCTION pg_catalog.reverse(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.reverse(text) IS 'Reverse string or part of string'; CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION concat(text, text) RETURNS text AS 'MODULE_PATHNAME','ora_concat' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings'; CREATE FUNCTION concat(text, anyarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, anyarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(text, anynonarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, anynonarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION pg_catalog.listagg1_transfn(internal, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg1_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg2_transfn(internal, text, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg2_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg_finalfn(internal) RETURNS text AS 'MODULE_PATHNAME','orafce_listagg_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.listagg(text) ( SFUNC=pg_catalog.listagg1_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE AGGREGATE pg_catalog.listagg(text, text) ( SFUNC=pg_catalog.listagg2_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE FUNCTION pg_catalog.median4_transfn(internal, real) RETURNS internal AS 'MODULE_PATHNAME','orafce_median4_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median4_finalfn(internal) RETURNS real AS 'MODULE_PATHNAME','orafce_median4_finalfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_transfn(internal, double precision) RETURNS internal AS 'MODULE_PATHNAME','orafce_median8_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_finalfn(internal) RETURNS double precision AS 'MODULE_PATHNAME','orafce_median8_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.median(real) ( SFUNC=pg_catalog.median4_transfn, STYPE=internal, FINALFUNC=pg_catalog.median4_finalfn ); CREATE AGGREGATE pg_catalog.median(double precision) ( SFUNC=pg_catalog.median8_transfn, STYPE=internal, FINALFUNC=pg_catalog.median8_finalfn ); COMMIT; orafce-VERSION_3_0_6/orafunc-9.0.sql000077500000000000000000000066641221300436000170160ustar00rootroot00000000000000CREATE FUNCTION pg_catalog.reverse(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.reverse(text) IS 'Reverse string or part of string'; CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION concat(text, text) RETURNS text AS 'MODULE_PATHNAME','ora_concat' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings'; CREATE FUNCTION concat(text, anyarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anyarray, anyarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(text, anynonarray) RETURNS text AS 'SELECT concat($1, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, text) RETURNS text AS 'SELECT concat($1::text, $2)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION concat(anynonarray, anynonarray) RETURNS text AS 'SELECT concat($1::text, $2::text)' LANGUAGE sql IMMUTABLE; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION pg_catalog.listagg1_transfn(internal, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg1_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg2_transfn(internal, text, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg2_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg_finalfn(internal) RETURNS text AS 'MODULE_PATHNAME','orafce_listagg_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.listagg(text) ( SFUNC=pg_catalog.listagg1_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE AGGREGATE pg_catalog.listagg(text, text) ( SFUNC=pg_catalog.listagg2_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE FUNCTION pg_catalog.median4_transfn(internal, real) RETURNS internal AS 'MODULE_PATHNAME','orafce_median4_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median4_finalfn(internal) RETURNS real AS 'MODULE_PATHNAME','orafce_median4_finalfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_transfn(internal, double precision) RETURNS internal AS 'MODULE_PATHNAME','orafce_median8_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_finalfn(internal) RETURNS double precision AS 'MODULE_PATHNAME','orafce_median8_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.median(real) ( SFUNC=pg_catalog.median4_transfn, STYPE=internal, FINALFUNC=pg_catalog.median4_finalfn ); CREATE AGGREGATE pg_catalog.median(double precision) ( SFUNC=pg_catalog.median8_transfn, STYPE=internal, FINALFUNC=pg_catalog.median8_finalfn ); COMMIT; orafce-VERSION_3_0_6/orafunc-9.1.sql000066400000000000000000000046021221300436000170020ustar00rootroot00000000000000CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION pg_catalog.listagg1_transfn(internal, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg1_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg2_transfn(internal, text, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg2_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg_finalfn(internal) RETURNS text AS 'MODULE_PATHNAME','orafce_listagg_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.listagg(text) ( SFUNC=pg_catalog.listagg1_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE AGGREGATE pg_catalog.listagg(text, text) ( SFUNC=pg_catalog.listagg2_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE FUNCTION pg_catalog.median4_transfn(internal, real) RETURNS internal AS 'MODULE_PATHNAME','orafce_median4_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median4_finalfn(internal) RETURNS real AS 'MODULE_PATHNAME','orafce_median4_finalfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_transfn(internal, double precision) RETURNS internal AS 'MODULE_PATHNAME','orafce_median8_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_finalfn(internal) RETURNS double precision AS 'MODULE_PATHNAME','orafce_median8_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.median(real) ( SFUNC=pg_catalog.median4_transfn, STYPE=internal, FINALFUNC=pg_catalog.median4_finalfn ); CREATE AGGREGATE pg_catalog.median(double precision) ( SFUNC=pg_catalog.median8_transfn, STYPE=internal, FINALFUNC=pg_catalog.median8_finalfn ); COMMIT; orafce-VERSION_3_0_6/orafunc-common-2.sql000066400000000000000000000046021221300436000201220ustar00rootroot00000000000000CREATE FUNCTION dump(text) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump(text, integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer anyelement, autoflush bool) RETURNS bool AS $$SELECT utl_file.put_line($1, $2::text, true); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, anyelement, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION pg_catalog.listagg1_transfn(internal, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg1_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg2_transfn(internal, text, text) RETURNS internal AS 'MODULE_PATHNAME','orafce_listagg2_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.listagg_finalfn(internal) RETURNS text AS 'MODULE_PATHNAME','orafce_listagg_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.listagg(text) ( SFUNC=pg_catalog.listagg1_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE AGGREGATE pg_catalog.listagg(text, text) ( SFUNC=pg_catalog.listagg2_transfn, STYPE=internal, FINALFUNC=pg_catalog.listagg_finalfn ); CREATE FUNCTION pg_catalog.median4_transfn(internal, real) RETURNS internal AS 'MODULE_PATHNAME','orafce_median4_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median4_finalfn(internal) RETURNS real AS 'MODULE_PATHNAME','orafce_median4_finalfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_transfn(internal, double precision) RETURNS internal AS 'MODULE_PATHNAME','orafce_median8_transfn' LANGUAGE C IMMUTABLE; CREATE FUNCTION pg_catalog.median8_finalfn(internal) RETURNS double precision AS 'MODULE_PATHNAME','orafce_median8_finalfn' LANGUAGE C IMMUTABLE; CREATE AGGREGATE pg_catalog.median(real) ( SFUNC=pg_catalog.median4_transfn, STYPE=internal, FINALFUNC=pg_catalog.median4_finalfn ); CREATE AGGREGATE pg_catalog.median(double precision) ( SFUNC=pg_catalog.median8_transfn, STYPE=internal, FINALFUNC=pg_catalog.median8_finalfn ); COMMIT; orafce-VERSION_3_0_6/orafunc-common.sql000077500000000000000000002027131221300436000177710ustar00rootroot00000000000000-- Adjust this setting to control where the objects get created. SET search_path = public; BEGIN; CREATE FUNCTION pg_catalog.trunc(value date, fmt text) RETURNS date AS 'MODULE_PATHNAME','ora_date_trunc' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(date,text) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.round(value date, fmt text) RETURNS date AS 'MODULE_PATHNAME','ora_date_round' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(date, text) IS 'round dates according to the specified format'; CREATE FUNCTION pg_catalog.next_day(value date, weekday text) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.next_day (date, text) IS 'returns the first weekday that is greather than a date value'; CREATE FUNCTION pg_catalog.next_day(value date, weekday integer) RETURNS date AS 'MODULE_PATHNAME', 'next_day_by_index' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.next_day (date, integer) IS 'returns the first weekday that is greather than a date value'; CREATE FUNCTION pg_catalog.last_day(value date) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.last_day(date) IS 'returns last day of the month based on a date value'; CREATE FUNCTION pg_catalog.months_between(date1 date, date2 date) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.months_between(date, date) IS 'returns the number of months between date1 and date2'; CREATE FUNCTION pg_catalog.add_months(day date, value int) RETURNS date AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.add_months(date, int) IS 'returns date plus n months'; CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone, fmt text) RETURNS timestamp with time zone AS 'MODULE_PATHNAME', 'ora_timestamptz_trunc' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone, text) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.round(value timestamp with time zone, fmt text) RETURNS timestamp with time zone AS 'MODULE_PATHNAME','ora_timestamptz_round' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone, text) IS 'round dates according to the specified format'; CREATE FUNCTION pg_catalog.round(value timestamp with time zone) RETURNS timestamp with time zone AS $$ SELECT pg_catalog.round($1, 'DDD'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone) IS 'will round dates according to the specified format'; CREATE FUNCTION pg_catalog.round(value date) RETURNS date AS $$ SELECT $1; $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.round(value date)IS 'will round dates according to the specified format'; CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone) RETURNS timestamp with time zone AS $$ SELECT pg_catalog.trunc($1, 'DDD'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.trunc(value date) RETURNS date AS $$ SELECT $1; $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.trunc(date) IS 'truncate date according to the specified format'; CREATE FUNCTION pg_catalog.nlssort(text, text) RETURNS bytea AS 'MODULE_PATHNAME', 'ora_nlssort' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION pg_catalog.nlssort(text, text) IS ''; CREATE FUNCTION pg_catalog.nlssort(text) RETURNS bytea AS $$ SELECT pg_catalog.nlssort($1, null); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.nlssort(text)IS ''; CREATE FUNCTION pg_catalog.set_nls_sort(text) RETURNS void AS 'MODULE_PATHNAME', 'ora_set_nls_sort' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.set_nls_sort(text) IS ''; CREATE FUNCTION pg_catalog.instr(str text, patt text, start int, nth int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text, int, int) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.instr(str text, patt text, start int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text, int) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.instr(str text, patt text) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.instr(text, text) IS 'Search pattern in string'; CREATE FUNCTION pg_catalog.to_char(num int) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_int4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(int) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num bigint) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_int8' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(bigint) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num real) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_float4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(real) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num double precision) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_float8' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(double precision) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_char(num numeric) RETURNS text AS 'MODULE_PATHNAME','orafce_to_char_numeric' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_char(numeric) IS 'Convert number to string'; CREATE FUNCTION pg_catalog.to_number(str text) RETURNS numeric AS 'MODULE_PATHNAME','orafce_to_number' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_number(text) IS 'Convert string to number'; CREATE FUNCTION pg_catalog.to_date(str text) RETURNS date AS $$ SELECT $1::date; $$ LANGUAGE sql IMMUTABLE STRICT; COMMENT ON FUNCTION pg_catalog.to_date(text) IS 'Convert string to date'; CREATE FUNCTION to_multi_byte(str text) RETURNS text AS 'MODULE_PATHNAME','orafce_to_multi_byte' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION to_multi_byte(text) IS 'Convert all single-byte characters to their corresponding multibyte characters'; CREATE FUNCTION bitand(bigint, bigint) RETURNS bigint AS $$ SELECT $1 & $2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION sinh(float8) RETURNS float8 AS $$ SELECT (exp($1) - exp(-$1)) / 2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION cosh(float8) RETURNS float8 AS $$ SELECT (exp($1) + exp(-$1)) / 2; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION tanh(float8) RETURNS float8 AS $$ SELECT sinh($1) / cosh($1); $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(float4, float4) RETURNS float4 AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(float8, float8) RETURNS float8 AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION nanvl(numeric, numeric) RETURNS numeric AS $$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$ LANGUAGE sql IMMUTABLE STRICT; CREATE FUNCTION dump("any") RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE FUNCTION dump("any", integer) RETURNS varchar AS 'MODULE_PATHNAME', 'orafce_dump' LANGUAGE C; CREATE SCHEMA plvstr; CREATE FUNCTION plvstr.rvrs(str text, start int, _end int) RETURNS text AS 'MODULE_PATHNAME','plvstr_rvrs' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.rvrs(text, int, int) IS 'Reverse string or part of string'; CREATE FUNCTION plvstr.rvrs(str text, start int) RETURNS text AS $$ SELECT plvstr.rvrs($1,$2,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rvrs(text, int) IS 'Reverse string or part of string'; CREATE FUNCTION plvstr.rvrs(str text) RETURNS text AS $$ SELECT plvstr.rvrs($1,1,NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rvrs(text) IS 'Reverse string or part of string'; CREATE FUNCTION pg_catalog.lnnvl(bool) RETURNS bool AS 'MODULE_PATHNAME','ora_lnnvl' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION pg_catalog.lnnvl(bool) IS ''; -- can't overwrite PostgreSQL functions!!!! CREATE SCHEMA oracle; CREATE FUNCTION oracle.substr(str text, start int) RETURNS text AS 'MODULE_PATHNAME','oracle_substr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION oracle.substr(text, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION oracle.substr(str text, start int, len int) RETURNS text AS 'MODULE_PATHNAME','oracle_substr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION oracle.substr(text, int, int) IS 'Returns substring started on start_in len chars'; -- emulation of dual table CREATE VIEW public.dual AS SELECT 'X'::varchar AS dummy; REVOKE ALL ON public.dual FROM PUBLIC; GRANT SELECT, REFERENCES ON public.dual TO PUBLIC; -- this packege is emulation of dbms_output Oracle packege -- CREATE SCHEMA dbms_output; CREATE FUNCTION dbms_output.enable(IN buffer_size int4) RETURNS void AS 'MODULE_PATHNAME','dbms_output_enable' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_output.enable(IN int4) IS 'Enable package functionality'; CREATE FUNCTION dbms_output.enable() RETURNS void AS 'MODULE_PATHNAME','dbms_output_enable_default' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.enable() IS 'Enable package functionality'; CREATE FUNCTION dbms_output.disable() RETURNS void AS 'MODULE_PATHNAME','dbms_output_disable' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.disable() IS 'Disable package functionality'; CREATE FUNCTION dbms_output.serveroutput(IN bool) RETURNS void AS 'MODULE_PATHNAME','dbms_output_serveroutput' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.serveroutput(IN bool) IS 'Set drowing output'; CREATE FUNCTION dbms_output.put(IN a text) RETURNS void AS 'MODULE_PATHNAME','dbms_output_put' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.put(IN text) IS 'Put some text to output'; CREATE FUNCTION dbms_output.put_line(IN a text) RETURNS void AS 'MODULE_PATHNAME','dbms_output_put_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.put_line(IN text) IS 'Put line to output'; CREATE FUNCTION dbms_output.new_line() RETURNS void AS 'MODULE_PATHNAME','dbms_output_new_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.new_line() IS 'Put new line char to output'; CREATE FUNCTION dbms_output.get_line(OUT line text, OUT status int4) AS 'MODULE_PATHNAME','dbms_output_get_line' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.get_line(OUT text, OUT int4) IS 'Get line from output buffer'; CREATE FUNCTION dbms_output.get_lines(OUT lines text[], INOUT numlines int4) AS 'MODULE_PATHNAME','dbms_output_get_lines' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_output.get_lines(OUT text[], INOUT int4) IS 'Get lines from output buffer'; -- others functions CREATE FUNCTION nvl(anyelement, anyelement) RETURNS anyelement AS 'MODULE_PATHNAME','ora_nvl' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION nvl(anyelement, anyelement) IS ''; CREATE FUNCTION nvl2(anyelement, anyelement, anyelement) RETURNS anyelement AS 'MODULE_PATHNAME','ora_nvl2' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION nvl2(anyelement, anyelement, anyelement) IS ''; CREATE FUNCTION decode(anyelement, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text) RETURNS text AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar) RETURNS bpchar AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer) RETURNS integer AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint) RETURNS bigint AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric) RETURNS numeric AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date) RETURNS date AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time) RETURNS time AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp) RETURNS timestamp AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz) RETURNS timestamptz AS 'MODULE_PATHNAME', 'ora_decode' LANGUAGE C IMMUTABLE; CREATE SCHEMA dbms_pipe; CREATE FUNCTION dbms_pipe.pack_message(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_text' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(text) IS 'Add text field to message'; CREATE FUNCTION dbms_pipe.unpack_message_text() RETURNS text AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_text' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.unpack_message_text() IS 'Get text fiedl from message'; CREATE FUNCTION dbms_pipe.receive_message(text, int) RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_receive_message' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.receive_message(text, int) IS 'Receive message from pipe'; CREATE FUNCTION dbms_pipe.receive_message(text) RETURNS int AS $$SELECT dbms_pipe.receive_message($1,NULL::int);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.receive_message(text) IS 'Receive message from pipe'; CREATE FUNCTION dbms_pipe.send_message(text, int, int) RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_send_message' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text, int, int) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.send_message(text, int) RETURNS int AS $$SELECT dbms_pipe.send_message($1,$2,NULL);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text, int) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.send_message(text) RETURNS int AS $$SELECT dbms_pipe.send_message($1,NULL,NULL);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION dbms_pipe.send_message(text) IS 'Send message to pipe'; CREATE FUNCTION dbms_pipe.unique_session_name() RETURNS varchar AS 'MODULE_PATHNAME','dbms_pipe_unique_session_name' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unique_session_name() IS 'Returns unique session name'; CREATE FUNCTION dbms_pipe.__list_pipes() RETURNS SETOF RECORD AS 'MODULE_PATHNAME','dbms_pipe_list_pipes' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.__list_pipes() IS ''; CREATE VIEW dbms_pipe.db_pipes AS SELECT * FROM dbms_pipe.__list_pipes() AS (Name varchar, Items int, Size int, "limit" int, "private" bool, "owner" varchar); CREATE FUNCTION dbms_pipe.next_item_type() RETURNS int AS 'MODULE_PATHNAME','dbms_pipe_next_item_type' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.next_item_type() IS 'Returns type of next field in message'; CREATE FUNCTION dbms_pipe.create_pipe(text, int, bool) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text, int, bool) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.create_pipe(text, int) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe_2' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text, int) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.create_pipe(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_create_pipe_1' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.create_pipe(text) IS 'Create named pipe'; CREATE FUNCTION dbms_pipe.reset_buffer() RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_reset_buffer' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_pipe.reset_buffer() IS 'Clean input buffer'; CREATE FUNCTION dbms_pipe.purge(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_purge' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.purge(text) IS 'Clean pipe'; CREATE FUNCTION dbms_pipe.remove_pipe(text) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_remove_pipe' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.remove_pipe(text) IS 'Destroy pipe'; CREATE FUNCTION dbms_pipe.pack_message(date) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_date' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(date) IS 'Add date field to message'; CREATE FUNCTION dbms_pipe.unpack_message_date() RETURNS date AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_date' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_date() IS 'Get date field from message'; CREATE FUNCTION dbms_pipe.pack_message(timestamp with time zone) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_timestamp' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(timestamp with time zone) IS 'Add timestamp field to message'; CREATE FUNCTION dbms_pipe.unpack_message_timestamp() RETURNS timestamp with time zone AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_timestamp' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_timestamp() IS 'Get timestamp field from message'; CREATE FUNCTION dbms_pipe.pack_message(numeric) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_number' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(numeric) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.unpack_message_number() RETURNS numeric AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_number' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_number() IS 'Get numeric field from message'; CREATE FUNCTION dbms_pipe.pack_message(integer) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_integer' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(integer) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.pack_message(bigint) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_bigint' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(bigint) IS 'Add numeric field to message'; CREATE FUNCTION dbms_pipe.pack_message(bytea) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_bytea' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(bytea) IS 'Add bytea field to message'; CREATE FUNCTION dbms_pipe.unpack_message_bytea() RETURNS bytea AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_bytea' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_bytea() IS 'Get bytea field from message'; CREATE FUNCTION dbms_pipe.pack_message(record) RETURNS void AS 'MODULE_PATHNAME','dbms_pipe_pack_message_record' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.pack_message(record) IS 'Add record field to message'; CREATE FUNCTION dbms_pipe.unpack_message_record() RETURNS record AS 'MODULE_PATHNAME','dbms_pipe_unpack_message_record' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_pipe.unpack_message_record() IS 'Get record field from message'; -- follow package PLVdate emulation CREATE SCHEMA plvdate; CREATE FUNCTION plvdate.add_bizdays(date, int) RETURNS date AS 'MODULE_PATHNAME','plvdate_add_bizdays' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.add_bizdays(date, int) IS 'Get the date created by adding business days to a date'; CREATE FUNCTION plvdate.nearest_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_nearest_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.nearest_bizday(date) IS 'Get the nearest business date to a given date, user defined'; CREATE FUNCTION plvdate.next_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_next_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.next_bizday(date) IS 'Get the next business date from a given date, user defined'; CREATE FUNCTION plvdate.bizdays_between(date, date) RETURNS int AS 'MODULE_PATHNAME','plvdate_bizdays_between' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.bizdays_between(date, date) IS 'Get the number of business days between two dates'; CREATE FUNCTION plvdate.prev_bizday(date) RETURNS date AS 'MODULE_PATHNAME','plvdate_prev_bizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.prev_bizday(date) IS 'Get the previous business date from a given date'; CREATE FUNCTION plvdate.isbizday(date) RETURNS bool AS 'MODULE_PATHNAME','plvdate_isbizday' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvdate.isbizday(date) IS 'Call this function to determine if a date is a business day'; CREATE FUNCTION plvdate.set_nonbizday(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_set_nonbizday_dow' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(text) IS 'Set day of week as non bussines day'; CREATE FUNCTION plvdate.unset_nonbizday(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_dow' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(text) IS 'Unset day of week as non bussines day'; CREATE FUNCTION plvdate.set_nonbizday(date, bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_set_nonbizday_day' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(date, bool) IS 'Set day as non bussines day, if repeat is true, then day is nonbiz every year'; CREATE FUNCTION plvdate.unset_nonbizday(date, bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_day' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(date, bool) IS 'Unset day as non bussines day, if repeat is true, then day is nonbiz every year'; CREATE FUNCTION plvdate.set_nonbizday(date) RETURNS bool AS $$SELECT plvdate.set_nonbizday($1, false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.set_nonbizday(date) IS 'Set day as non bussines day'; CREATE FUNCTION plvdate.unset_nonbizday(date) RETURNS bool AS $$SELECT plvdate.unset_nonbizday($1, false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unset_nonbizday(date) IS 'Unset day as non bussines day'; CREATE FUNCTION plvdate.use_easter(bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_use_easter' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.use_easter(bool) IS 'Easter Sunday and easter monday will be holiday'; CREATE FUNCTION plvdate.use_easter() RETURNS bool AS $$SELECT plvdate.use_easter(true); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.use_easter() IS 'Easter Sunday and easter monday will be holiday'; CREATE FUNCTION plvdate.unuse_easter() RETURNS bool AS $$SELECT plvdate.use_easter(false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.unuse_easter() IS 'Easter Sunday and easter monday will not be holiday'; CREATE FUNCTION plvdate.using_easter() RETURNS bool AS 'MODULE_PATHNAME','plvdate_using_easter' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.using_easter() IS 'Use easter?'; CREATE FUNCTION plvdate.include_start(bool) RETURNS void AS 'MODULE_PATHNAME','plvdate_include_start' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.include_start(bool) IS 'Include starting date in bizdays_between calculation'; CREATE FUNCTION plvdate.include_start() RETURNS bool AS $$SELECT plvdate.include_start(true); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.include_start() IS ''; CREATE FUNCTION plvdate.noinclude_start() RETURNS bool AS $$SELECT plvdate.include_start(false); SELECT NULL::boolean;$$ LANGUAGE SQL VOLATILE STRICT; COMMENT ON FUNCTION plvdate.noinclude_start() IS ''; CREATE FUNCTION plvdate.including_start() RETURNS bool AS 'MODULE_PATHNAME','plvdate_including_start' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.including_start() IS ''; CREATE FUNCTION plvdate.version() RETURNS cstring AS 'MODULE_PATHNAME','plvdate_version' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.version() IS ''; CREATE FUNCTION plvdate.default_holidays(text) RETURNS void AS 'MODULE_PATHNAME','plvdate_default_holidays' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.default_holidays(text) IS 'Load calendar for some nations'; CREATE FUNCTION plvdate.days_inmonth(date) RETURNS integer AS 'MODULE_PATHNAME','plvdate_days_inmonth' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.days_inmonth(date) IS 'Returns number of days in month'; CREATE FUNCTION plvdate.isleapyear(date) RETURNS bool AS 'MODULE_PATHNAME','plvdate_isleapyear' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION plvdate.isleapyear(date) IS 'Is leap year'; -- PLVstr package CREATE FUNCTION plvstr.normalize(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_normalize' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.normalize(text) IS 'Replace white chars by space, replace spaces by space'; CREATE FUNCTION plvstr.is_prefix(str text, prefix text, cs bool) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_text' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(text, text, bool) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str text, prefix text) RETURNS bool AS $$ SELECT plvstr.is_prefix($1,$2,true);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(text, text) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str int, prefix int) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_int' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(int, int) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.is_prefix(str bigint, prefix bigint) RETURNS bool AS 'MODULE_PATHNAME','plvstr_is_prefix_int64' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.is_prefix(bigint, bigint) IS 'Returns true, if prefix is prefix of str'; CREATE FUNCTION plvstr.substr(str text, start int, len int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_substr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.substr(text, int, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION plvstr.substr(str text, start int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_substr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.substr(text, int) IS 'Returns substring started on start_in to end'; CREATE FUNCTION plvstr.instr(str text, patt text, start int, nth int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr4' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text, int, int) IS 'Search pattern in string'; CREATE FUNCTION plvstr.instr(str text, patt text, start int) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr3' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text, int) IS 'Search pattern in string'; CREATE FUNCTION plvstr.instr(str text, patt text) RETURNS int AS 'MODULE_PATHNAME','plvstr_instr2' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.instr(text, text) IS 'Search pattern in string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int, all_if_notfound bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_lpart' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int, int, bool) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, $3, $4, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int, int) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text, start int) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, $3, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text, int) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.lpart(str text, div text) RETURNS text AS $$ SELECT plvstr.lpart($1,$2, 1, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lpart(text, text) IS 'Call this function to return the left part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int, all_if_notfound bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_rpart' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int, int, bool) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, $3, $4, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int, int) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text, start int) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, $3, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text, int) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.rpart(str text, div text) RETURNS text AS $$ SELECT plvstr.rpart($1,$2, 1, 1, false); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rpart(text, text) IS 'Call this function to return the right part of a string'; CREATE FUNCTION plvstr.lstrip(str text, substr text, num int) RETURNS text AS 'MODULE_PATHNAME','plvstr_lstrip' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lstrip(text, text, int) IS 'Call this function to remove characters from the beginning '; CREATE FUNCTION plvstr.lstrip(str text, substr text) RETURNS text AS $$ SELECT plvstr.lstrip($1, $2, 1); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.lstrip(text, text) IS 'Call this function to remove characters from the beginning '; CREATE FUNCTION plvstr.rstrip(str text, substr text, num int) RETURNS text AS 'MODULE_PATHNAME','plvstr_rstrip' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rstrip(text, text, int) IS 'Call this function to remove characters from the end'; CREATE FUNCTION plvstr.rstrip(str text, substr text) RETURNS text AS $$ SELECT plvstr.rstrip($1, $2, 1); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.rstrip(text, text) IS 'Call this function to remove characters from the end'; CREATE FUNCTION plvstr.swap(str text, replace text, start int, length int) RETURNS text AS 'MODULE_PATHNAME','plvstr_swap' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.swap(text,text, int, int) IS 'Replace a substring in a string with a specified string'; CREATE FUNCTION plvstr.swap(str text, replace text) RETURNS text AS $$ SELECT plvstr.swap($1,$2,1, NULL);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.swap(text,text) IS 'Replace a substring in a string with a specified string'; CREATE FUNCTION plvstr.betwn(str text, start int, _end int, inclusive bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_betwn_i' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.betwn(text, int, int, bool) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start int, _end int) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,true);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.betwn(text, int, int) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int, inclusive bool, gotoend bool) RETURNS text AS 'MODULE_PATHNAME','plvstr_betwn_c' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int, bool, bool) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,1,1,true,false);$$ LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text) IS 'Find the Substring Between Start and End Locations'; CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int) RETURNS text AS $$ SELECT plvstr.betwn($1,$2,$3,$4,$5,true,false);$$ LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int) IS 'Find the Substring Between Start and End Locations'; CREATE SCHEMA plvchr; CREATE FUNCTION plvchr.nth(str text, n int) RETURNS text AS 'MODULE_PATHNAME','plvchr_nth' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.nth(text, int) IS 'Call this function to return the Nth character in a string'; CREATE FUNCTION plvchr.first(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_first' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.first(text) IS 'Call this function to return the first character in a string'; CREATE FUNCTION plvchr.last(str text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_last' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.last(text) IS 'Call this function to return the last character in a string'; CREATE FUNCTION plvchr._is_kind(str text, kind int) RETURNS bool AS 'MODULE_PATHNAME','plvchr_is_kind_a' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr._is_kind(text, int) IS ''; CREATE FUNCTION plvchr._is_kind(c int, kind int) RETURNS bool AS 'MODULE_PATHNAME','plvchr_is_kind_i' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr._is_kind(int, int) IS ''; CREATE FUNCTION plvchr.is_blank(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 1);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_blank(int) IS ''; CREATE FUNCTION plvchr.is_blank(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 1);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_blank(text) IS ''; CREATE FUNCTION plvchr.is_digit(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 2);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_digit(int) IS ''; CREATE FUNCTION plvchr.is_digit(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 2);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_digit(text) IS ''; CREATE FUNCTION plvchr.is_quote(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 3);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_quote(int) IS ''; CREATE FUNCTION plvchr.is_quote(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 3);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_quote(text) IS ''; CREATE FUNCTION plvchr.is_other(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 4);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_other(int) IS ''; CREATE FUNCTION plvchr.is_other(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 4);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_other(text) IS ''; CREATE FUNCTION plvchr.is_letter(c int) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 5);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_letter(int) IS ''; CREATE FUNCTION plvchr.is_letter(c text) RETURNS BOOL AS $$ SELECT plvchr._is_kind($1, 5);$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.is_letter(text) IS ''; CREATE FUNCTION plvchr.char_name(c text) RETURNS varchar AS 'MODULE_PATHNAME','plvchr_char_name' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.char_name(text) IS ''; CREATE FUNCTION plvstr.left(str text, n int) RETURNS varchar AS 'MODULE_PATHNAME', 'plvstr_left' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.left(text, int) IS 'Returns firs num_in charaters. You can use negative num_in'; CREATE FUNCTION plvstr.right(str text, n int) RETURNS varchar AS 'MODULE_PATHNAME','plvstr_right' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvstr.right(text, int) IS 'Returns last num_in charaters. You can use negative num_ni'; CREATE FUNCTION plvchr.quoted1(str text) RETURNS varchar AS $$SELECT ''''||$1||'''';$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.quoted1(text) IS E'Quoted text between '''; CREATE FUNCTION plvchr.quoted2(str text) RETURNS varchar AS $$SELECT '"'||$1||'"';$$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.quoted2(text) IS 'Quoted text between "'; CREATE FUNCTION plvchr.stripped(str text, char_in text) RETURNS varchar AS $$ SELECT TRANSLATE($1, 'A'||$2, 'A'); $$ LANGUAGE SQL IMMUTABLE STRICT; COMMENT ON FUNCTION plvchr.stripped(text, text) IS 'Strips a string of all instances of the specified characters'; -- dbms_alert CREATE SCHEMA dbms_alert; CREATE FUNCTION dbms_alert.register(name text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_register' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_alert.register(text) IS 'Register session as recipient of alert name'; CREATE FUNCTION dbms_alert.remove(name text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_remove' LANGUAGE C VOLATILE STRICT; COMMENT ON FUNCTION dbms_alert.remove(text) IS 'Remove session as recipient of alert name'; CREATE FUNCTION dbms_alert.removeall() RETURNS void AS 'MODULE_PATHNAME','dbms_alert_removeall' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.removeall() IS 'Remove registration for all alerts'; CREATE FUNCTION dbms_alert._signal(name text, message text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_signal' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert._signal(text, text) IS ''; CREATE FUNCTION dbms_alert.waitany(OUT name text, OUT message text, OUT status integer, timeout float8) RETURNS record AS 'MODULE_PATHNAME','dbms_alert_waitany' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.waitany(OUT text, OUT text, OUT integer, float8) IS 'Wait for any signal'; CREATE FUNCTION dbms_alert.waitone(name text, OUT message text, OUT status integer, timeout float8) RETURNS record AS 'MODULE_PATHNAME','dbms_alert_waitone' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.waitone(text, OUT text, OUT integer, float8) IS 'Wait for specific signal'; CREATE FUNCTION dbms_alert.set_defaults(sensitivity float8) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_set_defaults' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_alert.set_defaults(float8) IS ''; CREATE FUNCTION dbms_alert.defered_signal() RETURNS trigger AS 'MODULE_PATHNAME','dbms_alert_defered_signal' LANGUAGE C SECURITY DEFINER; REVOKE ALL ON FUNCTION dbms_alert.defered_signal() FROM PUBLIC; CREATE FUNCTION dbms_alert.signal(_event text, _message text) RETURNS void AS 'MODULE_PATHNAME','dbms_alert_signal' LANGUAGE C SECURITY DEFINER; COMMENT ON FUNCTION dbms_alert.signal(text, text) IS 'Emit signal to all recipients'; CREATE SCHEMA plvsubst; CREATE FUNCTION plvsubst.string(template_in text, values_in text[], subst text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_array' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text[], text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, values_in text[]) RETURNS text AS $$SELECT plvsubst.string($1,$2, NULL);$$ LANGUAGE SQL STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.string(text, text[]) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text, subst_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text) RETURNS text AS 'MODULE_PATHNAME','plvsubst_string_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plvsubst.string(text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list'; CREATE FUNCTION plvsubst.setsubst(str text) RETURNS void AS 'MODULE_PATHNAME','plvsubst_setsubst' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.setsubst(text) IS 'Change the substitution keyword'; CREATE FUNCTION plvsubst.setsubst() RETURNS void AS 'MODULE_PATHNAME','plvsubst_setsubst_default' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.setsubst() IS 'Change the substitution keyword to default %s'; CREATE FUNCTION plvsubst.subst() RETURNS text AS 'MODULE_PATHNAME','plvsubst_subst' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION plvsubst.subst() IS 'Retrieve the current substitution keyword'; CREATE SCHEMA dbms_utility; CREATE FUNCTION dbms_utility.format_call_stack(text) RETURNS text AS 'MODULE_PATHNAME','dbms_utility_format_call_stack1' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION dbms_utility.format_call_stack(text) IS 'Return formated call stack'; CREATE FUNCTION dbms_utility.format_call_stack() RETURNS text AS 'MODULE_PATHNAME','dbms_utility_format_call_stack0' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_utility.format_call_stack() IS 'Return formated call stack'; CREATE SCHEMA plvlex; CREATE FUNCTION plvlex.tokens(IN str text, IN skip_spaces bool, IN qualified_names bool, OUT pos int, OUT token text, OUT code int, OUT class text, OUT separator text, OUT mod text) RETURNS SETOF RECORD AS 'MODULE_PATHNAME','plvlex_tokens' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION plvlex.tokens(text,bool,bool) IS 'Parse SQL string'; CREATE SCHEMA utl_file; CREATE DOMAIN utl_file.file_type integer; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text, max_linesize integer, encoding name) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fopen' LANGUAGE C VOLATILE SECURITY DEFINER; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer,name) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text, max_linesize integer) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fopen' LANGUAGE C VOLATILE SECURITY DEFINER; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.fopen(location text, filename text, open_mode text) RETURNS utl_file.file_type AS $$SELECT utl_file.fopen($1, $2, $3, 1024); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.fopen(text,text,text,integer) IS 'The FOPEN function open file and return file handle'; CREATE FUNCTION utl_file.is_open(file utl_file.file_type) RETURNS bool AS 'MODULE_PATHNAME','utl_file_is_open' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.is_open(utl_file.file_type) IS 'Functions returns true if handle points to file that is open'; CREATE FUNCTION utl_file.get_line(file utl_file.file_type, OUT buffer text) AS 'MODULE_PATHNAME','utl_file_get_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_line(utl_file.file_type) IS 'Returns one line from file'; CREATE FUNCTION utl_file.get_line(file utl_file.file_type, OUT buffer text, len integer) AS 'MODULE_PATHNAME','utl_file_get_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_line(utl_file.file_type, len integer) IS 'Returns one line from file'; CREATE FUNCTION utl_file.get_nextline(file utl_file.file_type, OUT buffer text) AS 'MODULE_PATHNAME','utl_file_get_nextline' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.get_nextline(utl_file.file_type) IS 'Returns one line from file or returns NULL'; CREATE FUNCTION utl_file.put(file utl_file.file_type, buffer text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put(utl_file.file_type, text) IS 'Puts data to specified file'; CREATE FUNCTION utl_file.put(file utl_file.file_type, buffer anyelement) RETURNS bool AS $$SELECT utl_file.put($1, $2::text); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.put(utl_file.file_type, anyelement) IS 'Puts data to specified file'; CREATE FUNCTION utl_file.new_line(file utl_file.file_type) RETURNS bool AS 'MODULE_PATHNAME','utl_file_new_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.new_line(file utl_file.file_type) IS 'Function inserts one ore more newline characters in specified file'; CREATE FUNCTION utl_file.new_line(file utl_file.file_type, lines int) RETURNS bool AS 'MODULE_PATHNAME','utl_file_new_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.new_line(file utl_file.file_type) IS 'Function inserts one ore more newline characters in specified file'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, text) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.put_line(file utl_file.file_type, buffer text, autoflush bool) RETURNS bool AS 'MODULE_PATHNAME','utl_file_put_line' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.put_line(utl_file.file_type, text, bool) IS 'Puts data to specified file and append newline character'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text, arg5 text) RETURNS bool AS 'MODULE_PATHNAME','utl_file_putf' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text, arg4 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, $5, $6, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text, arg3 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, $5, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text, arg2 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, $4, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text, arg1 text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, $3, NULL, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.putf(file utl_file.file_type, format text) RETURNS bool AS $$SELECT utl_file.putf($1, $2, NULL, NULL, NULL, NULL, NULL); $$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.putf(utl_file.file_type, text) IS 'Puts formatted data to specified file'; CREATE FUNCTION utl_file.fflush(file utl_file.file_type) RETURNS void AS 'MODULE_PATHNAME','utl_file_fflush' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fflush(file utl_file.file_type) IS 'This procedure makes sure that all pending data for specified file is written physically out to a file'; CREATE FUNCTION utl_file.fclose(file utl_file.file_type) RETURNS utl_file.file_type AS 'MODULE_PATHNAME','utl_file_fclose' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fclose(utl_file.file_type) IS 'Close file'; CREATE FUNCTION utl_file.fclose_all() RETURNS void AS 'MODULE_PATHNAME','utl_file_fclose_all' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fclose_all() IS 'Close all open files.'; CREATE FUNCTION utl_file.fremove(location text, filename text) RETURNS void AS 'MODULE_PATHNAME','utl_file_fremove' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fremove(text, text) IS 'Remove file.'; CREATE FUNCTION utl_file.frename(location text, filename text, dest_dir text, dest_file text, overwrite boolean) RETURNS void AS 'MODULE_PATHNAME','utl_file_frename' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.frename(text, text, text, text, boolean) IS 'Rename file.'; CREATE FUNCTION utl_file.frename(location text, filename text, dest_dir text, dest_file text) RETURNS void AS $$SELECT utl_file.frename($1, $2, $3, $4, false);$$ LANGUAGE SQL VOLATILE; COMMENT ON FUNCTION utl_file.frename(text, text, text, text) IS 'Rename file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text, integer) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fcopy(src_location text, src_filename text, dest_location text, dest_filename text, start_line integer, end_line integer) RETURNS void AS 'MODULE_PATHNAME','utl_file_fcopy' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fcopy(text, text, text, text, integer, integer) IS 'Copy a text file.'; CREATE FUNCTION utl_file.fgetattr(location text, filename text, OUT fexists boolean, OUT file_length bigint, OUT blocksize integer) AS 'MODULE_PATHNAME','utl_file_fgetattr' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.fgetattr(text, text) IS 'Get file attributes.'; CREATE FUNCTION utl_file.tmpdir() RETURNS text AS 'MODULE_PATHNAME','utl_file_tmpdir' LANGUAGE C VOLATILE; COMMENT ON FUNCTION utl_file.tmpdir() IS 'Get temp directory path.'; /* carry all safe directories */ CREATE TABLE utl_file.utl_file_dir(dir text); REVOKE ALL ON utl_file.utl_file_dir FROM PUBLIC; REVOKE ALL ON FUNCTION utl_file.tmpdir() FROM PUBLIC; -- dbms_assert CREATE SCHEMA dbms_assert; CREATE FUNCTION dbms_assert.enquote_literal(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_enquote_literal' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_assert.enquote_literal(varchar) IS 'Add leading and trailing quotes, verify that all single quotes are paired with adjacent single quotes'; CREATE FUNCTION dbms_assert.enquote_name(str varchar, loweralize boolean) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_enquote_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.enquote_name(varchar, boolean) IS 'Enclose name in double quotes'; CREATE FUNCTION dbms_assert.enquote_name(str varchar) RETURNS varchar AS 'SELECT dbms_assert.enquote_name($1, true)' LANGUAGE SQL IMMUTABLE; COMMENT ON FUNCTION dbms_assert.enquote_name(varchar) IS 'Enclose name in double quotes'; CREATE FUNCTION dbms_assert.noop(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_noop' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.noop(varchar) IS 'Returns value without any checking.'; CREATE FUNCTION dbms_assert.schema_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_schema_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.schema_name(varchar) IS 'Verify input string is an existing schema name.'; CREATE FUNCTION dbms_assert.object_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_object_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an existing object name.'; CREATE FUNCTION dbms_assert.simple_sql_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_simple_sql_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an sql name.'; CREATE FUNCTION dbms_assert.qualified_sql_name(str varchar) RETURNS varchar AS 'MODULE_PATHNAME','dbms_assert_qualified_sql_name' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an qualified sql name.'; CREATE SCHEMA plunit; CREATE FUNCTION plunit.assert_true(condition boolean) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_true' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_true(condition boolean) IS 'Asserts that the condition is true'; CREATE FUNCTION plunit.assert_true(condition boolean, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_true_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_true(condition boolean, message varchar) IS 'Asserts that the condition is true'; CREATE FUNCTION plunit.assert_false(condition boolean) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_false' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_false(condition boolean) IS 'Asserts that the condition is false'; CREATE FUNCTION plunit.assert_false(condition boolean, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_false_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_false(condition boolean, message varchar) IS 'Asserts that the condition is false'; CREATE FUNCTION plunit.assert_null(actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_null' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_null(actual anyelement) IS 'Asserts that the actual is null'; CREATE FUNCTION plunit.assert_null(actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_null_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_null(actual anyelement, message varchar) IS 'Asserts that the condition is null'; CREATE FUNCTION plunit.assert_not_null(actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_null' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement) IS 'Asserts that the actual is not null'; CREATE FUNCTION plunit.assert_not_null(actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_null_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement, message varchar) IS 'Asserts that the condition is not null'; CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_range' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_equals_range_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_range' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_assert_not_equals_range_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal'; CREATE FUNCTION plunit.fail() RETURNS void AS 'MODULE_PATHNAME','plunit_fail' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.fail() IS 'Immediately fail.'; CREATE FUNCTION plunit.fail(message varchar) RETURNS void AS 'MODULE_PATHNAME','plunit_fail_message' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION plunit.fail(message varchar) IS 'Immediately fail.'; -- dbms_random CREATE SCHEMA dbms_random; CREATE FUNCTION dbms_random.initialize(int) RETURNS void AS 'MODULE_PATHNAME','dbms_random_initialize' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.initialize(int) IS 'Initialize package with a seed value'; CREATE FUNCTION dbms_random.normal() RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_normal' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.normal() IS 'Returns random numbers in a standard normal distribution'; CREATE FUNCTION dbms_random.random() RETURNS integer AS 'MODULE_PATHNAME','dbms_random_random' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.random() IS 'Generate Random Numeric Values'; CREATE FUNCTION dbms_random.seed(integer) RETURNS void AS 'MODULE_PATHNAME','dbms_random_seed_int' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.seed(int) IS 'Reset the seed value'; CREATE FUNCTION dbms_random.seed(text) RETURNS void AS 'MODULE_PATHNAME','dbms_random_seed_varchar' LANGUAGE C IMMUTABLE STRICT; COMMENT ON FUNCTION dbms_random.seed(text) IS 'Reset the seed value'; CREATE FUNCTION dbms_random.string(opt text, len int) RETURNS text AS 'MODULE_PATHNAME','dbms_random_string' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_random.string(text,int) IS 'Create Random Strings'; CREATE FUNCTION dbms_random.terminate() RETURNS void AS 'MODULE_PATHNAME','dbms_random_terminate' LANGUAGE C IMMUTABLE; COMMENT ON FUNCTION dbms_random.terminate() IS 'Terminate use of the Package'; CREATE FUNCTION dbms_random.value(low double precision, high double precision) RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_value_range' LANGUAGE C STRICT VOLATILE; COMMENT ON FUNCTION dbms_random.value(double precision, double precision) IS 'Generate Random number x, where x is greather or equal to low and less then high'; CREATE FUNCTION dbms_random.value() RETURNS double precision AS 'MODULE_PATHNAME','dbms_random_value' LANGUAGE C VOLATILE; COMMENT ON FUNCTION dbms_random.value() IS 'Generate Random number x, where x is greather or equal to 0 and less then 1'; GRANT USAGE ON SCHEMA dbms_pipe TO PUBLIC; GRANT USAGE ON SCHEMA dbms_alert TO PUBLIC; GRANT USAGE ON SCHEMA plvdate TO PUBLIC; GRANT USAGE ON SCHEMA plvstr TO PUBLIC; GRANT USAGE ON SCHEMA plvchr TO PUBLIC; GRANT USAGE ON SCHEMA dbms_output TO PUBLIC; GRANT USAGE ON SCHEMA plvsubst TO PUBLIC; GRANT SELECT ON dbms_pipe.db_pipes to PUBLIC; GRANT USAGE ON SCHEMA dbms_utility TO PUBLIC; GRANT USAGE ON SCHEMA plvlex TO PUBLIC; GRANT USAGE ON SCHEMA utl_file TO PUBLIC; GRANT USAGE ON SCHEMA dbms_assert TO PUBLIC; GRANT USAGE ON SCHEMA dbms_random TO PUBLIC; GRANT USAGE ON SCHEMA oracle TO PUBLIC; orafce-VERSION_3_0_6/orafunc.h000066400000000000000000000037361221300436000161340ustar00rootroot00000000000000#ifndef __ORAFUNC__ #define __ORAFUNC__ #include "postgres.h" #include "catalog/catversion.h" #include "nodes/pg_list.h" #include #include "utils/datetime.h" #include "utils/datum.h" #ifndef PG_VERSION_NUM #define PG_VERSION_NUM 80100 /* assume 8.1. */ #endif #define TextPCopy(t) \ DatumGetTextP(datumCopy(PointerGetDatum(t), false, -1)) #define PG_GETARG_IF_EXISTS(n, type, defval) \ ((PG_NARGS() > (n) && !PG_ARGISNULL(n)) ? PG_GETARG_##type(n) : (defval)) /* alignment of this struct must fit for all types */ typedef union vardata { char c; short s; int i; long l; float f; double d; void *p; } vardata; int ora_instr(text *txt, text *pattern, int start, int nth); int ora_mb_strlen(text *str, char **sizes, int **positions); int ora_mb_strlen1(text *str); /* * Version compatibility */ #if PG_VERSION_NUM >= 80400 extern Oid equality_oper_funcid(Oid argtype); #endif #if PG_VERSION_NUM < 80400 #define CStringGetTextDatum(c) \ DirectFunctionCall1(textin, CStringGetDatum(c)) #define text_to_cstring(t) \ DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(t))) #define cstring_to_text(c) \ DatumGetTextP(CStringGetTextDatum(c)) text *cstring_to_text_with_len(const char *c, int n); #endif #if PG_VERSION_NUM < 80300 #define PGDLLIMPORT DLLIMPORT #define session_timezone global_timezone #define DatumGetTextPP(p) DatumGetTextP(p) #define SET_VARSIZE(PTR, len) (VARATT_SIZEP((PTR)) = (len)) #define PG_GETARG_TEXT_PP(n) PG_GETARG_TEXT_P((n)) #define VARDATA_ANY(PTR) VARDATA((PTR)) #define VARSIZE_ANY_EXHDR(PTR) (VARSIZE((PTR)) - VARHDRSZ) #define att_align_nominal(cur_offset, attalign) \ att_align((cur_offset), (attalign)) #define att_addlength_pointer(cur_offset, attlen, attptr) \ att_addlength((cur_offset), (attlen), (attptr)) #define stringToQualifiedNameList(string) \ stringToQualifiedNameList((string), "") typedef void *SPIPlanPtr; #endif #if PG_VERSION_NUM < 80200 #define ARR_NULLBITMAP(a) (NULL) #endif #endif orafce-VERSION_3_0_6/others.c000066400000000000000000000244011221300436000157660ustar00rootroot00000000000000#include "postgres.h" #include #include #include "catalog/pg_operator.h" #include "catalog/pg_type.h" #include "fmgr.h" #include "lib/stringinfo.h" #include "nodes/nodeFuncs.h" #include "nodes/pg_list.h" #include "nodes/primnodes.h" #include "parser/parse_expr.h" #include "parser/parse_oper.h" #include "utils/builtins.h" #include "utils/datum.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/syscache.h" #include "orafunc.h" #include "builtins.h" /* * Source code for nlssort is taken from postgresql-nls-string * package by Jan Pazdziora */ static char *lc_collate_cache = NULL; static int multiplication = 1; text *def_locale = NULL; PG_FUNCTION_INFO_V1(ora_lnnvl); Datum ora_lnnvl(PG_FUNCTION_ARGS) { if (PG_ARGISNULL(0)) PG_RETURN_BOOL(true); PG_RETURN_BOOL(!PG_GETARG_BOOL(0)); } PG_FUNCTION_INFO_V1(ora_concat); Datum ora_concat(PG_FUNCTION_ARGS) { text *t1; text *t2; int l1; int l2; text *result; if (PG_ARGISNULL(0) && PG_ARGISNULL(1)) PG_RETURN_NULL(); if (PG_ARGISNULL(0)) PG_RETURN_DATUM(PG_GETARG_DATUM(1)); if (PG_ARGISNULL(1)) PG_RETURN_DATUM(PG_GETARG_DATUM(0)); t1 = PG_GETARG_TEXT_PP(0); t2 = PG_GETARG_TEXT_PP(1); l1 = VARSIZE_ANY_EXHDR(t1); l2 = VARSIZE_ANY_EXHDR(t2); result = palloc(l1+l2+VARHDRSZ); memcpy(VARDATA(result), VARDATA_ANY(t1), l1); memcpy(VARDATA(result) + l1, VARDATA_ANY(t2), l2); SET_VARSIZE(result, l1 + l2 + VARHDRSZ); PG_RETURN_TEXT_P(result); } PG_FUNCTION_INFO_V1(ora_nvl); Datum ora_nvl(PG_FUNCTION_ARGS) { if (!PG_ARGISNULL(0)) PG_RETURN_DATUM(PG_GETARG_DATUM(0)); if (!PG_ARGISNULL(1)) PG_RETURN_DATUM(PG_GETARG_DATUM(1)); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ora_nvl2); Datum ora_nvl2(PG_FUNCTION_ARGS) { if (!PG_ARGISNULL(0)) { if (!PG_ARGISNULL(1)) PG_RETURN_DATUM(PG_GETARG_DATUM(1)); } else { if (!PG_ARGISNULL(2)) PG_RETURN_DATUM(PG_GETARG_DATUM(2)); } PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ora_set_nls_sort); Datum ora_set_nls_sort(PG_FUNCTION_ARGS) { text *arg = PG_GETARG_TEXT_P(0); if (def_locale != NULL) { pfree(def_locale); def_locale = NULL; } def_locale = (text*) MemoryContextAlloc(TopMemoryContext, VARSIZE(arg)); memcpy(def_locale, arg, VARSIZE(arg)); PG_RETURN_VOID(); } static text* _nls_run_strxfrm(text *string, text *locale) { char *string_str; int string_len; char *locale_str = NULL; int locale_len = 0; text *result; char *tmp = NULL; size_t size = 0; size_t rest = 0; int changed_locale = 0; /* * Save the default, server-wide locale setting. * It should not change during the life-span of the server so it * is safe to save it only once, during the first invocation. */ if (!lc_collate_cache) { if ((lc_collate_cache = setlocale(LC_COLLATE, NULL))) /* Make a copy of the locale name string. */ lc_collate_cache = strdup(lc_collate_cache); if (!lc_collate_cache) elog(ERROR, "failed to retrieve the default LC_COLLATE value"); } /* * To run strxfrm, we need a zero-terminated strings. */ string_len = VARSIZE_ANY_EXHDR(string); if (string_len < 0) return NULL; string_str = palloc(string_len + 1); memcpy(string_str, VARDATA_ANY(string), string_len); *(string_str + string_len) = '\0'; if (locale) { locale_len = VARSIZE_ANY_EXHDR(locale); } /* * If different than default locale is requested, call setlocale. */ if (locale_len > 0 && (strncmp(lc_collate_cache, VARDATA_ANY(locale), locale_len) || *(lc_collate_cache + locale_len) != '\0')) { locale_str = palloc(locale_len + 1); memcpy(locale_str, VARDATA_ANY(locale), locale_len); *(locale_str + locale_len) = '\0'; /* * Try to set correct locales. * If setlocale failed, we know the default stayed the same, * co we can safely elog. */ if (!setlocale(LC_COLLATE, locale_str)) elog(ERROR, "failed to set the requested LC_COLLATE value [%s]", locale_str); changed_locale = 1; } /* * We do TRY / CATCH / END_TRY to catch ereport / elog that might * happen during palloc. Ereport during palloc would not be * nice since it would leave the server with changed locales * setting, resulting in bad things. */ PG_TRY(); { /* * Text transformation. * Increase the buffer until the strxfrm is able to fit. */ size = string_len * multiplication + 1; tmp = palloc(size + VARHDRSZ); rest = strxfrm(tmp + VARHDRSZ, string_str, size); while (rest >= size) { pfree(tmp); size = rest + 1; tmp = palloc(size + VARHDRSZ); rest = strxfrm(tmp + VARHDRSZ, string_str, size); /* * Cache the multiplication factor so that the next * time we start with better value. */ if (string_len) multiplication = (rest / string_len) + 2; } } PG_CATCH (); { if (changed_locale) { /* * Set original locale */ if (!setlocale(LC_COLLATE, lc_collate_cache)) elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache); } } PG_END_TRY (); if (changed_locale) { /* * Set original locale */ if (!setlocale(LC_COLLATE, lc_collate_cache)) elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache); pfree(locale_str); } pfree(string_str); /* * If the multiplication factor went down, reset it. */ if (string_len && rest < string_len * multiplication / 4) multiplication = (rest / string_len) + 1; result = (text *) tmp; SET_VARSIZE(result, rest + VARHDRSZ); return result; } PG_FUNCTION_INFO_V1(ora_nlssort); Datum ora_nlssort(PG_FUNCTION_ARGS) { text *locale; text *result; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); if (PG_ARGISNULL(1)) { if (def_locale != NULL) locale = def_locale; else { locale = palloc(VARHDRSZ); SET_VARSIZE(locale, VARHDRSZ); } } else { locale = PG_GETARG_TEXT_PP(1); } result = _nls_run_strxfrm(PG_GETARG_TEXT_PP(0), locale); if (! result) PG_RETURN_NULL(); PG_RETURN_BYTEA_P(result); } PG_FUNCTION_INFO_V1(ora_decode); /* * decode(lhs, [rhs, ret], ..., [default]) */ Datum ora_decode(PG_FUNCTION_ARGS) { int nargs; int i; int retarg; /* default value is last arg or NULL. */ nargs = PG_NARGS(); if (nargs % 2 == 0) { retarg = nargs - 1; nargs -= 1; /* ignore the last argument */ } else retarg = -1; /* NULL */ if (PG_ARGISNULL(0)) { for (i = 1; i < nargs; i += 2) { if (PG_ARGISNULL(i)) { retarg = i + 1; break; } } } else { FmgrInfo *eq; #if PG_VERSION_NUM >= 90100 Oid collation = PG_GET_COLLATION(); #endif /* * On first call, get the input type's operator '=' and save at * fn_extra. */ if (fcinfo->flinfo->fn_extra == NULL) { MemoryContext oldctx; Oid typid = get_fn_expr_argtype(fcinfo->flinfo, 0); Oid eqoid = equality_oper_funcid(typid); oldctx = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt); eq = palloc(sizeof(FmgrInfo)); fmgr_info(eqoid, eq); MemoryContextSwitchTo(oldctx); fcinfo->flinfo->fn_extra = eq; } else eq = fcinfo->flinfo->fn_extra; for (i = 1; i < nargs; i += 2) { FunctionCallInfoData func; Datum result; if (PG_ARGISNULL(i)) continue; #if PG_VERSION_NUM >= 90100 InitFunctionCallInfoData(func, eq, 2, collation, NULL, NULL); #else InitFunctionCallInfoData(func, eq, 2, NULL, NULL); #endif func.arg[0] = PG_GETARG_DATUM(0); func.arg[1] = PG_GETARG_DATUM(i); func.argnull[0] = false; func.argnull[1] = false; result = FunctionCallInvoke(&func); if (!func.isnull && DatumGetBool(result)) { retarg = i + 1; break; } } } if (retarg < 0 || PG_ARGISNULL(retarg)) PG_RETURN_NULL(); else PG_RETURN_DATUM(PG_GETARG_DATUM(retarg)); } #if PG_VERSION_NUM >= 90100 Oid equality_oper_funcid(Oid argtype) { Oid eq; get_sort_group_operators(argtype, false, true, false, NULL, &eq, NULL, NULL); return get_opcode(eq); } #elif PG_VERSION_NUM >= 80400 Oid equality_oper_funcid(Oid argtype) { Oid eq; get_sort_group_operators(argtype, false, true, false, NULL, &eq, NULL); return get_opcode(eq); } #endif /* * dump(anyexpr [,format]) * * the dump function returns a varchar2 value that includes the datatype code, * the length in bytes, and the internal representation of the expression. */ PG_FUNCTION_INFO_V1(orafce_dump); static void appendDatum(StringInfo str, const void *ptr, size_t length, int format) { if (!PointerIsValid(ptr)) appendStringInfoChar(str, ':'); else { const unsigned char *s = (const unsigned char *) ptr; const char *formatstr; size_t i; switch (format) { case 8: formatstr = "%ho"; break; case 10: formatstr = "%hu"; break; case 16: formatstr = "%hx"; break; case 17: formatstr = "%hc"; break; default: elog(ERROR, "unknown format"); formatstr = NULL; /* quite compiler */ } /* append a byte array with the specified format */ for (i = 0; i < length; i++) { if (i > 0) appendStringInfoChar(str, ','); /* print only ANSI visible chars */ if (format == 17 && (iscntrl(s[i]) || !isascii(s[i]))) appendStringInfoChar(str, '?'); else appendStringInfo(str, formatstr, s[i]); } } } Datum orafce_dump(PG_FUNCTION_ARGS) { Oid valtype = get_fn_expr_argtype(fcinfo->flinfo, 0); List *args; int16 typlen; bool typbyval; Size length; Datum value; int format; StringInfoData str; if (!fcinfo->flinfo || !fcinfo->flinfo->fn_expr) elog(ERROR, "function is called from invalid context"); if (PG_ARGISNULL(0)) elog(ERROR, "argument is NULL"); value = PG_GETARG_DATUM(0); format = PG_GETARG_IF_EXISTS(1, INT32, 10); args = ((FuncExpr *) fcinfo->flinfo->fn_expr)->args; valtype = exprType((Node *) list_nth(args, 0)); get_typlenbyval(valtype, &typlen, &typbyval); length = datumGetSize(value, typbyval, typlen); initStringInfo(&str); appendStringInfo(&str, "Typ=%d Len=%d: ", valtype, (int) length); if (!typbyval) { appendDatum(&str, DatumGetPointer(value), length, format); } else if (length <= 1) { char v = DatumGetChar(value); appendDatum(&str, &v, sizeof(char), format); } else if (length <= 2) { int16 v = DatumGetInt16(value); appendDatum(&str, &v, sizeof(int16), format); } else if (length <= 4) { int32 v = DatumGetInt32(value); appendDatum(&str, &v, sizeof(int32), format); } else { int64 v = DatumGetInt64(value); appendDatum(&str, &v, sizeof(int64), format); } PG_RETURN_TEXT_P(cstring_to_text(str.data)); } orafce-VERSION_3_0_6/parallel_schedule000066400000000000000000000001761221300436000177140ustar00rootroot00000000000000test: init test: dbms_pipe_session_A dbms_pipe_session_B test: dbms_alert_session_A dbms_alert_session_B dbms_alert_session_C orafce-VERSION_3_0_6/pipe.c000066400000000000000000000627031221300436000154260ustar00rootroot00000000000000#include "postgres.h" #include "funcapi.h" #include "fmgr.h" #if PG_VERSION_NUM >= 90300 #include "access/htup_details.h" #endif #include "storage/shmem.h" #include "utils/memutils.h" #include "utils/timestamp.h" #include "storage/lwlock.h" #include "miscadmin.h" #include "string.h" #include "lib/stringinfo.h" #include "catalog/pg_type.h" #include "utils/builtins.h" #include "utils/date.h" #include "utils/numeric.h" #include "shmmc.h" #include "pipe.h" #include "orafunc.h" #include "builtins.h" /* * @ Pavel Stehule 2006 */ #ifndef _GetCurrentTimestamp #define _GetCurrentTimestamp() GetCurrentTimestamp() #endif #ifndef GetNowFloat #ifdef HAVE_INT64_TIMESTAMP #define GetNowFloat() ((float8) _GetCurrentTimestamp() / 1000000.0) #else #define GetNowFloat() _GetCurrentTimestamp() #endif #endif #define RESULT_DATA 0 #define RESULT_WAIT 1 #define NOT_INITIALIZED -1 #define ONE_YEAR (60*60*24*365) PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_text); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_text); PG_FUNCTION_INFO_V1(dbms_pipe_send_message); PG_FUNCTION_INFO_V1(dbms_pipe_receive_message); PG_FUNCTION_INFO_V1(dbms_pipe_unique_session_name); PG_FUNCTION_INFO_V1(dbms_pipe_list_pipes); PG_FUNCTION_INFO_V1(dbms_pipe_next_item_type); PG_FUNCTION_INFO_V1(dbms_pipe_create_pipe); PG_FUNCTION_INFO_V1(dbms_pipe_create_pipe_2); PG_FUNCTION_INFO_V1(dbms_pipe_create_pipe_1); PG_FUNCTION_INFO_V1(dbms_pipe_reset_buffer); PG_FUNCTION_INFO_V1(dbms_pipe_purge); PG_FUNCTION_INFO_V1(dbms_pipe_remove_pipe); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_date); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_date); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_timestamp); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_timestamp); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_number); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_number); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_bytea); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_bytea); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_record); PG_FUNCTION_INFO_V1(dbms_pipe_unpack_message_record); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_integer); PG_FUNCTION_INFO_V1(dbms_pipe_pack_message_bigint); typedef enum { IT_NO_MORE_ITEMS = 0, IT_NUMBER = 9, IT_VARCHAR = 11, IT_DATE = 12, IT_TIMESTAMPTZ = 13, IT_BYTEA = 23, IT_RECORD = 24 } message_data_type; typedef struct _queue_item { void *ptr; struct _queue_item *next_item; } queue_item; typedef struct { bool is_valid; bool registered; char *pipe_name; char *creator; Oid uid; struct _queue_item *items; int16 count; int16 limit; int size; } pipe; typedef struct { int32 size; message_data_type type; Oid tupType; } message_data_item; typedef struct { int32 size; int32 items_count; message_data_item *next; } message_buffer; #define message_buffer_size (MAXALIGN(sizeof(message_buffer))) #define message_buffer_get_content(buf) ((message_data_item *) (((char*)buf)+message_buffer_size)) #define message_data_item_size (MAXALIGN(sizeof(message_data_item))) #define message_data_get_content(msg) (((char *)msg) + message_data_item_size) #define message_data_item_next(msg) \ ((message_data_item *) (message_data_get_content(msg) + MAXALIGN(msg->size))) typedef struct PipesFctx { int pipe_nth; } PipesFctx; typedef struct { LWLockId shmem_lock; pipe *pipes; alert_event *events; alert_lock *locks; size_t size; unsigned int sid; vardata data[1]; /* flexible array member */ } sh_memory; #define sh_memory_size (offsetof(sh_memory, data)) message_buffer *output_buffer = NULL; message_buffer *input_buffer = NULL; pipe* pipes = NULL; LWLockId shmem_lock = NOT_INITIALIZED; unsigned int sid; /* session id */ extern alert_event *events; extern alert_lock *locks; /* * write on writer size bytes from ptr */ static void pack_field(message_buffer *buffer, message_data_type type, int32 size, void *ptr, Oid tupType) { int len; message_data_item *message; len = MAXALIGN(size) + message_data_item_size; if (MAXALIGN(buffer->size) + len > LOCALMSGSZ - message_buffer_size) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Packed message is bigger than local buffer."), errhint("Increase LOCALMSGSZ in 'pipe.h' and recompile library."))); if (buffer->next == NULL) buffer->next = message_buffer_get_content(buffer); message = buffer->next; message->size = size; message->type = type; message->tupType = tupType; /* padding bytes have to be zeroed - buffer creator is responsible to clear memory */ memcpy(message_data_get_content(message), ptr, size); buffer->size += len; buffer->items_count++; buffer->next = message_data_item_next(message); } static void* unpack_field(message_buffer *buffer, message_data_type *type, int32 *size, Oid *tupType) { void *ptr; message_data_item *message; Assert(buffer != NULL); Assert(buffer->items_count > 0); Assert(buffer->next != NULL); message = buffer->next; *size = message->size; *type = message->type; *tupType = message->tupType; ptr = message_data_get_content(message); buffer->next = --buffer->items_count > 0 ? message_data_item_next(message) : NULL; return ptr; } /* * Add ptr to queue. If pipe doesn't exist, register new pipe */ bool ora_lock_shmem(size_t size, int max_pipes, int max_events, int max_locks, bool reset) { int i; bool found; sh_memory *sh_mem; if (pipes == NULL) { sh_mem = ShmemInitStruct("dbms_pipe", size, &found); if (sh_mem == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while allocation block %lu bytes in shared memory.", (unsigned long) size))); if (!found) { shmem_lock = sh_mem->shmem_lock = LWLockAssign(); LWLockAcquire(sh_mem->shmem_lock, LW_EXCLUSIVE); sh_mem->size = size - sh_memory_size; ora_sinit(sh_mem->data, size, true); pipes = sh_mem->pipes = ora_salloc(max_pipes*sizeof(pipe)); sid = sh_mem->sid = 1; for (i = 0; i < max_pipes; i++) pipes[i].is_valid = false; events = sh_mem->events = ora_salloc(max_events*sizeof(alert_event)); locks = sh_mem->locks = ora_salloc(max_locks*sizeof(alert_lock)); for (i = 0; i < max_events; i++) { events[i].event_name = NULL; events[i].max_receivers = 0; events[i].receivers = NULL; events[i].messages = NULL; } for (i = 0; i < max_locks; i++) { locks[i].sid = -1; locks[i].echo = NULL; } } else if (sh_mem->shmem_lock != 0) { pipes = sh_mem->pipes; shmem_lock = sh_mem->shmem_lock; LWLockAcquire(sh_mem->shmem_lock, LW_EXCLUSIVE); ora_sinit(sh_mem->data, sh_mem->size, reset); sid = ++(sh_mem->sid); events = sh_mem->events; locks = sh_mem->locks; } } else { LWLockAcquire(shmem_lock, LW_EXCLUSIVE); } /* if (reset && pipes == NULL) elog(ERROR, "Can't purge memory"); */ return pipes != NULL; } /* * can be enhanced access/hash.h */ static pipe* find_pipe(text* pipe_name, bool* created, bool only_check) { int i; pipe *result = NULL; *created = false; for (i = 0; i < MAX_PIPES; i++) { if (pipes[i].is_valid && strncmp((char*)VARDATA(pipe_name), pipes[i].pipe_name, VARSIZE(pipe_name) - VARHDRSZ) == 0 && (strlen(pipes[i].pipe_name) == (VARSIZE(pipe_name) - VARHDRSZ))) { /* check owner if non public pipe */ if (pipes[i].creator != NULL && pipes[i].uid != GetUserId()) { LWLockRelease(shmem_lock); ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("insufficient privilege"), errdetail("Insufficient privilege to access pipe"))); } return &pipes[i]; } } if (only_check) return result; for (i = 0; i < MAX_PIPES; i++) if (!pipes[i].is_valid) { if (NULL != (pipes[i].pipe_name = ora_scstring(pipe_name))) { pipes[i].is_valid = true; pipes[i].registered = false; pipes[i].creator = NULL; pipes[i].uid = -1; pipes[i].count = 0; pipes[i].limit = -1; *created = true; result = &pipes[i]; } break; } return result; } static bool new_last(pipe *p, void *ptr) { queue_item *q, *aux_q; if (p->count >= p->limit && p->limit != -1) return false; if (p->items == NULL) { if (NULL == (p->items = ora_salloc(sizeof(queue_item)))) return false; p->items->next_item = NULL; p->items->ptr = ptr; p->count = 1; return true; } q = p->items; while (q->next_item != NULL) q = q->next_item; if (NULL == (aux_q = ora_salloc(sizeof(queue_item)))) return false; q->next_item = aux_q; aux_q->next_item = NULL; aux_q->ptr = ptr; p->count += 1; return true; } static void* remove_first(pipe *p, bool *found) { struct _queue_item *q; void *ptr = NULL; *found = false; if (NULL != (q = p->items)) { p->count -= 1; ptr = q->ptr; p->items = q->next_item; *found = true; ora_sfree(q); if (p->items == NULL && !p->registered) { ora_sfree(p->pipe_name); p->is_valid = false; } } return ptr; } /* copy message to local memory, if exists */ static message_buffer* get_from_pipe(text *pipe_name, bool *found) { pipe *p; bool created; message_buffer *shm_msg; message_buffer *result = NULL; if (!ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) return NULL; if (NULL != (p = find_pipe(pipe_name, &created,false))) { if (!created) { if (NULL != (shm_msg = remove_first(p, found))) { p->size -= shm_msg->size; result = (message_buffer*) MemoryContextAlloc(TopMemoryContext, shm_msg->size); memcpy(result, shm_msg, shm_msg->size); ora_sfree(shm_msg); } } } LWLockRelease(shmem_lock); return result; } /* * if ptr is null, then only register pipe */ static bool add_to_pipe(text *pipe_name, message_buffer *ptr, int limit, bool limit_is_valid) { pipe *p; bool created; bool result = false; message_buffer *sh_ptr; if (!ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS,false)) return false; for (;;) { if (NULL != (p = find_pipe(pipe_name, &created, false))) { if (created) p->registered = ptr == NULL; if (limit_is_valid && (created || (p->limit < limit))) p->limit = limit; if (ptr != NULL) { if (NULL != (sh_ptr = ora_salloc(ptr->size))) { memcpy(sh_ptr,ptr,ptr->size); if (new_last(p, sh_ptr)) { p->size += ptr->size; result = true; break; } ora_sfree(sh_ptr); } if (created) { /* I created new pipe, but haven't memory for new value */ ora_sfree(p->pipe_name); p->is_valid = false; result = false; } } else result = true; } break; } LWLockRelease(shmem_lock); return result; } static void remove_pipe(text *pipe_name, bool purge) { pipe *p; bool created; if (NULL != (p = find_pipe(pipe_name, &created, true))) { queue_item *q = p->items; while (q != NULL) { queue_item *aux_q; aux_q = q->next_item; if (q->ptr) ora_sfree(q->ptr); ora_sfree(q); q = aux_q; } p->items = NULL; p->size = 0; p->count = 0; if (!(purge && p->registered)) { ora_sfree(p->pipe_name); p->is_valid = false; } } } Datum dbms_pipe_next_item_type (PG_FUNCTION_ARGS) { PG_RETURN_INT32(input_buffer != NULL ? input_buffer->next->type : IT_NO_MORE_ITEMS); } static void init_buffer(message_buffer *buffer, int32 size) { memset(buffer, 0, size); buffer->size = message_buffer_size; buffer->items_count = 0; buffer->next = message_buffer_get_content(buffer); } static message_buffer* check_buffer(message_buffer *buffer, int32 size) { if (buffer == NULL) { buffer = (message_buffer*) MemoryContextAlloc(TopMemoryContext, size); if (buffer == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while allocation block %d bytes in memory.", size))); init_buffer(buffer, size); } return buffer; } Datum dbms_pipe_pack_message_text(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_VARCHAR, VARSIZE_ANY_EXHDR(str), VARDATA_ANY(str), InvalidOid); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_date(PG_FUNCTION_ARGS) { DateADT dt = PG_GETARG_DATEADT(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_DATE, sizeof(dt), &dt, InvalidOid); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_timestamp(PG_FUNCTION_ARGS) { TimestampTz dt = PG_GETARG_TIMESTAMPTZ(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_TIMESTAMPTZ, sizeof(dt), &dt, InvalidOid); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_number(PG_FUNCTION_ARGS) { Numeric num = PG_GETARG_NUMERIC(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_NUMBER, VARSIZE(num) - VARHDRSZ, VARDATA(num), InvalidOid); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_bytea(PG_FUNCTION_ARGS) { bytea *data = PG_GETARG_BYTEA_P(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_BYTEA, VARSIZE_ANY_EXHDR(data), VARDATA_ANY(data), InvalidOid); PG_RETURN_VOID(); } /* * We can serialize only typed record */ Datum dbms_pipe_pack_message_record(PG_FUNCTION_ARGS) { HeapTupleHeader rec = PG_GETARG_HEAPTUPLEHEADER(0); Oid tupType; bytea *data; FunctionCallInfoData info; tupType = HeapTupleHeaderGetTypeId(rec); /* * Normally one would call record_send() using DirectFunctionCall3, * but that does not work since record_send wants to cache some data * using fcinfo->flinfo->fn_extra. So we need to pass it our own * flinfo parameter. */ #if PG_VERSION_NUM >= 90100 InitFunctionCallInfoData(info, fcinfo->flinfo, 3, InvalidOid, NULL, NULL); #else InitFunctionCallInfoData(info, fcinfo->flinfo, 3, NULL, NULL); #endif info.arg[0] = PointerGetDatum(rec); info.arg[1] = ObjectIdGetDatum(tupType); info.arg[2] = Int32GetDatum(-1); info.argnull[0] = false; info.argnull[1] = false; info.argnull[2] = false; data = (bytea*) DatumGetPointer(record_send(&info)); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_RECORD, VARSIZE(data), VARDATA(data), tupType); PG_RETURN_VOID(); } static Datum dbms_pipe_unpack_message(PG_FUNCTION_ARGS, message_data_type dtype) { Oid tupType; void *ptr; message_data_type type; int32 size; Datum result; message_data_type next_type; if (input_buffer == NULL || input_buffer->items_count <= 0 || input_buffer->next == NULL || input_buffer->next->type == IT_NO_MORE_ITEMS) PG_RETURN_NULL(); next_type = input_buffer->next->type; if (next_type != dtype) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("datatype mismatch"), errdetail("unpack unexpected type: %d", next_type))); ptr = unpack_field(input_buffer, &type, &size, &tupType); Assert(ptr != NULL); switch (type) { case IT_TIMESTAMPTZ: result = TimestampTzGetDatum(*(TimestampTz*)ptr); break; case IT_DATE: result = DateADTGetDatum(*(DateADT*)ptr); break; case IT_VARCHAR: case IT_NUMBER: case IT_BYTEA: result = PointerGetDatum(cstring_to_text_with_len(ptr, size)); break; case IT_RECORD: { FunctionCallInfoData info; StringInfoData buf; text *data = cstring_to_text_with_len(ptr, size); buf.data = VARDATA(data); buf.len = VARSIZE(data) - VARHDRSZ; buf.maxlen = buf.len; buf.cursor = 0; /* * Normally one would call record_recv() using DirectFunctionCall3, * but that does not work since record_recv wants to cache some data * using fcinfo->flinfo->fn_extra. So we need to pass it our own * flinfo parameter. */ #if PG_VERSION_NUM >= 90100 InitFunctionCallInfoData(info, fcinfo->flinfo, 3, InvalidOid, NULL, NULL); #else InitFunctionCallInfoData(info, fcinfo->flinfo, 3, NULL, NULL); #endif info.arg[0] = PointerGetDatum(&buf); info.arg[1] = ObjectIdGetDatum(tupType); info.arg[2] = Int32GetDatum(-1); info.argnull[0] = false; info.argnull[1] = false; info.argnull[2] = false; result = record_recv(&info); break; } default: elog(ERROR, "unexpected type: %d", type); result = (Datum) 0; /* keep compiler quiet */ } if (input_buffer->items_count == 0) { pfree(input_buffer); input_buffer = NULL; } PG_RETURN_DATUM(result); } Datum dbms_pipe_unpack_message_text(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_VARCHAR); } Datum dbms_pipe_unpack_message_date(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_DATE); } Datum dbms_pipe_unpack_message_timestamp(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_TIMESTAMPTZ); } Datum dbms_pipe_unpack_message_number(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_NUMBER); } Datum dbms_pipe_unpack_message_bytea(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_BYTEA); } Datum dbms_pipe_unpack_message_record(PG_FUNCTION_ARGS) { return dbms_pipe_unpack_message(fcinfo, IT_RECORD); } #define WATCH_PRE(t, et, c) \ et = GetNowFloat() + (float8)t; c = 0; \ do \ { \ #define WATCH_POST(t,et,c) \ if (GetNowFloat() >= et) \ PG_RETURN_INT32(RESULT_WAIT); \ if (cycle++ % 100 == 0) \ CHECK_FOR_INTERRUPTS(); \ pg_usleep(10000L); \ } while(true && t != 0); Datum dbms_pipe_receive_message(PG_FUNCTION_ARGS) { text *pipe_name = NULL; int timeout = ONE_YEAR; int cycle = 0; float8 endtime; bool found = false; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pipe name is NULL"), errdetail("Pipename may not be NULL."))); else pipe_name = PG_GETARG_TEXT_P(0); if (!PG_ARGISNULL(1)) timeout = PG_GETARG_INT32(1); if (input_buffer != NULL) { pfree(input_buffer); input_buffer = NULL; } WATCH_PRE(timeout, endtime, cycle); if (NULL != (input_buffer = get_from_pipe(pipe_name, &found))) { input_buffer->next = message_buffer_get_content(input_buffer); break; } /* found empty message */ if (found) break; WATCH_POST(timeout, endtime, cycle); PG_RETURN_INT32(RESULT_DATA); } Datum dbms_pipe_send_message(PG_FUNCTION_ARGS) { text *pipe_name = NULL; int timeout = ONE_YEAR; int limit = 0; bool valid_limit; int cycle = 0; float8 endtime; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pipe name is NULL"), errdetail("Pipename may not be NULL."))); else pipe_name = PG_GETARG_TEXT_P(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); if (!PG_ARGISNULL(1)) timeout = PG_GETARG_INT32(1); if (PG_ARGISNULL(2)) valid_limit = false; else { limit = PG_GETARG_INT32(2); valid_limit = true; } if (input_buffer != NULL) /* XXX Strange? */ { pfree(input_buffer); input_buffer = NULL; } WATCH_PRE(timeout, endtime, cycle); if (add_to_pipe(pipe_name, output_buffer, limit, valid_limit)) break; WATCH_POST(timeout, endtime, cycle); init_buffer(output_buffer, LOCALMSGSZ); PG_RETURN_INT32(RESULT_DATA); } Datum dbms_pipe_unique_session_name (PG_FUNCTION_ARGS) { StringInfoData strbuf; text *result; float8 endtime; int cycle = 0; int timeout = 10; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { initStringInfo(&strbuf); appendStringInfo(&strbuf,"PG$PIPE$%d$%d",sid, MyProcPid); result = cstring_to_text_with_len(strbuf.data, strbuf.len); pfree(strbuf.data); LWLockRelease(shmem_lock); PG_RETURN_TEXT_P(result); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_NULL(); } #define DB_PIPES_COLS 6 Datum dbms_pipe_list_pipes(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; TupleDesc tupdesc; TupleTableSlot *slot; AttInMetadata *attinmeta; PipesFctx *fctx; float8 endtime; int cycle = 0; int timeout = 10; if (SRF_IS_FIRSTCALL()) { int i; MemoryContext oldcontext; bool has_lock = false; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { has_lock = true; break; } WATCH_POST(timeout, endtime, cycle); if (!has_lock) LOCK_ERROR(); funcctx = SRF_FIRSTCALL_INIT(); oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); fctx = palloc(sizeof(PipesFctx)); funcctx->user_fctx = fctx; fctx->pipe_nth = 0; tupdesc = CreateTemplateTupleDesc(DB_PIPES_COLS , false); i = 0; TupleDescInitEntry(tupdesc, ++i, "name", VARCHAROID, -1, 0); TupleDescInitEntry(tupdesc, ++i, "items", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, ++i, "size", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, ++i, "limit", INT4OID, -1, 0); TupleDescInitEntry(tupdesc, ++i, "private", BOOLOID, -1, 0); TupleDescInitEntry(tupdesc, ++i, "owner", VARCHAROID, -1, 0); Assert(i == DB_PIPES_COLS); slot = TupleDescGetSlot(tupdesc); funcctx->slot = slot; attinmeta = TupleDescGetAttInMetadata(tupdesc); funcctx->attinmeta = attinmeta; MemoryContextSwitchTo(oldcontext); } funcctx = SRF_PERCALL_SETUP(); fctx = (PipesFctx *) funcctx->user_fctx; while (fctx->pipe_nth < MAX_PIPES) { if (pipes[fctx->pipe_nth].is_valid) { Datum result; HeapTuple tuple; char *values[DB_PIPES_COLS]; char items[16]; char size[16]; char limit[16]; /* name */ values[0] = pipes[fctx->pipe_nth].pipe_name; /* items */ snprintf(items, lengthof(items), "%d", pipes[fctx->pipe_nth].count); values[1] = items; /* items */ snprintf(size, lengthof(size), "%d", pipes[fctx->pipe_nth].size); values[2] = size; /* limit */ if (pipes[fctx->pipe_nth].limit != -1) { snprintf(limit, lengthof(limit), "%d", pipes[fctx->pipe_nth].limit); values[3] = limit; } else values[3] = NULL; /* private */ values[4] = (pipes[fctx->pipe_nth].creator ? "true" : "false"); /* owner */ values[5] = pipes[fctx->pipe_nth].creator; tuple = BuildTupleFromCStrings(funcctx->attinmeta, values); result = TupleGetDatum(funcctx->slot, tuple); fctx->pipe_nth += 1; SRF_RETURN_NEXT(funcctx, result); } fctx->pipe_nth += 1; } LWLockRelease(shmem_lock); SRF_RETURN_DONE(funcctx); } /* * secondary functions */ /* * Registration explicit pipes * dbms_pipe.create_pipe(pipe_name varchar, limit := -1 int, private := false bool); */ Datum dbms_pipe_create_pipe (PG_FUNCTION_ARGS) { text *pipe_name = NULL; int limit = 0; bool is_private; bool limit_is_valid = false; bool created; float8 endtime; int cycle = 0; int timeout = 10; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pipe name is NULL"), errdetail("Pipename may not be NULL."))); else pipe_name = PG_GETARG_TEXT_P(0); if (!PG_ARGISNULL(1)) { limit = PG_GETARG_INT32(1); limit_is_valid = true; } is_private = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2); WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { pipe *p; if (NULL != (p = find_pipe(pipe_name, &created, false))) { if (!created) { LWLockRelease(shmem_lock); ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("pipe creation error"), errdetail("Pipe is registered."))); } if (is_private) { char *user; p->uid = GetUserId(); user = (char*)DirectFunctionCall1(namein, CStringGetDatum(GetUserNameFromId(p->uid))); p->creator = ora_sstrcpy(user); pfree(user); } p->limit = limit_is_valid ? limit : -1; p->registered = true; LWLockRelease(shmem_lock); PG_RETURN_VOID(); } } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * Clean local input, output buffers */ Datum dbms_pipe_reset_buffer(PG_FUNCTION_ARGS) { if (output_buffer != NULL) { pfree(output_buffer); output_buffer = NULL; } if (input_buffer != NULL) { pfree(input_buffer); input_buffer = NULL; } PG_RETURN_VOID(); } /* * Remove all stored messages in pipe. Remove implicit created * pipe. */ Datum dbms_pipe_purge (PG_FUNCTION_ARGS) { text *pipe_name = PG_GETARG_TEXT_P(0); float8 endtime; int cycle = 0; int timeout = 10; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { remove_pipe(pipe_name, true); LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * Remove pipe if exists */ Datum dbms_pipe_remove_pipe (PG_FUNCTION_ARGS) { text *pipe_name = PG_GETARG_TEXT_P(0); float8 endtime; int cycle = 0; int timeout = 10; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false)) { remove_pipe(pipe_name, false); LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); } /* * Some void udf which I can't wrap in sql */ Datum dbms_pipe_create_pipe_2 (PG_FUNCTION_ARGS) { Datum arg1 = PG_GETARG_DATUM(0); Datum arg2 = PG_GETARG_DATUM(1); DirectFunctionCall3(dbms_pipe_create_pipe, arg1, arg2, BoolGetDatum(false)); PG_RETURN_VOID(); } Datum dbms_pipe_create_pipe_1 (PG_FUNCTION_ARGS) { Datum arg1 = PG_GETARG_DATUM(0); DirectFunctionCall3(dbms_pipe_create_pipe, arg1, (Datum)0, BoolGetDatum(false)); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_integer(PG_FUNCTION_ARGS) { /* Casting from int4 to numeric */ DirectFunctionCall1(dbms_pipe_pack_message_number, DirectFunctionCall1(int4_numeric, PG_GETARG_DATUM(0))); PG_RETURN_VOID(); } Datum dbms_pipe_pack_message_bigint(PG_FUNCTION_ARGS) { /* Casting from int8 to numeric */ DirectFunctionCall1(dbms_pipe_pack_message_number, DirectFunctionCall1(int8_numeric, PG_GETARG_DATUM(0))); PG_RETURN_VOID(); } orafce-VERSION_3_0_6/pipe.h000066400000000000000000000023321221300436000154230ustar00rootroot00000000000000#ifndef __PIPE__ #define __PIPE__ #define LOCALMSGSZ (8*1024) #define SHMEMMSGSZ (30*1024) #define MAX_PIPES 30 #define MAX_EVENTS 30 #define MAX_LOCKS 256 typedef struct _message_item { char *message; float8 timestamp; struct _message_item *next_message; struct _message_item *prev_message; unsigned char message_id; int *receivers; /* copy of array all registered receivers */ int receivers_number; } message_item; typedef struct _message_echo { struct _message_item *message; unsigned char message_id; struct _message_echo *next_echo; } message_echo; typedef struct { char *event_name; unsigned char max_receivers; int *receivers; int receivers_number; struct _message_item *messages; } alert_event; typedef struct { unsigned int sid; message_echo *echo; } alert_lock; bool ora_lock_shmem(size_t size, int max_pipes, int max_events, int max_locks, bool reset); #define ERRCODE_ORA_PACKAGES_LOCK_REQUEST_ERROR MAKE_SQLSTATE('3','0', '0','0','1') #define LOCK_ERROR() \ ereport(ERROR, \ (errcode(ERRCODE_ORA_PACKAGES_LOCK_REQUEST_ERROR), \ errmsg("lock request error"), \ errdetail("Failed exclusive locking of shared memory."), \ errhint("Restart PostgreSQL server."))); #endif orafce-VERSION_3_0_6/plunit.c000066400000000000000000000277001221300436000160020ustar00rootroot00000000000000/* * This API is subset plunit lib with http://www.apollo-pro.com/help/pl_unit_assertions.htm * */ #include "postgres.h" #include "funcapi.h" #include "parser/parse_oper.h" #include "utils/builtins.h" #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(plunit_assert_true); PG_FUNCTION_INFO_V1(plunit_assert_true_message); PG_FUNCTION_INFO_V1(plunit_assert_false); PG_FUNCTION_INFO_V1(plunit_assert_false_message); PG_FUNCTION_INFO_V1(plunit_assert_null); PG_FUNCTION_INFO_V1(plunit_assert_null_message); PG_FUNCTION_INFO_V1(plunit_assert_not_null); PG_FUNCTION_INFO_V1(plunit_assert_not_null_message); PG_FUNCTION_INFO_V1(plunit_assert_equals); PG_FUNCTION_INFO_V1(plunit_assert_equals_message); PG_FUNCTION_INFO_V1(plunit_assert_equals_range); PG_FUNCTION_INFO_V1(plunit_assert_equals_range_message); PG_FUNCTION_INFO_V1(plunit_assert_not_equals); PG_FUNCTION_INFO_V1(plunit_assert_not_equals_message); PG_FUNCTION_INFO_V1(plunit_assert_not_equals_range); PG_FUNCTION_INFO_V1(plunit_assert_not_equals_range_message); PG_FUNCTION_INFO_V1(plunit_fail); PG_FUNCTION_INFO_V1(plunit_fail_message); static bool assert_equals_base(FunctionCallInfo fcinfo); static bool assert_equals_range_base(FunctionCallInfo fcinfo); static char *assert_get_message(FunctionCallInfo fcinfo, int nargs, char *default_message); /**************************************************************** * plunit.assert_true * plunit.assert_true_message * * Syntax: * PROCEDURE assert_true(condition boolean, message varchar default ''); * * Purpouse: * Asserts that the condition is true. The optional message will be * displayed if the assertion fails. If not supplied, a default message * is displayed. * ****************************************************************/ Datum plunit_assert_true(PG_FUNCTION_ARGS) { return plunit_assert_true_message(fcinfo); } Datum plunit_assert_true_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 2, "plunit.assert_true exception"); bool condition = PG_GETARG_BOOL(0); if (PG_ARGISNULL(0) || !condition) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_true)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.assert_false * plunit.assert_false_message * * Syntax: * PROCEDURE assert_false(condition boolean, message varchar default ''); * * Purpouse: * Asserts that the condition is false. The optional message will be * displayed if the assertion fails. If not supplied, a default message * is displayed. * ****************************************************************/ Datum plunit_assert_false(PG_FUNCTION_ARGS) { return plunit_assert_false_message(fcinfo); } Datum plunit_assert_false_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 2, "plunit.assert_false exception"); bool condition = PG_GETARG_BOOL(0); if (PG_ARGISNULL(0) || condition) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_false)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.assert_null * plunit.assert_null_message * * Syntax: * PROCEDURE assert_null(actual anyelement, message varchar default ''); * * Purpouse: * Asserts that the actual is null. The optional message will be * displayed if the assertion fails. If not supplied, a default message * is displayed. * ****************************************************************/ Datum plunit_assert_null(PG_FUNCTION_ARGS) { return plunit_assert_null_message(fcinfo); } Datum plunit_assert_null_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 2, "plunit.assert_null exception"); if (!PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_null)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.assert_not_null * plunit.assert_not_null_message * * Syntax: * PROCEDURE assert_not_null(actual anyelement, message varchar default ''); * * Purpouse: * Asserts that the actual isn't null. The optional message will be * displayed if the assertion fails. If not supplied, a default message * is displayed. * ****************************************************************/ Datum plunit_assert_not_null(PG_FUNCTION_ARGS) { return plunit_assert_not_null_message(fcinfo); } Datum plunit_assert_not_null_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 2, "plunit.assert_not_null exception"); if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_not_null)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.assert_equals * plunit.assert_equals_message * plunit.assert_equals_range * plunit.assert_equals_range_message * * Syntax: * PROCEDURE assert_equals(expected anyelement,actual anyelement, * message varchar default ''); * PROCEDURE assert_equals(expected double precision, actual double precision, * range double precision, message varchar default ''); * * Purpouse: * Asserts that expected and actual are equal. The optional message will be * displayed if the assertion fails. If not supplied, a default * message is displayed. * Asserts that expected and actual are within the specified range. * The optional message will be displayed if the assertion fails. * If not supplied, a default message is displayed. * ****************************************************************/ static char * assert_get_message(FunctionCallInfo fcinfo, int nargs, char *message) { char *result; if (PG_NARGS() == nargs) { text *msg; if (PG_ARGISNULL(nargs - 1)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("message is NULL"), errdetail("Message may not be NULL."))); msg = PG_GETARG_TEXT_P(nargs - 1); result = text_to_cstring(msg); } else result = message; return result; } static bool assert_equals_base(FunctionCallInfo fcinfo) { Datum value1 = PG_GETARG_DATUM(0); Datum value2 = PG_GETARG_DATUM(1); Oid *ptr; ptr = (Oid *) fcinfo->flinfo->fn_extra; if (ptr == NULL) { Oid valtype = get_fn_expr_argtype(fcinfo->flinfo, 0); Oid eqopfcid; if (!OidIsValid(valtype)) elog(ERROR, "could not determine data type of input"); eqopfcid = equality_oper_funcid(valtype); if (!OidIsValid(eqopfcid)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("unknown equal operand for datatype"))); /* First time calling for current query: allocate storage */ fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, sizeof(Oid)); ptr = (Oid *) fcinfo->flinfo->fn_extra; *ptr = eqopfcid; } return DatumGetBool(OidFunctionCall2(*ptr, value1, value2)); } Datum plunit_assert_equals(PG_FUNCTION_ARGS) { return plunit_assert_equals_message(fcinfo); } Datum plunit_assert_equals_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 3, "plunit.assert_equal exception"); /* skip all tests for NULL value */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_equals)."))); if (!assert_equals_base(fcinfo)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_equals)."))); PG_RETURN_VOID(); } Datum plunit_assert_equals_range(PG_FUNCTION_ARGS) { return plunit_assert_equals_range_message(fcinfo); } static bool assert_equals_range_base(FunctionCallInfo fcinfo) { float8 expected_value; float8 actual_value; float8 range_value; range_value = PG_GETARG_FLOAT8(2); if (range_value < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot set range to negative number"))); expected_value = PG_GETARG_FLOAT8(0); actual_value = PG_GETARG_FLOAT8(1); return fabs(expected_value - actual_value) < range_value; } Datum plunit_assert_equals_range_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 4, "plunit.assert_equal exception"); /* skip all tests for NULL value */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_equals)."))); if (!assert_equals_range_base(fcinfo)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_equals)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.assert_not_equals * plunit.assert_not_equals_message * plunit.assert_not_equals_range * plunit.assert_not_equals_range_message * * Syntax: * PROCEDURE assert_not_equals(expected anyelement,actual anyelement, * message varchar default ''); * PROCEDURE assert_not_equals(expected double precision, expected double precision, * range double precision, message varchar default ''); * * Purpouse: * Asserts that expected and actual are equal. The optional message will be * displayed if the assertion fails. If not supplied, a default * message is displayed. * Asserts that expected and actual are within the specified range. * The optional message will be displayed if the assertion fails. * If not supplied, a default message is displayed. * ****************************************************************/ Datum plunit_assert_not_equals(PG_FUNCTION_ARGS) { return plunit_assert_not_equals_message(fcinfo); } Datum plunit_assert_not_equals_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 3, "plunit.assert_not_equal exception"); /* skip all tests for NULL value */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_not_equals)."))); if (assert_equals_base(fcinfo)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_not_equals)."))); PG_RETURN_VOID(); } Datum plunit_assert_not_equals_range(PG_FUNCTION_ARGS) { return plunit_assert_not_equals_range_message(fcinfo); } Datum plunit_assert_not_equals_range_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 3, "plunit.assert_not_equal exception"); /* skip all tests for NULL value */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_not_equals)."))); if (assert_equals_range_base(fcinfo)) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation fails (assert_not_equals)."))); PG_RETURN_VOID(); } /**************************************************************** * plunit.fail * plunit.fail_message * * Syntax: * PROCEDURE fail(message varchar default ''); * * Purpouse: * Fail can be used to cause a test procedure to fail * immediately using the supplied message. * ****************************************************************/ Datum plunit_fail(PG_FUNCTION_ARGS) { return plunit_fail_message(fcinfo); } Datum plunit_fail_message(PG_FUNCTION_ARGS) { char *message = assert_get_message(fcinfo, 1, "plunit.assert_fail exception"); ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("%s", message), errdetail("Plunit.assertation (assert_fail)."))); PG_RETURN_VOID(); } orafce-VERSION_3_0_6/plvdate.c000066400000000000000000000474161221300436000161340ustar00rootroot00000000000000/* This code implements one part of functonality of free available library PL/Vision. Please look www.quest.com This library isn't optimalized for big numbers, for working with n days (n > 10000), can be slow (on my P4 31ms). Original author: Steven Feuerstein, 1996 - 2002 PostgreSQL implementation author: Pavel Stehule, 2006 This module is under BSD Licence History: 1.0. first public version 13. March 2006 */ #define PLVDATE_VERSION "PostgreSQL PLVdate, version 1.0, March 2006" #include "postgres.h" #include "utils/date.h" #include "utils/builtins.h" #include "utils/nabstime.h" #include #include #include "orafunc.h" #include "builtins.h" /* * External (defined in PgSQL datetime.c (timestamp utils)) */ extern PGDLLIMPORT char *days[]; PG_FUNCTION_INFO_V1(plvdate_add_bizdays); PG_FUNCTION_INFO_V1(plvdate_nearest_bizday); PG_FUNCTION_INFO_V1(plvdate_next_bizday); PG_FUNCTION_INFO_V1(plvdate_bizdays_between); PG_FUNCTION_INFO_V1(plvdate_prev_bizday); PG_FUNCTION_INFO_V1(plvdate_isbizday); PG_FUNCTION_INFO_V1(plvdate_set_nonbizday_dow); PG_FUNCTION_INFO_V1(plvdate_unset_nonbizday_dow); PG_FUNCTION_INFO_V1(plvdate_set_nonbizday_day); PG_FUNCTION_INFO_V1(plvdate_unset_nonbizday_day); PG_FUNCTION_INFO_V1(plvdate_use_easter); PG_FUNCTION_INFO_V1(plvdate_using_easter); PG_FUNCTION_INFO_V1(plvdate_include_start); PG_FUNCTION_INFO_V1(plvdate_including_start); PG_FUNCTION_INFO_V1(plvdate_default_holidays); PG_FUNCTION_INFO_V1(plvdate_version); PG_FUNCTION_INFO_V1(plvdate_days_inmonth); PG_FUNCTION_INFO_V1(plvdate_isleapyear); #define CHECK_SEQ_SEARCH(_l, _s) \ do { \ if ((_l) < 0) { \ ereport(ERROR, \ (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \ errmsg("invalid value for %s", (_s)))); \ } \ } while (0) extern int ora_seq_search(const char *name, /*const*/ char **array, int max); #define SUNDAY (1 << 0) #define SATURDAY (1 << 6) static unsigned char nonbizdays = SUNDAY | SATURDAY; static bool use_easter = true; static bool include_start = true; #define MAX_holidays 30 #define MAX_EXCEPTIONS 50 typedef struct { char day; char month; } holiday_desc; typedef struct { unsigned char nonbizdays; bool use_easter; holiday_desc *holidays; int holidays_c; } cultural_info; static holiday_desc holidays[MAX_holidays]; /* sorted array */ static DateADT exceptions[MAX_EXCEPTIONS]; /* sorted array */ static int holidays_c = 0; static int exceptions_c = 0; static holiday_desc czech_holidays[] = { {1,1}, // Novy rok {1,5}, // Svatek prace {8,5}, // Den osvobozeni {5,7}, // Den slovanskych verozvestu {6,7}, // Den upaleni mistra Jana Husa {28,9}, // Den ceske statnosti {28,10}, // Den vzniku samostatneho ceskoslovenskeho statu {17,11}, // Den boje za svobodu a demokracii {24,12}, // Stedry den {25,12}, // 1. svatek vanocni {26,12} // 2. svatek vanocni }; static holiday_desc germany_holidays[] = { {1,1},{1,5},{25,5},{4,6},{5,6}, {15,8},{3,10},{25,12},{26,12} }; static holiday_desc poland_holidays[] = { {1,1},{1,5},{3,5},{15,6},{15,8}, {1,11},{11,11},{25,12},{26,12} }; static holiday_desc austria_holidays[] = { {1,1},{6,1},{1,5},{25,5},{4,6}, {5,6},{15,6},{15,8},{26,10},{1,11}, {8,12},{25,12},{26,12} }; static holiday_desc slovakia_holidays[] = { {1,1},{6,1},{1,5},{8,5},{5,7}, {29,8},{1,9},{15,9},{1,11},{17,11}, {24,12},{25,12},{26,12} }; static holiday_desc russian_holidays[] = { {1,1},{2,1},{3,1},{4,1},{5,1}, {7,1},{23,2},{8,3},{1,5},{9,5}, {12,6}, {4,11} }; static holiday_desc england_holidays[] = { {1,1},{2,1},{1,5},{29,5},{28,8}, {25,12},{26,12} }; static holiday_desc usa_holidays[] = { {1,1},{16,1},{20,2},{29,5},{4,7}, {4,9},{9,10},{11,11},{23,11},{25,12} }; cultural_info defaults_ci[] = { {SUNDAY | SATURDAY, true, czech_holidays, 11}, {SUNDAY | SATURDAY, true, germany_holidays, 9}, {SUNDAY | SATURDAY, true, poland_holidays, 9}, {SUNDAY | SATURDAY, true, austria_holidays, 13}, {SUNDAY | SATURDAY, true, slovakia_holidays, 13}, {SUNDAY | SATURDAY, false, russian_holidays, 12}, {SUNDAY | SATURDAY, true, england_holidays, 7}, {SUNDAY | SATURDAY, false, usa_holidays, 10} }; static char *states[] = { "Czech", "Germany", "Poland", "Austria", "Slovakia", "Russia", "Gb", "Usa", NULL, }; static int dateadt_comp(const void* a, const void* b) { DateADT *_a = (DateADT*)a; DateADT *_b = (DateADT*)b; return *_a - *_b; } static int holiday_desc_comp(const void* a, const void* b) { int result; if (0 == (result = ((holiday_desc*)a)->month - ((holiday_desc*)b)->month)) result = ((holiday_desc*)a)->day - ((holiday_desc*)b)->day; return result; } static void easter_sunday(int year, int* dd, int* mm) { int b, d, e, q; if (year < 1900 || year > 2099) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("date is out of range"), errdetail("Easter is defined only for years between 1900 and 2099"))); b = 255 - 11 * (year % 19); d = ((b - 21) % 30) + 21; if (d > 38) d -= 1; e = (year + year/4 + d + 1) % 7; q = d + 7 - e; if (q < 32) { *dd = q; *mm = 3; } else { *dd = q - 31; *mm = 4; } } static Datum ora_add_bizdays(DateADT day, int days) { int d, dx; int y, m, auxd; holiday_desc hd; d = j2day(day+POSTGRES_EPOCH_JDATE); dx = days > 0? 1 : -1; while (days != 0) { d = (d+dx) % 7; d = (d < 0) ? 6:d; day += dx; if ((1 << d) & nonbizdays) continue; if (NULL != bsearch(&day, exceptions, exceptions_c, sizeof(DateADT), dateadt_comp)) continue; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &auxd); hd.day = (char) auxd; hd.month = (char) m; if (use_easter && (m == 3 || m == 4)) { easter_sunday(y, &auxd, &m); if (m == hd.month && (auxd == hd.day || d+1 == hd.day)) continue; } if (NULL != bsearch(&hd, holidays, holidays_c, sizeof(holiday_desc), holiday_desc_comp)) continue; days -= dx; } return day; } static int ora_diff_bizdays(DateADT day1, DateADT day2) { int d, days; int y, m, auxd; holiday_desc hd; int cycle_c = 0; bool start_is_bizday = false; DateADT aux_day; if (day1 > day2) { aux_day = day1; day1 = day2; day2 = aux_day; } d = j2day(day1+POSTGRES_EPOCH_JDATE); days = 0; while (day1 <= day2) { ++ cycle_c; d = (d+1) % 7; d = (d < 0) ? 6:d; day1 += 1; if ((1 << d) & nonbizdays) continue; if (NULL != bsearch(&day1, exceptions, exceptions_c, sizeof(DateADT), dateadt_comp)) continue; j2date(day1 + POSTGRES_EPOCH_JDATE, &y, &m, &auxd); hd.day = (char) auxd; hd.month = (char) m; if (use_easter && (m == 3 || m == 4)) { easter_sunday(y, &auxd, &m); if (m == hd.month && (auxd == hd.day || d+1 == hd.day)) continue; } if (NULL != bsearch(&hd, holidays, holidays_c, sizeof(holiday_desc), holiday_desc_comp)) continue; days += 1; if (cycle_c == 1) start_is_bizday = true; } if (include_start && start_is_bizday && days >= 1) days -= 1; return days; } /**************************************************************** * PLVdate.add_bizdays * * Syntax: * FUNCTION add_bizdays(IN dt DATE, IN days int) RETURNS DATE; * * Purpouse: * Get the date created by adding business days to a date * ****************************************************************/ Datum plvdate_add_bizdays (PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int days = PG_GETARG_INT32(1); PG_RETURN_DATEADT(ora_add_bizdays(day,days)); } /**************************************************************** * PLVdate.nearest_bizday * * Syntax: * FUNCTION nearest_bizday(IN dt DATE) RETURNS DATE; * * Purpouse: * Get the nearest business date to a given date, user defined * ****************************************************************/ Datum plvdate_nearest_bizday (PG_FUNCTION_ARGS) { DateADT dt = PG_GETARG_DATEADT(0); DateADT d1, d2, res; d1 = ora_add_bizdays(dt, -1); d2 = ora_add_bizdays(dt, 1); if ((dt - d1) > (d2 - dt)) res = d2; else res = d1; PG_RETURN_DATEADT(res); } /**************************************************************** * PLVdate.next_bizday * * Syntax: * FUNCTION next_bizday(IN dt DATE) RETURNS DATE; * * Purpouse: * Get the next business date from a given date, user defined * ****************************************************************/ Datum plvdate_next_bizday (PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); PG_RETURN_DATEADT(ora_add_bizdays(day,1)); } /**************************************************************** * PLVdate.bizdays_between * * Syntax: * FUNCTION bizdays_between(IN dt1 DATE, IN dt2 DATE) * RETURNS int; * * Purpouse: * Get the number of business days between two dates * ****************************************************************/ Datum plvdate_bizdays_between (PG_FUNCTION_ARGS) { DateADT day1 = PG_GETARG_DATEADT(0); DateADT day2 = PG_GETARG_DATEADT(1); PG_RETURN_INT32(ora_diff_bizdays(day1,day2)); } /**************************************************************** * PLVdate.prev_bizday * * Syntax: * FUNCTION prev_bizday(IN dt DATE) RETURNS date; * * Purpouse: * Get the previous business date from a given date, user * defined * ****************************************************************/ Datum plvdate_prev_bizday (PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); PG_RETURN_DATEADT(ora_add_bizdays(day,-1)); } /**************************************************************** * PLVdate.isbizday * * Syntax: * FUNCTION isbizday(IN dt DATE) RETURNS bool; * * Purpouse: * Call this function to determine if a date is a business day * ****************************************************************/ Datum plvdate_isbizday (PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int y, m, d; holiday_desc hd; if (0 != ((1 << j2day(day+POSTGRES_EPOCH_JDATE)) & nonbizdays)) return false; if (NULL != bsearch(&day, exceptions, exceptions_c, sizeof(DateADT), dateadt_comp)) return false; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); hd.month = m; hd.day = d; if (use_easter && (m == 3 || m == 4)) { easter_sunday(y, &d, &m); if (m == hd.month && (d == hd.day || d+1 == hd.day)) return false; } PG_RETURN_BOOL (NULL == bsearch(&hd, holidays, holidays_c, sizeof(holiday_desc), holiday_desc_comp)); } /**************************************************************** * PLVdate.set_nonbizday * * Syntax: * FUNCTION set_nonbizday(IN dow VARCHAR) RETURNS void; * * Purpouse: * Set day of week as non bussines day * ****************************************************************/ Datum plvdate_set_nonbizday_dow (PG_FUNCTION_ARGS) { unsigned char check; text *day_txt = PG_GETARG_TEXT_PP(0); int d = ora_seq_search(VARDATA_ANY(day_txt), days, VARSIZE_ANY_EXHDR(day_txt)); CHECK_SEQ_SEARCH(d, "DAY/Day/day"); check = nonbizdays | (1 << d); if (check == 0x7f) ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("nonbizday registeration error"), errdetail("Constraint violation."), errhint("One day in week have to be bizday."))); nonbizdays = nonbizdays | (1 << d); PG_RETURN_VOID(); } /**************************************************************** * PLVdate.unset_nonbizday * * Syntax: * FUNCTION unset_nonbizday(IN dow VARCHAR) RETURNS void; * * Purpouse: * Unset day of week as non bussines day * ****************************************************************/ Datum plvdate_unset_nonbizday_dow (PG_FUNCTION_ARGS) { text *day_txt = PG_GETARG_TEXT_PP(0); int d = ora_seq_search(VARDATA_ANY(day_txt), days, VARSIZE_ANY_EXHDR(day_txt)); CHECK_SEQ_SEARCH(d, "DAY/Day/day"); nonbizdays = (nonbizdays | (1 << d)) ^ (1 << d); PG_RETURN_VOID(); } /**************************************************************** * PLVdate.set_nonbizday * * Syntax: * FUNCTION set_nonbizday(IN day DATE) RETURNS void; * FUNCTION set_nonbizday(IN day DATE, IN repeat := false BOOL) RETURNS void; * * Purpouse: * Set day as non bussines day, second arg specify year's * periodicity * ****************************************************************/ Datum plvdate_set_nonbizday_day (PG_FUNCTION_ARGS) { DateADT arg1 = PG_GETARG_DATEADT(0); bool arg2 = PG_GETARG_BOOL(1); int y, m, d; holiday_desc hd; if (arg2) { if (holidays_c == MAX_holidays) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("nonbizday registeration error"), errdetail("Too much registered nonbizdays."), errhint("Increase MAX_holidays in 'plvdate.c'."))); j2date(arg1 + POSTGRES_EPOCH_JDATE, &y, &m, &d); hd.month = m; hd.day = d; if (NULL != bsearch(&hd, holidays, holidays_c, sizeof(holiday_desc), holiday_desc_comp)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("nonbizday registeration error"), errdetail("Date is registered."))); holidays[holidays_c].month = m; holidays[holidays_c].day = d; holidays_c += 1; qsort(holidays, holidays_c, sizeof(holiday_desc), holiday_desc_comp); } else { if (exceptions_c == MAX_EXCEPTIONS) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("nonbizday registeration error"), errdetail("Too much registered nonrepeated nonbizdays."), errhint("Increase MAX_EXCEPTIONS in 'plvdate.c'."))); if (NULL != bsearch(&arg1, exceptions, exceptions_c, sizeof(DateADT), dateadt_comp)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("nonbizday registeration error"), errdetail("Date is registered."))); exceptions[exceptions_c++] = arg1; qsort(exceptions, exceptions_c, sizeof(DateADT), dateadt_comp); } PG_RETURN_VOID(); } /**************************************************************** * PLVdate.unset_nonbizday * * Syntax: * FUNCTION unset_nonbizday(IN day DATE) RETURNS void; * FUNCTION unset_nonbizday(IN day DATE, IN repeat := false BOOL) RETURNS void; * * Purpouse: * Unset day as non bussines day, second arg specify year's * periodicity * ****************************************************************/ Datum plvdate_unset_nonbizday_day (PG_FUNCTION_ARGS) { DateADT arg1 = PG_GETARG_DATEADT(0); bool arg2 = PG_GETARG_BOOL(1); int y, m, d; bool found = false; int i; if (arg2) { j2date(arg1 + POSTGRES_EPOCH_JDATE, &y, &m, &d); for (i = 0; i < holidays_c; i++) { if (!found && holidays[i].month == m && holidays[i].day == d) found = true; else if (found) { holidays[i-1].month = holidays[i].month; holidays[i-1].day = holidays[i].day; } } if (found) holidays_c -= 1; } else { for (i = 0; i < exceptions_c; i++) if (!found && exceptions[i] == arg1) found = true; else if (found) exceptions[i-1] = exceptions[i]; if (found) exceptions_c -= 1; } if (!found) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("nonbizday unregisteration error"), errdetail("Nonbizday not found."))); PG_RETURN_VOID(); } /**************************************************************** * PLVdate.use_easter * * Syntax: * FUNCTION unuse_easter() RETURNS void; * FUNCTION use_easter() RETURNS void; * FUNCTION use_easter(IN bool) RETURNS void * * Purpouse: * Have to use easter as nonbizday? * ****************************************************************/ Datum plvdate_use_easter (PG_FUNCTION_ARGS) { use_easter = PG_GETARG_BOOL(0); PG_RETURN_VOID(); } /**************************************************************** * PLVdate.using_easter * * Syntax: * FUNCTION using_easter() RETURNS bool * * Purpouse: * Use it easter as nonbizday? * ****************************************************************/ Datum plvdate_using_easter (PG_FUNCTION_ARGS) { PG_RETURN_BOOL(use_easter); } /**************************************************************** * PLVdate.include_start * * Syntax: * FUNCTION include_start() RETURNS void; * FUNCTION noinclude_start() RETURNS void; * FUNCTION include_start(IN bool) RETURNS void * * Purpouse: * Have to include current day in bizdays_between calculation? * ****************************************************************/ Datum plvdate_include_start (PG_FUNCTION_ARGS) { include_start = PG_GETARG_BOOL(0); PG_RETURN_VOID(); } /**************************************************************** * PLVdate.including_start * * Syntax: * FUNCTION including_start() RETURNS bool * * Purpouse: * include current day in bizdays_between calculation? * ****************************************************************/ Datum plvdate_including_start (PG_FUNCTION_ARGS) { PG_RETURN_BOOL(include_start); } /* * Load some national configurations * */ Datum plvdate_default_holidays (PG_FUNCTION_ARGS) { text *country = PG_GETARG_TEXT_PP(0); int c = ora_seq_search(VARDATA_ANY(country), states, VARSIZE_ANY_EXHDR(country)); CHECK_SEQ_SEARCH(c, "STATE/State/state"); nonbizdays = defaults_ci[c].nonbizdays; use_easter = defaults_ci[c].use_easter; exceptions_c = 0; holidays_c = defaults_ci[c].holidays_c; memcpy(holidays, defaults_ci[c].holidays, holidays_c*sizeof(holiday_desc)); PG_RETURN_VOID(); } /* * helper maintaince functions */ Datum plvdate_version (PG_FUNCTION_ARGS) { PG_RETURN_CSTRING(PLVDATE_VERSION); } /**************************************************************** * PLVdate.days_inmonth * * Syntax: * FUNCTION days_inmonth(date) RETURNS integer * * Purpouse: * Returns month's length * ****************************************************************/ Datum plvdate_days_inmonth(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int result; int y, m, d; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); result = date2j(y, m+1, 1) - date2j(y, m, 1); PG_RETURN_INT32(result); } /**************************************************************** * PLVdate.isleapyear * * Syntax: * FUNCTION isleapyear() RETURNS bool * * Purpouse: * Returns true, if year is leap * ****************************************************************/ Datum plvdate_isleapyear(PG_FUNCTION_ARGS) { DateADT day = PG_GETARG_DATEADT(0); int y, m, d; bool result; j2date(day + POSTGRES_EPOCH_JDATE, &y, &m, &d); result = ((( y % 4) == 0) && ((y % 100) != 0)) || ((y / 400) == 0); PG_RETURN_BOOL(result); } /**************************************************************** * PLVdate.set_nonbizdays * * Syntax: * FUNCTION set_nonbizdays(IN dow bool[7]) RETURNS void; * * Purpouse: * Set pattern bussines/nonbussines days in week * ****************************************************************/ /**************************************************************** * PLVdate.set_nonbizday * * Syntax: * FUNCTION set_nonbizdays(IN days DATE[]) RETURNS void; * FUNCTION set_nonbizdays(IN days DATE[], IN repeat := false BOOL) RETURNS void; * * Purpouse: * Set days as non bussines day, second arg specify year's * periodicity * ****************************************************************/ /**************************************************************** * PLVdate.display * * Syntax: * FUNCTION display() RETURNS void; * * Purpouse: * Show current calendar * ****************************************************************/ orafce-VERSION_3_0_6/plvlex.c000066400000000000000000000153321221300436000157770ustar00rootroot00000000000000/* This code implements one part of functonality of free available library PL/Vision. Please look www.quest.com Original author: Steven Feuerstein, 1996 - 2002 PostgreSQL implementation author: Pavel Stehule, 2006 This module is under BSD Licence History: 1.0. first public version 13. March 2006 */ #include "postgres.h" #include "utils/date.h" #include "utils/builtins.h" #include "utils/nabstime.h" #include #include #include "lib/stringinfo.h" #include "plvlex.h" #include "sqlparse.h" #include "nodes/pg_list.h" #include "funcapi.h" #include "catalog/pg_type.h" #include "orafunc.h" #include "builtins.h" typedef struct { List *nodes; int nnodes; int cnode; char **values; } tokensFctx; PG_FUNCTION_INFO_V1(plvlex_tokens); extern int orafce_sql_yyparse(); extern void orafce_sql_yyerror(const char *message); extern void orafce_sql_scanner_init(const char *str); extern void orafce_sql_scanner_finish(void); static orafce_lexnode *__node; static char *__result; static int __len; #define CSTRING(txt) \ ( \ __len = VARSIZE(txt) - VARHDRSZ, \ __result = palloc(__len + 1), \ memcpy(__result, VARDATA(txt), __len), \ __result[__len] = '\0', \ __result) #define COPY_TO_S(src,dest,col) (dest->col = (src->col ? pstrdup(src->col) : NULL)) #define COPY_TO(src,dest,col) (dest->col = src->col) #define COPY_FIELDS(src,dest) \ COPY_TO(src, dest, typenode), \ COPY_TO_S(src,dest,str), \ COPY_TO(src,dest,keycode), \ COPY_TO(src,dest,lloc), \ COPY_TO_S(src,dest,sep), \ COPY_TO(src,dest,modificator), \ COPY_TO(src,dest,classname) #define COPY_NODE(src) \ ( \ __node = (orafce_lexnode*) palloc(sizeof(orafce_lexnode)), \ COPY_FIELDS(src,__node), \ __node) /* Finding triplet a.b --> a */ #define IsType(node, type) (node->typenode == X_##type) #define APPEND_NODE(list,nd) \ if (nd) \ { \ list = lappend(list, nd); \ nd = NULL; \ } #define mod(a) (a->modificator) #define SF(a) (a ? a : "") #define NEWNODE(type) \ ( \ __node = (orafce_lexnode *) palloc(sizeof(orafce_lexnode)), \ __node->typenode = X_##type, \ __node->modificator = NULL, \ __node->sep = NULL, \ __node->keycode = -1, \ __node->classname = #type, \ __node->lloc = 0, \ __node ) static orafce_lexnode * compose(orafce_lexnode *a, orafce_lexnode *b) { orafce_lexnode *result; StringInfo sinfo; sinfo = makeStringInfo(); result = NEWNODE(IDENT); result->lloc = a->lloc; if (strcmp(SF(mod(a)), "dq") == 0) appendStringInfo(sinfo, "\"%s\".", a->str); else { appendStringInfoString(sinfo, a->str); appendStringInfoChar(sinfo, '.'); } if (strcmp(SF(mod(b)), "dq") == 0) appendStringInfo(sinfo, "\"%s\"", b->str); else appendStringInfoString(sinfo, b->str); result->str = sinfo->data; return result; } static List * filterList(List *list, bool skip_spaces, bool qnames) { List *result = NIL; ListCell *cell; bool isdot = false; orafce_lexnode *a = NULL; orafce_lexnode *dot = NULL; foreach(cell, list) { orafce_lexnode *nd = (orafce_lexnode *) lfirst(cell); if (qnames) { isdot = (IsType(nd, OTHERS) && (nd->str[0] == '.')); if (IsType(nd, IDENT) && dot && a) { a = compose(a, nd); dot = NULL; continue; } else if (isdot && !dot && a) { dot = COPY_NODE(nd); continue; } else if (IsType(nd, IDENT) && !a) { a = COPY_NODE(nd); continue; } } /* clean buffered values */ APPEND_NODE(result,a); APPEND_NODE(result,dot); if (!(skip_spaces && IsType(nd, WHITESPACE))) { result = lappend(result, COPY_NODE(nd)); } } /* clean buffered values */ APPEND_NODE(result,a); APPEND_NODE(result,dot); return result; } Datum plvlex_tokens(PG_FUNCTION_ARGS) { #ifdef _MSC_VER ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("plvlex.tokens is not available in the built"))); PG_RETURN_VOID(); #else FuncCallContext *funcctx; TupleDesc tupdesc; TupleTableSlot *slot; AttInMetadata *attinmeta; tokensFctx *fctx; if (SRF_IS_FIRSTCALL ()) { MemoryContext oldcontext; List *lexems; text *src = PG_GETARG_TEXT_P(0); bool skip_spaces = PG_GETARG_BOOL(1); bool qnames = PG_GETARG_BOOL(2); orafce_sql_scanner_init(CSTRING(src)); if (orafce_sql_yyparse(&lexems) != 0) orafce_sql_yyerror("bogus input"); orafce_sql_scanner_finish(); funcctx = SRF_FIRSTCALL_INIT (); oldcontext = MemoryContextSwitchTo (funcctx->multi_call_memory_ctx); fctx = (tokensFctx*) palloc (sizeof (tokensFctx)); funcctx->user_fctx = (void *)fctx; fctx->nodes = filterList(lexems, skip_spaces, qnames); fctx->nnodes = list_length(fctx->nodes); fctx->cnode = 0; fctx->values = (char **) palloc (6 * sizeof (char *)); fctx->values [0] = (char*) palloc (16 * sizeof (char)); fctx->values [1] = (char*) palloc (1024 * sizeof (char)); fctx->values [2] = (char*) palloc (16 * sizeof (char)); fctx->values [3] = (char*) palloc (16 * sizeof (char)); fctx->values [4] = (char*) palloc (255 * sizeof (char)); fctx->values [5] = (char*) palloc (255 * sizeof (char)); tupdesc = CreateTemplateTupleDesc (6 , false); TupleDescInitEntry (tupdesc, 1, "start_pos", INT4OID, -1, 0); TupleDescInitEntry (tupdesc, 2, "token", TEXTOID, -1, 0); TupleDescInitEntry (tupdesc, 3, "keycode", INT4OID, -1, 0); TupleDescInitEntry (tupdesc, 4, "class", TEXTOID, -1, 0); TupleDescInitEntry (tupdesc, 5, "separator", TEXTOID, -1, 0); TupleDescInitEntry (tupdesc, 6, "mod", TEXTOID, -1, 0); slot = TupleDescGetSlot (tupdesc); funcctx -> slot = slot; attinmeta = TupleDescGetAttInMetadata (tupdesc); funcctx -> attinmeta = attinmeta; MemoryContextSwitchTo (oldcontext); } funcctx = SRF_PERCALL_SETUP (); fctx = (tokensFctx*) funcctx->user_fctx; while (fctx->cnode < fctx->nnodes) { char **values; Datum result; HeapTuple tuple; char *back_vals[6]; orafce_lexnode *nd = (orafce_lexnode*) list_nth(fctx->nodes, fctx->cnode++); values = fctx->values; back_vals[2] = values[2]; back_vals[4] = values[4]; back_vals[5] = values[5]; snprintf(values[0], 16, "%d", nd->lloc); snprintf(values[1], 10000, "%s", SF(nd->str)); snprintf(values[2], 16, "%d", nd->keycode); snprintf(values[3], 16, "%s", nd->classname); snprintf(values[4], 255, "%s", SF(nd->sep)); snprintf(values[5], 48, "%s", SF(nd->modificator)); if (nd->keycode == -1) values[2] = NULL; if (!nd->sep) values[4] = NULL; if (!nd->modificator) values[5] = NULL; tuple = BuildTupleFromCStrings (funcctx -> attinmeta, fctx -> values); result = TupleGetDatum (funcctx -> slot, tuple); values[2] = back_vals[2]; values[4] = back_vals[4]; values[5] = back_vals[5]; SRF_RETURN_NEXT (funcctx, result); } SRF_RETURN_DONE (funcctx); #endif } orafce-VERSION_3_0_6/plvlex.h000066400000000000000000000002251221300436000157770ustar00rootroot00000000000000typedef struct { int typenode; char *str; int keycode; int lloc; char *sep; char *modificator; char *classname; } orafce_lexnode; orafce-VERSION_3_0_6/plvstr.c000066400000000000000000000661511221300436000160240ustar00rootroot00000000000000/* This code implements one part of functonality of free available library PL/Vision. Please look www.quest.com Original author: Steven Feuerstein, 1996 - 2002 PostgreSQL implementation author: Pavel Stehule, 2006 This module is under BSD Licence History: 1.0. first public version 13. March 2006 */ #include "postgres.h" #include "utils/builtins.h" #include "utils/numeric.h" #include "string.h" #include "stdlib.h" #include "utils/pg_locale.h" #include "mb/pg_wchar.h" #include "nodes/execnodes.h" #include "catalog/pg_type.h" #include "libpq/pqformat.h" #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(plvstr_rvrs); PG_FUNCTION_INFO_V1(plvstr_normalize); PG_FUNCTION_INFO_V1(plvstr_is_prefix); PG_FUNCTION_INFO_V1(plvstr_is_prefix_text); PG_FUNCTION_INFO_V1(plvstr_is_prefix_int); PG_FUNCTION_INFO_V1(plvstr_is_prefix_int64); PG_FUNCTION_INFO_V1(plvstr_lpart); PG_FUNCTION_INFO_V1(plvstr_rpart); PG_FUNCTION_INFO_V1(plvstr_lstrip); PG_FUNCTION_INFO_V1(plvstr_rstrip); PG_FUNCTION_INFO_V1(plvstr_left); PG_FUNCTION_INFO_V1(plvstr_right); PG_FUNCTION_INFO_V1(plvstr_substr2); PG_FUNCTION_INFO_V1(plvstr_substr3); PG_FUNCTION_INFO_V1(plvstr_instr2); PG_FUNCTION_INFO_V1(plvstr_instr3); PG_FUNCTION_INFO_V1(plvstr_instr4); PG_FUNCTION_INFO_V1(plvstr_betwn_i); PG_FUNCTION_INFO_V1(plvstr_betwn_c); PG_FUNCTION_INFO_V1(plvstr_swap); PG_FUNCTION_INFO_V1(plvchr_nth); PG_FUNCTION_INFO_V1(plvchr_first); PG_FUNCTION_INFO_V1(plvchr_last); PG_FUNCTION_INFO_V1(plvchr_is_kind_i); PG_FUNCTION_INFO_V1(plvchr_is_kind_a); PG_FUNCTION_INFO_V1(plvchr_char_name); PG_FUNCTION_INFO_V1(oracle_substr2); PG_FUNCTION_INFO_V1(oracle_substr3); static text *ora_substr(Datum str, int start, int len); #define ora_substr_text(str, start, len) \ ora_substr(PointerGetDatum((str)), (start), (len)) static const char* char_names[] = { "NULL","SOH","STX","ETX","EOT","ENQ","ACK","DEL", "BS", "HT", "NL", "VT", "NP", "CR", "SO", "SI", "DLE", "DC1","DC2","DC3","DC4","NAK","SYN","ETB", "CAN", "EM","SUB","ESC","FS","GS","RS","US","SP" }; #define NON_EMPTY_CHECK(str) \ if (VARSIZE_ANY_EXHDR(str) == 0) \ ereport(ERROR, \ (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ errmsg("invalid parameter"), \ errdetail("Not allowed empty string."))); #define PARAMETER_ERROR(detail) \ ereport(ERROR, \ (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ errmsg("invalid parameter"), \ errdetail(detail))); #ifndef _pg_mblen #define _pg_mblen pg_mblen #endif typedef enum { POSITION, FIRST, LAST } position_mode; #if PG_VERSION_NUM < 80400 text * cstring_to_text_with_len(const char *c, int n) { text *result; result = palloc(n + VARHDRSZ); SET_VARSIZE(result, n + VARHDRSZ); memcpy(VARDATA(result), c, n); return result; } #endif /* * Make substring, can handle negative start * */ int ora_mb_strlen(text *str, char **sizes, int **positions) { int r_len; int cur_size = 0; int sz; char *p; int cur = 0; p = VARDATA_ANY(str); r_len = VARSIZE_ANY_EXHDR(str); if (NULL != sizes) *sizes = palloc(r_len * sizeof(char)); if (NULL != positions) *positions = palloc(r_len * sizeof(int)); while (cur < r_len) { sz = _pg_mblen(p); if (sizes) (*sizes)[cur_size] = sz; if (positions) (*positions)[cur_size] = cur; cur += sz; p += sz; cur_size += 1; } return cur_size; } int ora_mb_strlen1(text *str) { int r_len; int c; char *p; r_len = VARSIZE_ANY_EXHDR(str); if (pg_database_encoding_max_length() == 1) return r_len; p = VARDATA_ANY(str); c = 0; while (r_len > 0) { int sz; sz = _pg_mblen(p); p += sz; r_len -= sz; c += 1; } return c; } /* * len < 0 means "length is not specified". */ static text * ora_substr(Datum str, int start, int len) { if (start == 0) start = 1; /* 0 is interpreted as 1 */ else if (start < 0) { text *t; int32 n; t = DatumGetTextPP(str); n = pg_mbstrlen_with_len(VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)); start = n + start + 1; if (start <= 0) return cstring_to_text(""); str = PointerGetDatum(t); /* save detoasted text */ } if (len < 0) return DatumGetTextP(DirectFunctionCall2(text_substr_no_len, str, Int32GetDatum(start))); else return DatumGetTextP(DirectFunctionCall3(text_substr, str, Int32GetDatum(start), Int32GetDatum(len))); } /* simply search algorhitm - can be better */ static int ora_instr_mb(text *txt, text *pattern, int start, int nth) { int c_len_txt, c_len_pat; int b_len_pat; int *pos_txt; const char *str_txt, *str_pat; int beg, end, i, dx; str_txt = VARDATA_ANY(txt); c_len_txt = ora_mb_strlen(txt, NULL, &pos_txt); str_pat = VARDATA_ANY(pattern); b_len_pat = VARSIZE_ANY_EXHDR(pattern); c_len_pat = pg_mbstrlen_with_len(str_pat, b_len_pat); if (start > 0) { dx = 1; beg = start - 1; end = c_len_txt - c_len_pat + 1; if (beg >= end) return 0; /* out of range */ } else { dx = -1; beg = Min(c_len_txt + start, c_len_txt - c_len_pat); end = -1; if (beg <= end) return 0; /* out of range */ } for (i = beg; i != end; i += dx) { if (memcmp(str_txt + pos_txt[i], str_pat, b_len_pat) == 0) { if (--nth == 0) return i + 1; } } return 0; } int ora_instr(text *txt, text *pattern, int start, int nth) { int len_txt, len_pat; const char *str_txt, *str_pat; int beg, end, i, dx; if (nth <= 0) PARAMETER_ERROR("Four parameter isn't positive."); /* Forward for multibyte strings */ if (pg_database_encoding_max_length() > 1) return ora_instr_mb(txt, pattern, start, nth); str_txt = VARDATA_ANY(txt); len_txt = VARSIZE_ANY_EXHDR(txt); str_pat = VARDATA_ANY(pattern); len_pat = VARSIZE_ANY_EXHDR(pattern); if (start > 0) { dx = 1; beg = start - 1; end = len_txt - len_pat + 1; if (beg >= end) return 0; /* out of range */ } else { dx = -1; beg = Min(len_txt + start, len_txt - len_pat); end = -1; if (beg <= end) return 0; /* out of range */ } for (i = beg; i != end; i += dx) { if (memcmp(str_txt + i, str_pat, len_pat) == 0) { if (--nth == 0) return i + 1; } } return 0; } /**************************************************************** * PLVstr.normalize * * Syntax: * FUNCTION plvstr.normalize (string_in IN VARCHAR) * RETURN VARCHAR; * * Purpouse: * Normalize string - replace white chars by space, replace * spaces by space * ****************************************************************/ Datum plvstr_normalize(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); text *result; char *aux, *aux_cur; int i, l; char c, *cur; bool write_spc = false; bool ignore_stsp = true; bool mb_encode; int sz; mb_encode = pg_database_encoding_max_length() > 1; l = VARSIZE_ANY_EXHDR(str); aux_cur = aux = palloc(l); write_spc = false; cur = VARDATA_ANY(str); for (i = 0; i < l; i++) { switch ((c = *cur)) { case '\t': case '\n': case '\r': case ' ': write_spc = ignore_stsp ? false : true; break; default: /* ignore all other unvisible chars */ if (mb_encode) { sz = _pg_mblen(cur); if (sz > 1 || (sz == 1 && c > 32)) { int j; if (write_spc) { *aux_cur++ = ' '; write_spc = false; } for (j = 0; j < sz; j++) { *aux_cur++ = *cur++; } ignore_stsp = false; i += sz - 1; } continue; } else if (c > 32) { if (write_spc) { *aux_cur++ = ' '; write_spc = false; } *aux_cur++ = c; ignore_stsp = false; continue; } } cur += 1; } l = aux_cur - aux; result = palloc(l+VARHDRSZ); SET_VARSIZE(result, l + VARHDRSZ); memcpy(VARDATA(result), aux, l); PG_RETURN_TEXT_P(result); } /**************************************************************** * PLVstr.instr * * Syntax: * FUNCTION plvstr.instr (string_in VARCHAR, pattern VARCHAR) * FUNCTION plvstr.instr (string_in VARCHAR, pattern VARCHAR, * start_in INTEGER) * FUNCTION plvstr.instr (string_in VARCHAR, pattern VARCHAR, * start_in INTEGER, nth INTEGER) * RETURN INT; * * Purpouse: * Search pattern in string. * ****************************************************************/ Datum plvstr_instr2 (PG_FUNCTION_ARGS) { text *arg1 = PG_GETARG_TEXT_PP(0); text *arg2 = PG_GETARG_TEXT_PP(1); PG_RETURN_INT32(ora_instr(arg1, arg2, 1, 1)); } Datum plvstr_instr3 (PG_FUNCTION_ARGS) { text *arg1 = PG_GETARG_TEXT_PP(0); text *arg2 = PG_GETARG_TEXT_PP(1); int arg3 = PG_GETARG_INT32(2); PG_RETURN_INT32(ora_instr(arg1, arg2, arg3, 1)); } Datum plvstr_instr4 (PG_FUNCTION_ARGS) { text *arg1 = PG_GETARG_TEXT_PP(0); text *arg2 = PG_GETARG_TEXT_PP(1); int arg3 = PG_GETARG_INT32(2); int arg4 = PG_GETARG_INT32(3); PG_RETURN_INT32(ora_instr(arg1, arg2, arg3, arg4)); } /**************************************************************** * PLVstr.is_prefix * * Syntax: * FUNCTION plvstr.is_prefix (string_in IN VARCHAR, * prefix_in VARCHAR, * case_sensitive BOOL := true) * RETURN bool; * FUNCTION plvstr.is_prefix (num_in IN NUMERIC, * prefix_in NUMERIC) RETURN bool; * FUNCTION plvstr.is_prefix (int_in IN INT, * prefix_in INT) RETURN bool; * * Purpouse: * Returns true, if prefix_in is prefix of string_in * ****************************************************************/ Datum plvstr_is_prefix_text (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); text *prefix = PG_GETARG_TEXT_PP(1); bool case_sens = PG_GETARG_BOOL(2); bool mb_encode; int str_len = VARSIZE_ANY_EXHDR(str); int pref_len = VARSIZE_ANY_EXHDR(prefix); int i; char *ap, *bp; mb_encode = pg_database_encoding_max_length() > 1; if (mb_encode && !case_sens) { str = (text*)DatumGetPointer(DirectFunctionCall1(lower, PointerGetDatum(str))); prefix = (text*)DatumGetPointer(DirectFunctionCall1(lower, PointerGetDatum(prefix))); } ap = VARDATA_ANY(str); bp = VARDATA_ANY(prefix); for (i = 0; i < pref_len; i++) { if (i >= str_len) break; if (case_sens || mb_encode) { if (*ap++ != *bp++) break; } else if (!mb_encode) { if (pg_toupper((unsigned char) *ap++) != pg_toupper((unsigned char) *bp++)) break; } } PG_RETURN_BOOL(i == pref_len); } Datum plvstr_is_prefix_int (PG_FUNCTION_ARGS) { int n = PG_GETARG_INT32(0); int prefix = PG_GETARG_INT32(1); bool result = false; do { if (n == prefix) { result = true; break; } n = n / 10; } while (n >= prefix); PG_RETURN_BOOL(result); } Datum plvstr_is_prefix_int64 (PG_FUNCTION_ARGS) { int64 n = PG_GETARG_INT64(0); int64 prefix = PG_GETARG_INT64(1); bool result = false; do { if (n == prefix) { result = true; break; } n = n / 10; } while (n >= prefix); PG_RETURN_BOOL(result); } /**************************************************************** * PLVstr.rvrs * * Syntax: * FUNCTION plvstr.rvrs (string_in IN VARCHAR, * start_in IN INTEGER := 1, * end_in IN INTEGER := NULL) * RETURN VARCHAR2; * * Purpouse: * Reverse string or part of string * ****************************************************************/ Datum plvstr_rvrs(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); int start = PG_GETARG_INT32(1); int end = PG_GETARG_INT32(2); int len; int i; int new_len; text *result; char *data; char *sizes = NULL; int *positions = NULL; bool mb_encode; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); mb_encode = pg_database_encoding_max_length() > 1; if (!mb_encode) len = VARSIZE_ANY_EXHDR(str); else len = ora_mb_strlen(str, &sizes, &positions); start = PG_ARGISNULL(1) ? 1 : start; end = PG_ARGISNULL(2) ? (start < 0 ? -len : len) : end; if ((start > end && start > 0) || (start < end && start < 0)) PARAMETER_ERROR("Second parameter is bigger than third."); if (start < 0) { end = len + start + 1; start = end; } new_len = end - start + 1; if (mb_encode) { int max_size; int cur_size; char *p; int j; int fz_size; fz_size = VARSIZE_ANY_EXHDR(str); if ((max_size = (new_len*pg_database_encoding_max_length())) > fz_size) result = palloc(fz_size + VARHDRSZ); else result = palloc(max_size + VARHDRSZ); data = (char*) VARDATA(result); cur_size = 0; p = VARDATA_ANY(str); for (i = end - 1; i>= start - 1; i--) { for (j=0; j= start - 1; i--) *data++ = p[i]; } PG_RETURN_TEXT_P(result); } /**************************************************************** * PLVstr.lpart * * Syntax: * FUNCTION PLVstr.lpart (string_in IN VARCHAR, * divider_in IN VARCHAR, * start_in IN INTEGER := 1, * nth_in IN INTEGER := 1, * all_if_notfound_in IN BOOLEAN := FALSE) * RETURN VARCHAR2; * * Purpouse: * Call this function to return the left part of a string. * ****************************************************************/ Datum plvstr_lpart (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_P(0); text *div = PG_GETARG_TEXT_P(1); int start = PG_GETARG_INT32(2); int nth = PG_GETARG_INT32(3); bool all_if_notfound = PG_GETARG_BOOL(4); int loc; loc = ora_instr(str, div, start, nth); if (loc == 0) { if (all_if_notfound) PG_RETURN_TEXT_P(TextPCopy(str)); else PG_RETURN_NULL(); } else PG_RETURN_TEXT_P(ora_substr_text(str, 1, loc-1)); } /**************************************************************** * PLVstr.rpart * * Syntax: * FUNCTION PLVstr.rpart (string_in IN VARCHAR, * divider_in IN VARCHAR, * start_in IN INTEGER := 1, * nth_in IN INTEGER := 1, * all_if_notfound_in IN BOOLEAN := FALSE) * RETURN VARCHAR2; * * Purpouse: * Call this function to return the right part of a string. * ****************************************************************/ Datum plvstr_rpart (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_P(0); text *div = PG_GETARG_TEXT_P(1); int start = PG_GETARG_INT32(2); int nth = PG_GETARG_INT32(3); bool all_if_notfound = PG_GETARG_BOOL(4); int loc; loc = ora_instr(str, div, start, nth); if (loc == 0) { if (all_if_notfound) PG_RETURN_TEXT_P(TextPCopy(str)); else PG_RETURN_NULL(); } else PG_RETURN_TEXT_P(ora_substr_text(str, loc+1, -1)); } /**************************************************************** * PLVstr.lstrip * * Syntax: * FUNCTION plvstr.lstrip (string_in IN VARCHAR, * substring_in IN VARCHAR, * num_in IN INTEGER := 1) * RETURN VARCHAR; * * Purpouse: * Call this function to remove characters from the beginning * (left) of a string. * ****************************************************************/ Datum plvstr_lstrip (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); text *pat = PG_GETARG_TEXT_PP(1); int num = PG_GETARG_INT32(2); int count = 0; int len_p, len_s, i; char *str_p, *aux_str_p, *pat_p; len_p = VARSIZE_ANY_EXHDR(pat); len_s = VARSIZE_ANY_EXHDR(str); str_p = VARDATA_ANY(str); while (count < num) { pat_p = VARDATA_ANY(pat); aux_str_p = str_p; if (len_s < len_p) break; for (i = 0; i < len_p; i++) if (*aux_str_p++ != *pat_p++) break; if (i >= len_p) { count++; /* found */ str_p = aux_str_p; len_s -= len_p; continue; } break; } PG_RETURN_TEXT_P(cstring_to_text_with_len(str_p,len_s)); } /**************************************************************** * PLVstr.rstrip * * Syntax: * FUNCTION plvstr.rstrip (string_in IN VARCHAR, * substring_in IN VARCHAR, * num_in IN INTEGER := 1) * RETURN VARCHAR; * * Purpouse: * Call this function to remove characters from the end * (right) of a string. * ****************************************************************/ Datum plvstr_rstrip (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); text *pat = PG_GETARG_TEXT_PP(1); int num = PG_GETARG_INT32(2); int count = 0; int len_p, len_s, i; char *str_p, *aux_str_p, *pat_p; len_p = VARSIZE_ANY_EXHDR(pat); len_s = VARSIZE_ANY_EXHDR(str); str_p = VARDATA_ANY(str) + len_s - 1; while (count < num) { pat_p = VARDATA_ANY(pat) + len_p - 1; aux_str_p = str_p; if (len_s < len_p) break; for (i = 0; i < len_p; i++) if (*aux_str_p-- != *pat_p--) break; if (i >= len_p) { count++; /* found */ str_p = aux_str_p; len_s -= len_p; continue; } break; } PG_RETURN_TEXT_P(cstring_to_text_with_len(VARDATA_ANY(str),len_s)); } /**************************************************************** * PLVstr.left * * Syntax: * FUNCTION plvstr.left (string_in IN VARCHAR, * num_in INTEGER) * RETURN VARCHAR; * * Purpouse: * Returns firs num_in charaters. You can use negative num_in * left('abcde', -2) -> abc * ****************************************************************/ Datum plvstr_left (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_P(0); int n = PG_GETARG_INT32(1); if (n < 0) n = ora_mb_strlen1(str) + n; n = n < 0 ? 0 : n; PG_RETURN_TEXT_P(ora_substr_text(str, 1, n)); } /**************************************************************** * PLVstr.right * * Syntax: * FUNCTION plvstr.right (string_in IN VARCHAR, * num_in INTEGER) * RETURN VARCHAR; * * Purpouse: * Returns last (right) num_in characters. * ****************************************************************/ Datum plvstr_right (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_P(0); int n = PG_GETARG_INT32(1); if (n < 0) n = ora_mb_strlen1(str) + n; n = (n < 0) ? 0 : n; PG_RETURN_TEXT_P(ora_substr_text(str, -n, -1)); } /**************************************************************** * PLVstr.substr2 * * Syntax: * FUNCTION plvstr.substr (string_in IN VARCHAR, * start INTEGER) * RETURN VARCHAR; * * Purpouse: * Returns substring started on start_in to end * ****************************************************************/ Datum plvstr_substr2 (PG_FUNCTION_ARGS) { return oracle_substr2(fcinfo); } /**************************************************************** * PLVstr.substr3 * * Syntax: * FUNCTION plvstr.substr (string_in IN VARCHAR, * start INTEGER, len INTEGER) * RETURN VARCHAR; * * Purpouse: * Returns len chars from start_in position * ****************************************************************/ Datum plvstr_substr3 (PG_FUNCTION_ARGS) { return oracle_substr3(fcinfo); } /**************************************************************** * PLVchr.nth * * Syntax: * FUNCTION plvchr.nth (string_in IN VARCHAR, * nth_in IN INTEGER) * RETURN VARCHAR; * * Purpouse: * Call this function to return the Nth character in a string. * ****************************************************************/ Datum plvchr_nth (PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(ora_substr(PG_GETARG_DATUM(0), PG_GETARG_INT32(1), 1)); } /**************************************************************** * PLVchr.first * * Syntax: * FUNCTION plvchr.first (string_in IN VARCHAR, * RETURN VARCHAR; * * Purpouse: * Call this function to return the first character in a string. * ****************************************************************/ Datum plvchr_first (PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(ora_substr(PG_GETARG_DATUM(0), 1, 1)); } /**************************************************************** * PLVchr.last * * Syntax: * FUNCTION plvchr.last (string_in IN VARCHAR, * RETURN VARCHAR; * * Purpouse: * Call this function to return the last character in a string. * ****************************************************************/ Datum plvchr_last (PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(ora_substr(PG_GETARG_DATUM(0), -1, 1)); } /**************************************************************** * PLVchr.is_blank, plvchr.is_digit, ... * * Syntax: * FUNCTION plvchr.is_kind (string_in IN VARCHAR, * kind INT) * RETURN VARCHAR; * * Purpouse: * Call this function to see if a character is blank, ... * 1 blank, 2 digit, 3 quote, 4 other, 5 letter * ****************************************************************/ static bool is_kind(char c, int kind) { switch (kind) { case 1: return c == ' '; case 2: return '0' <= c && c <= '9'; case 3: return c == '\''; case 4: return (32 <= c && c <= 47) || (58 <= c && c <= 64) || (91 <= c && c <= 96) || (123 <= c && c <= 126); case 5: return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); default: PARAMETER_ERROR("Second parametr isn't in enum {1,2,3,4,5}"); return false; } } Datum plvchr_is_kind_i (PG_FUNCTION_ARGS) { int32 c = PG_GETARG_INT32(0); int32 k = PG_GETARG_INT32(1); PG_RETURN_INT32(is_kind((char)c,k)); } Datum plvchr_is_kind_a (PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); int32 k = PG_GETARG_INT32(1); char c; NON_EMPTY_CHECK(str); if (pg_database_encoding_max_length() > 1) { if (_pg_mblen(VARDATA_ANY(str)) > 1) PG_RETURN_INT32( (k == 5) ); } c = *VARDATA_ANY(str); PG_RETURN_INT32(is_kind(c,k)); } /**************************************************************** * PLVchr.char_name * * Syntax: * FUNCTION plvchr.char_name (letter_in IN VARCHAR) * RETURN VARCHAR; * * Purpouse: * Returns the name of the character to ascii code as a VARCHAR. * ****************************************************************/ Datum plvchr_char_name(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); text *result; unsigned char c; NON_EMPTY_CHECK(str); c = (unsigned char)*(VARDATA_ANY(str)); if (c >= lengthof(char_names)) result = ora_substr_text(str, 1, 1); else result = cstring_to_text(char_names[c]); PG_RETURN_TEXT_P(result); } /**************************************************************** * substr * * Syntax: * FUNCTION substr (string, start_position, [length]) * RETURN VARCHAR; * * Purpouse: * Returns len chars from start_in position, compatible with Oracle * ****************************************************************/ Datum oracle_substr3(PG_FUNCTION_ARGS) { int32 len = PG_GETARG_INT32(2); if (len < 0) PG_RETURN_NULL(); PG_RETURN_TEXT_P(ora_substr(PG_GETARG_DATUM(0), PG_GETARG_INT32(1), len)); } Datum oracle_substr2(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(ora_substr(PG_GETARG_DATUM(0), PG_GETARG_INT32(1), -1)); } static text* ora_concat2(text *str1, text *str2) { int l1; int l2; text *result; l1 = VARSIZE_ANY_EXHDR(str1); l2 = VARSIZE_ANY_EXHDR(str2); result = palloc(l1+l2+VARHDRSZ); memcpy(VARDATA(result), VARDATA_ANY(str1), l1); memcpy(VARDATA(result) + l1, VARDATA_ANY(str2), l2); SET_VARSIZE(result, l1 + l2 + VARHDRSZ); return result; } static text* ora_concat3(text *str1, text *str2, text *str3) { int l1; int l2; int l3; text *result; l1 = VARSIZE_ANY_EXHDR(str1); l2 = VARSIZE_ANY_EXHDR(str2); l3 = VARSIZE_ANY_EXHDR(str3); result = palloc(l1+l2+l3+VARHDRSZ); memcpy(VARDATA(result), VARDATA_ANY(str1), l1); memcpy(VARDATA(result) + l1, VARDATA_ANY(str2), l2); memcpy(VARDATA(result) + l1+l2, VARDATA_ANY(str3), l3); SET_VARSIZE(result, l1 + l2 + l3 + VARHDRSZ); return result; } /**************************************************************** * PLVchr.swap * * Syntax: * FUNCTION swap * (string_in IN VARCHAR2, * replace_in IN VARCHAR2, * start_in IN INTEGER := 1, * oldlen_in IN INTEGER := NULL) * RETURN VARCHAR2 * * Purpouse: * Replace a substring in a string with a specified string. * ****************************************************************/ Datum plvstr_swap(PG_FUNCTION_ARGS) { text *string_in; text *replace_in; int start_in = 1; int oldlen_in; int v_len; if (PG_ARGISNULL(0)) PG_RETURN_NULL(); else string_in = PG_GETARG_TEXT_P(0); if (PG_ARGISNULL(1)) PG_RETURN_NULL(); else replace_in = PG_GETARG_TEXT_P(1); if (!PG_ARGISNULL(2)) start_in = PG_GETARG_INT32(2); if (PG_ARGISNULL(3)) oldlen_in = ora_mb_strlen1(replace_in); else oldlen_in = PG_GETARG_INT32(3); v_len = ora_mb_strlen1(string_in); start_in = start_in > 0 ? start_in : v_len + start_in + 1; if (start_in == 0 || start_in > v_len) PG_RETURN_TEXT_P(TextPCopy(string_in)); else if (start_in == 1) PG_RETURN_TEXT_P(ora_concat2( replace_in, ora_substr_text(string_in, oldlen_in+1, -1))); else PG_RETURN_TEXT_P(ora_concat3( ora_substr_text(string_in, 1, start_in - 1), replace_in, ora_substr_text(string_in, start_in + oldlen_in, -1))); } /**************************************************************** * PLVchr.betwn * * Find the Substring Between Start and End Locations * * Syntax: * FUNCTION plvstr.betwn (string_in IN VARCHAR2, * start_in IN INTEGER, * end_in IN INTEGER, * inclusive IN BOOLEAN := TRUE) * RETURN VARCHAR2; * * FUNCTION plvstr.betwn (string_in IN VARCHAR2, * start_in IN VARCHAR2, * end_in IN VARCHAR2 := NULL, * startnth_in IN INTEGER := 1, * endnth_in IN INTEGER := 1, * inclusive IN BOOLEAN := TRUE, * gotoend IN BOOLEAN := FALSE) * RETURN VARCHAR2; * * Purpouse: * Call this function to extract a sub-string from a string. This * function is overloaded. You can either provide the start and end * locations or you can provide start and end substrings. * ****************************************************************/ Datum plvstr_betwn_i(PG_FUNCTION_ARGS) { text *string_in = PG_GETARG_TEXT_P(0); int start_in = PG_GETARG_INT32(1); int end_in = PG_GETARG_INT32(2); bool inclusive = PG_GETARG_BOOL(3); if ((start_in < 0 && end_in > 0) || (start_in > 0 && end_in < 0) || (start_in > end_in)) PARAMETER_ERROR("Wrong positions."); if (start_in < 0) { int v_len = ora_mb_strlen1(string_in); start_in = v_len + start_in + 1; end_in = v_len + start_in + 1; } if (!inclusive) { start_in += 1; end_in -= 1; if (start_in > end_in) PG_RETURN_TEXT_P(cstring_to_text("")); } PG_RETURN_TEXT_P(ora_substr_text(string_in, start_in, end_in - start_in + 1)); } Datum plvstr_betwn_c(PG_FUNCTION_ARGS) { text *string_in; text *start_in; text *end_in; int startnth_in; int endnth_in; bool inclusive; bool gotoend; int v_start; int v_end; if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(3) || PG_ARGISNULL(4) || PG_ARGISNULL(5) || PG_ARGISNULL(6)) PG_RETURN_NULL(); string_in = PG_GETARG_TEXT_P(0); start_in = PG_GETARG_TEXT_P(1); end_in = PG_ARGISNULL(2) ? start_in : PG_GETARG_TEXT_P(2); startnth_in = PG_GETARG_INT32(3); endnth_in = PG_GETARG_INT32(4); inclusive = PG_GETARG_BOOL(5); gotoend = PG_GETARG_BOOL(6); if (startnth_in == 0) { v_start = 1; v_end = ora_instr(string_in, end_in, 1, endnth_in); } else { v_start = ora_instr(string_in, start_in, 1, startnth_in); v_end = ora_instr(string_in, end_in, v_start + 1, endnth_in); } if (v_start == 0) PG_RETURN_NULL(); if (!inclusive) { if (startnth_in > 0) v_start += ora_mb_strlen1(start_in); v_end -= 1; } else v_end += (ora_mb_strlen1(end_in) - 1); if (((v_start > v_end) && (v_end > 0)) || (v_end <= 0 && !gotoend)) PG_RETURN_NULL(); if (v_end <= 0) v_end = ora_mb_strlen1(string_in); PG_RETURN_TEXT_P(ora_substr_text(string_in, v_start, v_end - v_start + 1)); } orafce-VERSION_3_0_6/plvsubst.c000066400000000000000000000127061221300436000163510ustar00rootroot00000000000000/* This code implements one part of functonality of free available library PL/Vision. Please look www.quest.com Original author: Steven Feuerstein, 1996 - 2002 PostgreSQL implementation author: Pavel Stehule, 2006 This module is under BSD Licence History: 1.0. first public version 22. September 2006 */ #include "postgres.h" #include "utils/builtins.h" #include "utils/numeric.h" #include "string.h" #include "stdlib.h" #include "utils/pg_locale.h" #include "mb/pg_wchar.h" #include "lib/stringinfo.h" #include "catalog/pg_type.h" #include "libpq/pqformat.h" #include "utils/array.h" #include "utils/memutils.h" #include "utils/lsyscache.h" #include "access/tupmacs.h" #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(plvsubst_string_array); PG_FUNCTION_INFO_V1(plvsubst_string_string); PG_FUNCTION_INFO_V1(plvsubst_setsubst); PG_FUNCTION_INFO_V1(plvsubst_setsubst_default); PG_FUNCTION_INFO_V1(plvsubst_subst); #define C_SUBST "%s" text *c_subst = NULL; static void init_c_subst() { if (!c_subst) { MemoryContext oldctx; oldctx = MemoryContextSwitchTo(TopMemoryContext); c_subst = cstring_to_text(C_SUBST); MemoryContextSwitchTo(oldctx); } } static void set_c_subst(text *sc) { MemoryContext oldctx; if (c_subst) pfree(c_subst); oldctx = MemoryContextSwitchTo(TopMemoryContext); c_subst = sc ? TextPCopy(sc) : cstring_to_text(C_SUBST); MemoryContextSwitchTo(oldctx); } static text* plvsubst_string(text *template_in, ArrayType *vals_in, text *c_subst, FunctionCallInfo fcinfo) { ArrayType *v = vals_in; int nitems, *dims, ndims; char *p; int16 typlen; bool typbyval; char typalign; char typdelim; Oid typelem; Oid typiofunc; FmgrInfo proc; int i = 0, items = 0; StringInfo sinfo; const char *template_str; int template_len; char *sizes; int *positions; int subst_mb_len; int subst_len; const bits8 *bitmap; int bitmask; if (v != NULL && (ndims = ARR_NDIM(v)) > 0) { if (ndims != 1) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid parameter"), errdetail("Array of arguments has wrong dimension: %d", ndims))); p = ARR_DATA_PTR(v); dims = ARR_DIMS(v); nitems = ArrayGetNItems(ndims, dims); bitmap = ARR_NULLBITMAP(v); get_type_io_data(ARR_ELEMTYPE(v), IOFunc_output, &typlen, &typbyval, &typalign, &typdelim, &typelem, &typiofunc); fmgr_info_cxt(typiofunc, &proc, fcinfo->flinfo->fn_mcxt); } else { nitems = 0; p = NULL; bitmap = NULL; } template_str = VARDATA(template_in); template_len = ora_mb_strlen(template_in, &sizes, &positions); subst_mb_len = ora_mb_strlen1(c_subst); subst_len = VARSIZE_ANY_EXHDR(c_subst); sinfo = makeStringInfo(); bitmask = 1; for (i = 0; i < template_len; i++) { if (strncmp(&template_str[positions[i]], VARDATA(c_subst), subst_len) == 0) { Datum itemvalue; char *value; if (items++ < nitems) { if (bitmap && (*bitmap & bitmask) == 0) value = pstrdup("NULL"); else { itemvalue = fetch_att(p, typbyval, typlen); value = DatumGetCString(FunctionCall3(&proc, itemvalue, ObjectIdGetDatum(typelem), Int32GetDatum(-1))); p = att_addlength_pointer(p, typlen, p); p = (char *) att_align_nominal(p, typalign); } appendStringInfoString(sinfo, value); pfree(value); if (bitmap) { bitmask <<= 1; if (bitmask == 0x100) { bitmap++; bitmask = 1; } } } else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("too few parameters specified for template string"))); i += subst_mb_len - 1; } else appendBinaryStringInfo(sinfo, &template_str[positions[i]], sizes[i]); } return cstring_to_text(sinfo->data); } Datum plvsubst_string_array(PG_FUNCTION_ARGS) { init_c_subst(); if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) PG_RETURN_NULL(); PG_RETURN_TEXT_P(plvsubst_string(PG_GETARG_TEXT_P(0), PG_GETARG_ARRAYTYPE_P(1), PG_ARGISNULL(2) ? c_subst : PG_GETARG_TEXT_P(2), fcinfo)); } Datum plvsubst_string_string(PG_FUNCTION_ARGS) { Datum r; ArrayType *array; FunctionCallInfoData locfcinfo; #if PG_VERSION_NUM >= 90100 Oid collation = PG_GET_COLLATION(); #endif init_c_subst(); if (PG_ARGISNULL(0) || PG_ARGISNULL(1)) PG_RETURN_NULL(); /* * I can't use DirectFunctionCall2 */ #if PG_VERSION_NUM >= 90100 InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 2, collation, NULL, NULL); #else InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 2, NULL, NULL); #endif locfcinfo.arg[0] = PG_GETARG_DATUM(1); locfcinfo.arg[1] = PG_GETARG_IF_EXISTS(2, DATUM, CStringGetTextDatum(",")); locfcinfo.argnull[0] = false; locfcinfo.argnull[1] = false; r = text_to_array(&locfcinfo); if (locfcinfo.isnull || r == (Datum) 0) array = NULL; else array = DatumGetArrayTypeP(r); PG_RETURN_TEXT_P(plvsubst_string(PG_GETARG_TEXT_P(0), array, PG_GETARG_IF_EXISTS(3, TEXT_P, c_subst), fcinfo)); } Datum plvsubst_setsubst(PG_FUNCTION_ARGS) { if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("substition is NULL"), errdetail("Substitution keyword may not be NULL."))); set_c_subst(PG_GETARG_TEXT_P(0)); PG_RETURN_VOID(); } Datum plvsubst_setsubst_default(PG_FUNCTION_ARGS) { set_c_subst(NULL); PG_RETURN_VOID(); } Datum plvsubst_subst(PG_FUNCTION_ARGS) { init_c_subst(); PG_RETURN_TEXT_P(TextPCopy(c_subst)); } orafce-VERSION_3_0_6/putline.c000066400000000000000000000161161221300436000161460ustar00rootroot00000000000000#include "postgres.h" #include "funcapi.h" #include "access/heapam.h" #if PG_VERSION_NUM >= 90300 #include "access/htup_details.h" #endif #include "catalog/pg_type.h" #include "lib/stringinfo.h" #undef USE_SSL #undef ENABLE_GSS #include "libpq/libpq.h" #include "libpq/pqformat.h" #include "utils/memutils.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" #include "orafunc.h" #include "builtins.h" #if defined(WIN32) && !defined(_MSC_VER) extern PGDLLIMPORT ProtocolVersion FrontendProtocol; /* for mingw */ #endif /* * TODO: BUFSIZE_UNLIMITED to be truely unlimited (or INT_MAX), * and allocate buffers on-demand. */ #define BUFSIZE_DEFAULT 20000 #define BUFSIZE_MIN 2000 #define BUFSIZE_MAX 1000000 #define BUFSIZE_UNLIMITED BUFSIZE_MAX static bool is_server_output = false; static char *buffer = NULL; static int buffer_size = 0; /* allocated bytes in buffer */ static int buffer_len = 0; /* used bytes in buffer */ static int buffer_get = 0; /* retrieved bytes in buffer */ static void add_str(const char *str, int len); static void add_text(text *str); static void add_newline(void); static void send_buffer(void); /* * Aux. buffer functionality */ static void add_str(const char *str, int len) { /* Discard all buffers if get_line was called. */ if (buffer_get > 0) { buffer_get = 0; buffer_len = 0; } if (buffer_len + len > buffer_size) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_RESOURCES), errmsg("buffer overflow"), errdetail("Buffer overflow, limit of %d bytes", buffer_size), errhint("Increase buffer size in dbms_output.enable() next time"))); memcpy(buffer + buffer_len, str, len); buffer_len += len; buffer[buffer_len] = '\0'; } static void add_text(text *str) { add_str(VARDATA_ANY(str), VARSIZE_ANY_EXHDR(str)); } static void add_newline(void) { add_str("", 1); /* add \0 */ if (is_server_output) send_buffer(); } static void send_buffer() { if (buffer_len > 0) { StringInfoData msgbuf; char *cursor = buffer; while (--buffer_len > 0) { if (*cursor == '\0') *cursor = '\n'; cursor++; } if (*cursor != '\0') ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("internal error"), errdetail("Wrong message format detected"))); pq_beginmessage(&msgbuf, 'N'); /* * FrontendProtocol is not avalilable in MSVC because it is not * PGDLLEXPORT'ed. So, we assume always the protocol >= 3. */ #ifndef _MSC_VER if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3) { #endif pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_PRIMARY); pq_sendstring(&msgbuf, buffer); pq_sendbyte(&msgbuf, '\0'); #ifndef _MSC_VER } else { *cursor++ = '\n'; *cursor = '\0'; pq_sendstring(&msgbuf, buffer); } #endif pq_endmessage(&msgbuf); pq_flush(); } } /* * Aux db functions * */ static void dbms_output_enable_internal(int32 n_buf_size) { /* We allocate +2 bytes for an end-of-line and a string terminator. */ if (buffer == NULL) { buffer = MemoryContextAlloc(TopMemoryContext, n_buf_size + 2); buffer_size = n_buf_size; buffer_len = 0; buffer_get = 0; } else if (n_buf_size > buffer_len) { /* We cannot shrink buffer less than current length. */ buffer = repalloc(buffer, n_buf_size + 2); buffer_size = n_buf_size; } } PG_FUNCTION_INFO_V1(dbms_output_enable_default); Datum dbms_output_enable_default(PG_FUNCTION_ARGS) { dbms_output_enable_internal(BUFSIZE_DEFAULT); PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(dbms_output_enable); Datum dbms_output_enable(PG_FUNCTION_ARGS) { int32 n_buf_size; if (PG_ARGISNULL(0)) n_buf_size = BUFSIZE_UNLIMITED; else { n_buf_size = PG_GETARG_INT32(0); if (n_buf_size > BUFSIZE_MAX) { n_buf_size = BUFSIZE_MAX; elog(WARNING, "Limit decreased to %d bytes.", BUFSIZE_MAX); } else if (n_buf_size < BUFSIZE_MIN) { n_buf_size = BUFSIZE_MIN; elog(WARNING, "Limit increased to %d bytes.", BUFSIZE_MIN); } } dbms_output_enable_internal(n_buf_size); PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(dbms_output_disable); Datum dbms_output_disable(PG_FUNCTION_ARGS) { if (buffer) pfree(buffer); buffer = NULL; buffer_size = 0; buffer_len = 0; buffer_get = 0; PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(dbms_output_serveroutput); Datum dbms_output_serveroutput(PG_FUNCTION_ARGS) { is_server_output = PG_GETARG_BOOL(0); if (is_server_output && !buffer) dbms_output_enable_internal(BUFSIZE_DEFAULT); PG_RETURN_VOID(); } /* * main functions */ PG_FUNCTION_INFO_V1(dbms_output_put); Datum dbms_output_put(PG_FUNCTION_ARGS) { if (buffer) add_text(PG_GETARG_TEXT_PP(0)); PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(dbms_output_put_line); Datum dbms_output_put_line(PG_FUNCTION_ARGS) { if (buffer) { add_text(PG_GETARG_TEXT_PP(0)); add_newline(); } PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(dbms_output_new_line); Datum dbms_output_new_line(PG_FUNCTION_ARGS) { if (buffer) add_newline(); PG_RETURN_VOID(); } static text * dbms_output_next(void) { if (buffer_get < buffer_len) { text *line = cstring_to_text(buffer + buffer_get); buffer_get += VARSIZE_ANY_EXHDR(line) + 1; return line; } else return NULL; } PG_FUNCTION_INFO_V1(dbms_output_get_line); Datum dbms_output_get_line(PG_FUNCTION_ARGS) { TupleDesc tupdesc; Datum result; HeapTuple tuple; Datum values[2]; bool nulls[2] = { false, false }; text *line; /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); if ((line = dbms_output_next()) != NULL) { values[0] = PointerGetDatum(line); values[1] = Int32GetDatum(0); /* 0: succeeded */ } else { nulls[0] = true; values[1] = Int32GetDatum(1); /* 1: failed */ } tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); PG_RETURN_DATUM(result); } PG_FUNCTION_INFO_V1(dbms_output_get_lines); Datum dbms_output_get_lines(PG_FUNCTION_ARGS) { TupleDesc tupdesc; Datum result; HeapTuple tuple; Datum values[2]; bool nulls[2] = { false, false }; text *line; int32 max_lines = PG_GETARG_INT32(0); int32 n; ArrayBuildState *astate = NULL; /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); for (n = 0; n < max_lines && (line = dbms_output_next()) != NULL; n++) { astate = accumArrayResult(astate, PointerGetDatum(line), false, TEXTOID, CurrentMemoryContext); } /* 0: lines as text array */ if (n > 0) values[0] = makeArrayResult(astate, CurrentMemoryContext); else { int16 typlen; bool typbyval; char typalign; ArrayType *arr; get_typlenbyvalalign(TEXTOID, &typlen, &typbyval, &typalign); arr = construct_md_array( NULL, #if PG_VERSION_NUM >= 80200 NULL, #endif 0, NULL, NULL, TEXTOID, typlen, typbyval, typalign); values[0] = PointerGetDatum(arr); } /* 1: # of lines as integer */ values[1] = Int32GetDatum(n); tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); PG_RETURN_DATUM(result); } orafce-VERSION_3_0_6/random.c000066400000000000000000000170651221300436000157520ustar00rootroot00000000000000/* * Note - I don't find any documentation about pseudo random * number generator used in Oracle. So the results of these * functions should be different then native Oracle functions! * This library is based on ANSI C implementation. */ #include "postgres.h" #include "access/hash.h" #include "lib/stringinfo.h" #include "utils/builtins.h" #include "stdlib.h" #include "time.h" #include #include #include "orafunc.h" #include "builtins.h" PG_FUNCTION_INFO_V1(dbms_random_initialize); PG_FUNCTION_INFO_V1(dbms_random_normal); PG_FUNCTION_INFO_V1(dbms_random_random); PG_FUNCTION_INFO_V1(dbms_random_seed_int); PG_FUNCTION_INFO_V1(dbms_random_seed_varchar); PG_FUNCTION_INFO_V1(dbms_random_string); PG_FUNCTION_INFO_V1(dbms_random_terminate); PG_FUNCTION_INFO_V1(dbms_random_value); PG_FUNCTION_INFO_V1(dbms_random_value_range); /* Coefficients in rational approximations. */ static const double a[] = { -3.969683028665376e+01, 2.209460984245205e+02, -2.759285104469687e+02, 1.383577518672690e+02, -3.066479806614716e+01, 2.506628277459239e+00 }; static const double b[] = { -5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02, 6.680131188771972e+01, -1.328068155288572e+01 }; static const double c[] = { -7.784894002430293e-03, -3.223964580411365e-01, -2.400758277161838e+00, -2.549732539343734e+00, 4.374664141464968e+00, 2.938163982698783e+00 }; static const double d[] = { 7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00, 3.754408661907416e+00 }; #define LOW 0.02425 #define HIGH 0.97575 static double ltqnorm(double p); /* * dbms_random.initialize (seed IN BINARY_INTEGER) * * Initialize package with a seed value */ Datum dbms_random_initialize(PG_FUNCTION_ARGS) { int seed = PG_GETARG_INT32(0); srand(seed); PG_RETURN_VOID(); } /* * dbms_random.normal() RETURN NUMBER; * * Returns random numbers in a standard normal distribution */ Datum dbms_random_normal(PG_FUNCTION_ARGS) { float8 result; /* need random value from (0..1) */ result = ltqnorm(((double) rand() + 1) / ((double) RAND_MAX + 2)); PG_RETURN_FLOAT8(result); } /* * dbms_random.random() RETURN BINARY_INTEGER; * * Generate Random Numeric Values */ Datum dbms_random_random(PG_FUNCTION_ARGS) { int result; /* * Oracle generator generates numebers from -2^31 and +2^31, * ANSI C only from 0 .. RAND_MAX, */ result = 2 * (rand() - RAND_MAX / 2); PG_RETURN_INT32(result); } /* * dbms_random.seed(val IN BINARY_INTEGER); * dbms_random.seed(val IN VARCHAR2); * * Reset the seed value */ Datum dbms_random_seed_int(PG_FUNCTION_ARGS) { int seed = PG_GETARG_INT32(0); srand(seed); PG_RETURN_VOID(); } /* * Atention! * * Hash function should be changed between mayor pg versions, * don't use text based seed for regres tests! */ Datum dbms_random_seed_varchar(PG_FUNCTION_ARGS) { text *key = PG_GETARG_TEXT_P(0); Datum seed; seed = hash_any((unsigned char *) VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); srand((int) seed); PG_RETURN_VOID(); } /* * dbms_random.string(opt IN CHAR, len IN NUMBER) RETURN VARCHAR2; * * Create Random Strings * opt seed values: * 'a','A' alpha characters only (mixed case) * 'l','L' lower case alpha characters only * 'p','P' any printable characters * 'u','U' upper case alpha characters only * 'x','X' any alpha-numeric characters (upper) */ static text * random_string(const char *charset, int chrset_size, int len) { StringInfo str; int i; str = makeStringInfo(); for (i = 0; i < len; i++) { int pos = (int) ((double) rand() / ((double) RAND_MAX + 1) * chrset_size); appendStringInfoChar(str, charset[pos]); } return cstring_to_text(str->data); } Datum dbms_random_string(PG_FUNCTION_ARGS) { char *option; int len; const char *charset; int chrset_size; const char *alpha_mixed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *lower_only = "abcdefghijklmnopqrstuvwxyz"; const char *upper_only = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *upper_alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *printable = "`1234567890-=qwertyuiop[]asdfghjkl;'zxcvbnm,./!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVVBNM<>? "; option = text_to_cstring(PG_GETARG_TEXT_P(0)); len = PG_GETARG_INT32(1); switch (option[0]) { case 'a': case 'A': charset = alpha_mixed; chrset_size = strlen(alpha_mixed); break; case 'l': case 'L': charset = lower_only; chrset_size = strlen(lower_only); break; case 'u': case 'U': charset = upper_only; chrset_size = strlen(upper_only); break; case 'x': case 'X': charset = upper_alphanum; chrset_size = strlen(upper_alphanum); break; case 'p': case 'P': charset = printable; chrset_size = strlen(printable); break; default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("unknown option '%s'", option), errhint("available option \"aAlLuUxXpP\""))); /* be compiler a quiete */ charset = NULL; chrset_size = 0; } PG_RETURN_TEXT_P(random_string(charset, chrset_size, len)); } /* * dbms_random.terminate; * * Terminate use of the Package */ Datum dbms_random_terminate(PG_FUNCTION_ARGS) { /* do nothing */ PG_RETURN_VOID(); } /* * dbms_random.value() RETURN NUMBER; * * Gets a random number, greater than or equal to 0 and less than 1. */ Datum dbms_random_value(PG_FUNCTION_ARGS) { float8 result; /* result [0.0 - 1.0) */ result = (double) rand() / ((double) RAND_MAX + 1); PG_RETURN_FLOAT8(result); } /* * dbms_random.value(low NUMBER, high NUMBER) RETURN NUMBER * * Alternatively, you can get a random Oracle number x, * where x is greater than or equal to low and less than high */ Datum dbms_random_value_range(PG_FUNCTION_ARGS) { float8 low = PG_GETARG_FLOAT8(0); float8 high = PG_GETARG_FLOAT8(1); float8 result; if (low > high) PG_RETURN_NULL(); result = ((double) rand() / ((double) RAND_MAX + 1)) * ( high - low) + low; PG_RETURN_FLOAT8(result); } /* * Lower tail quantile for standard normal distribution function. * * This function returns an approximation of the inverse cumulative * standard normal distribution function. I.e., given P, it returns * an approximation to the X satisfying P = Pr{Z <= X} where Z is a * random variable from the standard normal distribution. * * The algorithm uses a minimax approximation by rational functions * and the result has a relative error whose absolute value is less * than 1.15e-9. * * Author: Peter J. Acklam * Time-stamp: 2002-06-09 18:45:44 +0200 * E-mail: jacklam@math.uio.no * WWW URL: http://www.math.uio.no/~jacklam * * C implementation adapted from Peter's Perl version */ static double ltqnorm(double p) { double q, r; errno = 0; if (p < 0 || p > 1) { errno = EDOM; return 0.0; } else if (p == 0) { errno = ERANGE; return -HUGE_VAL /* minus "infinity" */; } else if (p == 1) { errno = ERANGE; return HUGE_VAL /* "infinity" */; } else if (p < LOW) { /* Rational approximation for lower region */ q = sqrt(-2*log(p)); return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1); } else if (p > HIGH) { /* Rational approximation for upper region */ q = sqrt(-2*log(1-p)); return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1); } else { /* Rational approximation for central region */ q = p - 0.5; r = q*q; return (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q / (((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1); } } orafce-VERSION_3_0_6/shmmc.c000066400000000000000000000154011221300436000155710ustar00rootroot00000000000000/* * * Shared memory control - based on alocating chunks aligned on * asize array (fibonachi), and dividing free bigger block. * */ #include "postgres.h" #include "shmmc.h" #include "stdlib.h" #include "string.h" #include "orafunc.h" #define LIST_ITEMS 512 int context; typedef struct { size_t size; void* first_byte_ptr; bool dispossible; /* int16 context; */ } list_item; typedef struct { int list_c; int max_size; vardata data[1]; /* flexible array member */ } mem_desc; #define MAX_SIZE 82688 static size_t asize[] = { 32, 64, 96, 160, 256, 416, 672, 1088, 1760, 2848, 4608, 7456, 12064, 19520, 31584, 51104, 82688}; int *list_c = NULL; list_item *list = NULL; size_t max_size; int cycle = 0; /* align requested size */ static int ptr_comp(const void* a, const void* b) { list_item *_a = (list_item*) a; list_item *_b = (list_item*) b; return (long)_a->first_byte_ptr - (long)_b->first_byte_ptr; } char * ora_sstrcpy(char *str) { int len; char *result; len = strlen(str); if (NULL != (result = ora_salloc(len+1))) memcpy(result, str, len + 1); else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while allocation block %d bytes in shared memory.", len+1), errhint("Increase SHMEMMSGSZ and recompile package."))); return result; } char * ora_scstring(text *str) { int len; char *result; len = VARSIZE_ANY_EXHDR(str); if (NULL != (result = ora_salloc(len+1))) { memcpy(result, VARDATA_ANY(str), len); result[len] = '\0'; } else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while allocation block %d bytes in shared memory.", len+1), errhint("Increase SHMEMMSGSZ and recompile package."))); return result; } /* * Compact the list of slots, by merging adjacent unused slots into larger * slots. */ static void defragmentation() { int src, target; /* Sort the array to pointer order */ qsort(list, *list_c, sizeof(list_item), ptr_comp); /* Merge adjacent dispossible slots, and move up other slots */ target = 0; for (src = 0; src < *list_c; src++) { if (target > 0 && list[src].dispossible && list[target - 1].dispossible) { list[target - 1].size += list[src].size; } else { if (src != target) memcpy(&list[target], &list[src], sizeof(list_item)); target++; } } *list_c = target; } static size_t align_size(size_t size) { int i; /* default, we can allocate max MAX_SIZE memory block */ for (i = 0; i < 17; i++) if (asize[i] >= size) return asize[i]; ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("too much large memory block request"), errdetail("Failed while allocation block %lu bytes in shared memory.", (unsigned long) size), errhint("Increase MAX_SIZE constant, fill table a_size and recompile package."))); return 0; } /* initialize shared memory. It works in two modes, create and no create. No create is used for mounting shared memory buffer. Top of memory is used for list_item array. */ void ora_sinit(void *ptr, size_t size, bool create) { if (list == NULL) { mem_desc *m = (mem_desc*)ptr; list = (list_item*)m->data; list_c = &m->list_c; max_size = m->max_size = size; if (create) { list[0].size = size - sizeof(list_item)*LIST_ITEMS - sizeof(mem_desc); list[0].first_byte_ptr = ((char *) &m->data) + sizeof(list_item)*LIST_ITEMS; list[0].dispossible = true; *list_c = 1; } } } void* ora_salloc(size_t size) { size_t aligned_size; int repeat_c; void *ptr = NULL; aligned_size = align_size(size); for (repeat_c = 0; repeat_c < 2; repeat_c++) { size_t max_min = max_size; int select = -1; int i; /* find first good free block */ for (i = 0; i < *list_c; i++) { if (list[i].dispossible) { /* If this block is just the right size, return it */ if (list[i].size == aligned_size) { list[i].dispossible = false; ptr = list[i].first_byte_ptr; /* list[i].context = context; */ return ptr; } if (list[i].size > aligned_size && list[i].size < max_min) { max_min = list[i].size; select = i; } } } /* If no suitable free slot found, defragment and try again. */ if (select == -1 || *list_c == LIST_ITEMS) { defragmentation(); continue; } /* * A slot larger than required was found. Divide it to avoid wasting * space, and return the slot of the right size. */ list[*list_c].size = list[select].size - aligned_size; list[*list_c].first_byte_ptr = (char*)list[select].first_byte_ptr + aligned_size; list[*list_c].dispossible = true; list[select].size = aligned_size; list[select].dispossible = false; /* list[select].context = context; */ ptr = list[select].first_byte_ptr; *list_c += 1; break; } return ptr; } void ora_sfree(void* ptr) { int i; /* if (cycle++ % 100 == 0) { size_t suma = 0; for (i = 0; i < *list_c; i++) if (list[i].dispossible) suma += list[i].size; elog(NOTICE, "=============== FREE MEM REPORT === %10d ================", suma); } */ for (i = 0; i < *list_c; i++) if (list[i].first_byte_ptr == ptr) { list[i].dispossible = true; /* list[i].context = -1; */ memset(list[i].first_byte_ptr, '#', list[i].size); return; } ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("corrupted pointer"), errdetail("Failed while reallocating memory block in shared memory."), errhint("Report this bug to autors."))); } void* ora_srealloc(void *ptr, size_t size) { void *result; size_t aux_s = 0; int i; for (i = 0; i < *list_c; i++) if (list[i].first_byte_ptr == ptr) { if (align_size(size) <= list[i].size) return ptr; aux_s = list[i].size; } if (aux_s == 0) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("corrupted pointer"), errdetail("Failed while reallocating memory block in shared memory."), errhint("Report this bug to autors."))); if (NULL != (result = ora_salloc(size))) { memcpy(result, ptr, aux_s); ora_sfree(ptr); } return result; } /* * alloc shared memory, raise exception if not */ void* salloc(size_t size) { void* result; if (NULL == (result = ora_salloc(size))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while allocation block %lu bytes in shared memory.", (unsigned long) size), errhint("Increase SHMEMMSGSZ and recompile package."))); return result; } void* srealloc(void *ptr, size_t size) { void* result; if (NULL == (result = ora_srealloc(ptr, size))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed while reallocation block %lu bytes in shared memory.", (unsigned long) size), errhint("Increase SHMEMMSGSZ and recompile package."))); return result; } orafce-VERSION_3_0_6/shmmc.h000066400000000000000000000005101221300436000155710ustar00rootroot00000000000000#ifndef __SHMMC__ #define __SHMMC__ void ora_sinit(void *ptr, size_t size, bool create); void* ora_salloc(size_t size); void* ora_srealloc(void *ptr, size_t size); void ora_sfree(void* ptr); char* ora_sstrcpy(char *str); char* ora_scstring(text *str); void* salloc(size_t size); void* srealloc(void *ptr,size_t size); #endif orafce-VERSION_3_0_6/sql/000077500000000000000000000000001221300436000151145ustar00rootroot00000000000000orafce-VERSION_3_0_6/sql/aggregates.sql000066400000000000000000000053701221300436000177530ustar00rootroot00000000000000-- Tests for the aggregate listagg SELECT listagg(i::text) from generate_series(1,3) g(i); SELECT listagg(i::text, ',') from generate_series(1,3) g(i); SELECT coalesce(listagg(i::text), '') from (SELECT ''::text) g(i); SELECT coalesce(listagg(i::text), '') from generate_series(1,0) g(i); -- Tests for the aggregate median( real | double ) CREATE FUNCTION checkMedianRealOdd() RETURNS real AS $$ DECLARE med real; BEGIN CREATE TABLE median_test (salary real); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (NULL); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); SELECT into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianRealEven() RETURNS real AS $$ DECLARE med real; BEGIN CREATE TABLE median_test (salary real); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (1000); INSERT INTO median_test VALUES (4000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianDoubleOdd() RETURNS double precision AS $$ DECLARE med double precision; BEGIN CREATE TABLE median_test (salary double precision); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; CREATE FUNCTION checkMedianDoubleEven() RETURNS double precision AS $$ DECLARE med double precision; BEGIN CREATE TABLE median_test (salary double precision); INSERT INTO median_test VALUES (4500); INSERT INTO median_test VALUES (1500); INSERT INTO median_test VALUES (2100); INSERT INTO median_test VALUES (3600); INSERT INTO median_test VALUES (4000); INSERT INTO median_test VALUES (1000); select into med median(salary) from median_test; DROP TABLE median_test; return med; END; $$ LANGUAGE plpgsql; SELECT checkMedianRealOdd(); SELECT checkMedianRealEven(); SELECT checkMedianDoubleOdd(); SELECT checkMedianDoubleEven(); DROP FUNCTION checkMedianRealOdd(); DROP FUNCTION checkMedianRealEven(); DROP FUNCTION checkMedianDoubleOdd(); DROP FUNCTION checkMedianDoubleEven(); orafce-VERSION_3_0_6/sql/dbms_alert_session_A.sql000066400000000000000000000042041221300436000217540ustar00rootroot00000000000000\set ECHO all /* * DBMS_ALERT is used for one-way communication of one session to other. * * This session mainly sends signals for testing the alert functionality in * session B and C. * * The following alerts are used to ensure that signals are sent at correct * times to session B for testing. These signals are sent from session B * indicating completion of an event. * After the signal is received, the next required signal for testing is sent * from this session. */ SELECT dbms_alert.register('b1'); SELECT dbms_alert.register('b2'); SELECT dbms_alert.register('b3'); SELECT dbms_alert.register('b4'); SELECT dbms_alert.register('b5'); SELECT dbms_alert.signal('a1','Msg1 for a1'); SELECT dbms_alert.signal('a2','Msg1 for a2'); /* * Test: defered_signal * The signal is received only when the signalling transaction commits. * To test this, an explict BEGIN-COMMIT block is used. */ SELECT dbms_alert.signal('tds','Begin defered_signal test'); BEGIN; SELECT dbms_alert.signal('tds','Testing defered_signal'); /* The signal is received while transaction is running */ SELECT dbms_alert.waitone('b1',15); COMMIT; /* The signal is received after transaction completed. * After this the tds signal is received in session B indicating that the * signal is received only after commit. */ SELECT dbms_alert.waitone('b1',15); SELECT dbms_alert.waitone('b2',15); /* This signals a3 which is not registered in Session B */ SELECT dbms_alert.signal('a3','Msg1 for a3'); /* alert a4 is signalled soon after a3 */ SELECT dbms_alert.signal('a4','Test- Register after signal'); /* This signal indicates at remove() is called */ SELECT dbms_alert.waitone('b3',15); /* Send signal which is removed in session B */ SELECT dbms_alert.signal('a1','Msg2 for a1'); SELECT dbms_alert.waitone('b4',15); /* Send signal which is registered in B and not removed */ SELECT dbms_alert.signal('a4','Msg1 for a4'); /* This signal inidcates that removeall() is called */ SELECT dbms_alert.waitone('b5',15); /* Send a signal to test if session B receives it after removeall() */ SELECT dbms_alert.signal('a2','Msg2 for a2'); /* cleanup */ SELECT dbms_alert.removeall(); orafce-VERSION_3_0_6/sql/dbms_alert_session_B.sql000066400000000000000000000032271221300436000217610ustar00rootroot00000000000000\set ECHO all /* Register alerts */ SELECT dbms_alert.register('a1'); SELECT dbms_alert.register('a2'); SELECT dbms_alert.register('tds'); /* Test: multisession waitone */ SELECT dbms_alert.waitone('a1',10); /* Test: multisession waitany */ SELECT dbms_alert.waitany(2); /* Test defered_signal */ /* This indicated that the transaction has begun */ SELECT dbms_alert.waitone('tds',2); /* The signal will not be received because the transaction is running */ SELECT dbms_alert.waitone('tds',2); SELECT dbms_alert.signal('b1','Transaction still running'); SELECT dbms_alert.signal('b1','Transaction committed'); /* Since the transaction has commited, the signal will be received */ SELECT dbms_alert.waitone('tds',2); /* Signal session A to send msg1 for a3 */ SELECT dbms_alert.signal('b2','to check unregistered alert wait'); /* Test: wait for unregistered alert which is signaled*/ SELECT dbms_alert.waitone('a3',2); /* Test: Register after alert is signaled and wait */ SELECT dbms_alert.register('a4'); SELECT dbms_alert.waitone('a4',2); /* Test: remove one */ SELECT dbms_alert.remove('a1'); /* Signal session A to send msg2 for a1 */ SELECT dbms_alert.signal('b3','remove(a1) called'); /* Test: wait for removed alert */ SELECT dbms_alert.waitone('a1',2); /* Signal session A to send msg1 for a4 */ SELECT dbms_alert.signal('b4','to check unremoved alert'); /* Test: Check if unremoved alert is received */ SELECT dbms_alert.waitone('a4',2); /* Test removeall */ SELECT dbms_alert.removeall(); /* Signal session A to send msg2 for a2 */ SELECT dbms_alert.signal('b5','removeall called'); /* Test: Use waitany to see if any alert is received */ SELECT dbms_alert.waitany(2); orafce-VERSION_3_0_6/sql/dbms_alert_session_C.sql000066400000000000000000000004351221300436000217600ustar00rootroot00000000000000\set ECHO all /* Register alerts */ SELECT dbms_alert.register('a1'); SELECT dbms_alert.register('a2'); /* Test: multisession waitone */ SELECT dbms_alert.waitone('a1',2); /* Test: multisession waitany */ SELECT dbms_alert.waitany(2); /* cleanup */ SELECT dbms_alert.removeall(); orafce-VERSION_3_0_6/sql/dbms_output.sql000066400000000000000000000572351221300436000202160ustar00rootroot00000000000000\set ECHO none SET client_min_messages = warning; SET DATESTYLE TO ISO; SET client_encoding = utf8; \pset null '' \set ECHO all DROP FUNCTION dbms_output_test(); DROP TABLE dbms_output_test; -- DBMS_OUTPUT.DISABLE [0] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT_LINE [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20) := 'orafce'; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE'); PERFORM DBMS_OUTPUT.PUT_LINE (buff1); PERFORM DBMS_OUTPUT.PUT ('ABC'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT_LINE [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20) := 'ora'; buff2 VARCHAR(20) := 'f'; buff3 VARCHAR(20) := 'ce'; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.PUT ('F'); PERFORM DBMS_OUTPUT.PUT ('CE'); PERFORM DBMS_OUTPUT.PUT_LINE (''); PERFORM DBMS_OUTPUT.PUT ('ABC'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.PUT [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORA F CE'); PERFORM DBMS_OUTPUT.PUT_LINE (''); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORA'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [4] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1 '); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT REPLACE(buff, ' ', '') FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINE [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT regexp_replace(buff, E'\n', '', 'g') FROM dbms_output_test limit 1; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); buff1 VARCHAR(20); buff2 VARCHAR(20); buff3 VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff1,buff2,buff3,stts lines[1],lines[2],lines[3],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); INSERT INTO dbms_output_test VALUES (buff3, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); buff1 VARCHAR(20); buff2 VARCHAR(20); stts INTEGER := 2; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff1,buff2,stts lines[1],lines[2],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [4] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORA'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.GET_LINES [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT regexp_replace(buff, E'\n', '', 'g') FROM dbms_output_test limit 1; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.NEW_LINE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(20); buff2 VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.PUT ('FCE'); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff1,buff2,stts lines[1],lines[2],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); INSERT INTO dbms_output_test VALUES (buff2, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.NEW_LINE [2] CREATE TABLE dbms_output_test (buff VARCHAR(3000), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff1 VARCHAR(3000); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.ENABLE(2000); FOR j IN 1..1999 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); END LOOP; PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff1,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff1, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT buff FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.DISABLE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); PERFORM DBMS_OUTPUT.DISABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 4'); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 5'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.DISABLE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [1] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); status INTEGER; num INTEGER := 2000; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.ENABLE(2000); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [2] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.NEW_LINE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [3] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); INSERT INTO dbms_output_test VALUES (buff, stts); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [4] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); FOR j IN 1..2000 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); END LOOP; PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [5] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(NULL); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- DBMS_OUTPUT.ENABLE [6] CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); INSERT INTO dbms_output_test VALUES (buff, stts); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); SELECT * FROM dbms_output_test; DROP TABLE dbms_output_test; DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [1] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIn PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [2] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.NEW_LINE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); -- SERVEROUTPUT [3] CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); PERFORM DBMS_OUTPUT.DISABLE(); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ BEGIN PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); orafce-VERSION_3_0_6/sql/dbms_pipe.sql000066400000000000000000000031471221300436000176040ustar00rootroot00000000000000CREATE TYPE testt AS (x integer, y integer, v varchar); CREATE OR REPLACE FUNCTION st(integer, integer, varchar) RETURNS void AS $$ DECLARE t testt; r record; BEGIN t.x := $1; t.y := $2; t.v := $3; select into r 10,10,'boo'; PERFORM dbms_pipe.pack_message(t); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION sk() RETURNS void AS $$ DECLARE t testt; o testt; BEGIN t.x := 1; t.y := 2; t.v := 'Pavel Stehule'; RAISE NOTICE 'SEND'; PERFORM dbms_pipe.pack_message(t); PERFORM dbms_pipe.send_message('boo',4,10); RAISE NOTICE 'RECEIVE'; -- PERFORM dbms_pipe.receive_message('boo',4); -- SELECT INTO o * from dbms_pipe.unpack_message_record() as (x integer, y integer, v varchar); -- RAISE NOTICE 'received %', o.v; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION SessionA() RETURNS void AS $$ BEGIN FOR i IN 1..100000 LOOP PERFORM dbms_pipe.pack_message('Prvni '||i); PERFORM dbms_pipe.pack_message('Druhy '||i); RAISE NOTICE 'SEND'; IF dbms_pipe.send_message('pipe_name',4,10) = 1 THEN RAISE NOTICE 'Timeout'; PERFORM pg_sleep(5); PERFORM dbms_pipe.send_message('pipe_name',4,10); END IF; PERFORM pg_sleep(random()); END LOOP; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION SessionB() RETURNS void AS $$ BEGIN FOR i IN 1..100000 LOOP IF dbms_pipe.receive_message('pipe_name',4) = 1 THEN RAISE NOTICE 'Timeout'; PERFORM pg_sleep(5); CONTINUE; END IF; RAISE NOTICE 'RECEIVE % %', dbms_pipe.unpack_message_text(), dbms_pipe.unpack_message_text(); PERFORM pg_sleep(random()); END LOOP; END; $$ LANGUAGE plpgsql; orafce-VERSION_3_0_6/sql/dbms_pipe_session_A.sql000066400000000000000000000156501221300436000216110ustar00rootroot00000000000000\set ECHO none SET client_min_messages = warning; DROP TABLE IF EXISTS TEMP; CREATE TABLE TEMP(id integer,name text); INSERT INTO TEMP VALUES (1,'bob'),(2,'rob'),(3,'john'); DROP USER IF EXISTS pipe_test_owner; CREATE USER pipe_test_owner WITH CREATEUSER; SET client_min_messages = notice; -- Notify session B of 'pipe_test_owner' having been created. SELECT dbms_pipe.pack_message(1); SELECT dbms_pipe.send_message('pipe_test_owner_created_notifier'); -- Create a new connection under the userid of pipe_test_owner SET SESSION AUTHORIZATION pipe_test_owner; /* create an implicit pipe and sends message using * send_message(text,integer,integer) */ CREATE OR REPLACE FUNCTION send(pipename text) RETURNS void AS $$ BEGIN IF dbms_pipe.send_message(pipename,2,10) = 1 THEN RAISE NOTICE 'Timeout'; PERFORM pg_sleep(2); PERFORM dbms_pipe.send_message(pipename,2,10); END IF; END; $$ LANGUAGE plpgsql; -- Test pack_message for all supported types and send_message CREATE OR REPLACE FUNCTION createImplicitPipe() RETURNS void AS $$ DECLARE row TEMP%ROWTYPE; BEGIN PERFORM dbms_pipe.pack_message('Message From Session A'::text); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message('2013-01-01'::date); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00'::timestamp); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00-08'::timestamptz); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message(12345.6789::numeric); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message(12345::integer); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message(99999999999::bigint); PERFORM send('named_pipe'); PERFORM dbms_pipe.pack_message(E'\\201'::bytea); PERFORM send('named_pipe'); SELECT * INTO row FROM TEMP WHERE id=2; PERFORM dbms_pipe.pack_message(row); PERFORM send('named_pipe'); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION bulkSend() RETURNS void AS $$ DECLARE row TEMP%ROWTYPE; BEGIN PERFORM dbms_pipe.pack_message('Message From Session A'::text); PERFORM dbms_pipe.pack_message('2013-01-01'::date); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00'::timestamp); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00-08'::timestamptz); PERFORM dbms_pipe.pack_message(12345.6789::numeric); PERFORM dbms_pipe.pack_message(12345::integer); PERFORM dbms_pipe.pack_message(99999999999::bigint); PERFORM dbms_pipe.pack_message(E'\\201'::bytea); SELECT * INTO row FROM TEMP WHERE id=2; PERFORM dbms_pipe.pack_message(row); PERFORM send('named_pipe_2'); END; $$ LANGUAGE plpgsql; /* Creates an explicit pipe using either create_pipe(text,integer,bool), * create_pipe(text,integer) OR create_pipe(text). * In case third parameter (bool) absent, default is false, that is, it's a public pipe. */ CREATE OR REPLACE FUNCTION createPipe(name text,ver integer) RETURNS void AS $$ BEGIN IF ver = 3 THEN PERFORM dbms_pipe.create_pipe(name,4,true); ELSIF ver = 2 THEN PERFORM dbms_pipe.create_pipe(name,4); ELSE PERFORM dbms_pipe.create_pipe(name); END IF; END; $$ LANGUAGE plpgsql; /* Testing create_pipe for different versions, one of them, is the case of * private pipe */ CREATE OR REPLACE FUNCTION createExplicitPipe(pipename text,create_version integer) RETURNS void AS $$ DECLARE row TEMP%ROWTYPE; BEGIN PERFORM createPipe(pipename,create_version); PERFORM dbms_pipe.reset_buffer(); PERFORM dbms_pipe.pack_message('Message From Session A'::text); PERFORM send(pipename); PERFORM dbms_pipe.pack_message('2013-01-01'::date); PERFORM send(pipename); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00'::timestamp); PERFORM send(pipename); PERFORM dbms_pipe.pack_message('2013-01-01 09:00:00-08'::timestamptz); PERFORM send(pipename); PERFORM dbms_pipe.pack_message(12345.6789::numeric); PERFORM send(pipename); PERFORM dbms_pipe.pack_message(12345::integer); PERFORM send(pipename); PERFORM dbms_pipe.pack_message(99999999999::bigint); PERFORM send(pipename); PERFORM dbms_pipe.pack_message(E'\\201'::bytea); PERFORM send(pipename); SELECT * INTO row FROM TEMP WHERE id=2; PERFORM dbms_pipe.pack_message(row); PERFORM send(pipename); END; $$ LANGUAGE plpgsql; -- Test send_message(text) CREATE OR REPLACE FUNCTION checkSend1() RETURNS void AS $$ BEGIN PERFORM dbms_pipe.pack_message('checking one-argument send_message()'); PERFORM dbms_pipe.send_message('pipe_name_1'); END; $$ LANGUAGE plpgsql; -- Test send_message(text,integer) CREATE OR REPLACE FUNCTION checkSend2() RETURNS void AS $$ BEGIN PERFORM dbms_pipe.pack_message('checking two-argument send_message()'); IF dbms_pipe.send_message('pipe_name_2',2) = 1 THEN RAISE NOTICE 'Timeout'; PERFORM pg_sleep(2); PERFORM dbms_pipe.send_message('pipe_name_2',2); END IF; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION notifyDropTemp() RETURNS void AS $$ BEGIN PERFORM dbms_pipe.pack_message(1); PERFORM dbms_pipe.send_message('pipe_name_3'); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION checkUniqueSessionNameA() RETURNS void AS $$ BEGIN PERFORM dbms_pipe.pack_message(dbms_pipe.unique_session_name()); PERFORM dbms_pipe.send_message('pipe_name_4'); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION notify(pipename text) RETURNS void AS $$ BEGIN PERFORM dbms_pipe.pack_message(1); PERFORM dbms_pipe.send_message(pipename); END; $$ LANGUAGE plpgsql; \set ECHO all; SELECT createImplicitPipe(); -- Bulk send messages SELECT bulkSend(); -- An explicit private pipe SELECT notify('recv_private1_notifier'); SELECT createExplicitPipe('private_pipe_1',3); -- An explicit private pipe SELECT notify('recv_private2_notifier'); SELECT createExplicitPipe('private_pipe_2',3); -- An explicit public pipe (uses two-argument create_pipe) SELECT notify('recv_public1_notifier'); SELECT createExplicitPipe('public_pipe_3',2); -- An explicit public pipe (uses one-argument create_pipe) SELECT notify('recv_public2_notifier'); SELECT createExplicitPipe('public_pipe_4',1); -- tests send_message(text) SELECT checkSend1(); -- tests send_message(text,integer) SELECT checkSend2(); SELECT notifyDropTemp(); -- tests unique_session_name() SELECT checkUniqueSessionNameA(); DROP FUNCTION createImplicitPipe(); DROP FUNCTION createExplicitPipe(text,integer); DROP FUNCTION createPipe(text,integer); DROP FUNCTION checkSend1(); DROP FUNCTION checkSend2(); DROP FUNCTION checkUniqueSessionNameA(); DROP FUNCTION bulkSend(); DROP FUNCTION notifyDropTemp(); DROP FUNCTION notify(text); DROP FUNCTION send(text); orafce-VERSION_3_0_6/sql/dbms_pipe_session_B.sql000066400000000000000000000137071221300436000216130ustar00rootroot00000000000000\set ECHO none \set VERBOSITY terse --Wait for 'pipe_test_owner' created notification to be sent by session A SELECT dbms_pipe.receive_message('pipe_test_owner_created_notifier'); -- create new connection under the userid of 'pipe_test_owner' SET SESSION AUTHORIZATION pipe_test_owner; /* Tests receive_message(text,integer), next_item_type() and all versions of * unpack_message_() and purge(text) */ CREATE OR REPLACE FUNCTION receiveFrom(pipename text) RETURNS void AS $$ DECLARE typ INTEGER; BEGIN WHILE true LOOP PERFORM dbms_pipe.receive_message(pipename,2); SELECT dbms_pipe.next_item_type() INTO typ; IF typ = 0 THEN EXIT; ELSIF typ=9 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_number(); ELSIF typ=11 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_text(); ELSIF typ=12 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_date(); ELSIF typ=13 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_timestamp(); ELSIF typ=23 THEN RAISE NOTICE 'RECEIVE %: %', typ, encode(dbms_pipe.unpack_message_bytea(),'escape'); ELSIF typ=24 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_record(); END IF; END LOOP; PERFORM dbms_pipe.purge(pipename); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION bulkReceive() RETURNS void AS $$ DECLARE typ INTEGER; BEGIN IF dbms_pipe.receive_message('named_pipe_2',2) = 1 THEN RAISE NOTICE 'Timeout'; PERFORM pg_sleep(2); PERFORM dbms_pipe.receive_message('named_pipe_2',2); END IF; WHILE true LOOP SELECT dbms_pipe.next_item_type() INTO typ; IF typ = 0 THEN EXIT; ELSIF typ=9 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_number(); ELSIF typ=11 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_text(); ELSIF typ=12 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_date(); ELSIF typ=13 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_timestamp(); ELSIF typ=23 THEN RAISE NOTICE 'RECEIVE %: %', typ, encode(dbms_pipe.unpack_message_bytea()::bytea,'escape'); ELSIF typ=24 THEN RAISE NOTICE 'RECEIVE %: %', typ, dbms_pipe.unpack_message_record(); END IF; END LOOP; PERFORM dbms_pipe.purge('named_pipe_2'); END; $$ LANGUAGE plpgsql; -- Tests receive_message(text) CREATE OR REPLACE FUNCTION checkReceive1(pipename text) RETURNS void AS $$ BEGIN PERFORM dbms_pipe.receive_message(pipename); RAISE NOTICE 'RECEIVE %',dbms_pipe.unpack_message_text(); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION dropTempTable() RETURNS void AS $$ BEGIN WHILE dbms_pipe.receive_message('pipe_name_3') <> 0 LOOP CONTINUE; END LOOP; DROP TABLE TEMP; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION checkUniqueSessionNameB() RETURNS bool AS $$ DECLARE result bool; BEGIN PERFORM dbms_pipe.receive_message('pipe_name_4'); SELECT dbms_pipe.unpack_message_text() = dbms_pipe.unique_session_name() INTO result; RETURN result; END; $$ LANGUAGE plpgsql; \set ECHO all; -- Receives messages sent via an implicit pipe SELECT receiveFrom('named_pipe'); -- Bulk receive messages SELECT bulkReceive(); -- Receives messages sent via an explicit private pipe under the same user -- 'pipe_test_owner' SELECT dbms_pipe.receive_message('recv_private1_notifier'); SELECT receiveFrom('private_pipe_1'); -- Switch user to 'pipe_test_other' DROP USER IF EXISTS pipe_test_other; CREATE USER pipe_test_other; SET SESSION AUTHORIZATION pipe_test_other; -- Try to receive messages sent via an explicit private pipe under the user -- 'pipe_test_other' who is not the owner of pipe. -- insufficient privileges in case of 'private_pipe_2'. SELECT dbms_pipe.receive_message('recv_private2_notifier'); SELECT receiveFrom('private_pipe_2'); -- These are explicit private pipes created using create_pipe(text,integer) -- and create_pipe(text) SELECT dbms_pipe.receive_message('recv_public1_notifier'); SELECT receiveFrom('public_pipe_3'); SELECT dbms_pipe.receive_message('recv_public2_notifier'); SELECT receiveFrom('public_pipe_4'); -- Switch back to user 'pipe_test_owner' SET SESSION AUTHORIZATION pipe_test_owner; DROP USER pipe_test_other; -- Tests receive_message(text) SELECT checkReceive1('pipe_name_1'); SELECT checkReceive1('pipe_name_2'); -- Tests dbms_pipe.db_pipes view SELECT name, items, "limit", private, owner FROM dbms_pipe.db_pipes WHERE name LIKE 'private%' ORDER BY name; -- Tests dbms_pipe.__list_pipes(); attribute size is not included -- since it can be different across runs. SELECT name, items, "limit", private, owner FROM dbms_pipe.__list_pipes() AS (name varchar, items int4, siz int4, "limit" int4, private bool, owner varchar) WHERE name <> 'pipe_name_4' ORDER BY 1; -- Tests remove_pipe(text) SELECT dbms_pipe.remove_pipe('private_pipe_1'); SELECT dbms_pipe.remove_pipe('private_pipe_2'); SELECT dbms_pipe.remove_pipe('public_pipe_3'); SELECT dbms_pipe.remove_pipe('public_pipe_4'); SELECT dbms_pipe.purge('pipe_name_1'); SELECT dbms_pipe.purge('pipe_name_2'); -- Receives drop table notification from session A via 'pipe_name_3' SELECT dropTempTable(); SELECT dbms_pipe.purge('pipe_name_3'); -- tests unique_session_name() (uses 'pipe_name_4') SELECT checkUniqueSessionNameB(); SELECT dbms_pipe.purge('pipe_name_4'); DROP FUNCTION receiveFrom(text); DROP FUNCTION checkReceive1(text); DROP FUNCTION checkUniqueSessionNameB(); DROP FUNCTION bulkReceive(); DROP FUNCTION dropTempTable(); -- Perform a recieve on removed pipe resulting on timeout SELECT dbms_pipe.receive_message('public_pipe_4',2); SELECT dbms_pipe.purge('public_pipe_4'); SET SESSION AUTHORIZATION DEFAULT; DROP USER pipe_test_owner; orafce-VERSION_3_0_6/sql/dbms_random.sql000066400000000000000000000007721221300436000201300ustar00rootroot00000000000000-- Tests for package DBMS_RANDOM SELECT dbms_random.initialize(8); SELECT dbms_random.normal(); SELECT dbms_random.normal(); SELECT dbms_random.seed(8); SELECT dbms_random.random(); SELECT dbms_random.seed('test'); SELECT dbms_random.string('U',5); SELECT dbms_random.string('P',2); SELECT dbms_random.string('x',4); SELECT dbms_random.string('a',2); SELECT dbms_random.string('l',3); SELECT dbms_random.seed(5); SELECT dbms_random.value(); SELECT dbms_random.value(10,15); SELECT dbms_random.terminate(); orafce-VERSION_3_0_6/sql/dbms_utility.sql000066400000000000000000000041521221300436000203470ustar00rootroot00000000000000\set ECHO none \pset format unaligned /* * Test for dbms_utility.format_call_stack(char mode). * Mode is hex. * The callstack returned is passed to regex_replace function. * Regex_replace replaces the function oid from the stack with zero. * This is done to avoid random results due to different oids generated. * Also the line number and () of the function is removed since it is different * across different pg version. */ CREATE OR REPLACE FUNCTION checkHexCallStack() returns text as $$ DECLARE stack text; BEGIN select * INTO stack from dbms_utility.format_call_stack('o'); select * INTO stack from regexp_replace(stack,'[ 0-9a-fA-F]{4}[0-9a-fA-F]{4}',' 0','g'); select * INTO stack from regexp_replace(stack,'[45()]','','g'); return stack; END; $$ LANGUAGE plpgsql; /* * Test for dbms_utility.format_call_stack(char mode). * Mode is integer. */ CREATE OR REPLACE FUNCTION checkIntCallStack() returns text as $$ DECLARE stack text; BEGIN select * INTO stack from dbms_utility.format_call_stack('p'); select * INTO stack from regexp_replace(stack,'[ 0-9]{3}[0-9]{5}',' 0','g'); select * INTO stack from regexp_replace(stack,'[45()]','','g'); return stack; END; $$ LANGUAGE plpgsql; /* * Test for dbms_utility.format_call_stack(char mode). * Mode is integer with unpadded output. */ CREATE OR REPLACE FUNCTION checkIntUnpaddedCallStack() returns text as $$ DECLARE stack text; BEGIN select * INTO stack from dbms_utility.format_call_stack('s'); select * INTO stack from regexp_replace(stack,'[0-9]{5,}','0','g'); select * INTO stack from regexp_replace(stack,'[45()]','','g'); return stack; END; $$ LANGUAGE plpgsql; select * from checkHexCallStack(); select * from checkIntCallStack(); select * from checkIntUnpaddedCallStack(); DROP FUNCTION checkHexCallStack(); DROP FUNCTION checkIntCallStack(); DROP FUNCTION checkIntUnpaddedCallStack(); orafce-VERSION_3_0_6/sql/files.sql000066400000000000000000000106751221300436000167500ustar00rootroot00000000000000SET client_min_messages = NOTICE; \set VERBOSITY terse \set ECHO all CREATE OR REPLACE FUNCTION gen_file(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; BEGIN f := utl_file.fopen(dir, 'regress_orafce.txt', 'w'); PERFORM utl_file.put_line(f, 'ABC'); PERFORM utl_file.put_line(f, '123'::numeric); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f, 0); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.new_line(f, 2); PERFORM utl_file.put_line(f, '-----'); PERFORM utl_file.put(f, 'A'); PERFORM utl_file.put(f, 'B'); PERFORM utl_file.new_line(f); PERFORM utl_file.putf(f, '[1=%s, 2=%s, 3=%s, 4=%s, 5=%s]', '1', '2', '3', '4', '5'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '1234567890'); f := utl_file.fclose(f); END; $$ LANGUAGE plpgsql; /* Test functions utl_file.fflush(utl_file.file_type) and * utl_file.get_nextline(utl_file.file_type) * This function tests the positive test case of fflush by reading from the * file after flushing the contents to the file. */ CREATE OR REPLACE FUNCTION checkFlushFile(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; f1 utl_file.file_type; ret_val text; i integer; BEGIN f := utl_file.fopen(dir, 'regressflush_orafce.txt', 'a'); PERFORM utl_file.put_line(f, 'ABC'); PERFORM utl_file.new_line(f); PERFORM utl_file.put_line(f, '123'::numeric); PERFORM utl_file.new_line(f); PERFORM utl_file.putf(f, '[1=%s, 2=%s, 3=%s, 4=%s, 5=%s]', '1', '2', '3', '4', '5'); PERFORM utl_file.fflush(f); f1 := utl_file.fopen(dir, 'regressflush_orafce.txt', 'r'); ret_val=utl_file.get_nextline(f1); i:=1; WHILE ret_val IS NOT NULL LOOP RAISE NOTICE '[%] >>%<<', i,ret_val; ret_val := utl_file.get_nextline(f1); i:=i+1; END LOOP; RAISE NOTICE '>>%<<', ret_val; f1 := utl_file.fclose(f1); f := utl_file.fclose(f); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION read_file(dir text) RETURNS void AS $$ DECLARE f utl_file.file_type; BEGIN f := utl_file.fopen(dir, 'regress_orafce.txt', 'r'); FOR i IN 1..11 LOOP RAISE NOTICE '[%] >>%<<', i, utl_file.get_line(f); END LOOP; RAISE NOTICE '>>%<<', utl_file.get_line(f, 4); RAISE NOTICE '>>%<<', utl_file.get_line(f, 4); RAISE NOTICE '>>%<<', utl_file.get_line(f); RAISE NOTICE '>>%<<', utl_file.get_line(f); EXCEPTION -- WHEN no_data_found THEN, 8.1 plpgsql doesn't know no_data_found WHEN others THEN RAISE NOTICE 'finish % ', sqlerrm; RAISE NOTICE 'is_open = %', utl_file.is_open(f); PERFORM utl_file.fclose_all(); RAISE NOTICE 'is_open = %', utl_file.is_open(f); END; $$ LANGUAGE plpgsql; SELECT EXISTS(SELECT * FROM pg_catalog.pg_class where relname='utl_file_dir') AS exists; SELECT EXISTS(SELECT * FROM pg_catalog.pg_type where typname='file_type') AS exists; -- Trying to access a file in path not registered SELECT utl_file.fopen(utl_file.tmpdir(),'sample.txt','r'); -- Trying to access file in a non-existent directory INSERT INTO utl_file.utl_file_dir(dir) VALUES('test_tmp_dir'); SELECT utl_file.fopen('test_tmp_dir','file.txt.','w'); DELETE FROM utl_file.utl_file_dir WHERE dir LIKE 'test_tmp_dir'; -- Add tmpdir() to utl_file_dir table INSERT INTO utl_file.utl_file_dir(dir) VALUES(utl_file.tmpdir()); SELECT * from utl_file.utl_file_dir; -- Trying to access non-existent file SELECT utl_file.fopen(utl_file.tmpdir(),'non_existent_file.txt','r'); --Other test cases SELECT gen_file(utl_file.tmpdir()); SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); SELECT utl_file.fcopy(utl_file.tmpdir(), 'regress_orafce.txt', utl_file.tmpdir(), 'regress_orafce2.txt'); SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt'); SELECT utl_file.frename(utl_file.tmpdir(), 'regress_orafce2.txt', utl_file.tmpdir(), 'regress_orafce.txt', true); SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt'); SELECT read_file(utl_file.tmpdir()); SELECT utl_file.fremove(utl_file.tmpdir(), 'regress_orafce.txt'); SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt'); DROP FUNCTION gen_file(text); DROP FUNCTION read_file(text); SELECT checkFlushFile(utl_file.tmpdir()); SELECT utl_file.fremove(utl_file.tmpdir(), 'regressflush_orafce.txt'); DROP FUNCTION checkFlushFile(text); DELETE FROM utl_file.utl_file_dir; orafce-VERSION_3_0_6/sql/init.sql000066400000000000000000000000361221300436000165770ustar00rootroot00000000000000\set ECHO none \i orafunc.sql orafce-VERSION_3_0_6/sql/nlssort.sql000066400000000000000000000014541221300436000173450ustar00rootroot00000000000000-- Tests for nlssort \set ECHO none SET client_min_messages = warning; DROP DATABASE IF EXISTS regression_sort; CREATE DATABASE regression_sort WITH TEMPLATE = template0 ENCODING='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C'; \c regression_sort \set ECHO none \i orafunc.sql CREATE TABLE test_sort (name TEXT); INSERT INTO test_sort VALUES ('red'), ('brown'), ('yellow'), ('Purple'); SELECT * FROM test_sort ORDER BY NLSSORT(name, 'en_US.utf8'); SELECT * FROM test_sort ORDER BY NLSSORT(name, ''); SELECT set_nls_sort('invalid'); SELECT * FROM test_sort ORDER BY NLSSORT(name); SELECT set_nls_sort(''); SELECT * FROM test_sort ORDER BY NLSSORT(name); SELECT set_nls_sort('en_US.utf8'); SELECT * FROM test_sort ORDER BY NLSSORT(name); INSERT INTO test_sort VALUES(NULL); SELECT * FROM test_sort ORDER BY NLSSORT(name); orafce-VERSION_3_0_6/sql/orafunc.sql000066400000000000000000000764001221300436000173010ustar00rootroot00000000000000\set ECHO none SET client_min_messages = warning; SET DATESTYLE TO ISO; SET client_encoding = utf8; \set ECHO all -- -- test built-in date type oracle compatibility functions -- SELECT add_months ('2003-08-01', 3); SELECT add_months ('2003-08-01', -3); SELECT add_months ('2003-08-21', -3); SELECT add_months ('2003-01-31', 1); SELECT add_months ('2008-02-28', 1); SELECT add_months ('2008-02-29', 1); SELECT add_months ('2008-01-31', 12); SELECT add_months ('2008-01-31', -12); SELECT add_months ('2008-01-31', 95903); SELECT add_months ('2008-01-31', -80640); SELECT add_months ('03-21-2008',3); SELECT add_months ('21-MAR-2008',3); SELECT add_months ('21-MAR-08',3); SELECT add_months ('2008-MAR-21',3); SELECT add_months ('March 21,2008',3); SELECT add_months('03/21/2008',3); SELECT add_months('20080321',3); SELECT add_months('080321',3); SELECT last_day(to_date('2003/03/15', 'yyyy/mm/dd')); SELECT last_day(to_date('2003/02/03', 'yyyy/mm/dd')); SELECT last_day(to_date('2004/02/03', 'yyyy/mm/dd')); SELECT last_day('1900-02-01'); SELECT last_day('2000-02-01'); SELECT last_day('2007-02-01'); SELECT last_day('2008-02-01'); SELECT next_day ('2003-08-01', 'TUESDAY'); SELECT next_day ('2003-08-06', 'WEDNESDAY'); SELECT next_day ('2003-08-06', 'SUNDAY'); SELECT next_day ('2008-01-01', 'sun'); SELECT next_day ('2008-01-01', 'sunAAA'); SELECT next_day ('2008-01-01', 1); SELECT next_day ('2008-01-01', 7); SELECT months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); SELECT months_between (to_date ('2003/07/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd')); SELECT months_between (to_date ('2003/07/02', 'yyyy/mm/dd'), to_date ('2003/07/02', 'yyyy/mm/dd')); SELECT months_between (to_date ('2003/08/02', 'yyyy/mm/dd'), to_date ('2003/06/02', 'yyyy/mm/dd')); SELECT months_between ('2007-02-28', '2007-04-30'); SELECT months_between ('2008-01-31', '2008-02-29'); SELECT months_between ('2008-02-29', '2008-03-31'); SELECT months_between ('2008-02-29', '2008-04-30'); SELECT trunc(months_between('21-feb-2008', '2008-02-29')); select length('jmenuji se Pavel Stehule'),dbms_pipe.pack_message('jmenuji se Pavel Stehule'); select length('a bydlim ve Skalici'),dbms_pipe.pack_message('a bydlim ve Skalici'); select dbms_pipe.send_message('pavel',0,1); select dbms_pipe.send_message('pavel',0,2); select dbms_pipe.receive_message('pavel',0); select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; select '>>>>'||dbms_pipe.unpack_message_text()||'<<<<'; select dbms_pipe.receive_message('pavel',0); select dbms_pipe.purge('bob'); select dbms_pipe.reset_buffer(); select dbms_pipe.pack_message('012345678901234+1'); select dbms_pipe.send_message('bob',0,10); select dbms_pipe.pack_message('012345678901234+2'); select dbms_pipe.send_message('bob',0,10); select dbms_pipe.pack_message('012345678901234+3'); select dbms_pipe.send_message('bob',0,10); -------------------------------------------- select dbms_pipe.receive_message('bob',0); select dbms_pipe.unpack_message_text(); select dbms_pipe.receive_message('bob',0); select dbms_pipe.unpack_message_text(); select dbms_pipe.receive_message('bob',0); select dbms_pipe.unpack_message_text(); select dbms_pipe.unique_session_name() LIKE 'PG$PIPE$%'; select dbms_pipe.pack_message('012345678901234-1'); select dbms_pipe.send_message('bob',0,10); select dbms_pipe.receive_message('bob',0); select dbms_pipe.unpack_message_text(); select dbms_pipe.pack_message('012345678901234-2'); select dbms_pipe.send_message('bob',0,10); select dbms_pipe.send_message('bob',0,10); select dbms_pipe.receive_message('bob',0); select dbms_pipe.unpack_message_text(); select dbms_pipe.pack_message(TO_DATE('2006-10-11', 'YYYY-MM-DD')); select dbms_pipe.send_message('test_date'); select dbms_pipe.receive_message('test_date'); select dbms_pipe.next_item_type(); select dbms_pipe.unpack_message_date(); select dbms_pipe.pack_message(to_timestamp('2008-10-30 01:23:45', 'YYYY-MM-DD HH24:MI:SS')); select dbms_pipe.send_message('test_timestamp'); select dbms_pipe.receive_message('test_timestamp'); select dbms_pipe.next_item_type(); select to_char(dbms_pipe.unpack_message_timestamp(), 'YYYY-MM-DD HH24:MI:SS'); select dbms_pipe.pack_message(6262626262::numeric); select dbms_pipe.send_message('test_int'); select dbms_pipe.receive_message('test_int'); select dbms_pipe.next_item_type(); select dbms_pipe.unpack_message_number(); select dbms_pipe.purge('bob'); select name, items, "limit", private, owner from dbms_pipe.db_pipes where name = 'bob'; select PLVstr.betwn('Harry and Sally are very happy', 7, 9); select PLVstr.betwn('Harry and Sally are very happy', 7, 9, FALSE); select PLVstr.betwn('Harry and Sally are very happy', -3, -1); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry'); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 1,1,FALSE,FALSE); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'ry', 2,1,TRUE,FALSE); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'y', 2,1); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 2); select PLVstr.betwn('Harry and Sally are very happy', 'a', 'a', 2, 3, FALSE,FALSE); select plvsubst.string('My name is %s %s.', ARRAY['Pavel','Stěhule']); select plvsubst.string('My name is % %.', ARRAY['Pavel','Stěhule'], '%'); select plvsubst.string('My name is %s.', ARRAY['Stěhule']); select plvsubst.string('My name is %s %s.', 'Pavel,Stěhule'); select plvsubst.string('My name is %s %s.', 'Pavel|Stěhule','|'); select plvsubst.string('My name is %s.', 'Stěhule'); select plvsubst.string('My name is %s.', ''); select plvsubst.string('My name is empty.', ''); select round(to_date ('22-AUG-03', 'DD-MON-YY'),'YEAR') = to_date ('01-JAN-04', 'DD-MON-YY'); select round(to_date ('22-AUG-03', 'DD-MON-YY'),'Q') = to_date ('01-OCT-03', 'DD-MON-YY'); select round(to_date ('22-AUG-03', 'DD-MON-YY'),'MONTH') = to_date ('01-SEP-03', 'DD-MON-YY'); select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); select round(to_date ('22-AUG-03', 'DD-MON-YY'),'DAY') = to_date ('24-AUG-03', 'DD-MON-YY'); select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'YEAR') = to_date ('01-JAN-03', 'DD-MON-YY'); select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'Q') = to_date ('01-JUL-03', 'DD-MON-YY'); select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'MONTH') = to_date ('01-AUG-03', 'DD-MON-YY'); select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DDD') = to_date ('22-AUG-03', 'DD-MON-YY'); select trunc(to_date('22-AUG-03', 'DD-MON-YY'), 'DAY') = to_date ('17-AUG-03', 'DD-MON-YY'); select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','YEAR') = '2004-01-01 00:00:00-08'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','Q') = '2004-10-01 00:00:00-07'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MONTH') = '2004-10-01 00:00:00-07'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DDD') = '2004-10-19 00:00:00-07'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','DAY') = '2004-10-17 00:00:00-07'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','HH') = '2004-10-19 01:00:00-07'; select trunc(TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02','MI') = '2004-10-19 01:23:00-07'; select next_day(to_date('01-Aug-03', 'DD-MON-YY'), 'TUESDAY') = to_date ('05-Aug-03', 'DD-MON-YY'); select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'WEDNESDAY') = to_date ('13-Aug-03', 'DD-MON-YY'); select next_day(to_date('06-Aug-03', 'DD-MON-YY'), 'SUNDAY') = to_date ('10-Aug-03', 'DD-MON-YY'); select instr('Tech on the net', 'e') =2; select instr('Tech on the net', 'e', 1, 1) = 2; select instr('Tech on the net', 'e', 1, 2) = 11; select instr('Tech on the net', 'e', 1, 3) = 14; select instr('Tech on the net', 'e', -3, 2) = 2; select instr('abc', NULL) IS NULL; select 1 = instr('abc', ''); select 1 = instr('abc', 'a'); select 3 = instr('abc', 'c'); select 0 = instr('abc', 'z'); select 1 = instr('abcabcabc', 'abca', 1); select 4 = instr('abcabcabc', 'abca', 2); select 0 = instr('abcabcabc', 'abca', 7); select 0 = instr('abcabcabc', 'abca', 9); select 4 = instr('abcabcabc', 'abca', -1); select 1 = instr('abcabcabc', 'abca', -8); select 1 = instr('abcabcabc', 'abca', -9); select 0 = instr('abcabcabc', 'abca', -10); select 1 = instr('abcabcabc', 'abca', 1, 1); select 4 = instr('abcabcabc', 'abca', 1, 2); select 0 = instr('abcabcabc', 'abca', 1, 3); select oracle.substr('This is a test', 6, 2) = 'is'; select oracle.substr('This is a test', 6) = 'is a test'; select oracle.substr('TechOnTheNet', 1, 4) = 'Tech'; select oracle.substr('TechOnTheNet', -3, 3) = 'Net'; select oracle.substr('TechOnTheNet', -6, 3) = 'The'; select oracle.substr('TechOnTheNet', -8, 2) = 'On'; select oracle.substr('TechOnTheNet', -8, 0) = ''; select oracle.substr('TechOnTheNet', -8, -1) = ''; select concat('Tech on', ' the Net') = 'Tech on the Net'; select concat('a', 'b') = 'ab'; select concat('a', NULL) = 'a'; select concat(NULL, 'b') = 'b'; select concat('a', 2) = 'a2'; select concat(1, 'b') = '1b'; select concat(1, 2) = '12'; select concat(1, NULL) = '1'; select concat(NULL, 2) = '2'; select nvl('A'::text, 'B'); select nvl(NULL::text, 'B'); select nvl(NULL::text, NULL); select nvl(1, 2); select nvl(NULL, 2); select nvl2('A'::text, 'B', 'C'); select nvl2(NULL::text, 'B', 'C'); select nvl2('A'::text, NULL, 'C'); select nvl2(NULL::text, 'B', NULL); select nvl2(1, 2, 3); select nvl2(NULL, 2, 3); select lnnvl(true); select lnnvl(false); select lnnvl(NULL); select decode(1, 1, 100, 2, 200); select decode(2, 1, 100, 2, 200); select decode(3, 1, 100, 2, 200); select decode(3, 1, 100, 2, 200, 300); select decode(NULL, 1, 100, NULL, 200, 300); select decode('1'::text, '1', 100, '2', 200); select decode(2, 1, 'ABC', 2, 'DEF'); select decode('2009-02-05'::date, '2009-02-05', 'ok'); select decode('2009-02-05 01:02:03'::timestamp, '2009-02-05 01:02:03', 'ok'); -- For type 'bpchar' select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar); select decode('c'::bpchar, 'a'::bpchar,'postgres'::bpchar); select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); select decode('c', 'a'::bpchar,'postgres'::bpchar,'default value'::bpchar); select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar); select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar,'default value'::bpchar); select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar); select decode('a'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); select decode('d'::bpchar, 'a'::bpchar,'postgres'::bpchar,'b'::bpchar,'database'::bpchar, 'c'::bpchar, 'system'::bpchar,'default value'::bpchar); select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar); select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar); select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, NULL,'database'::bpchar,'default value'::bpchar); select decode(NULL, 'a'::bpchar, 'postgres'::bpchar, 'b'::bpchar,'database'::bpchar,'default value'::bpchar); -- For type 'bigint' select decode(2147483651::bigint, 2147483650::bigint,2147483650::bigint); select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint); select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); select decode(2147483653::bigint, 2147483651::bigint,2147483650::bigint,9999999999::bigint); select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint); select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint,2147483652::bigint,2147483651::bigint,9999999999::bigint); select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint); select decode(2147483651::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); select decode(2147483654::bigint, 2147483651::bigint,2147483650::bigint, 2147483652::bigint,2147483651::bigint, 2147483653::bigint, 2147483652::bigint,9999999999::bigint); select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint); select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint); select decode(NULL, 2147483651::bigint, 2147483650::bigint, NULL,2147483651::bigint,9999999999::bigint); select decode(NULL, 2147483651::bigint, 2147483650::bigint, 2147483652::bigint,2147483651::bigint,9999999999::bigint); -- For type 'numeric' select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4)); select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); select decode(12.003::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),999999.9999::numeric(10,4)); select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4)); select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4)); select decode(12.001::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); select decode(12.004::numeric(5,3), 12.001::numeric(5,3),214748.3650::numeric(10,4),12.002::numeric(5,3),214748.3651::numeric(10,4), 12.003::numeric(5,3), 214748.3652::numeric(10,4),999999.9999::numeric(10,4)); select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4)); select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4)); select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), NULL,214748.3651::numeric(10,4),999999.9999::numeric(10,4)); select decode(NULL, 12.001::numeric(5,3), 214748.3650::numeric(10,4), 12.002::numeric(5,3),214748.3651::numeric(10,4),999999.9999::numeric(10,4)); --For type 'date' select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date); select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date); select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); select decode('2020-01-03'::date, '2020-01-01'::date,'2012-12-20'::date,'2012-12-21'::date); select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date); select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date); select decode('2020-01-01'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); select decode('2020-01-04'::date, '2020-01-01'::date,'2012-12-20'::date,'2020-01-02'::date,'2012-12-21'::date, '2020-01-03'::date, '2012-12-31'::date,'2013-01-01'::date); select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date); select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date); select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, NULL,'2012-12-21'::date,'2012-12-31'::date); select decode(NULL, '2020-01-01'::date, '2012-12-20'::date, '2020-01-02'::date,'2012-12-21'::date,'2012-12-31'::date); -- For type 'time' select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time); select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time); select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); select decode('01:00:03'::time, '01:00:01'::time,'09:00:00'::time,'00:00:00'::time); select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time); select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time,'00:00:00'::time); select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:01'::time,'12:00:00'::time,'00:00:00'::time); select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time); select decode('01:00:01'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); select decode('01:00:04'::time, '01:00:01'::time,'09:00:00'::time,'01:00:02'::time,'12:00:00'::time, '01:00:03'::time, '15:00:00'::time,'00:00:00'::time); select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time); select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time); select decode(NULL, '01:00:01'::time, '09:00:00'::time, NULL,'12:00:00'::time,'00:00:00'::time); select decode(NULL, '01:00:01'::time, '09:00:00'::time, '01:00:02'::time,'12:00:00'::time,'00:00:00'::time); -- For type 'timestamp' select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp); select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode('2020-01-03 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp); select decode('2020-01-01 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode('2020-01-04 01:00:01'::timestamp, '2020-01-01 01:00:01'::timestamp,'2012-12-20 09:00:00'::timestamp,'2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp, '2020-01-03 01:00:01'::timestamp, '2012-12-20 15:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp); select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp); select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, NULL,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); select decode(NULL, '2020-01-01 01:00:01'::timestamp, '2012-12-20 09:00:00'::timestamp, '2020-01-02 01:00:01'::timestamp,'2012-12-20 12:00:00'::timestamp,'2012-12-20 00:00:00'::timestamp); -- For type 'timestamptz' select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz); select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode('2020-01-03 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); select decode('2020-01-04 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz); select decode('2020-01-01 01:00:01-08'::timestamptz, '2020-01-01 01:00:01-08'::timestamptz,'2012-12-20 09:00:00-08'::timestamptz,'2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz, '2020-01-03 01:00:01-08'::timestamptz, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode(4, 1,'2012-12-20 09:00:00-08'::timestamptz,2,'2012-12-20 12:00:00-08'::timestamptz, 3, '2012-12-20 15:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz); select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz); select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, NULL,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); select decode(NULL, '2020-01-01 01:00:01-08'::timestamptz, '2012-12-20 09:00:00-08'::timestamptz, '2020-01-02 01:00:01-08'::timestamptz,'2012-12-20 12:00:00-08'::timestamptz,'2012-12-20 00:00:00-08'::timestamptz); --Test case to check if decode accepts other expressions as a key CREATE OR REPLACE FUNCTION five() RETURNS integer AS $$ BEGIN RETURN 5; END; $$ LANGUAGE plpgsql; select decode(five(), 1, 'one', 2, 'two', 5, 'five'); DROP FUNCTION five(); -- Test case to check duplicate keys in search list select decode(1, 1, 'one', 2, 'two', 1, 'one-again') = 'one'; /* Test case to check explicit type casting of keys in search list in * case of ambiguous key (1st argument) provided. */ -- 1) succeed and return 'result-1' select decode('2012-01-01', '2012-01-01'::date,'result-1','2012-01-02', 'result-2'); select decode('2012-01-01', '2012-01-01', 'result-1', '2012-02-01'::date, 'result-2'); -- 2) fails and throws error: 'ERROR: could not determine polymorphic type -- because input has type "unknown"' select decode('2012-01-01', '2012-01-01', 23, '2012-01-02', 24); select PLVstr.rvrs ('Jumping Jack Flash') ='hsalF kcaJ gnipmuJ'; select PLVstr.rvrs ('Jumping Jack Flash', 9) = 'hsalF kcaJ'; select PLVstr.rvrs ('Jumping Jack Flash', 4, 6) = 'nip'; select PLVstr.lstrip ('*val1|val2|val3|*', '*') = 'val1|val2|val3|*'; select PLVstr.lstrip (',,,val1,val2,val3,', ',', 3)= 'val1,val2,val3,'; select PLVstr.lstrip ('WHERE WHITE = ''FRONT'' AND COMP# = 1500', 'WHERE ') = 'WHITE = ''FRONT'' AND COMP# = 1500'; select plvstr.left('Příliš žluťoučký kůň',4) = pg_catalog.substr('Příl', 1, 4); select pos,token from plvlex.tokens('select * from a.b.c join d ON x=y', true, true); SET lc_numeric TO 'C'; select to_char(22); select to_char(-44444); select to_char(1234567890123456::bigint); select to_char(123.456::real); select to_char(1234.5678::double precision); select to_char(12345678901234567890::numeric); select to_char(1234567890.12345); select to_char('4.00'::numeric); select to_char('4.0010'::numeric); SELECT to_number('123'::text); SELECT to_number('123.456'::text); SELECT to_date('2009-01-02'); SELECT bitand(5,1), bitand(5,2), bitand(5,4); SELECT sinh(1.570796), cosh(1.570796), tanh(4); SELECT nanvl(12345, 1), nanvl('NaN', 1); SELECT nanvl(12345::float4, 1), nanvl('NaN'::float4, 1); SELECT nanvl(12345::float8, 1), nanvl('NaN'::float8, 1); SELECT nanvl(12345::numeric, 1), nanvl('NaN'::numeric, 1); select dbms_assert.enquote_literal('some text '' some text'); select dbms_assert.enquote_name('''"AAA'); select dbms_assert.enquote_name('''"AAA', false); select dbms_assert.noop('some string'); select dbms_assert.qualified_sql_name('aaa.bbb.ccc."aaaa""aaa"'); select dbms_assert.qualified_sql_name('aaa.bbb.cc%c."aaaa""aaa"'); select dbms_assert.schema_name('dbms_assert'); select dbms_assert.schema_name('jabadabado'); select dbms_assert.simple_sql_name('"Aaa dghh shsh"'); select dbms_assert.simple_sql_name('ajajaj -- ajaj'); select dbms_assert.object_name('pg_catalog.pg_class'); select dbms_assert.object_name('dbms_assert.fooo'); select plunit.assert_true(NULL); select plunit.assert_true(1 = 2); select plunit.assert_true(1 = 2, 'one is not two'); select plunit.assert_true(1 = 1); select plunit.assert_false(1 = 1); select plunit.assert_false(1 = 1, 'trap is open'); select plunit.assert_false(NULL); select plunit.assert_null(current_date); select plunit.assert_null(NULL::date); select plunit.assert_not_null(current_date); select plunit.assert_not_null(NULL::date); select plunit.assert_equals('Pavel','Pa'||'vel'); select plunit.assert_equals(current_date, current_date + 1, 'diff dates'); select plunit.assert_equals(10.2, 10.3, 0.5); select plunit.assert_equals(10.2, 10.3, 0.01, 'attention some diff'); select plunit.assert_not_equals(current_date, current_date + 1, 'yestarday is today'); select plunit.fail(); select plunit.fail('custom exception'); SELECT dump('Yellow dog'::text) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; SELECT dump('Yellow dog'::text, 10) ~ E'^Typ=25 Len=(\\d+): \\d+(,\\d+)*$' AS t; SELECT dump('Yellow dog'::text, 17) ~ E'^Typ=25 Len=(\\d+): .(,.)*$' AS t; SELECT dump(10::int2) ~ E'^Typ=21 Len=2: \\d+(,\\d+){1}$' AS t; SELECT dump(10::int4) ~ E'^Typ=23 Len=4: \\d+(,\\d+){3}$' AS t; SELECT dump(10::int8) ~ E'^Typ=20 Len=8: \\d+(,\\d+){7}$' AS t; SELECT dump(10.23::float4) ~ E'^Typ=700 Len=4: \\d+(,\\d+){3}$' AS t; SELECT dump(10.23::float8) ~ E'^Typ=701 Len=8: \\d+(,\\d+){7}$' AS t; SELECT dump(10.23::numeric) ~ E'^Typ=1700 Len=(\\d+): \\d+(,\\d+)*$' AS t; SELECT dump('2008-10-10'::date) ~ E'^Typ=1082 Len=4: \\d+(,\\d+){3}$' AS t; SELECT dump('2008-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; SELECT dump('2009-10-10'::timestamp) ~ E'^Typ=1114 Len=8: \\d+(,\\d+){7}$' AS t; -- Tests for to_multi_byte SELECT to_multi_byte('123$test'); -- Check internal representation difference SELECT octet_length('abc'); SELECT octet_length(to_multi_byte('abc')); -- Tests for round(TIMESTAMP WITH TIME ZONE) select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','YEAR') = '1991-01-01 00:00:00'; select round(TIMESTAMP WITH TIME ZONE'05/08/1990 05:35:25','Q') = '1990-04-01 00:00:00'; select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','MONTH') = '1990-12-01 00:00:00'; select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DDD') = '1990-12-08 00:00:00'; select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','DAY') = '1990-12-09 00:00:00'; select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','hh') = '1990-12-08 06:00:00'; select round(TIMESTAMP WITH TIME ZONE'12/08/1990 05:35:25','mi') = '1990-12-08 05:35:00'; -- Tests for to_date SET DATESTYLE TO SQL, MDY; SELECT to_date('2009-01-02'); select to_date('January 8,1999'); SET DATESTYLE TO POSTGRES, MDY; select to_date('1999-01-08'); select to_date('1/12/1999'); SET DATESTYLE TO SQL, DMY; select to_date('01/02/03'); select to_date('1999-Jan-08'); select to_date('Jan-08-1999'); select to_date('08-Jan-1999'); SET DATESTYLE TO ISO, YMD; select to_date('99-Jan-08'); SET DATESTYLE TO ISO, DMY; select to_date('08-Jan-99'); select to_date('Jan-08-99'); select to_date('19990108'); select to_date('990108'); select to_date('J2451187'); orafce-VERSION_3_0_6/sqlparse.y000066400000000000000000000046011221300436000163420ustar00rootroot00000000000000%{ #define YYDEBUG 1 #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ if (N) \ (Current) = (Rhs)[1]; \ else \ (Current) = (Rhs)[0]; \ } while (0) #include "postgres.h" #include "orafunc.h" #include "plvlex.h" #include "nodes/pg_list.h" #define MOVE_TO_S(src,dest,col) dest->col = src.col ? pstrdup(src.col) : NULL #define MOVE_TO(src,dest,col) dest->col = src.col #define FILL_NODE(src,dest) \ MOVE_TO_S(src,dest,str), \ MOVE_TO(src,dest,keycode), \ MOVE_TO(src,dest,lloc), \ MOVE_TO_S(src,dest,sep), \ MOVE_TO(src,dest,modificator) static orafce_lexnode *__node; #define CREATE_NODE(src,type) \ ( \ __node = (orafce_lexnode*) palloc(sizeof(orafce_lexnode)), \ __node->typenode = X_##type, \ __node->classname = #type, \ FILL_NODE(src,__node), \ __node) extern int yylex(void); /* defined as fdate_yylex in fdatescan.l */ static char *scanbuf; static int scanbuflen; void orafce_sql_yyerror(List **result, const char *message); #define YYLTYPE int #define YYMALLOC malloc /* XXX: should use palloc? */ #define YYFREE free /* XXX: should use pfree? */ %} %name-prefix="orafce_sql_yy" %locations %parse-param {List **result} %union { int ival; orafce_lexnode *node; List *list; struct { char *str; int keycode; int lloc; char *sep; char *modificator; } val; } /* BISON Declarations */ %token X_IDENT X_NCONST X_SCONST X_OP X_PARAM X_COMMENT X_WHITESPACE X_KEYWORD X_OTHERS X_TYPECAST %type elements %type anyelement %type root %start root /* Grammar follows */ %% root: elements { *((void**)result) = $1; } ; elements: anyelement { $$ = list_make1($1);} | elements anyelement { $$ = lappend($1, $2);} ; anyelement: X_IDENT { $$ = (orafce_lexnode*) CREATE_NODE($1, IDENT); } | X_NCONST { $$ = (orafce_lexnode*) CREATE_NODE($1, NCONST); } | X_SCONST { $$ = (orafce_lexnode*) CREATE_NODE($1, SCONST); } | X_OP { $$ = (orafce_lexnode*) CREATE_NODE($1, OP); } | X_PARAM { $$ = (orafce_lexnode*) CREATE_NODE($1, PARAM); } | X_COMMENT { $$ = (orafce_lexnode*) CREATE_NODE($1, COMMENT); } | X_WHITESPACE { $$ = (orafce_lexnode*) CREATE_NODE($1, WHITESPACE); } | X_KEYWORD { $$ = (orafce_lexnode*) CREATE_NODE($1, KEYWORD); } | X_OTHERS { $$ = (orafce_lexnode*) CREATE_NODE($1, OTHERS); } ; %% #include "sqlscan.c" orafce-VERSION_3_0_6/sqlscan.l000066400000000000000000000661771221300436000161570ustar00rootroot00000000000000%{ /* ** A scanner for EMP-style numeric ranges */ #include "postgres.h" #include "parser/keywords.h" #undef yyparse /* don't need it now and solve problems with 8.1 */ #include "parser/gramparse.h" #include "parser/keywords.h" /* Not needed now that this file is compiled as part of gram.y */ /* #include "parser/parse.h" */ #include "parser/scansup.h" #include "mb/pg_wchar.h" #if PG_VERSION_NUM >= 80500 extern PGDLLIMPORT const ScanKeyword ScanKeywords[]; extern PGDLLIMPORT const int NumScanKeywords; #define ScanKeywordLookupArgs , ScanKeywords, NumScanKeywords #else #define ScanKeywordLookupArgs #endif /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */ #undef fprintf #define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg) static void fprintf_to_ereport(const char *fmt, const char *msg) { ereport(ERROR, (errmsg_internal("%s", msg))); } static int xcdepth = 0; /* depth of nesting in slash-star comments */ static char *dolqstart; /* current $foo$ quote start string */ static bool extended_string = false; /* No reason to constrain amount of data slurped */ #define YY_READ_BUF_SIZE 16777216 /* Handles to the buffer that the lexer uses internally */ static YY_BUFFER_STATE scanbufhandle; #define SET_YYLLOC() (yylval.val.lloc = yylloc = yytext - scanbuf) /* Handles to the buffer that the lexer uses internally */ static char *scanbuf; /* flex 2.5.4 doesn't bother with a decl for this */ int orafce_sql_yylex(void); extern YYSTYPE yylval; void orafce_sql_scanner_init(const char *str); void orafce_sql_scanner_finish(void); /* * literalbuf is used to accumulate literal values when multiple rules * are needed to parse a single literal. Call startlit to reset buffer * to empty, addlit to add text. Note that the buffer is palloc'd and * starts life afresh on every parse cycle. */ static char *literalbuf; /* expandable buffer */ static int literallen; /* actual current length */ static int literalalloc; /* current allocated buffer size */ #define startlit() (literalbuf[0] = '\0', literallen = 0) static void addlit(char *ytext, int yleng); static void addlitchar(unsigned char ychar); static char *litbufdup(void); static int lexer_errposition(void); /* * Each call to yylex must set yylloc to the location of the found token * (expressed as a byte offset from the start of the input text). * When we parse a token that requires multiple lexer rules to process, * this should be done in the first such rule, else yylloc will point * into the middle of the token. */ /* Handles to the buffer that the lexer uses internally */ static char *scanbuf; static unsigned char unescape_single_char(unsigned char c); #ifndef _pg_mbstrlen_with_len #define _pg_mbstrlen_with_len(buf,loc) pg_mbstrlen_with_len(buf,loc) #endif %} %option 8bit %option never-interactive %option nodefault %option noinput %option nounput %option noyywrap %option prefix="orafce_sql_yy" /* * OK, here is a short description of lex/flex rules behavior. * The longest pattern which matches an input string is always chosen. * For equal-length patterns, the first occurring in the rules list is chosen. * INITIAL is the starting state, to which all non-conditional rules apply. * Exclusive states change parsing rules while the state is active. When in * an exclusive state, only those rules defined for that state apply. * * We use exclusive states for quoted strings, extended comments, * and to eliminate parsing troubles for numeric strings. * Exclusive states: * bit string literal * extended C-style comments * delimited identifiers (double-quoted identifiers) * hexadecimal numeric string * standard quoted strings * extended quoted strings (support backslash escape sequences) * $foo$ quoted strings */ %x xb %x xc %x xd %x xh %x xe %x xq %x xdolq /* * In order to make the world safe for Windows and Mac clients as well as * Unix ones, we accept either \n or \r as a newline. A DOS-style \r\n * sequence will be seen as two successive newlines, but that doesn't cause * any problems. Comments that start with -- and extend to the next * newline are treated as equivalent to a single whitespace character. * * NOTE a fine point: if there is no newline following --, we will absorb * everything to the end of the input as a comment. This is correct. Older * versions of Postgres failed to recognize -- as a comment if the input * did not end with a newline. * * XXX perhaps \f (formfeed) should be treated as a newline as well? * * XXX if you change the set of whitespace characters, fix scanner_isspace() * to agree, and see also the plpgsql lexer. */ space [ \t\n\r\f] horiz_space [ \t\f] newline [\n\r] non_newline [^\n\r] comment ("--"{non_newline}*) whitespace {space}+ /* * SQL requires at least one newline in the whitespace separating * string literals that are to be concatenated. Silly, but who are we * to argue? Note that {whitespace_with_newline} should not have * after * it, whereas {whitespace} should generally have a * after it... */ special_whitespace ({space}+|{comment}{newline}) horiz_whitespace ({horiz_space}|{comment}) whitespace_with_newline ({horiz_whitespace}*{newline}{special_whitespace}*) /* * To ensure that {quotecontinue} can be scanned without having to back up * if the full pattern isn't matched, we include trailing whitespace in * {quotestop}. This matches all cases where {quotecontinue} fails to match, * except for {quote} followed by whitespace and just one "-" (not two, * which would start a {comment}). To cover that we have {quotefail}. * The actions for {quotestop} and {quotefail} must throw back characters * beyond the quote proper. */ quote ' quotestop {quote}{whitespace}* quotecontinue {quote}{whitespace_with_newline}{quote} quotefail {quote}{whitespace}*"-" /* Bit string * It is tempting to scan the string for only those characters * which are allowed. However, this leads to silently swallowed * characters if illegal characters are included in the string. * For example, if xbinside is [01] then B'ABCD' is interpreted * as a zero-length string, and the ABCD' is lost! * Better to pass the string forward and let the input routines * validate the contents. */ xbstart [bB]{quote} xbinside [^']* /* Hexadecimal number */ xhstart [xX]{quote} xhinside [^']* /* National character */ xnstart [nN]{quote} /* Quoted string that allows backslash escapes */ xestart [eE]{quote} xeinside [^\\']+ xeescape [\\][^0-7] xeoctesc [\\][0-7]{1,3} xehexesc [\\]x[0-9A-Fa-f]{1,2} /* Extended quote * xqdouble implements embedded quote, '''' */ xqstart {quote} xqdouble {quote}{quote} xqinside [^']+ /* $foo$ style quotes ("dollar quoting") * The quoted string starts with $foo$ where "foo" is an optional string * in the form of an identifier, except that it may not contain "$", * and extends to the first occurrence of an identical string. * There is *no* processing of the quoted text. * * {dolqfailed} is an error rule to avoid scanner backup when {dolqdelim} * fails to match its trailing "$". */ dolq_start [A-Za-z\200-\377_] dolq_cont [A-Za-z\200-\377_0-9] dolqdelim \$({dolq_start}{dolq_cont}*)?\$ dolqfailed \${dolq_start}{dolq_cont}* dolqinside [^$]+ /* Double quote * Allows embedded spaces and other special characters into identifiers. */ dquote \" xdstart {dquote} xdstop {dquote} xddouble {dquote}{dquote} xdinside [^"]+ /* C-style comments * * The "extended comment" syntax closely resembles allowable operator syntax. * The tricky part here is to get lex to recognize a string starting with * slash-star as a comment, when interpreting it as an operator would produce * a longer match --- remember lex will prefer a longer match! Also, if we * have something like plus-slash-star, lex will think this is a 3-character * operator whereas we want to see it as a + operator and a comment start. * The solution is two-fold: * 1. append {op_chars}* to xcstart so that it matches as much text as * {operator} would. Then the tie-breaker (first matching rule of same * length) ensures xcstart wins. We put back the extra stuff with yyless() * in case it contains a star-slash that should terminate the comment. * 2. In the operator rule, check for slash-star within the operator, and * if found throw it back with yyless(). This handles the plus-slash-star * problem. * Dash-dash comments have similar interactions with the operator rule. */ xcstart \/\*{op_chars}* xcstop \*+\/ xcinside [^*/]+ digit [0-9] ident_start [A-Za-z\200-\377_] ident_cont [A-Za-z\200-\377_0-9\$] identifier {ident_start}{ident_cont}* typecast "::" /* * "self" is the set of chars that should be returned as single-character * tokens. "op_chars" is the set of chars that can make up "Op" tokens, * which can be one or more characters long (but if a single-char token * appears in the "self" set, it is not to be returned as an Op). Note * that the sets overlap, but each has some chars that are not in the other. * * If you change either set, adjust the character lists appearing in the * rule for "operator"! */ self [,()\[\].;\:\+\-\*\/\%\^\<\>\=] op_chars [\~\!\@\#\^\&\|\`\?\+\-\*\/\%\<\>\=] operator {op_chars}+ /* we no longer allow unary minus in numbers. * instead we pass it separately to parser. there it gets * coerced via doNegate() -- Leon aug 20 1999 * * {realfail1} and {realfail2} are added to prevent the need for scanner * backup when the {real} rule fails to match completely. */ integer {digit}+ decimal (({digit}*\.{digit}+)|({digit}+\.{digit}*)) real ({integer}|{decimal})[Ee][-+]?{digit}+ realfail1 ({integer}|{decimal})[Ee] realfail2 ({integer}|{decimal})[Ee][-+] param \${integer} other . /* * Dollar quoted strings are totally opaque, and no escaping is done on them. * Other quoted strings must allow some special characters such as single-quote * and newline. * Embedded single-quotes are implemented both in the SQL standard * style of two adjacent single quotes "''" and in the Postgres/Java style * of escaped-quote "\'". * Other embedded escaped characters are matched explicitly and the leading * backslash is dropped from the string. * Note that xcstart must appear before operator, as explained above! * Also whitespace (comment) must appear before operator. */ %% {whitespace} { SET_YYLLOC(); yylval.val.str = yytext; yylval.val.modificator = NULL; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_WHITESPACE; } {comment} { SET_YYLLOC(); yylval.val.str = yytext; yylval.val.modificator = "sc"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_COMMENT; } {xcstart} { /* Set location in case of syntax error in comment */ SET_YYLLOC(); xcdepth = 0; BEGIN(xc); /* Put back any characters past slash-star; see above */ startlit(); addlitchar('/'); addlitchar('*'); yyless(2); } {xcstart} { xcdepth++; /* Put back any characters past slash-star; see above */ addlitchar('/'); addlitchar('*'); yyless(2); } {xcstop} { if (xcdepth <= 0) { BEGIN(INITIAL); addlitchar('*'); addlitchar('/'); yylval.val.str = litbufdup(); yylval.val.modificator = "ec"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_COMMENT; } else { xcdepth--; addlitchar('*'); addlitchar('/'); } } {xcinside} { addlit(yytext, yyleng); } {op_chars} { addlit(yytext, yyleng); } \*+ { addlit(yytext, yyleng); } <> { yylval.val.str = litbufdup(); yylval.val.modificator = "ecu"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_COMMENT; } {xbstart} { /* Binary bit type. * At some point we should simply pass the string * forward to the parser and label it there. * In the meantime, place a leading "b" on the string * to mark it for the input routine as a binary string. */ SET_YYLLOC(); BEGIN(xb); startlit(); addlitchar('b'); } {quotestop} | {quotefail} { yyless(1); BEGIN(INITIAL); yylval.val.str = litbufdup(); yylval.val.modificator = "b"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {xhinside} | {xbinside} { addlit(yytext, yyleng); } {quotecontinue} | {quotecontinue} { /* ignore */ } <> { yylval.val.str = litbufdup(); yylval.val.modificator = "bu"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {xhstart} { /* Hexadecimal bit type. * At some point we should simply pass the string * forward to the parser and label it there. * In the meantime, place a leading "x" on the string * to mark it for the input routine as a hex string. */ SET_YYLLOC(); BEGIN(xh); startlit(); addlitchar('x'); } {quotestop} | {quotefail} { yyless(1); BEGIN(INITIAL); yylval.val.str = litbufdup(); yylval.val.modificator = "x"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } <> { yylval.val.str = litbufdup(); yylval.val.modificator = "xu"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {xnstart} { /* National character. * We will pass this along as a normal character string, * but preceded with an internally-generated "NCHAR". */ const ScanKeyword *keyword; SET_YYLLOC(); yyless(1); /* eat only 'n' this time */ /* nchar had better be a keyword! */ keyword = ScanKeywordLookup("nchar" ScanKeywordLookupArgs); Assert(keyword != NULL); yylval.val.str = (char*) keyword->name; yylval.val.keycode = keyword->value; yylval.val.modificator = NULL; yylval.val.sep = NULL; return X_KEYWORD; } {xqstart} { SET_YYLLOC(); BEGIN(xq); extended_string = false; startlit(); } {xestart} { SET_YYLLOC(); BEGIN(xe); extended_string = true; startlit(); } {quotestop} | {quotefail} { yyless(1); BEGIN(INITIAL); yylval.val.str = litbufdup(); yylval.val.modificator = extended_string ? "es" : "qs"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_SCONST; } {xqdouble} { addlitchar('\''); } {xqinside} { addlit(yytext, yyleng); } {xeinside} { addlit(yytext, yyleng); } {xeescape} { addlitchar(unescape_single_char(yytext[1])); } {xeoctesc} { unsigned char c = strtoul(yytext+1, NULL, 8); addlitchar(c); } {xehexesc} { unsigned char c = strtoul(yytext+2, NULL, 16); addlitchar(c); } {quotecontinue} { /* ignore */ } . { /* This is only needed for \ just before EOF */ addlitchar(yytext[0]); } <> { yylval.val.str = litbufdup(); yylval.val.modificator = extended_string ? "esu" : "qsu"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_SCONST; } {dolqdelim} { SET_YYLLOC(); dolqstart = pstrdup(yytext); BEGIN(xdolq); startlit(); } {dolqfailed} { /* throw back all but the initial "$" */ yyless(1); /* and treat it as {other} */ yylval.val.str = yytext; yylval.val.modificator = "dolqf"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_OTHERS; } {dolqdelim} { if (strcmp(yytext, dolqstart) == 0) { yylval.val.sep = dolqstart; yylval.val.modificator = "dolq"; BEGIN(INITIAL); yylval.val.str = litbufdup(); yylval.val.keycode = -1; return X_SCONST; } else { /* * When we fail to match $...$ to dolqstart, transfer * the $... part to the output, but put back the final * $ for rescanning. Consider $delim$...$junk$delim$ */ addlit(yytext, yyleng-1); yyless(yyleng-1); } } {dolqinside} { addlit(yytext, yyleng); } {dolqfailed} { addlit(yytext, yyleng); } . { /* This is only needed for inside the quoted text */ addlitchar(yytext[0]); } <> { yylval.val.sep = dolqstart; yylval.val.modificator = "dolqu"; yylval.val.str = litbufdup(); yylval.val.keycode = -1; yylval.val.sep = NULL; return X_SCONST; } {xdstart} { SET_YYLLOC(); BEGIN(xd); startlit(); } {xdstop} { char *ident; BEGIN(INITIAL); if (literallen == 0) yyerror(NULL, "zero-length delimited identifier"); ident = litbufdup(); if (literallen >= NAMEDATALEN) truncate_identifier(ident, literallen, true); yylval.val.modificator = "dq"; yylval.val.str = ident; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_IDENT; } {xddouble} { addlitchar('"'); } {xdinside} { addlit(yytext, yyleng); } <> { yylval.val.modificator = "dqu"; yylval.val.str = litbufdup(); yylval.val.keycode = -1; yylval.val.sep = NULL; return X_IDENT; } {typecast} { SET_YYLLOC(); yylval.val.modificator = "typecast"; yylval.val.keycode = X_TYPECAST; yylval.val.sep = NULL; return X_OTHERS; } {self} { SET_YYLLOC(); yylval.val.str = yytext; yylval.val.modificator = "self"; yylval.val.keycode = yytext[0]; yylval.val.sep = NULL; return X_OTHERS; } {operator} { /* * Check for embedded slash-star or dash-dash; those * are comment starts, so operator must stop there. * Note that slash-star or dash-dash at the first * character will match a prior rule, not this one. */ int nchars = yyleng; char *slashstar = strstr(yytext, "/*"); char *dashdash = strstr(yytext, "--"); if (slashstar && dashdash) { /* if both appear, take the first one */ if (slashstar > dashdash) slashstar = dashdash; } else if (!slashstar) slashstar = dashdash; if (slashstar) nchars = slashstar - yytext; /* * For SQL compatibility, '+' and '-' cannot be the * last char of a multi-char operator unless the operator * contains chars that are not in SQL operators. * The idea is to lex '=-' as two operators, but not * to forbid operator names like '?-' that could not be * sequences of SQL operators. */ while (nchars > 1 && (yytext[nchars-1] == '+' || yytext[nchars-1] == '-')) { int ic; for (ic = nchars-2; ic >= 0; ic--) { if (strchr("~!@#^&|`?%", yytext[ic])) break; } if (ic >= 0) break; /* found a char that makes it OK */ nchars--; /* else remove the +/-, and check again */ } SET_YYLLOC(); if (nchars < yyleng) { /* Strip the unwanted chars from the token */ yyless(nchars); /* * If what we have left is only one char, and it's * one of the characters matching "self", then * return it as a character token the same way * that the "self" rule would have. */ if (nchars == 1 && strchr(",()[].;:+-*/%^<>=", yytext[0])) { yylval.val.str = yytext; yylval.val.modificator = NULL; yylval.val.keycode = yytext[0]; yylval.val.sep = NULL; return X_OTHERS; } } /* * Complain if operator is too long. Unlike the case * for identifiers, we make this an error not a notice- * and-truncate, because the odds are we are looking at * a syntactic mistake anyway. */ if (nchars >= NAMEDATALEN) yyerror(NULL, "operator too long"); /* Convert "!=" operator to "<>" for compatibility */ yylval.val.modificator = NULL; if (strcmp(yytext, "!=") == 0) yylval.val.str = pstrdup("<>"); else yylval.val.str = pstrdup(yytext); yylval.val.keycode = -1; yylval.val.sep = NULL; return X_OP; } {param} { SET_YYLLOC(); yylval.val.modificator = NULL; yylval.val.str = yytext; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_PARAM; } {integer} { long val; char* endptr; SET_YYLLOC(); errno = 0; val = strtol(yytext, &endptr, 10); if (*endptr != '\0' || errno == ERANGE #ifdef HAVE_LONG_INT_64 /* if long > 32 bits, check for overflow of int4 */ || val != (long) ((int32) val) #endif ) { /* integer too large, treat it as a float */ yylval.val.str = pstrdup(yytext); yylval.val.modificator = "f"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } yylval.val.str = yytext; yylval.val.modificator = "i"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {decimal} { SET_YYLLOC(); yylval.val.str = pstrdup(yytext); yylval.val.modificator = "f"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {real} { SET_YYLLOC(); yylval.val.str = pstrdup(yytext); yylval.val.modificator = "f"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {realfail1} { /* * throw back the [Ee], and treat as {decimal}. Note * that it is possible the input is actually {integer}, * but since this case will almost certainly lead to a * syntax error anyway, we don't bother to distinguish. */ yyless(yyleng-1); SET_YYLLOC(); yylval.val.str = pstrdup(yytext); yylval.val.modificator = "f"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {realfail2} { /* throw back the [Ee][+-], and proceed as above */ yyless(yyleng-2); SET_YYLLOC(); yylval.val.str = pstrdup(yytext); yylval.val.modificator = "f"; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_NCONST; } {identifier} { const ScanKeyword *keyword; char *ident; SET_YYLLOC(); /* Is it a keyword? */ keyword = ScanKeywordLookup(yytext ScanKeywordLookupArgs); if (keyword != NULL) { yylval.val.str = (char*) keyword->name; yylval.val.keycode = keyword->value; yylval.val.modificator = NULL; yylval.val.sep = NULL; return X_KEYWORD; } /* * No. Convert the identifier to lower case, and truncate * if necessary. */ ident = downcase_truncate_identifier(yytext, yyleng, true); yylval.val.str = ident; yylval.val.modificator = NULL; yylval.val.keycode = -1; yylval.val.sep = NULL; return X_IDENT; } {other} { SET_YYLLOC(); yylval.val.str = yytext; yylval.val.modificator = NULL; yylval.val.keycode = yytext[0]; yylval.val.sep = NULL; return X_OTHERS; } <> { SET_YYLLOC(); yyterminate(); } %% /* * lexer_errposition * Report a lexical-analysis-time cursor position, if possible. * * This is expected to be used within an ereport() call. The return value * is a dummy (always 0, in fact). * * Note that this can only be used for messages from the lexer itself, * since it depends on scanbuf to still be valid. */ static int lexer_errposition(void) { int pos; /* Convert byte offset to character number */ pos = _pg_mbstrlen_with_len(scanbuf, yylloc) + 1; /* And pass it to the ereport mechanism */ return errposition(pos); } /* * yyerror * Report a lexer or grammar error. * * The message's cursor position identifies the most recently lexed token. * This is OK for syntax error messages from the Bison parser, because Bison * parsers report error as soon as the first unparsable token is reached. * Beware of using yyerror for other purposes, as the cursor position might * be misleading! */ void yyerror(List **result, const char *message) { const char *loc = scanbuf + yylloc; if (*loc == YY_END_OF_BUFFER_CHAR) { ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), /* translator: %s is typically "syntax error" */ errmsg("%s at end of input", _(message)), lexer_errposition())); } else { ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), /* translator: first %s is typically "syntax error" */ errmsg("%s at or near \"%s\"", _(message), loc), lexer_errposition())); } } /* * Called before any actual parsing is done */ void orafce_sql_scanner_init(const char *str) { Size slen = strlen(str); /* * Might be left over after ereport() */ if (YY_CURRENT_BUFFER) yy_delete_buffer(YY_CURRENT_BUFFER); /* * Make a scan buffer with special termination needed by flex. */ scanbuflen = slen; scanbuf = palloc(slen + 2); memcpy(scanbuf, str, slen); scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; scanbufhandle = yy_scan_buffer(scanbuf, slen + 2); /* initialize literal buffer to a reasonable but expansible size */ literalalloc = 128; literalbuf = (char *) palloc(literalalloc); startlit(); BEGIN(INITIAL); } /* * Called after parsing is done to clean up after fdate_scanner_init() */ void orafce_sql_scanner_finish(void) { yy_delete_buffer(scanbufhandle); pfree(scanbuf); } static void addlit(char *ytext, int yleng) { /* enlarge buffer if needed */ if ((literallen+yleng) >= literalalloc) { do { literalalloc *= 2; } while ((literallen+yleng) >= literalalloc); literalbuf = (char *) repalloc(literalbuf, literalalloc); } /* append new data, add trailing null */ memcpy(literalbuf+literallen, ytext, yleng); literallen += yleng; literalbuf[literallen] = '\0'; } static void addlitchar(unsigned char ychar) { /* enlarge buffer if needed */ if ((literallen+1) >= literalalloc) { literalalloc *= 2; literalbuf = (char *) repalloc(literalbuf, literalalloc); } /* append new data, add trailing null */ literalbuf[literallen] = ychar; literallen += 1; literalbuf[literallen] = '\0'; } /* * One might be tempted to write pstrdup(literalbuf) instead of this, * but for long literals this is much faster because the length is * already known. */ static char * litbufdup(void) { char *new; new = palloc(literallen + 1); memcpy(new, literalbuf, literallen+1); return new; } static unsigned char unescape_single_char(unsigned char c) { switch (c) { case 'b': return '\b'; case 'f': return '\f'; case 'n': return '\n'; case 'r': return '\r'; case 't': return '\t'; default: return c; } } orafce-VERSION_3_0_6/uninstall_orafunc.sql000077500000000000000000000175711221300436000206020ustar00rootroot00000000000000DROP FUNCTION pg_catalog.trunc(value date, fmt text); DROP FUNCTION pg_catalog.round(value date, fmt text); DROP FUNCTION pg_catalog.next_day(value date, weekday text); DROP FUNCTION pg_catalog.last_day(value date); DROP FUNCTION pg_catalog.months_between(date1 date, date2 date); DROP FUNCTION pg_catalog.add_months(day date, value int); DROP FUNCTION pg_catalog.trunc(value timestamp with time zone, fmt text); DROP FUNCTION pg_catalog.round(value timestamp with time zone, fmt text); DROP FUNCTION pg_catalog.round(value timestamp with time zone); DROP FUNCTION pg_catalog.round(value date); DROP FUNCTION pg_catalog.trunc(value timestamp with time zone); DROP FUNCTION pg_catalog.trunc(value date); DROP FUNCTION pg_catalog.nlssort(text, text); DROP FUNCTION pg_catalog.nlssort(text); DROP FUNCTION pg_catalog.set_nls_sort(text); DROP FUNCTION pg_catalog.instr(str text, patt text, start int, nth int); DROP FUNCTION pg_catalog.instr(str text, patt text, start int); DROP FUNCTION pg_catalog.instr(str text, patt text); DROP FUNCTION pg_catalog.to_char(num int); DROP FUNCTION pg_catalog.to_char(num bigint); DROP FUNCTION pg_catalog.to_char(num real); DROP FUNCTION pg_catalog.to_char(num double precision); DROP FUNCTION pg_catalog.to_char(num numeric); DROP FUNCTION pg_catalog.to_number(str text); DROP FUNCTION pg_catalog.to_date(str text); DROP FUNCTION pg_catalog.reverse(str text); DROP FUNCTION pg_catalog.lnnvl(bool); DROP AGGREGATE pg_catalog.listagg(text); DROP AGGREGATE pg_catalog.listagg(text, text); DROP FUNCTION pg_catalog.listagg1_transfn(internal, text); DROP FUNCTION pg_catalog.listagg2_transfn(internal, text, text); DROP FUNCTION pg_catalog.listagg_finalfn(internal); DROP AGGREGATE pg_catalog.median(real); DROP AGGREGATE pg_catalog.median(double precision); DROP FUNCTION pg_catalog.median4_transfn(internal, real); DROP FUNCTION pg_catalog.median8_transfn(internal, double precision); DROP FUNCTION pg_catalog.median4_finalfn(internal); DROP FUNCTION pg_catalog.median8_finalfn(internal); DROP FUNCTION dump("any"); DROP FUNCTION dump(text); DROP FUNCTION dump("any", integer); DROP FUNCTION dump(text, integer); DROP VIEW public.dual CASCADE; DROP FUNCTION nvl(anyelement, anyelement); DROP FUNCTION nvl2(anyelement, anyelement, anyelement); DROP FUNCTION concat(text, text); DROP FUNCTION concat(text, anyarray); DROP FUNCTION concat(anyarray, text); DROP FUNCTION concat(anyarray, anyarray); DROP FUNCTION concat(text, anynonarray); DROP FUNCTION concat(anynonarray, text); DROP FUNCTION concat(anynonarray, anynonarray); DROP FUNCTION concat(text, anyelement); DROP FUNCTION concat(anyelement, text); DROP FUNCTION concat(anyelement, anyelement); DROP FUNCTION bitand(bigint, bigint); DROP FUNCTION sinh(float8); DROP FUNCTION cosh(float8); DROP FUNCTION tanh(float8); DROP FUNCTION nanvl(float4, float4); DROP FUNCTION nanvl(float8, float8); DROP FUNCTION nanvl(numeric, numeric); DROP FUNCTION to_multi_byte(text); DROP FUNCTION decode(anyelement, anyelement, text); DROP FUNCTION decode(anyelement, anyelement, text, text); DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text); DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, text); DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text); DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text); DROP FUNCTION decode(anyelement, anyelement, bpchar); DROP FUNCTION decode(anyelement, anyelement, bpchar, bpchar); DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar); DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar); DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar); DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar); DROP FUNCTION decode(anyelement, anyelement, integer); DROP FUNCTION decode(anyelement, anyelement, integer, integer); DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer); DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, integer); DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer); DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer); DROP FUNCTION decode(anyelement, anyelement, bigint); DROP FUNCTION decode(anyelement, anyelement, bigint, bigint); DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint); DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, bigint); DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint); DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint); DROP FUNCTION decode(anyelement, anyelement, numeric); DROP FUNCTION decode(anyelement, anyelement, numeric, numeric); DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric); DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, numeric); DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric); DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric); DROP FUNCTION decode(anyelement, anyelement, date); DROP FUNCTION decode(anyelement, anyelement, date, date); DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date); DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, date); DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date); DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date); DROP FUNCTION decode(anyelement, anyelement, time); DROP FUNCTION decode(anyelement, anyelement, time, time); DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time); DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, time); DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time); DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time); DROP FUNCTION decode(anyelement, anyelement, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamp, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp); DROP FUNCTION decode(anyelement, anyelement, timestamptz); DROP FUNCTION decode(anyelement, anyelement, timestamptz, timestamptz); DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz); DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz); DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz); DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz); DROP FUNCTION dbms_random.initialize(); DROP FUNCTION dbms_random.normal(); DROP FUNCTION dbms_random.random(); DROP FUNCTION dbms_random.seed(integer); DROP FUNCTION dbms_random.seed(text); DROP FUNCTION dbms_random.string(opt text, len int); DROP FUNCTION dbms_random.terminate(); DROP FUNCTION dbms_random.value(low double precision, high double precision); DROP FUNCTION dbms_random.value(); DROP SCHEMA dbms_alert CASCADE; DROP SCHEMA dbms_assert CASCADE; DROP SCHEMA dbms_output CASCADE; DROP SCHEMA dbms_pipe CASCADE; DROP SCHEMA dbms_random CASCADE; DROP SCHEMA dbms_utility CASCADE; DROP SCHEMA oracle CASCADE; DROP SCHEMA plunit CASCADE; DROP SCHEMA plvchr CASCADE; DROP SCHEMA plvdate CASCADE; DROP SCHEMA plvlex CASCADE; DROP SCHEMA plvstr CASCADE; DROP SCHEMA plvsubst CASCADE; DROP SCHEMA utl_file CASCADE; orafce-VERSION_3_0_6/utility.c000066400000000000000000000101751221300436000161700ustar00rootroot00000000000000/* This code implements one part of functonality of free available library PL/Vision. Please look www.quest.com Original author: Steven Feuerstein, 1996 - 2002 PostgreSQL implementation author: Pavel Stehule, 2006 This module is under BSD Licence History: 1.0. first public version 22. September 2006 */ #include "postgres.h" #include "utils/builtins.h" #include "utils/numeric.h" #include "string.h" #include "stdlib.h" #include "utils/pg_locale.h" #include "mb/pg_wchar.h" #include "lib/stringinfo.h" #include "catalog/pg_type.h" #include "libpq/pqformat.h" #include "utils/array.h" #include "utils/memutils.h" #include "utils/lsyscache.h" #include "access/tupmacs.h" #include "orafunc.h" #include "builtins.h" #include "utils/elog.h" PG_FUNCTION_INFO_V1(dbms_utility_format_call_stack0); PG_FUNCTION_INFO_V1(dbms_utility_format_call_stack1); static char* dbms_utility_format_call_stack(char mode) { MemoryContext oldcontext = CurrentMemoryContext; ErrorData *edata; ErrorContextCallback *econtext; StringInfo sinfo; #if PG_VERSION_NUM >= 80400 errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN); #else errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO); #endif MemoryContextSwitchTo(oldcontext); for (econtext = error_context_stack; econtext != NULL; econtext = econtext->previous) (*econtext->callback) (econtext->arg); edata = CopyErrorData(); FlushErrorState(); /* Now I wont to parse edata->context to more traditional format */ /* I am not sure about order */ sinfo = makeStringInfo(); switch (mode) { case 'o': appendStringInfoString(sinfo, "----- PL/pgSQL Call Stack -----\n"); appendStringInfoString(sinfo, " object line object\n"); appendStringInfoString(sinfo, " handle number name\n"); break; } if (edata->context) { char *start = edata->context; while (*start) { char *oname = "anonymous object"; char *line = ""; char *eol = strchr(start, '\n'); Oid fnoid = InvalidOid; /* first, solve multilines */ if (eol) *eol = '\0'; /* first know format */ if (strncmp(start, "PL/pgSQL function ",18) == 0) { char *p1, *p2; if ((p1 = strstr(start, "function \""))) { p1 += strlen("function \""); if ((p2 = strchr(p1, '"'))) { *p2++ = '\0'; oname = p1; start = p2; } } else if ((p1 = strstr(start, "function "))) { p1 += strlen("function "); if ((p2 = strchr(p1, ')'))) { char c = *++p2; *p2 = '\0'; oname = pstrdup(p1); fnoid = DatumGetObjectId(DirectFunctionCall1(regprocedurein, CStringGetDatum(oname))); *p2 = c; start = p2; } } if ((p1 = strstr(start, "line "))) { int p2i; char c; p1 += strlen("line "); p2i = strspn(p1, "0123456789"); /* safe separator */ c = p1[p2i]; p1[p2i] = '\0'; line = pstrdup(p1); p1[p2i] = c; start = p1 + p2i; } } switch (mode) { case 'o': appendStringInfo(sinfo, "%8x %5s function %s", (int)fnoid, line, oname); break; case 'p': appendStringInfo(sinfo, "%8d %5s function %s", (int)fnoid, line, oname); break; case 's': appendStringInfo(sinfo, "%d,%s,%s", (int)fnoid, line, oname); break; } if (eol) { start = eol + 1; appendStringInfoChar(sinfo, '\n'); } else break; } } return sinfo->data; } Datum dbms_utility_format_call_stack0(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(cstring_to_text(dbms_utility_format_call_stack('o'))); }; Datum dbms_utility_format_call_stack1(PG_FUNCTION_ARGS) { text *arg = PG_GETARG_TEXT_P(0); char mode; if ((1 != VARSIZE(arg) - VARHDRSZ)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid parameter"), errdetail("Allowed only chars [ops]."))); mode = *VARDATA(arg); switch (mode) { case 'o': case 'p': case 's': break; default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid parameter"), errdetail("Allowed only chars [ops]."))); } PG_RETURN_TEXT_P(cstring_to_text(dbms_utility_format_call_stack(mode))); }