Amigo tengo un problema, sucede que tengo una tabla y cuando le hago un update desde vfp se duplican los datos apesar q tengo un primary key, abajo t detalle todo. El Postgres q uso es la version 7.3
Tabla : en el POSTGRESQL
- Table: dba.sobre
-- DROP TABLE dba.sobre;
CREATE TABLE dba.sobre
(
-- Heredado: usercrea char(5),
-- Heredado: feccrea timestamp,
-- Heredado: userupd char(5),
-- Heredado: fecupd timestamp,
numorden int4 NOT NULL DEFAULT 0,
numsec int4 NOT NULL DEFAULT 1,
codexterno char(15),
codsuborden char(6),
fecproceso date NOT NULL,
fecdespacho date,
hordespacho time,
coddespacho char(5),
numsalidas int2 NOT NULL DEFAULT 0,
numruc char(11),
dscdestinatario char(60),
dscdireccion char(60),
dscdirecrefer char(60),
numcuadrante int2 NOT NULL DEFAULT 0,
codmotivo char(2),
codtipdocumento char(3),
codpostal char(3) NOT NULL,
codrazon char(2),
codmaestro char(12),
numruta
char(6),
swestado char(1) NOT NULL DEFAULT 'A',
codubicacion char(2),
numguiadigit char(6),
codcliente char(5),
coddescargo char(5),
fecdescargo date,
fecretorno date,
ndoc char(15),
codproducto char(8),
fecentrega_telecall date,
hordesde_telecall int2,
horhasta_telecall int2,
qpiezas int4 NOT NULL DEFAULT 0,
CONSTRAINT pk_sobre PRIMARY KEY (numorden, numsec),
CONSTRAINT fk_cliente FOREIGN KEY (codcliente)
REFERENCES dba.cliente (codcliente)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_distrito FOREIGN KEY (codpostal)
REFERENCES dba.distrito (codpostal)
ON UPDATE RESTRICT ON DELETE
RESTRICT,
CONSTRAINT fk_guiadigital FOREIGN KEY (numguiadigit)
REFERENCES dba.guiadigital (numguiadigit)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_hruta FOREIGN KEY (numruta)
REFERENCES dba.hruta (numruta)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_orden FOREIGN KEY (numorden)
REFERENCES dba.orden (numorden)
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_personal_desc FOREIGN KEY (coddescargo)
REFERENCES dba.personal (codpersonal)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_personal_desp FOREIGN KEY
(coddespacho)
REFERENCES dba.personal (codpersonal)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_producto FOREIGN KEY (numorden, codproducto)
REFERENCES dba.producto (numorden, codproducto)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_razon FOREIGN KEY (codrazon)
REFERENCES dba.razon (codrazon)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_sub_orden FOREIGN KEY (numorden, codsuborden)
REFERENCES dba.sub_orden (numorden, numsorden)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_tipo_documento FOREIGN KEY
(codtipdocumento)
REFERENCES dba.tipo_documento (codtipdocumento)
ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT chk_estado CHECK (((swestado = 'A'::bpchar) OR (swestado = 'C'::bpchar))),
CONSTRAINT chk_numcuadrante CHECK ((numcuadrante >= 0)),
CONSTRAINT chk_numsalidas CHECK ((numsalidas >= 0))
) INHERITS (dba.campos_comunes)
WITH OIDS;
ALTER TABLE dba.sobre OWNER TO dba;
-- Index: dba.idx_codexterno
-- DROP INDEX dba.idx_codexterno;
CREATE INDEX idx_codexterno
ON dba.sobre
USING btree
(codexterno)
WHERE (codexterno IS NOT NULL);
-- Index: dba.idx_primary
-- DROP INDEX dba.idx_primary;
CREATE UNIQUE INDEX idx_primary
ON dba.sobre
USING btree
(numorden, numsec);
-- Index: dba.xsobre_ruta
-- DROP INDEX dba.xsobre_ruta;
CREATE INDEX xsobre_ruta
ON dba.sobre
USING btree
(numruta)
WHERE (numruta IS NOT NULL);
-- Trigger: ti_update on dba.sobre
-- DROP TRIGGER ti_update ON dba.sobre;
CREATE TRIGGER ti_update
BEFORE UPDATE
ON dba.sobre
FOR EACH ROW
EXECUTE PROCEDURE dba.f_actualizacion_sobre();
*-------- Detalle del Trigger ---------------------------
CREATE OR REPLACE FUNCTION dba.f_actualizacion_sobre()
RETURNS "trigger" AS
'BEGIN
IF NEW.codmotivo IS NOT NULL Then
-- Adiciono al Log entrada
If (OLD.codmotivo IS NULL) OR (NEW.Codmotivo <> OLD.CodMotivo) Then
--INSERT INTO dba.sobre_log Values (NEW.*) ;
Insert Into dba.sobre_log Values
(new.usercrea,
new.feccrea,
new.userupd,
new.fecupd,
new.numorden,
new.numsec,
new.codexterno,
new.codsuborden,
new.fecproceso,
new.fecdespacho,
new.hordespacho,
new.coddespacho,
new.numsalidas,
new.numruc,
new.dscdestinatario,
new.dscdireccion,
new.dscdirecrefer,
new.numcuadrante,
new.codmotivo,
new.codtipdocumento,
new.codpostal,
new.codrazon,
new.codmaestro,
new.numruta,
new.swestado,
&n
bsp; new.codubicacion,
new.numguiadigit,
new.codcliente,
new.coddescargo,
new.fecdescargo,
new.fecretorno) ;
End If ;
End if ;
RETURN NEW ;
END ;'
LANGUAGE 'plpgsql' VOLATILE;
GRANT EXECUTE ON FUNCTION dba.f_actualizacion_sobre() TO public;
GRANT EXECUTE ON FUNCTION dba.f_actualizacion_sobre() TO postgres;
GRANT EXECUTE ON FUNCTION dba.f_actualizacion_sobre() TO GROUP administradores;
*-----------------------------------------------------------------------------------------------------------------
Aca uso la Instruccion en el VFP para actualizar, las variables precedidas con "?" son
variables q almacen datos en el VFP
lSQL = "Update dba.sobre Set coddescargo = ?pUserApp , " + ;
" fecdescargo = ?lDTE , fecretorno = ?lFRet , " + ;
" CodMotivo = ?lMot , codrazon = ?lCRaz " + ;
" Where NumOrden = ?lNumOrden and NumSec = ?lNumSec"
lHndExec = SQLEXEC(lHndConn,lSQL)