Changeset 15 for trunk/epic

Show
Ignore:
Timestamp:
08/26/08 00:52:14 (4 years ago)
Author:
fumanchu
Message:

New 'statement' function. The funcs 'global', 'assert_void', and 'assert_raises' now allow full SELECT statements.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/epic.sql

    r14 r15  
    111111     
    112112    * test.assert_raises(call text, errm text, state text):  
    113         Raises an exception if 'SELECT * FROM [call];' does not raise errm 
     113        Raises an exception if call does not raise errm 
    114114        (if provided) or state (if provided). 
    115115 
     
    211211 
    212212 
     213CREATE OR REPLACE FUNCTION test.statement(call text) RETURNS text AS $$ 
     214DECLARE 
     215  result    text; 
     216BEGIN 
     217  result := rtrim(call, ';'); 
     218  IF NOT result ILIKE 'SELECT%' THEN 
     219    result := 'SELECT * FROM ' || result; 
     220  END IF; 
     221  RETURN result; 
     222END; 
     223$$ LANGUAGE plpgsql; 
     224 
     225 
    213226-------------------------------- global records -------------------------------- 
    214227 
     
    234247-- Stores the given call's output in a TEMP table, and returns it as a record. 
    235248--  
    236 -- 'call' can be any table, view, or procedure that returns records. 
     249-- 'call' can be any SELECT, table, view, or procedure that returns records. 
    237250--  
    238251-- The returned record includes the following additional attributes: 
     
    246259BEGIN 
    247260  tablename := '_global_' || nextval('_global_ids'); 
    248   EXECUTE 'CREATE TEMP TABLE ' || tablename || ' AS SELECT * FROM ' || call; 
     261  EXECUTE 'CREATE TEMP TABLE ' || tablename || ' AS ' || statement(call); 
    249262  EXECUTE 'SELECT ''' || tablename || '''::text AS tablename, * FROM ' || tablename INTO result; 
    250263  RETURN result; 
     
    421434  retval    text; 
    422435BEGIN 
    423   EXECUTE ('SELECT * FROM ' || call || ';') INTO retval; 
     436  EXECUTE statement(call) INTO retval; 
    424437  IF retval != '' THEN 
    425438    RAISE EXCEPTION 'Call: ''%'' did not return void. Got ''%'' instead.', call, retval; 
     
    538551 
    539552CREATE OR REPLACE FUNCTION test.assert_raises(call text, errm text, state text) RETURNS VOID AS $$ 
    540 -- Raises an exception if 'SELECT * FROM [call];' does not raise errm and/or state. 
     553-- Raises an exception if call does not raise errm and/or state. 
    541554--  
    542555-- Example: 
     
    553566BEGIN 
    554567  BEGIN 
    555     EXECUTE 'SELECT * FROM '||call||';'; 
     568    EXECUTE statement(call); 
    556569  EXCEPTION 
    557570    WHEN OTHERS THEN 
     
    598611  e       text; 
    599612BEGIN 
    600   s := rtrim(source, ';'); 
    601   IF NOT s ILIKE 'SELECT%' THEN 
    602     s := 'SELECT * FROM ' || s; 
    603   END IF; 
    604    
    605   e := rtrim(expected, ';'); 
    606   IF NOT e ILIKE 'SELECT%' THEN 
    607     e := 'SELECT * FROM ' || e; 
    608   END IF; 
     613  s := statement(source); 
     614  e := statement(expected); 
    609615   
    610616  FOR rec in EXECUTE s || ' EXCEPT ' || e 
     
    643649  -- Dump the call output into a temp table 
    644650  IF colname IS NULL THEN 
    645     EXECUTE 'CREATE TEMPORARY TABLE _test_assert_values_base AS ' || 
    646       'SELECT * FROM ' || call || ';'; 
     651    EXECUTE 'CREATE TEMPORARY TABLE _test_assert_values_base AS ' || statement(call); 
    647652    SELECT INTO firstname a.attname 
    648653      FROM pg_class c LEFT JOIN pg_attribute a ON c.oid = a.attrelid