Ver Mensaje Individual
  #9  
Antiguo 11-09-2010
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Reputación: 18
yapt Va por buen camino
Chelard,

normalmente esto no funciona así. Tienes unas directrices generales, al menos intentalo y vuelve con las dudas concretas que puedas tener.

Pero veo que, al menos, eres de los que responden y.... bueno... que aquí va (para referencia futura):

En PostGreSQL (8.4):

Código SQL [-]
/*
  Creamos la función que será llamada por el TRIGGER.
*/

CREATE OR REPLACE FUNCTION "f_eventoInsert"()
  RETURNS trigger AS
$BODY$BEGIN
  NOTIFY pgEventoInsert;
  RETURN NEW;
END;$BODY$
  LANGUAGE 'plpgsql' VOLATILE COST 100;

/*
  Creamos la tabla.
*/
CREATE TABLE "testEventos"
(
  id numeric(5,0) NOT NULL,
  nombre character varying(10),
  CONSTRAINT "pk_testEventos" PRIMARY KEY (id)
)
WITH (OIDS=FALSE);


/*
  Creamos el Trigger y lo asociamos a la tabla.
*/
-- Trigger: tg_test_eventoInsert on "testEventos"
-- DROP TRIGGER "tg_test_eventoInsert" ON "testEventos";
CREATE TRIGGER "tg_test_eventoInsert"
  AFTER INSERT
  ON "testEventos"
  FOR EACH ROW
  EXECUTE PROCEDURE "f_eventoInsert"();



Y en Delphi. Esto está hecho con los controles de las Devart (PgDAC) que son los que yo tengo licenciados y no con UNIDAC que es el que has comprado tú (tengo la esperanza de que así sea).


Delphi:

{ El formulario.... }

Código Delphi [-]
object Form1: TForm1
  Left = 382
  Top = 212
  Caption = 'Form1'
  ClientHeight = 255
  ClientWidth = 288
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    AlignWithMargins = True
    Left = 3
    Top = 87
    Width = 282
    Height = 165
    Align = alClient
    TabOrder = 0
    ExplicitLeft = 40
    ExplicitTop = 144
    ExplicitWidth = 185
    ExplicitHeight = 89
  end
  object Panel1: TPanel
    AlignWithMargins = True
    Left = 3
    Top = 3
    Width = 282
    Height = 78
    Align = alTop
    BevelOuter = bvNone
    TabOrder = 1
    ExplicitWidth = 178
    object Button1: TButton
      Left = 8
      Top = 8
      Width = 75
      Height = 25
      Caption = 'Conectar'
      TabOrder = 0
      OnClick = Button1Click
    end
    object Button2: TButton
      Left = 89
      Top = 16
      Width = 75
      Height = 25
      Caption = 'Suscribir'
      TabOrder = 1
      OnClick = Button2Click
    end
    object Button3: TButton
      Left = 89
      Top = 45
      Width = 75
      Height = 25
      Caption = 'DeSuscribir'
      TabOrder = 2
      OnClick = Button3Click
    end
    object Button4: TButton
      Left = 8
      Top = 53
      Width = 75
      Height = 25
      Caption = 'Desconectar'
      TabOrder = 3
      OnClick = Button4Click
    end
  end
  object PgConnection1: TPgConnection
    Username = 'usuario'
    Password = 'clave'
    Server = 'localhost'
    Connected = True
    LoginPrompt = False
    Database = 'postgres'
    Left = 195
    Top = 19
  end
  object PgAlerter1: TPgAlerter
    Events = 'pgEventoInsert'
    Connection = PgConnection1
    OnEvent = PgAlerter1Event
    Left = 203
    Top = 67
  end
end


{ El Código.... }

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBAccess, PgAccess, StdCtrls, ExtCtrls, DAAlerter, PgAlerter;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    PgConnection1: TPgConnection;
    PgAlerter1: TPgAlerter;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure PgAlerter1Event(Sender: TObject; const EventName: string;
      PID: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  PgConnection1.Connect;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  PgAlerter1.Active := true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  PgAlerter1.Active := false;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  PgConnection1.Disconnect;
end;

procedure TForm1.PgAlerter1Event(Sender: TObject; const EventName: string;
  PID: Integer);
begin
  Memo1.Lines.Add('['+TimeToStr(now)+']'+'El proceso: ' + IntToStr(PID) + ' ha lanzado el evento: ' + EventName);
end;

end.

Cuando lo conviertas a UNIDAC, deja aquí los cambios para que sirvan para futuros visitantes.

Gracias.
Responder Con Cita