Operation (selector)

De Wiki1000
(Différences entre les versions)
(Page créée avec « {{version2025r2}} <source lang='delphi'>property Operation:string;</source> '''Lecture/Ecriture''' Cette propriété définit le nom d'une opération SQL de mise à jou... »)
 
 
Ligne 8 : Ligne 8 :
  
 
{{tip|Nécessite conjointement OpeId}}
 
{{tip|Nécessite conjointement OpeId}}
 +
 +
Lorsque les propriétés Operation et OperationId sont définies, l'opération CopyTo alimente une classe SQL des objets insérés.
 +
 +
Cette table peut ensuite être jointe dans des opérations SQL successives.
  
  
 
Exemple  
 
Exemple  
 +
 +
'''Use of TsqlOperation to chain SQL operations'''
  
 
<source lang='delphi'>
 
<source lang='delphi'>
 +
Type
 +
  // We want to create a TPiece from a TBordereauReglement
 +
  vueBordereau = viewOf(TBordereauReglement)
 +
  .... define TPiece columns  ....
 +
  end;
 +
 +
  // Then we want to add one ecriture by reglement of the borderau to this piece
 +
  //
 +
  vueReglement = viewOf(TReglement)
 +
  vl:TsqlOperation = join('(opeId=%ArgOpeId) and (operation=%ArgOperation)');
 +
  oidBordereau:TOID = oidBordereauReglement;
 +
  oidpiece:TOID = vl.oidTargetObject; // OID of the piece which has been created
 +
  .... define TEcriture columns ....
 +
  end;
 +
 +
  // And finally we want to update the TReglement with the oid of the TEcriture created for this reglement.
 +
  //
 +
  vueUpdateReglement = viewOf(TReglement)
 +
  vl:TsqlOperation = join('(opeId=%ArgOpeId) and (operation=%ArgOperation) and (oidSourceObject=self.oid)');
 +
  oidEcriture:TOID = oidEcriture;
 +
  oidTargetEcriture:TOID = vl.oidTargetObject; // OID of the TEcriture for this TReglement
 +
  oidBordereau:TOID = oidBordereauReglement;
 +
  end;
 +
 +
// foo(oidBordereauReglement)
 +
var opeId:string;
 +
begin
 +
  opeId := CreateGuid;
 +
  try
 +
  withP long transaction do
 +
  begin
 +
 +
    // Create a TPiece from this TBordereauReglement
 +
    // 
 +
    sel := vueBordereau.CreateSelector('(oid=%1)','',True,[oidBordereauReglement]);
 +
    sel.OpeId := opeId;
 +
    sel.Operation := 'Piece';
 +
    sel.CopyTo('TPiece',[],[]);
 +
 +
    // We could also retrieve the OID of the TPiece from the selector result
 +
    // because the operation has created only one object
 +
    // aOidPiece := sel.lastOpeFirstOID;
 +
 +
    // Create TEcriture (s) from TReglement (s) of the TBordereauReglement
 +
    //
 +
    sel := vueReglement.CreateSelector('(oidBordereau=%1)','',True,[oidBordereauReglement]);
 +
 +
    // To retreive the TPiece OID
 +
    sel.AddParameter('ArgOpeId',opeId);
 +
    sel.AddParameter('ArgOperation','Piece');
 +
 +
    // To insert in the TsqlOperation the TEcriture we create
 +
    sel.OpeId := opeId;
 +
    sel.Operation := 'EcrReg';
 +
    sel.CopyTo('TEcriture',[],[]);
 +
 
 +
    // Update the TReglement from the TEcriture which has been created for this Reglement
 +
    //
 +
    sel := vueUpdateReglement.CreateSelector('(oidBordereau=%1)','',True,[oidBordereauReglement]);
 +
    // To match TReglement with TEcriture
 +
    sel.AddParameter('ArgOpeId',iOpeId);
 +
    sel.AddParameter('ArgOperation','EcrReg');
 +
    sel.Update(['oidEcriture'],['oidTargetEcriture']);
 +
 +
    end;
 +
 +
  finally
 +
  // Clean up the TsqlOperation
 +
  TsqlOperation.CleanOpe(aOpeId);
 +
  end;
 +
end;
 +
 +
 +
 
</source>
 
</source>
  

Version actuelle en date du 23 décembre 2025 à 11:15

Modèle:Version2025r2

property Operation:string;

Lecture/Ecriture

Cette propriété définit le nom d'une opération SQL de mise à jour.

Tip-20px.png Tip : Nécessite conjointement OpeId

Lorsque les propriétés Operation et OperationId sont définies, l'opération CopyTo alimente une classe SQL des objets insérés.

Cette table peut ensuite être jointe dans des opérations SQL successives.


Exemple

Use of TsqlOperation to chain SQL operations

Type
  // We want to create a TPiece from a TBordereauReglement
  vueBordereau = viewOf(TBordereauReglement)
   .... define TPiece columns  ....
  end;
 
  // Then we want to add one ecriture by reglement of the borderau to this piece
  //
  vueReglement = viewOf(TReglement)
   vl:TsqlOperation = join('(opeId=%ArgOpeId) and (operation=%ArgOperation)'); 
   oidBordereau:TOID = oidBordereauReglement;
   oidpiece:TOID = vl.oidTargetObject; // OID of the piece which has been created 
   .... define TEcriture columns ....
  end; 
 
  // And finally we want to update the TReglement with the oid of the TEcriture created for this reglement.
  //
  vueUpdateReglement = viewOf(TReglement)
   vl:TsqlOperation = join('(opeId=%ArgOpeId) and (operation=%ArgOperation) and (oidSourceObject=self.oid)'); 
   oidEcriture:TOID = oidEcriture; 
   oidTargetEcriture:TOID = vl.oidTargetObject; // OID of the TEcriture for this TReglement
   oidBordereau:TOID = oidBordereauReglement; 
  end;
 
// foo(oidBordereauReglement)
var opeId:string;
begin
  opeId := CreateGuid;
  try
  withP long transaction do
   begin
 
     // Create a TPiece from this TBordereauReglement
     //  
     sel := vueBordereau.CreateSelector('(oid=%1)','',True,[oidBordereauReglement]);
     sel.OpeId := opeId;
     sel.Operation := 'Piece';
     sel.CopyTo('TPiece',[],[]);
 
     // We could also retrieve the OID of the TPiece from the selector result
     // because the operation has created only one object
     // aOidPiece := sel.lastOpeFirstOID;
 
     // Create TEcriture (s) from TReglement (s) of the TBordereauReglement
     //
     sel := vueReglement.CreateSelector('(oidBordereau=%1)','',True,[oidBordereauReglement]); 
 
     // To retreive the TPiece OID
     sel.AddParameter('ArgOpeId',opeId);
     sel.AddParameter('ArgOperation','Piece');
 
     // To insert in the TsqlOperation the TEcriture we create
     sel.OpeId := opeId;
     sel.Operation := 'EcrReg';
     sel.CopyTo('TEcriture',[],[]); 
 
     // Update the TReglement from the TEcriture which has been created for this Reglement
     //
     sel := vueUpdateReglement.CreateSelector('(oidBordereau=%1)','',True,[oidBordereauReglement]); 
     // To match TReglement with TEcriture
     sel.AddParameter('ArgOpeId',iOpeId); 
     sel.AddParameter('ArgOperation','EcrReg'); 
     sel.Update(['oidEcriture'],['oidTargetEcriture']); 
 
    end;
 
  finally
   // Clean up the TsqlOperation
   TsqlOperation.CleanOpe(aOpeId); 
  end;
end;

Voir aussi :

Selecteur (tech)Développement DSM





Whos here now:   Members 0   Guests 0   Bots & Crawlers 1
 
Outils personnels