Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > PostgreSQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 11-09-2010
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Poder: 20
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
  #2  
Antiguo 12-09-2010
chelard chelard is offline
Miembro
 
Registrado: nov 2009
Posts: 12
Poder: 0
chelard Va por buen camino
Hola Yapt:

Muchisimas gracias por responder, y practicamente lo hiciste todo, mucho mas de lo que esperaba,

Si lo intente, desgraciadamente el primer paso era el trigger y ahi es donde me quede,

Manos a la obra para pasarlo a Unidac y en seguida posteo los cambios,

Vamos te mereces un millon de gracias, me has ahorrado mucho trabajo.
Volvere pronto para poner los cambios.
Responder Con Cita
  #3  
Antiguo 12-09-2010
chelard chelard is offline
Miembro
 
Registrado: nov 2009
Posts: 12
Poder: 0
chelard Va por buen camino
Capturando Eventos con Unidac

Hola Yapt:
Muchas gracias nuevamente funciona perfecto.

Bueno y como me lo pediste dejo aca el codigo para que funcione con los componentes Unidac.

Primeramente el trigger y la BD, igual como tu lo hiciste, el formulario quedo asi

Código Delphi [-]
object Form1: TForm1
  Left = 438
  Top = 103
  Width = 349
  Height = 289
  Caption = 'Form1'
  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
    Left = 8
    Top = 80
    Width = 329
    Height = 169
    Lines.Strings = (
      'Memo1')
    TabOrder = 0
  end
  object btn1: TButton
    Left = 121
    Top = 45
    Width = 75
    Height = 25
    Caption = 'DeSuscribir'
    TabOrder = 1
    OnClick = btn1Click
  end
  object btn2: TButton
    Left = 121
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Suscribir'
    TabOrder = 2
    OnClick = btn2Click
  end
  object btn3: TButton
    Left = 8
    Top = 53
    Width = 75
    Height = 25
    Caption = 'Desconectar'
    TabOrder = 3
    OnClick = btn3Click
  end
  object btn4: TButton
    Left = 8
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Conectar'
    TabOrder = 4
    OnClick = btn4Click
  end
  object unipg1: TPostgreSQLUniProvider
    Left = 208
    Top = 8
  end
  object con1: TUniConnection
    ProviderName = 'PostgreSQL'
    Port = 5432
    Database = 'BasedeDatos'
    Username = 'Usuario'
    Password = 'clave'
    Server = 'localhost'
    Connected = True
    LoginPrompt = False
    Left = 208
    Top = 32
  end
  object ale1: TUniAlerter
    Connection = con1
    Events = 'pgEventoInsert'
    OnEvent = ale1Event
    Left = 240
    Top = 8
  end
end

... Y el codigo quedo de esta manera,

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DB, DBAccess, Uni, UniProvider,
  PostgreSQLUniProvider, DAAlerter, UniAlerter;

type
  TForm1 = class(TForm)
    unipg1: TPostgreSQLUniProvider;
    con1: TUniConnection;
    ale1: TUniAlerter;
    Memo1: TMemo;
    btn1: TButton;
    btn2: TButton;
    btn3: TButton;
    btn4: TButton;
    procedure btn4Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
    procedure ale1Event(Sender: TDAAlerter; const EventName,
      Message: String);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn4Click(Sender: TObject);
begin
  con1.Connect;
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
  ale1.Active := True;


end;

procedure TForm1.btn1Click(Sender: TObject);
begin
        ale1.Active := False;
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
  con1.Disconnect;
end;

procedure TForm1.ale1Event(Sender: TDAAlerter; const EventName,
  Message: String);
begin
    Memo1.Lines.Add('['+TimeToStr(now)+']'+'El proceso:  ha lanzado el evento: ' + EventName);
end;

end.
Responder Con Cita
  #4  
Antiguo 12-09-2010
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Poder: 20
yapt Va por buen camino
Me alegro que haya sido fácil trasladar el código a UNIDAC.

Suerte.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Capturar Eventos de Windows berna API de Windows 4 07-10-2008 19:40:52
Capturar Eventos del Control Remoto lachuza API de Windows 2 05-06-2008 20:36:05
capturar eventos de un telefono fedeloko API de Windows 0 04-10-2006 01:35:48
Capturar eventos de Windows Carlos G. C++ Builder 1 19-08-2004 14:22:28
Capturar eventos de componentes vichovi OOP 3 13-06-2003 19:01:33


La franja horaria es GMT +2. Ahora son las 07:37:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi