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