darold / ora2pg

Ora2Pg is a free tool used to migrate an Oracle database to a PostgreSQL compatible schema. It connects your Oracle database, scan it automatically and extracts its structure or data, it then generates SQL scripts that you can load into PostgreSQL.
http://www.ora2pg.com/
GNU General Public License v3.0
978 stars 341 forks source link

Bug from commit cabd72a #1737

Closed carenswijaya01 closed 4 months ago

carenswijaya01 commented 4 months ago
          Got it, commit cabd72a fix this issue with trigger input file.

Originally posted by @darold in https://github.com/darold/ora2pg/issues/1736#issuecomment-1951868703

Haha it still bug my friend, the output like this

CREATE TRIGGER trg_absensi_online
    BEFORE INSERT ON absensi_online TRG_ABSENSI_ONLINE
BEFORE INSERT
ON SM.ABSENSI_ONLINE
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
    EXECUTE PROCEDURE trigger_fct_trg_absensi_online();

Look at BEFORE INSERT, there are 2 statements. For the FOR EACH ROW glad u fixed it, thanks. But for BEFORE INSERT, it still bug.

Thanks.

darold commented 4 months ago

I do not the same issue. Using Oracle code:

CREATE OR REPLACE TRIGGER SCHM_NAME.TRG_T_ENVOI
BEFORE INSERT
ON SCHM_NAME.T_ENVOI
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
declare
  v integer;
  json_str varchar2(30);
  mKOD VARCHAR2(128);
begin
  json_str := '{"code": 1}';
  SELECT FIELD_1 into v FROM TEST_TRIGGER;

  mKOD:= substr(:new.nazev,1,instr(:new.nazev,'-',1)-1);
  IF v = 0 then
    return;
  end if;

  SELECT FIELD_1 into v FROM TEST_TRIGGER;
end;
/

I have the following output

DROP TRIGGER IF EXISTS trg_t_envoi ON schm_name.t_envoi CASCADE;
CREATE OR REPLACE FUNCTION trigger_fct_trg_t_envoi() RETURNS trigger AS $BODY$
declare
  v integer;
  json_str varchar(30);
  mKOD varchar(128);
BEGIN
  json_str := '{"code": 1}';
  SELECT FIELD_1 into STRICT v FROM TEST_TRIGGER;

  mKOD:= substr(NEW.nazev,1,position('-' in NEW.nazev)-1);
  IF v = 0 then
    RETURN NEW;
  end if;

  SELECT FIELD_1 into STRICT v FROM TEST_TRIGGER;
RETURN NEW;
end
$BODY$
 LANGUAGE 'plpgsql';

CREATE TRIGGER trg_t_envoi
    BEFORE INSERT ON schm_name.t_envoi  REFERENCING NEW AS New OLD AS Old
 FOR EACH ROW
    EXECUTE PROCEDURE trigger_fct_trg_t_envoi();

which look to be correct for me.

Please post the oracle DDL.

darold commented 4 months ago

Sorry got it, I still see the double "BEFORE INSERT" in export from database. I will fix that.

darold commented 4 months ago

Then how about commit 394399b ? :-)

carenswijaya01 commented 4 months ago

Then how about commit 394399b ? :-)

Wait, i'll check it tomorrow, because i already at home rn :D

carenswijaya01 commented 4 months ago

Then how about commit 394399b ? :-)

Yup it works perfectly. Thanks darold :D