diff --git a/src/pgspot/visitors.py b/src/pgspot/visitors.py index 05f0a08..fcc0d1c 100644 --- a/src/pgspot/visitors.py +++ b/src/pgspot/visitors.py @@ -182,6 +182,14 @@ def visit(self, node): self.state, "SELECT " + value["expr"]["PLpgSQL_expr"]["query"], ) + case "PLpgSQL_stmt_while": + if "cond" in value: + visit_sql( + self.state, + "SELECT " + value["cond"]["PLpgSQL_expr"]["query"], + ) + if "body" in value: + self.visit(value["body"]) case _: self.visit(value) diff --git a/testdata/expected/while.out b/testdata/expected/while.out new file mode 100644 index 0000000..6b31312 --- /dev/null +++ b/testdata/expected/while.out @@ -0,0 +1,10 @@ +PS002: Unsafe function creation: w1() at line 1 +PS005: Function without explicit search_path: w1() at line 1 +PS017: Unqualified object reference: bool in CAST(format1('%s', 'false') AS bool) at line 1 +PS016: Unqualified function call: format1 at line 1 +PS001: Unqualified operator: '<' in 0 < _count at line 1 +PS001: Unqualified operator: '-' in _count - 1 at line 1 +PS016: Unqualified function call: format2 at line 1 + + Errors: 1 Warnings: 6 Unknown: 0 + diff --git a/testdata/while.sql b/testdata/while.sql new file mode 100644 index 0000000..ee9f52f --- /dev/null +++ b/testdata/while.sql @@ -0,0 +1,13 @@ +create or replace function w1() returns void as $func$ +declare + _count bigint; +begin + select 100 into strict _count; + while format1('%s','false')::bool loop + end loop; + while 0 < _count loop + _count := _count - 1; + PERFORM format2('%s','true'); + end loop; +end +$func$ language plpgsql;