home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / db / rdbms71 / prvtpipe.sql < prev    next >
Encoding:
Text File  |  1994-08-07  |  6.8 KB  |  178 lines

  1. rem 
  2. rem $Header: prvtpipe.sql 7010300.2 94/04/04 02:35:36 snataraj Generic<base> $ 
  3. rem 
  4. Rem
  5. Rem    NAME
  6. Rem      prvtpipe.sql - send and receive from dbms "pipes"
  7. Rem    DESCRIPTION
  8. Rem      These are private functions to be released in PL/SQL binary form.
  9. Rem      Allow sessions to pass information between them through 
  10. Rem      named SGA memory "pipes"
  11. Rem    RETURNS
  12. Rem 
  13. Rem    NOTES
  14. Rem      The procedural option is needed to use this facility.
  15. Rem      
  16. Rem    MODIFIED   (MM/DD/YY)
  17. Rem     wmaimone   02/22/94 -  use create or replace
  18. Rem     adowning   02/04/94 -  Branch_for_patch
  19. Rem     adowning   02/04/94 -  Creation
  20. Rem     adowning   02/02/94 -  split file into public / private binary files
  21. Rem     dsdaniel   07/09/93 -  dbms_defer longifaction for async rep
  22. Rem     rkooi      10/18/92 -  better comments 
  23. Rem     rkooi      08/20/92 -  comments and cleanup 
  24. Rem     rkooi      05/18/92 -  change comment 
  25. Rem     rkooi      04/28/92 -  change put to pack, etc. 
  26. Rem     rkooi      04/25/92 -  Creation 
  27.  
  28. REM ********************************************************************
  29. REM THIS PACKAGE MUST NOT BE MODIFIED BY THE CUSTOMER.  DOING SO
  30. REM COULD CAUSE INTERNAL ERRORS AND SECURITY VIOLATIONS IN THE
  31. REM RDBMS.  SPECIFICALLY, THE PSD* ROUTINES MUST NOT BE CALLED
  32. REM DIRECTLY BY ANY CLIENT AND MUST REMAIN PRIVATE TO THE PACKAGE BODY.
  33. REM ********************************************************************
  34.  
  35. create or replace package body dbms_pipe is
  36.   argbuf    char(4096) := 'a';  -- must be 'char' to get preallocated space
  37.                                 -- and must be assigned something in order
  38.                                 -- to be non-null
  39.   packpos   binary_integer := 0;
  40.   unpackpos binary_integer := 2000000000; -- i.e., no more data
  41.  
  42.   procedure sendpipe(pipename in varchar2, pos in binary_integer,
  43.         buffer in out char, maxpipesize in binary_integer,
  44.         timeout in binary_integer, retval out binary_integer);
  45.     pragma interface (C, sendpipe);                         -- 1 (see psdicd.c)
  46.   procedure receivepipe(pipename in varchar2, buffer in out char,
  47.       timeout in binary_integer, retval out binary_integer);
  48.     pragma interface (C, receivepipe);                      -- 2 (see psdicd.c)
  49.   
  50.   procedure copyintobuf(a in varchar2, pos in out binary_integer,
  51.       buf in out char);
  52.     pragma interface (C, copyintobuf);                      -- 3 (see psdicd.c)
  53.   procedure copyintobuf(a in number, pos in out binary_integer, 
  54.       buf in out char);
  55.     pragma interface (C, copyintobuf);                      -- 4 (see psdicd.c)
  56.   procedure copyintobuf(a in date, pos in out binary_integer, 
  57.       buf in out char);
  58.     pragma interface (C, copyintobuf);                      -- 5 (see psdicd.c)
  59.  
  60.   procedure copyfrombuf(a out varchar2, pos in out binary_integer, 
  61.       buf in char);
  62.     pragma interface (C, copyfrombuf);                      -- 6 (see psdicd.c)
  63.   procedure copyfrombuf(a out number, pos in out binary_integer, buf in char);
  64.     pragma interface (C, copyfrombuf);                      -- 7 (see psdicd.c)
  65.   procedure copyfrombuf(a out date, pos in out binary_integer, buf in char);
  66.     pragma interface (C, copyfrombuf);                      -- 8 (see psdicd.c)
  67.  
  68.   function gettypefrombuf(pos in binary_integer, buf in char) 
  69.       return binary_integer;
  70.     pragma interface (C, gettypefrombuf);                   -- 9 (see psdicd.c)
  71.  
  72.   procedure copyintobufbinary(a in raw, pos in out binary_integer,
  73.       buf in out char);
  74.     pragma interface (C, copyintobufbinary);               -- 10 (see psdicd.c)
  75.   procedure copyintobufrowid(a in rowid, pos in out binary_integer,
  76.       buf in out char);
  77.     pragma interface (C, copyintobufrowid);                -- 11 (see psdicd.c)
  78.  
  79.   procedure copyfrombufbinary(a out raw , pos in out binary_integer, 
  80.       buf in char);
  81.     pragma interface (C, copyfrombufbinary);                -- 12 (see psdicd.c)
  82.   procedure copyfrombufrowid(a out rowid, pos in out binary_integer, 
  83.       buf in char);
  84.     pragma interface (C, copyfrombufrowid);                 -- 13 (see psdicd.c)
  85.  
  86.   procedure pack_message(item in varchar2) is 
  87.     begin copyintobuf(item, packpos, argbuf); end;
  88.   procedure pack_message_raw(item in raw) is 
  89.     begin copyintobufbinary(item, packpos, argbuf); end;
  90.   procedure pack_message_rowid(item in rowid) is 
  91.     begin copyintobufrowid(item, packpos, argbuf); end;
  92.   procedure pack_message(item in number) is 
  93.     begin copyintobuf(item, packpos, argbuf); end;
  94.   procedure pack_message(item in date) is 
  95.     begin copyintobuf(item, packpos, argbuf); end;
  96.  
  97.   procedure unpack_message(item out varchar2) is
  98.     begin copyfrombuf(item, unpackpos, argbuf); end;
  99.   procedure unpack_message_raw(item out raw) is
  100.     begin copyfrombufbinary(item, unpackpos, argbuf); end;
  101.   procedure unpack_message_rowid(item out rowid) is
  102.     begin copyfrombufrowid(item, unpackpos, argbuf); end;
  103.   procedure unpack_message(item out number) is 
  104.     begin copyfrombuf(item, unpackpos, argbuf); end;
  105.   procedure unpack_message(item out date) is 
  106.     begin copyfrombuf(item, unpackpos, argbuf); end;
  107.  
  108.   function next_item_type return integer is
  109.   internal_type binary_integer;
  110.   begin
  111.     internal_type :=  gettypefrombuf(unpackpos, argbuf);
  112.     /* translate internal type code to declared external type code */
  113.     if internal_type = 1 then
  114.       return 9;
  115.     elsif internal_type = 2 then
  116.       return 6;
  117.     else return internal_type;
  118.     end if;
  119.   end;
  120.  
  121.   function send_message(pipename in varchar2, 
  122.                 timeout in integer default maxwait,
  123.                 maxpipesize in integer default 8192)
  124.       return integer is
  125.     retval binary_integer;
  126.     mps    binary_integer := maxpipesize;
  127.     tmo    binary_integer := timeout;
  128.   begin
  129.     if pipename is null then
  130.       raise_application_error(-20000, 'ORU-10026: Pipename may not be null');
  131.     end if;
  132.     sendpipe(upper(pipename), packpos, argbuf, mps, tmo, retval);
  133.     if retval = 0 then
  134.       packpos := 0;
  135.     end if;
  136.     return retval;
  137.   end;
  138.  
  139.   function receive_message(pipename in varchar2,
  140.                 timeout in integer default maxwait)
  141.       return integer is
  142.     retval binary_integer;
  143.     tmo    binary_integer := timeout;
  144.   begin
  145.     if pipename is null then
  146.       raise_application_error(-20000, 'ORU-10026: Pipename may not be null');
  147.     end if;
  148.     receivepipe(upper(pipename), argbuf, tmo, retval);
  149.     if retval = 0 then
  150.       unpackpos := 0;
  151.     else
  152.       unpackpos := 2000000000;  -- i.e., no more data in pipe
  153.     end if;
  154.     return retval;
  155.   end;
  156.  
  157.   procedure reset_buffer is
  158.   begin
  159.     unpackpos := 0; 
  160.     packpos := 0; 
  161.   end;
  162.  
  163.   procedure purge(pipename in varchar2) is
  164.   begin
  165.     loop
  166.       if receive_message(pipename, 0) <> 0 then
  167.         exit;
  168.       end if;
  169.     end loop;
  170.   end;
  171.  
  172.   function unique_session_name return varchar2 is
  173.   begin
  174.     return ('ORA$PIPE$' || dbms_session.unique_session_id);
  175.   end;
  176. end;
  177. /
  178.