kputnam / piggly

PL/pgSQL stored procedure code coverage tool
Other
69 stars 14 forks source link

declare statement before begin causes parse failure #36

Closed born-in-brooklyn closed 6 years ago

born-in-brooklyn commented 6 years ago

here's the proc that caused the issue (with names changed to protect the innocent) the proc takes in an array of a record type, the unnests it, and joins it to a table, and finally inserts the result into another table, captures the count and reports it in a message

CREATE OR REPLACE FUNCTION foo.bar_store(p_baz foo.type_baz[])
  RETURNS integer AS
$BODY$
DECLARE
  v_cnt INTEGER;
BEGIN
  INSERT INTO foo.foo_table(bar, barbar_fl, foofoo_fl, bazbaz_ts)
    SELECT
      a.zoorzoor_id,
      b.zap_fl,
      b.zip_fl,
      current_timestamp
    FROM unnest(p_baz) a
      INNER JOIN foo.zimzam b
        ON a.zoor_id = b.zoor_id
  ON CONFLICT (bar)
    DO UPDATE SET barbar_fl= excluded.barbar_fl, foofoo_fl= excluded.foofoo_fl, last_updt_ts=current_timestamp;
  GET DIAGNOSTICS v_cnt = ROW_COUNT;
  RAISE NOTICE '[risk.bar_store] Updated % bar stuffs', v_cnt;
  RETURN v_cnt;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

this results in the following error:

            ****
            Error compiling procedure foo.bar_store
            Source: C:/Users/K26962/RAW/comp-workspace/src/test/resources/sql/piggly/cache/Dumper/4cde0c9accf97c38a7592321d00d388e.plpgsql
            Exception Message:
            Expected one of /*, --, stacked at line 18, column 7 (byte 582) after declare
kputnam commented 6 years ago

It seems #28 only implemented parsing for GET STACKED DIAGNOSTICS, not also for GET DIAGNOSTICS so this was fairly easy to fix.

born-in-brooklyn commented 6 years ago

sweet! please build a new gem and I'll give it a try!

kputnam commented 6 years ago

Sorry, forgot to mention that I'd done that earlier. It's published now

born-in-brooklyn commented 6 years ago

Np. Tested it. Looks like all my procs are covered now. Thank you so much! Going to open some issues regarding rules next