Précédent   Forum du club des développeurs et IT Pro > C et C++ > Outils pour C & C++ > C++Builder
C++Builder Environnement de développement RAD C++Builder. Avant de poster -> F.A.Q C++Builder, Sources C++Builder
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 29/12/2012, 01h43   #1
o_live
Membre du Club
 
Inscription : juin 2002
Messages : 206
Détails du profil
Informations forums :
Inscription : juin 2002
Messages : 206
Points : 40
Points : 40
Par défaut BCB6/FireBird/TClientDataSet/SQL perte de valeur dans mise a jour

Bonjour,
lorsque je fais une insertion avec ce code je n'ai pas de problème.
Un problème surviens lors de la mise a jour.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
bool  __fastcall TDataModule1::ApplyUpdatePers()
{
     /* procedure qui permet la mise a jour en cache OK */
 
TClientDataSet *pCdsDelta = new TClientDataSet(CDSPers);
 
//CDSPERS est un TClientDataSet contenu un DataModule
 
try{
 
  // ATTENTION une exception est levée si l'historique est vide
  // compenser par des contrôle
   try{
   pCdsDelta->Data= DataModule1->CDSPers->Delta;
   }
   catch(EDBClient &E)  {
     return false;
   }
 
   try{
 
      if(!DataModule1->IBDatabase->DefaultTransaction->InTransaction){
       DataModule1->IBDatabase->DefaultTransaction->StartTransaction();
      }
 
 
      pCdsDelta->First();
 
      int ID=0;
 
      while(!pCdsDelta->Eof) {
 
        switch(pCdsDelta->UpdateStatus())  {
 
            case usUnmodified:{
 
 
            break;
            }
 
            case usInserted: {
 
                 _INSERT_PERSONNE(pCdsDelta);
 
                break;
 
 
            }
 
            case usModified :{
 
            _UPDATE_PERSONNE(pCdsDelta);
 
 
            break;
            }
 
            case usDeleted: {           
 
            break;
            }
 
        }  // fin switch
 
        pCdsDelta->Next();
 
      } //fin boucle
 
      DataModule1->IBDatabase->DefaultTransaction->Commit() ;
      // refraichit le jeux de données
      DataModule1->CDSPers->Active=false;
      DataModule1->CDSPers->Active=true;
 
   }catch(...){
 
         ; // on annule la transaction
       DataModule1->IBDatabase->DefaultTransaction->Rollback();
 
   }
 
}__finally{
 
    delete pCdsDelta;
 
 }
}
Cependant lorsque je modifie un enregistrent je perds le valeur sauf la ou j'ai fais la modification dans un champ( la procédure d'insertion est quasiment la même a par que j'appelle une autre PS)

voici comment je modifie:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bool __fastcall TDataModule1::_UPDATE_PERSONNE(TClientDataSet * pCds)
{
        //TODO: mise a jour d'un enreg table personne
  try
  {
      IBStoredProc1->StoredProcName="UPDATE_PERSONNE";
 
      TParams *Param=new TParams();
      Param->CreateParam(ftInteger,"ID_PERS",ptInput);
      Param->CreateParam(ftString,"NOM",ptInput);
      Param->CreateParam(ftString,"PRENOM",ptInput);
      Param->CreateParam(ftString,"ADRESSE",ptInput);
      Param->CreateParam(ftString,"VILLE",ptInput);
      Param->CreateParam(ftString,"CODE_POSTAL",ptInput);
      Param->CreateParam(ftString,"ENTREPRISE",ptInput);
 
      // regardez si on lit
      //ShowMessage(pCdsDelta->FieldB&yName("NOM")->AsString);
 
 
      Param->ParamByName("ID_PERS")->AsInteger=pCds->FieldByName("ID_PERS")->AsInteger;
 
      Param->ParamByName("NOM")->AsString=pCds->FieldByName("NOM")->AsString;
      Param->ParamByName("PRENOM")->AsString=pCds->FieldByName("PRENOM")->AsString;
      Param->ParamByName("ADRESSE")->AsString=pCds->FieldByName("ADRESSE")->AsString;
      Param->ParamByName("VILLE")->AsString=pCds->FieldByName("VILLE")->AsString;
      Param->ParamByName("CODE_POSTAL")->AsString=pCds->FieldByName("CODE_POSTAL")->AsInteger;
      Param->ParamByName("ENTREPRISE")->AsString=pCds->FieldByName("ENTREPRISE")->AsString;
 
      DataModule1->IBStoredProc1->Params=Param;
      DataModule1->IBStoredProc1->ExecProc();
 
      delete Param;
      return true;
 
  }
  catch(...)
  {
  return false; // en cas d'erreur
  }
}
la procédure stockée coté serveur

Code sql :
1
2
3
4
5
6
7
8
9
10
11
BEGIN
  /* MISE A JOUR D'UNE PERSONNE */
 
    UPDATE PERSONNE
 
    SET  NOM=:NOM,PRENOM=:PRENOM,ADRESSE=:ADRESSE,
         CODE_POSTAL=:CODE_POSTAL ,ENTREPRISE=:ENTREPRISE
 
    WHERE ID_PERS=:ID_PERS  ;
 
END


Ou est l'erreur ?
Comment se fait il que je perde des valeurs ? (j'ai uniquement celle ou les champs sont modifie)

je ne comprends pas, qui peut m'expliquer?

merci et bonnes fêtes a vous tous et touteS
__________________
Outils utilisés : FireBird 2.1 - IbExert Free - C++ Builder 6 Pro Update 4- Windows Xp pro Sp3
o_live est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/01/2013, 02h28   #2
o_live
Membre du Club
 
Inscription : juin 2002
Messages : 206
Détails du profil
Informations forums :
Inscription : juin 2002
Messages : 206
Points : 40
Points : 40
ok j'ai résolu mon problème (voir dernier post)

"[Debutant]C++Builder6/Firebird sql error=-303"
__________________
Outils utilisés : FireBird 2.1 - IbExert Free - C++ Builder 6 Pro Update 4- Windows Xp pro Sp3
o_live est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 17h52.


 
 
 
 
Partenaires

Hébergement Web