IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bases de données Delphi Discussion :

Transaction : Cohabitation de 2 requêtes


Sujet :

Bases de données Delphi

  1. #1
    Membre confirmé Avatar de SkYsO
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    217
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 217
    Par défaut Transaction : Cohabitation de 2 requêtes
    Salut,

    Voila mon problème :

    J'ai une premiere requête qui est exécutée, elle est lancé avec un TADOQuery et je fais une boucle sur ses résultats.

    Suivant certain cas il m'arrive d'executer ce code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    lareq:=TADOQuery.Create(scrollbox);
             lareq.Connection:=Mondata.ADOConnec;
             lareq.Active:=false;
             Mondata.ADOConnec.BeginTrans;
            try
              lareq.SQL.Add('INSERT INTO Donnee (ID_Source,           ID_Type_Donnee_Heritiere, ID_Donnees_historiques,ID_entite,ID_propriete_entite) VALUES (0,12,0,' + inttostr(Entite_foca.ID) + ',' + inttostr(propriete_entite_local.ID) + ');');
              lareq.ExecSQL;
              lareq.Close;
              Lareq.SQL.Clear;
              lareq.SQL.Add('SELECT @@IDENTITY AS ID;');
              lareq.Active:=true;
              Mondata.ADOConnec.CommitTrans;
             except
               Mondata.ADOConnec.RollbackTrans;
             end;
    Or si jamais ce code est executé, je me tape l'erreur suivante quand je fais MaTADOQuery.next.

    erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    EOleExceptio ITransaction::Commit ou ITransaction::abort appellé, l'objet est dans un état passif
    Alors qu'est ce qui ne va pas ?
    mauvais paramétrage de mon composant query ?

    merci de votre aide, ça me bloque vraiment.

  2. #2
    Expert confirmé
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 932
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 932
    Par défaut
    Tu parles de 2 requètes...

    Où est la 2ème ? (qui serait plutôt la 1ère ?)

    En fait, si ces requètes sont imbriquées, l'intégralité du code correspondant devrait nous être fourni...

  3. #3
    Membre confirmé Avatar de SkYsO
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    217
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 217
    Par défaut
    Voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    Mondata.ADOConnec.BeginTrans;
    mondata.ADOQuery_duplication.Active:=false;
    Mondata.ADOQuery_duplication.Parameters.ParamByName('param_id1').Value:=entite_foca.ID;
    Mondata.ADOQuery_duplication.Active:=true;
    //on obtient l'ensemble des données avec leur valeurs respective suivant les cas
    //chaque ligne correspond à type de donnée que l'on reconnait grace à lid_type_donnee_heritiere
    mareq2:=TADOQuery.Create(nil);
    mareq2.Connection:=Mondata.ADOConnec;
    Mareq2.Active:=false;
            while not Mondata.ADOQuery_duplication.Eof do
            begin
                    ID_duplique:=mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value;
                    //on va pouvoir remplir la table donnée
                    textereq:='INSERT INTO Donnee (ID_Type_Donnee_Heritiere, ID_Donnees_Historiques, ID_Source, ID_entite,ID_Propriete_entite) VALUES (' + inttostr(Mondata.ADOQuery_duplication.fieldByName('ID_Type_Donnee_Heritiere').Value) + ',' + inttostr(Mondata.ADOQuery_duplication.fieldByName('ID_Donnees_Historiques').Value) + ',' + inttostr(Mondata.ADOQuery_duplication.fieldByName('ID_Source').Value) + ',' + inttostr(NodeDnew.Entite.ID) + ',' + inttostr(Mondata.ADOQuery_duplication.fieldByName('ID_Propriete_entite').Value) +  ');';
                    mareq.active:=false;
                    mareq.SQL.Clear;
                    mareq.SQL.add(textereq);
     
                      mareq.ExecSQL;
                      mareq.Close;
                      mareq.SQL.Clear;
                      mareq.SQL.Add('SELECT @@IDENTITY AS ID;');
                      Mareq.Active:=true;
     
                    if not mareq.Eof then
                    case Mondata.ADOQuery_duplication.FieldByName('ID_Type_Donnee_Heritiere').Value of
                    1 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Booleen FROM Donnee_booleen WHERE ID_Donnee_Booleen=' + inttostr(mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO  Donnee_Booleen  (ID_Donnee_Booleen , Booleen) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + booltostr(mareq2.FieldByName('Booleen').value) + ');';
                      mareq2.Close;
                    end;
     
                    2 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Entier FROM Donnee_Entier WHERE ID_Donnee_Entier=' + inttostr(ID_duplique));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO  Donnee_Entier  (ID_Donnee_Entier , Entier) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + inttostr(mareq2.FieldByName('Entier').value) + ');';
                      mareq2.Close;
                    end;
     
                    3 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Chaine FROM Donnee_Chaine WHERE ID_Donnee_Chaine=' + inttostr(mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO  Donnee_Chaine  (ID_Donnee_Chaine , Chaine) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + quotedstr(mareq2.FieldByName('Chaine').AsString) + ');';
                      mareq2.Close;
                    end;
     
                 //   4 :
                 //  begin
                 //           textereq:='INSERT INTO  Donnee_Enum  (ID_Donnee_Enumeration , ID_Enumeration) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + inttostr(mondata.ADOQuery_duplication.FieldByName('Enum').value) + ');';
                //    end;
                    5 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Min,Max,moyenne,ID_Unite FROM Donnee_Point WHERE ID_Donnee_Point=' + inttostr(mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO Donnee_Point (ID_Donnee_Point,Min,Max,moyenne,ID_Unite) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + floattostr(mareq2.FieldByName('Min').value) + ',' + floattostr(mareq2.FieldByName('Max').value) + ',' + floattostr(mareq2.FieldByName('Moyenne').value) + ',' + inttostr(mareq2.FieldByName('ID_Unite').value) +');' ;
                      mareq2.Close;
                    end;
                    6 : showmessage('une courbe');
                    7 : showmessage('une image');
                    8 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Date FROM Donnee_Date WHERE ID_Donnee_Date=' + inttostr(mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO  Donnee_Date (ID_Donnee_Date , Date) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + Datetostr(mareq2.FieldByName('Date').value) + ');';
                      mareq2.Close;
                    end;
     
                    9 :
                    begin
                      mareq2.SQL.Clear;
                      mareq2.SQL.Add('SELECT Texte FROM Donnee_Texte WHERE ID_Donnee_Texte=' + inttostr(mondata.ADOQuery_duplication.FieldByName('ID_Donnee').value));
                      mareq2.Active:=true;
                      if not Mareq2.Eof then
                            textereq:='INSERT INTO  Donnee_Texte (ID_Donnee_Texte , Texte) VALUES (' + inttostr(mareq.fieldbyname('ID').Value) + ',' + quotedstr(mareq2.FieldByName('Texte').AsString) + ');';
                      mareq2.close;
                    end;
     
                    10 : showmessage('un doc');
                    11 : showmessage('une personne');
                    12 : showmessage('lien');// execute_lien(TObjects_visuels2_Lien(lobject_visu));   //on soccupe des liens à part
                    end;
                    if Mondata.ADOQuery_duplication.FieldByName('ID_Type_Donnee_Heritiere').Value<>12 then
                    begin
                            mareq.Active:=false;
                            mareq.SQL.Delete(0);
                            mareq.SQL.Add(textereq);
                          //  mareq.Connection.BeginTrans;
                           // try
                              mareq.ExecSQL;
                            //  mareq.SQL.Delete(0);
                            //  mareq.Connection.CommitTrans;
                           // except
                           //   mareq.Connection.RollbackTrans;
                          //  end;
                    end;
                    Mondata.ADOQuery_duplication.Next;
            end;
            Mondata.ADOQuery_duplication.Active:=false;
            Mondata.ADOQuery_duplication.Close;
      Mondata.ADOConnec.CommitTrans;
    except
      Mondata.ADOConnec.RollbackTrans;
    end;
    Et j'ai mon message d'erreur sur le Mondata.ADOQuery_duplication.Next

  4. #4
    Expert confirmé
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 932
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 932
    Par défaut
    Suggestion:

    Quand tu crées
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mareq2:=TADOQuery.Create(nil);
    sais-tu si un autocommit est positionné, et à quelle valeur ?

    Il faudrait aussi savoir si l'erreur se produit aléatoirement, ou systématiquement après 1, 2 ou x passages ?

  5. #5
    Membre confirmé Avatar de SkYsO
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    217
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 217
    Par défaut
    Salut,

    Comment puis-je savoir si j'ai un autocommit ?

    Je viens de découvrir que si je mets la propriété CursorLocation sur Client du composant query qui déclenché l'erreur, je n'ai plus l'erreur.

    Qu'est ce que cela change au niveau transaction ce genre de chose ?

    Y-a-t-il une configuration requise des objets ADOQuery pour qu'ils fonctionnent correctement en transaction ?

    merci

Discussions similaires

  1. Utilisation d'une fonction Transact-SQL ds une requête SQL
    Par Fl0ppeur dans le forum Langage SQL
    Réponses: 1
    Dernier message: 21/02/2006, 13h42
  2. Réponses: 2
    Dernier message: 22/11/2005, 14h06
  3. Requêtes sur le journal de transactions
    Par Pierrick dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 05/10/2005, 11h07
  4. Réponses: 8
    Dernier message: 01/03/2005, 16h01
  5. [Petite requête] Nombre de transactions par jour
    Par Braim dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 15/04/2003, 10h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo