Changeset 15 for trunk/epic
- Timestamp:
- 08/26/08 00:52:14 (4 years ago)
- Files:
-
- 1 modified
-
trunk/epic/epic.sql (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/epic/epic.sql
r14 r15 111 111 112 112 * test.assert_raises(call text, errm text, state text): 113 Raises an exception if 'SELECT * FROM [call];'does not raise errm113 Raises an exception if call does not raise errm 114 114 (if provided) or state (if provided). 115 115 … … 211 211 212 212 213 CREATE OR REPLACE FUNCTION test.statement(call text) RETURNS text AS $$ 214 DECLARE 215 result text; 216 BEGIN 217 result := rtrim(call, ';'); 218 IF NOT result ILIKE 'SELECT%' THEN 219 result := 'SELECT * FROM ' || result; 220 END IF; 221 RETURN result; 222 END; 223 $$ LANGUAGE plpgsql; 224 225 213 226 -------------------------------- global records -------------------------------- 214 227 … … 234 247 -- Stores the given call's output in a TEMP table, and returns it as a record. 235 248 -- 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. 237 250 -- 238 251 -- The returned record includes the following additional attributes: … … 246 259 BEGIN 247 260 tablename := '_global_' || nextval('_global_ids'); 248 EXECUTE 'CREATE TEMP TABLE ' || tablename || ' AS SELECT * FROM ' || call;261 EXECUTE 'CREATE TEMP TABLE ' || tablename || ' AS ' || statement(call); 249 262 EXECUTE 'SELECT ''' || tablename || '''::text AS tablename, * FROM ' || tablename INTO result; 250 263 RETURN result; … … 421 434 retval text; 422 435 BEGIN 423 EXECUTE ('SELECT * FROM ' || call || ';') INTO retval;436 EXECUTE statement(call) INTO retval; 424 437 IF retval != '' THEN 425 438 RAISE EXCEPTION 'Call: ''%'' did not return void. Got ''%'' instead.', call, retval; … … 538 551 539 552 CREATE 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. 541 554 -- 542 555 -- Example: … … 553 566 BEGIN 554 567 BEGIN 555 EXECUTE 'SELECT * FROM '||call||';';568 EXECUTE statement(call); 556 569 EXCEPTION 557 570 WHEN OTHERS THEN … … 598 611 e text; 599 612 BEGIN 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); 609 615 610 616 FOR rec in EXECUTE s || ' EXCEPT ' || e … … 643 649 -- Dump the call output into a temp table 644 650 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); 647 652 SELECT INTO firstname a.attname 648 653 FROM pg_class c LEFT JOIN pg_attribute a ON c.oid = a.attrelid
