UpdateFrom (selector)
De Wiki1000
function UpdateFrom(iSelector:TSelector; const iMatchedProps:Array of String; const iUpdatePropNames:Array of string; const iUpdatePropValues:Array of variant):Integer;
Cette méthode met à jour les objets sélectionnés par le sélecteur en utilisant un sélecteur source
| Paramètre | Usage |
|---|---|
| Result | Nombre d'objets affectés par l'opération |
| iSelector | Sélecteur source |
| iMatchedProps | Tableau de noms d'attribut qui doivent être égaux entre les deux sélecteurs |
| iUpdatePropNames | Tableau de noms d'attribut devant être mis à jour dans la même opération |
| iUpdatePropValues | Tableau de valeurs pour les attributs mis à jour |
Cette fonction retourne le nombre d'objets affectés par l'opération.
- iSelector
- Sélecteur source de l'opération, doit être en mode CTE
- iMatchedProps
- Tableau de propriétés qui doivent matcher dans l'opération de mise à jour CTE
- iUpdatePropnames,iUpdatePropValues
- Ces deux tableaux doivent avoir le même nombre d'élément et doivent référencer des attributs de la classe du sélecteur
| Tip : L'opération est effectué par un ordre SQL en mode auto commit, si une transaction longue est ouverte la session de la transaction longue est utilisée. |
MERGE target AS tm1 USING (source) AS tm0 ON ( tm0 matched properties tm1) WHEN MATCHED THEN UPDATE tm1.iUpdatePropNames = tm0.iUpdateSourceValues ;
Exemple :
//function _MAJPieceEtatPieceTypeAucun(aDateLimiteTraitement:datetime):integer; Type vuePieceTypeAucun = viewOf(TEcheance) idPiece : TOID = Ecriture.oidPiece; idLettrage : TOID = oidLettrage notInSelect; typeEcheance : integer = Ecriture.Piece.TypePiece.typeEcheance notInSelect; [typeEcheance=TypeEcheance_Aucun] end; vueEcheanceAvecPieceTypeAucun = viewOf(TEcheance) oidpieceEtat : TOID = oidPieceEtat; typeEcheance : integer = Ecriture.Piece.TypePiece.typeEcheance notInSelect; estLettrageTotal : boolean = Lettrage.LettrageEcriture.total notInSelect; dateLettrage : datetime = Lettrage.LettrageEcriture.lDate notInSelect; cNature:integer = Ecriture.CompteGeneral.natureCompte notInSelect; // idPieceDestination : TOID = vuePieceTypeAucun.select('idPiece','(idLettrage=self.oidLettrage)','-Ecriture.eDate,-dateEcheance,-oid',true,[]); aExistePieceDestination : TOID = vuePieceTypeAucun.select('idPiece','(idLettrage=self.oidLettrage)','',true,[]) notInSelect; [(typeEcheance in (TypeEcheance_Facture, TypeEcheance_FactureTVA, TypeEcheance_Reprise)) and (cNature=NatureCompte_TTC) and (((estLettrageTotal=true) and (dateLettrage>=%ArgDateLettrage)) or (estLettrageTotal=false)) and (oidPieceEtat='') and (Lettrage.oidEcritureDestination='') and (aExistePieceDestination<>'')] end; vueEcheance = viewOf(TEcheance) oidpieceEtat : TOID = oidPieceEtat; end; var vSel, vSelUpdate : TSelector; vBatchCount : integer; begin Result := 0; // Mise à jour de la pièce état des échéances Facture/Facture TVA/Reprise des deux derniers exercices // La pièce état est la pièce la plus récente de type "Aucun" du groupe de lettrage vBatchCount := 0; Repeat // Source selector of the CTE operation // (MUST BE CTE) // vSel := vueEcheanceAvecPieceTypeAucun.CreateSelector('', '', true, []); vSel.AddParameter('ArgDateLettrage', aDateLimiteTraitement); vSel.MaxInstances := nbElementParLot; vSel.useCTE := true; // ON match TEcheance on "oid" THEN update "oidpieceEtat" of dest FROM "idPieceDestination" of source // vSelUpdate := vueEcheance.CreateSelector('', '', true, []); vBatchCount := vSelUpdate.UpdateFrom(vSel, ['oid'], ['oidpieceEtat'], ['idPieceDestination']); Result := Result + vBatchCount; Until (vBatchCount<nbElementParLot); end;
Voir aussi :
| Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |