Ver Mensaje Individual
  #8  
Antiguo 09-03-2010
nena_yei nena_yei is offline
Miembro
 
Registrado: abr 2009
Posts: 60
Reputación: 16
nena_yei Va por buen camino
Holaa de nuevo!
Tal y como hablé con Al González, aquí pongo el código de la función que lanza el showmessage problemático, para ver si alguien ve algo que podría estar fallando. Vuelvo a remarcar que funciona correctamente el procedimiento, que no me salta ningún error ni warning ni nada.
Gracias de antemano

Código Delphi [-]
procedure Tmultiple.executaconsulta();
var final,temp,condicio,contemp,con:widestring;
var i,num:integer;
begin

image12.Cursor:=crHourglass;
screen.Cursor:=crHourglass;
self.Cursor:=crHourglass;
busllengua:=0;
numopcions:=0;
busdoc:=0;
buslema:=0;
dades.q2.SQL.text:='delete from temp';
dades.q2.ExecSQL;
con:='select lema,subvoce,apartado,lemabusc,lemaord,id,lemaordinv from adm_lema where  ';
  temp:=StringReplace(lema.text,'$','%',[rfReplaceAll]);
  temp:=StringReplace(temp,'#','_',[rfReplaceAll]);
  //lema
  if(lema.Text<>'') then begin
    dades.q3.SQL.Text:='select id,lema from adm_lema where (adm_lema.lema like "'+ansilowercase(temp)+'" or adm_lema.lema like "'+ansiuppercase(temp)+'")';
    dades.q3.open;
    contemp:='';
    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    buslema:=1;
    condicio:='actiu';
  end;

  //llengues
  final:='';
  llengues.totll:=0;

  for i:=0 to busqueda.items.Count-1 do
  begin
   if(busqueda.Items.Strings[i]='Y') then
   begin
    condicio:='and';
   end else if(busqueda.Items.Strings[i]='O') then begin
    condicio:='or';
   end else if(copy(busqueda.Items.Strings[i],0,1)='>') then
   begin
   contemp:=llengues.treureLlengues2(strtoint(ids.Items.Strings[i]));
   contemp:=copy(contemp,0,length(contemp)-3);
   if(contemp<>'')then begin
     if(condicio='and') then begin
       dades.q3.SQL.text:='select id_adm_lem from adm_etims right join temp on temp.id_adm_lem=adm_etims.id_adm_lem where '+contemp+' group by id_adm_lem';
       dades.q3.open;
     end else begin
       if(condicio='actiu') then
         dades.q3.SQL.text:='select id_adm_lem from adm_etims INNER JOIN temp ON adm_etims.id_adm_lem=temp.id_adm_lem where ('+contemp+') and id_adm_lem<>"" group by id_adm_lem'
       else
         dades.q3.SQL.text:='select id_adm_lem from adm_etims where ('+contemp+') and id_adm_lem<>"" group by id_adm_lem';

       dades.q3.open;
       dades.q2.SQL.Text:='delete from temp';
       dades.q2.ExecSQL;
       dades.q2.close;
     end;
     while not dades.q3.Eof do begin
       dades.q2.SQL.Text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
       dades.q2.ExecSQL;
       dades.q2.close;
       dades.q3.next;
     end;
     dades.q3.Close;
   end;

   end else begin
     if(condicio='and') or (condicio='actiu') then begin
       dades.q3.SQL.text:='select id_adm_lem from adm_etims right join temp on temp.id_adm_lem=adm_etims.id_adm_lem where id_adm_len='+trim(ids.Items.Strings[i])+' group by id_adm_lem';
       dades.q3.Open;
       dades.q2.close;
     end else begin
        dades.q3.SQL.text:='select id_adm_lem from adm_etims where id_adm_len='+trim(ids.Items.Strings[i])+' and id_adm_lem<>"" group by id_adm_lem';
        dades.q3.Open;
     end;
     dades.q2.SQL.Text:='delete from temp';
     dades.q2.ExecSQL;

     while not dades.q3.Eof do begin
      dades.q2.SQL.Text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q2.close;
      dades.q3.next;
     end;
     dades.q3.Close;
    llengues.abrlle[llengues.totll]:=trim(ids.Items.Strings[i]);
    llengues.totll:=llengues.totll+1;
   end;
  end;

  if(busqueda.items.Count>0)then begin
    con:=con+final+' and';
    busllengua:=1;
    condicio:='actiu';
  end;

  //transmission
  if (semicultismo.Checked) or  (cultismo.Checked) or  (patrimonial.Checked) then begin
    if(condicio='actiu')then
      con:='select id_adm_lem from adm_etims RIGHT JOIN temp ON temp.id_adm_lem=adm_etims.id_adm_lem where '
    else
      con:='select id_adm_lem from adm_etims where ';

    buslema:=1;
  end;

  if semicultismo.Checked then con:=con+'(transmisio=''S-'' or transmisio=''DS'') or';
  if cultismo.Checked then
  begin
    con:=con+' (transmisio=''C-'' or transmisio=''DC'') or';
  end;

  if patrimonial.Checked then
  begin
    con:=con+' (transmisio=''H-'' or transmisio=''DH'') or';
  end;

  if (semicultismo.Checked) or  (cultismo.Checked) or  (patrimonial.Checked) then
  begin
    con:=copy(con,0,length(con)-3);
    dades.q3.SQL.Text:=con+' and id_adm_lem<>"" group by id_adm_lem';
    dades.q3.open;
    dades.q2.SQL.text:='delete from temp';
    dades.q2.ExecSQL;
    contemp:='';
    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    con:=con+') and ';
    condicio:='actiu';
  end;

  //documentacio
  //anys i primeradoc
  temp:='';
  if f_ini.text<>'' then
  begin
    busdoc:=1;
    temp:=' and ';
    if f_ini.text=f_fi.text then
      temp:=temp+' adm_documentacio.data_ini='+f_ini.Text+' and '
    else
      temp:=temp+' ((adm_documentacio.data_ini<="'+f_ini.Text+'" and adm_documentacio.data_fi>="'+f_fi.text+'") or (data_ini BETWEEN "'+f_ini.text+'" and "'+f_fi.text+'")) ';
  end;
  if primeradoc.Checked then temp:=temp+' and primeradoc="Sí" ';
  //obra
  paraulabusc:=0;
  if (autor.Text<>'') and (autor.text<>'Todos') then begin
    if(condicio='actiu')then
      contemp:='select id_adm_lem from adm_documentacio INNER JOIN temp ON temp.id_adm_lem=adm_documentacio.id_adm_lem where id_adm_aut in (select id from adm_autors where (adm_autors.autor_norm="'+autor.Text+'")) '+temp
    else
      contemp:='select id_adm_lem from adm_autors INNER JOIN adm_documentacio ON adm_autors.id = adm_documentacio.id_adm_aut where (adm_autors.autor_norm="'+autor.Text+'") and id_adm_lem<>"" '+temp;

    dades.q3.SQL.Text:=contemp;
    dades.q3.open;
    dades.q2.SQL.text:='delete from temp';
    dades.q2.ExecSQL;
    contemp:='';
    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    busdoc:=1;
    paraulabusc:=2;
    numopcions:=1;
    condicio:='actiu';
  end;

  if (obra.Text<>'') and (obra.text<>'Todas') then
  begin
      if(condicio='actiu')then
        contemp:='select id_adm_lem from adm_documentacio INNER JOIN temp ON temp.id_adm_lem=adm_documentacio.id_adm_lem where id_adm_obr in (select id from adm_obras where adm_obras.obra_norm="'+obra.Text+'") '+temp
      else
        contemp:='select id_adm_lem from adm_obras INNER JOIN adm_documentacio ON adm_obras.id = adm_documentacio.id_adm_obr where (adm_obras.obra_norm="'+obra.Text+'") and id_adm_lem<>"" '+temp;

    dades.q3.SQL.Text:=contemp;
    dades.q3.open;
    dades.q2.SQL.text:='delete from temp';
    dades.q2.ExecSQL;
    contemp:='';

    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    busdoc:=1;
    paraulabusc:=3;
    condicio:='actiu';
  end;

  if (f_ini.text<>'') and (paraulabusc<2)then
  begin
    busdoc:=1;
    if(condicio='actiu')then
      contemp:='select id_adm_lem from adm_documentacio INNER JOIN temp ON temp.id_adm_lem=adm_documentacio.id_adm_lem where'
    else
      contemp:='select id_adm_lem from adm_documentacio where';

    if f_ini.text=f_fi.text then
      contemp:=contemp+' adm_documentacio.data_ini="'+f_ini.Text+'" '
    else
        contemp:=contemp+'(((adm_documentacio.data_ini<="'+f_ini.Text+'" and adm_documentacio.data_fi>="'+f_fi.text+'") and adm_documentacio.data_fi<>0) or ((adm_documentacio.data_ini between "'+f_ini.Text+'" and "'+f_fi.text+'"))) ';

    if primeradoc.Checked then contemp:=contemp+' and primeradoc="Sí" ';

    dades.q3.SQL.Text:=contemp;
    dades.q3.open;
    dades.q2.SQL.text:='delete from temp';
    dades.q2.ExecSQL;
    contemp:='';
    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    paraulabusc:=1;
    condicio:='actiu';
  end;

  if (paraulabusc=0) and (primeradoc.Checked) then
  begin
    if(condicio='actiu')then
      contemp:='select id_adm_lem from adm_documentacio INNER JOIN temp ON temp.id_adm_lem=adm_documentacio.id_adm_lem where primeradoc="Sí"'
    else
      contemp:='select id_adm_lem from adm_documentacio where primeradoc="Sí"';

    dades.q3.SQL.Text:=contemp;
    dades.q3.open;
    dades.q2.SQL.text:='delete from temp';
    dades.q2.ExecSQL;
    contemp:='';
    while not dades.q3.eof do begin
      dades.q2.SQL.text:='insert into temp (id_adm_lem) values ('+dades.q3.Fields.Fields[0].AsString+')';
      dades.q2.ExecSQL;
      dades.q3.Next;
    end;
    paraulabusc:=3;
    busdoc:=1;
    condicio:='actiu';
  end;

  con:='select lema,subvoce,apartado,lemabusc,lemaord,id,lema as temp,lemaordinv from adm_lema INNER JOIN temp ON adm_lema.id=temp.id_adm_lem where lema<>"" group by lema,subvoce,apartado,lemabusc,lemaord,id,lemaordinv order by lemaord';
  dades.q1.close;
  dades.q1.sql.text:=con;
  dades.q1.Open;
  num:=dades.q1.RecordCount;
  carga.Close;

  image12.Cursor:=crDefault;
  screen.Cursor:=crDefault;
  self.Cursor:=crDefault;

  if(num<1)then begin
    ShowMessage('No existen casos para esta consulta');
    exit;
  end;

  central.primeravegada:=false;
  dades.dsllistat.DataSet:=dades.q1;
  central.statusbar.panels[0].text:=inttostr(num)+' Registros';
  close;

end;
Responder Con Cita