cs_Mawie
Messages postés8Date d'inscriptionvendredi 21 mars 2003StatutMembreDernière intervention21 juin 2006
-
21 juin 2006 à 10:02
cs_Delphiprog
Messages postés4297Date d'inscriptionsamedi 19 janvier 2002StatutMembreDernière intervention 9 janvier 2013
-
21 juin 2006 à 23:12
Salut à tous,
j'ai un souci lorsque je veux mettre à jour un enregistrement dans une table mysql, voici mon code:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('SELECT AP_ID_Lecteur, AP_Type_support, EXTRACT(YEAR FROM AP_Date_Pret) AS annee, COUNT( * )');
ADOQuery1.SQL.Add('FROM archives_prets');
ADOQuery1.SQL.Add('GROUP BY annee,AP_ID_Lecteur,AP_Type_support');
ADOQuery1.SQL.Add('ORDER BY annee,AP_ID_Lecteur,AP_Type_support');
ADOQuery1.Active;
ADOQuery1.Open;
ProgressBar1.Visible := True;
ProgressBar1.Position := 0;
ProgressBar1.Max := ADOQuery1.RecordCount;
ADOQuery1.first;
while not ADOQuery1.Eof do
begin
xidlect := ADOQuery1.Fields[0].AsInteger;
xsupport := ADOQuery1.Fields[1].AsString;
xannee := ADOQuery1.Fields[2].AsInteger;
xcount := ADOQuery1.Fields[3].AsInteger;
if pret_annee.Locate('Id_Lect;Annee', VarArrayOf([xidlect, xannee]), [loCaseInsensitive]) then
pret_annee.Edit
else pret_annee.Append;
pret_annee.Fields[8].AsInteger := xidlect; //id_lect
pret_annee.Fields[1].AsInteger := xannee; //annee
if xsupport = '1' then
pret_annee.Fields[2].AsInteger := xcount; //pret_mono
if xsupport = '2' then
pret_annee.Fields[3].AsInteger := xcount; //pret_perio
if xsupport = '3' then
pret_annee.Fields[4].AsInteger := xcount; //pret_son
if xsupport = '4' then
pret_annee.Fields[5].AsInteger := xcount; //pret_video
if xsupport = '5' then
pret_annee.Fields[6].AsInteger := xcount; //pret_mmedia
if xsupport = '6' then
pret_annee.Fields[7].AsInteger := xcount; //pret_autres
pret_annee.Post;
ADOQuery1.Next;
end;
label24.Visible := True;
ProgressBar1.Visible := False;
end;
procedure TfrmAcqui.archives_prets_BtClick(Sender: TObject);
begin
Label26.Visible := False;
ActiveTable(Self);
ProgressBar1.Visible := True;
ProgressBar1.Position := 0;
ProgressBar1.Max := Table029.RecordCount;
Table029.First;
while not Table029.Eof do
begin
FindLect(Table029.Fields[19].AsString); //id_lecteur
if id_lect <> '0' then
begin
if expl.Locate('N_Inventaire', Table029.Fields[0].AsString, [loCaseInsensitive]) then
begin
archives_prets.Append;
archives_prets.Fields[8].AsString := expl.Fields[3].AsString; //id_notice
notices.Filter := 'ID_Notice=''' + expl.Fields[3].AsString + '''';
notices.Filtered := True;
archives_prets.Fields[9].AsString := notices.Fields[1].AsString; //titre
if langue.Locate('Id_Langue', notices.Fields[2].AsString, [loCaseInsensitive]) then
archives_prets.Fields[10].AsString := langue.Fields[2].AsString; //langue
archives_prets.Fields[11].AsString := notices.Fields[5].AsString; //vedette
archives_prets.Fields[12].AsString := notices.Fields[9].AsString; //type_xsupport
archives_prets.Fields[26].AsString := notices.Fields[7].AsString; //type_ved
if notices.Fields[7].AsString = '1' then
begin
if not_ved.Locate('ID_Notice', expl.Fields[3].AsString, [loCaseInsensitive]) then
archives_prets.Fields[25].AsString := not_ved.Fields[2].AsString; //id_ved
end
else if notices.Fields[7].AsString = '2' then
begin
if ved_col.Locate('Collectivite', notices.Fields[5].AsString, [loCaseInsensitive]) then
archives_prets.Fields[25].AsString := ved_col.Fields[0].AsString; //id_ved
end;
archives_prets.Fields[13].AsString := expl.Fields[0].AsString; //id_expl
if cotes.Locate('ID_Cote', expl.Fields[4].AsString, [loCaseInsensitive]) then
archives_prets.Fields[14].AsString := cotes.Fields[1].AsString; //cote
if bullet.Locate('ID_Expl', expl.Fields[0].AsString, [loCaseInsensitive]) then
begin
archives_prets.Fields[15].AsString := bullet.Fields[3].AsString; //fascicule
archives_prets.Fields[24].AsString := bullet.Fields[0].AsString; //id_bul
end;
archives_prets.Fields[23].AsString := Table029.Fields[0].AsString; //n_inventaire
if lecteurs.Locate('Id_Lect', id_lect, [loCaseInsensitive]) then
begin
archives_prets.Fields[1].AsString := id_lect;
archives_prets.Fields[2].AsString := lecteurs.Fields[5].AsString; //nom_lect
archives_prets.Fields[3].AsString := lecteurs.Fields[6].AsString; //prenom_lect
archives_prets.Fields[4].AsString := lecteurs.Fields[2].AsString; //type_lect 1:pers;2:collec
archives_prets.Fields[5].AsString := lecteurs.Fields[3].AsString; //type_public 1:ad;2:enf
archives_prets.Fields[6].AsString := lecteurs.Fields[7].AsString; //datenais
archives_prets.Fields[7].AsString := lecteurs.Fields[48].AsString; //civilité
archives_prets.Fields[19].AsString := lecteurs.Fields[43].AsString; //id_csp
if csp.Locate('ID_csp', lecteurs.Fields[43].AsString, [loCaseInsensitive]) then
archives_prets.Fields[20].AsString := csp.Fields[1].AsString; //lib_csp
end;
archives_prets.Fields[21].AsString := '1'; //id_bib
if pret.Locate('Id_Lecteur;Id_Expl', VarArrayOf([id_lect, expl.Fields[0].AsString]), [loCaseInsensitive]) then
begin
archives_prets.Fields[16].AsString := pret.Fields[0].AsString; //id_pret
archives_prets.Fields[17].AsString := pret.Fields[3].AsString; //date_pret
archives_prets.Fields[18].AsString := pret.Fields[4].AsString; //date_retour
end
else
begin
archives_prets.Fields[17].AsString := Table029.Fields[2].AsString; //date_pret
archives_prets.Fields[18].AsString := Table029.Fields[15].AsString; //date_retour
archives_prets.Fields[21].AsString := '1'; //pret.Fields[8].AsString; //id_bib
end;
if not_edi.Locate('ID_Notice', notices.Fields[0].AsString, [loCaseInsensitive]) then
begin
archives_prets.Fields[28].AsString := not_edi.Fields[2].AsString; //id_edi
if editeurs.Locate('Id_Edi', not_edi.Fields[2].AsString, [loCaseInsensitive]) then
archives_prets.Fields[27].AsString := editeurs.Fields[1].AsString; //editeur
end;
if not_ens.Locate('ID_Notice', notices.Fields[0].AsString, [loCaseInsensitive]) then
begin
archives_prets.Fields[30].AsString := not_ens.Fields[2].AsString; //id_tens
if ens.Locate('Id_Ens', not_ens.Fields[2].AsString, [loCaseInsensitive]) then
archives_prets.Fields[29].AsString := ens.Fields[1].AsString; //titre_ens
archives_prets.Fields[31].AsString := not_ens.Fields[3].AsString; //tome
end;
if stitres.Locate('ID_Notice', notices.Fields[0].AsString, [loCaseInsensitive]) then
archives_prets.Fields[32].AsString := stitres.Fields[1].AsString; //sous_titre
archives_prets.Post;
end;
end;
ProgressBar1.Position := ProgressBar1.Position + 1;
Table029.Next;
end;
Voilà, je suis sous Delphi7, mysql avec ODBC.
Merci de m'aider le plus vite possible, c'est très très urgent. Mon Client attend et je dois finir aujourd'hui de l'installer.
Merci d'avance.
cs_Delphiprog
Messages postés4297Date d'inscriptionsamedi 19 janvier 2002StatutMembreDernière intervention 9 janvier 201332 21 juin 2006 à 23:12
Tu pourrais au moins nous indiquer l'exception déclenchée.
Cela dit, tu pourrais au moins aérer le code de ta requête SQL car chaque ligne est ajoutée et donne ceci au final :
SELECT AP_ID_Lecteur, AP_Type_support, EXTRACT(YEAR FROM AP_Date_Pret) AS annee, COUNT( * )FROM archives_pretsGROUP BY annee,AP_ID_Lecteur,AP_Type_supportORDER BY annee,AP_ID_Lecteur,AP_Type_support
Si le parser du moteur SQL arrive à s'y retrouver, je lui tire mon chapeau...
Une autre remarque : la personne qui devra déboguer ton code risque la dépression nerveuse ou la calvitie. Bonjour les champs adressés avec un index numérique et les composants Table029...
Pourvu qu'un imbécile ne change pas l'ordre des champs dans les composants table ou requête, sinon tout tombe par terre et ça devient impossible de s'y retrouver !
Et là, inutile de nous appeler au secours, chacun sa m....e !!!
May Delphi be with you !
<hr color="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.