Skip to content

Commit abaebdb

Browse files
committed
Fix - Raised notices are printed backwards dbcli#1443
1 parent e2ff38d commit abaebdb

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

pgcli/pgexecute.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def execute_normal_sql(self, split_sql):
437437

438438
def handle_notices(n):
439439
nonlocal title
440-
title = f"{n.message_primary}\n{n.message_detail}\n{title}"
440+
title = f"{title}{n.message_primary}\n{n.message_detail}\n"
441441

442442
self.conn.add_notice_handler(handle_notices)
443443

tests/features/steps/crud_database.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Each step is defined by the string decorating it.
44
This string is used to call the step in "*.feature" file.
55
"""
6+
67
import pexpect
78

89
from behave import when, then

tests/test_pgexecute.py

+36
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,42 @@ def test_function_definition(executor):
690690
result = executor.function_definition("the_number_three")
691691

692692

693+
@dbtest
694+
def test_function_notice_order(executor):
695+
run(
696+
executor,
697+
"""
698+
CREATE OR REPLACE FUNCTION pgcli_demo_order() RETURNS VOID AS
699+
$$
700+
BEGIN
701+
RAISE NOTICE 'first';
702+
RAISE NOTICE 'second';
703+
RAISE NOTICE 'third';
704+
RAISE NOTICE 'fourth';
705+
RAISE NOTICE 'fifth';
706+
RAISE NOTICE 'sixth';
707+
END;
708+
$$
709+
LANGUAGE plpgsql;
710+
""",
711+
)
712+
result = executor.function_definition("pgcli_demo_order")
713+
714+
result = run(executor, "select demo_order()")
715+
assert (
716+
"first\nNone\nsecond\nNone\nthird\nNone\nfourth\nNone\nfifth\nNone\nsixth\nNone\n"
717+
in result[0]
718+
)
719+
assert "+------------+" in result[1]
720+
assert "| demo_order |" in result[2]
721+
assert "|------------|" in result[3]
722+
assert "| |" in result[4]
723+
assert "+------------+" in result[5]
724+
assert "SELECT 1" in result[6]
725+
726+
print(result)
727+
728+
693729
@dbtest
694730
def test_view_definition(executor):
695731
run(executor, "create table tbl1 (a text, b numeric)")

0 commit comments

Comments
 (0)