| 692 | | FOR i IN array_lower(expected, 1)..array_upper(expected, 1) |
| 693 | | LOOP |
| 694 | | IF expected[i] IS NULL THEN |
| 695 | | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (NULL);'; |
| 696 | | ELSEIF typename(expected[i]) IN ('text', 'varchar', 'char', 'bytea', 'date', 'timestamp', 'timestamptz', 'time', 'timetz') THEN |
| 697 | | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (' |
| 698 | | || quote_literal(expected[i]) || ');'; |
| 699 | | ELSE |
| 700 | | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (' |
| 701 | | || expected[i] || ');'; |
| 702 | | END IF; |
| 703 | | END LOOP; |
| | 691 | IF array_lower(expected, 1) iS NOT NULL THEN |
| | 692 | FOR i IN array_lower(expected, 1)..array_upper(expected, 1) |
| | 693 | LOOP |
| | 694 | IF expected[i] IS NULL THEN |
| | 695 | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (NULL);'; |
| | 696 | ELSEIF typename(expected[i]) IN ('text', 'varchar', 'char', 'bytea', 'date', 'timestamp', 'timestamptz', 'time', 'timetz') THEN |
| | 697 | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (' |
| | 698 | || quote_literal(expected[i]) || ');'; |
| | 699 | ELSE |
| | 700 | EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (' |
| | 701 | || expected[i] || ');'; |
| | 702 | END IF; |
| | 703 | END LOOP; |
| | 704 | END IF; |
| 770 | | i int; |
| 771 | | BEGIN |
| 772 | | FOR i in array_lower(tablenames, 1)..array_upper(tablenames, 1) |
| 773 | | LOOP |
| 774 | | EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablenames[i] || '));' INTO result; |
| 775 | | IF result THEN |
| 776 | | failed := failed || ('"' || btrim(tablenames[i]) || '"'); |
| | 771 | BEGIN |
| | 772 | IF array_lower(tablenames, 1) IS NOT NULL THEN |
| | 773 | FOR i in array_lower(tablenames, 1)..array_upper(tablenames, 1) |
| | 774 | LOOP |
| | 775 | EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablenames[i] || '));' INTO result; |
| | 776 | IF result THEN |
| | 777 | failed := failed || ('"' || btrim(tablenames[i]) || '"'); |
| | 778 | END IF; |
| | 779 | END LOOP; |
| | 780 | END IF; |
| | 781 | |
| | 782 | IF array_lower(failed, 1) IS NOT NULL THEN |
| | 783 | failed_len := (array_upper(failed, 1) - array_lower(failed, 1)) + 1; |
| | 784 | IF failed_len = 1 THEN |
| | 785 | PERFORM test.fail('The table ' || array_to_string(failed, ', ') || ' is not empty.'); |
| | 786 | ELSEIF failed_len > 1 THEN |
| | 787 | PERFORM test.fail('The tables ' || array_to_string(failed, ', ') || ' are not empty.'); |
| | 810 | |
| | 811 | CREATE OR REPLACE FUNCTION test.assert_not_empty(tablenames text[]) RETURNS VOID AS $$ |
| | 812 | -- Raises an exception if the given tables have no rows. |
| | 813 | DECLARE |
| | 814 | result bool; |
| | 815 | failed text[]; |
| | 816 | failed_len int; |
| | 817 | BEGIN |
| | 818 | IF array_lower(tablenames, 1) IS NOT NULL THEN |
| | 819 | FOR i in array_lower(tablenames, 1)..array_upper(tablenames, 1) |
| | 820 | LOOP |
| | 821 | EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablenames[i] || '));' INTO result; |
| | 822 | IF NOT result THEN |
| | 823 | failed := failed || ('"' || btrim(tablenames[i]) || '"'); |
| | 824 | END IF; |
| | 825 | END LOOP; |
| | 826 | END IF; |
| | 827 | |
| | 828 | IF array_lower(failed, 1) IS NULL THEN |
| | 829 | -- failed is an empty array (no failures). |
| | 830 | NULL; |
| | 831 | ELSE |
| | 832 | failed_len := (array_upper(failed, 1) - array_lower(failed, 1)) + 1; |
| | 833 | IF failed_len = 1 THEN |
| | 834 | PERFORM test.fail('The table ' || array_to_string(failed, ', ') || ' is empty.'); |
| | 835 | ELSEIF failed_len > 1 THEN |
| | 836 | PERFORM test.fail('The tables ' || array_to_string(failed, ', ') || ' are empty.'); |
| | 837 | END IF; |
| | 838 | END IF; |
| | 839 | END; |
| | 840 | $$ LANGUAGE plpgsql; |
| | 841 | |
| | 842 | CREATE OR REPLACE FUNCTION test.assert_not_empty(tablename text) RETURNS VOID AS $$ |
| | 843 | -- Raises an exception if the given table has no rows. |
| | 844 | DECLARE |
| | 845 | result bool; |
| | 846 | BEGIN |
| | 847 | IF tablename LIKE '%,%' THEN |
| | 848 | PERFORM test.assert_not_empty(string_to_array(tablename, ',')); |
| | 849 | RETURN; |
| | 850 | END IF; |
| | 851 | |
| | 852 | EXECUTE 'SELECT (EXISTS (SELECT 1 FROM ' || tablename || '));' INTO result; |
| | 853 | IF NOT result THEN |
| | 854 | PERFORM test.fail('The table "' || tablename || '" is empty.'); |
| | 855 | END IF; |
| | 856 | END; |
| | 857 | $$ LANGUAGE plpgsql; |
| | 858 | |