Skip to content

Commit 27b2bc2

Browse files
authored
Raised notices (#1450)
* Fix - Raised notices are printed backwards #1443 * updated changelog * removed a print * fixed up syntax error * removing unneeded Nones from output * rem var due to github recommendation * adjusting if statements.
1 parent e2ff38d commit 27b2bc2

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug fixes:
99
----------
1010

1111
* Fix display of "short host" in prompt (with `\h`) for IPv4 addresses ([issue 964](https://github.com/dbcli/pgcli/issues/964)).
12+
* Fix backwards display of NOTICEs from a Function ([issue 1443](https://github.com/dbcli/pgcli/issues/1443))
1213

1314

1415
==================

pgcli/pgexecute.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ 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}"
441+
if n.message_primary is not None:
442+
title = f"{title}\n{n.message_primary}"
443+
if n.message_detail is not None:
444+
title = f"{title}\n{n.message_detail}"
441445

442446
self.conn.add_notice_handler(handle_notices)
443447

tests/features/steps/crud_database.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,38 @@ 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 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+
713+
executor.function_definition("demo_order")
714+
715+
result = run(executor, "select demo_order()")
716+
assert "first\nsecond\nthird\nfourth\nfifth\nsixth" in result[0]
717+
assert "+------------+" in result[1]
718+
assert "| demo_order |" in result[2]
719+
assert "|------------|" in result[3]
720+
assert "| |" in result[4]
721+
assert "+------------+" in result[5]
722+
assert "SELECT 1" in result[6]
723+
724+
693725
@dbtest
694726
def test_view_definition(executor):
695727
run(executor, "create table tbl1 (a text, b numeric)")

0 commit comments

Comments
 (0)