Subject | What's the correct way to trigger an IB_query reprepare and refresh? |
---|---|
Author | G. Nau |
Post date | 2005-10-03T11:48:03Z |
Hi,
I have a complex OnPrepareSQL event, which is generating a longer
"where" statement depending on a number of radioboxes, tEdits and
checkboxes on a filterform.
It is working quite well, but I can't get a good re-prepare and refresh action
running. The user can modify the settings of the filter form and then press
the "refresh" button.
I've tried IB_query.unprepare, prepare and refresh, but this does not work
and gives an empty dataset after the first refresh (not on the initial run for
the query activation).
Doing a ib_query.active:=false; ib_query.prepare and ib_query.active:=true
again is working. I'd like to speed things up a little bit and avoid this query
activation triggering.
The PrepareSQL event is triggered on the refresh click.
Maybe I'm missing something here in my onprepareSQL event and it's not
directly related to the way to do a re-prepare?
Basically I'm just doing sqlwhereitems.add(' ...')
----------
procedure TForm_AAW_Main.IB_Query_FaktuheadPrepareSQL(
Sender: TIB_Statement);
VAR Join_AAW_Lines : Boolean;
Join_AAW_L_Lagerteil : Boolean;
Procedure Join_AAWLines;
Begin
If Join_AAW_Lines then exit;
IB_Query_Faktuhead.SQLFrom.Add('join aaw_lines on
aaw_main.ref=aaw_lines.ref0');
Join_AAW_Lines:=True;
End;
Procedure Join_AAWLLagerteil;
Begin
If Join_AAW_L_Lagerteil then exit;
IB_Query_Faktuhead.SQLFrom.Add('join aaw_L_Lagerteil on
aaw_Lines.ref=aaw_L_lagerteil.ref0');
Join_AAW_L_Lagerteil:=True;
End;
Function Add_Or(S:String) : String;
Begin
if S='' then result:=''
else result:=S+' or ';
End;
VAR F1, F2 : ShortString;
I : Smallint;
begin
inherited;
Join_aaw_Lines :=False;
Join_AAW_L_Lagerteil:=False;
if Radio_Datum_last3.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+AusgabeDatum(now-3*30)+''' and '''+AusgabeDatum(now)+'''');
if Radio_Datum_last18.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+AusgabeDatum(now-18*30)+''' and '''+AusgabeDatum(now)+'''');
if Radio_Datum_fromto.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+Datum_von.text+''' and '''+Datum_bis.text+'''');
if Radio_Summe_vonbis.checked then
Begin
Str(Summe_von.FloatValue:10:2,F1);
Str(Summe_bis.FloatValue:10:2,F2);
IB_Query_Faktuhead.SQLWhereItems.Add('Summebrutto between
'''+F1+''' and '''+F2+'''');
End;
if Filter_Kurzname.Text<>'' then
Begin
if EnthaeltWildcards(Filter_Kurzname.text) then
Begin //yop, Wildcards drin ...
F1:=Wildcard_to_FireBird (Filter_Kurzname.text);
IB_Query_Faktuhead.SQLWhereItems.Add('kurzname like
'''+F1+'''');
End
else // nur beginnend mit
Begin
IB_Query_Faktuhead.SQLWhereItems.Add('kurzname starting
with '''+Filter_Kurzname.text+'''');
End;
End;
if filter_AdressNr.text<>'' then
Begin
IB_Query_Faktuhead.SQLWhereItems.Add('adressnr starting with
'''+filter_adressnr.text+'''');
End;
if filter_belegtext.text<>'' then
Begin
F1:=Wildcard_to_FireBird (Filter_Belegtext.text);
Join_AAWLines;
IB_Query_Faktuhead.SQLWhereItems.Add('upper(aaw_lines.textzeile)
like '''+F1+'''');
End;
if Filter_Lagerort.text<>Filter_Lagerort.LeererText then
Begin
Join_AAWLines;
Join_AAWLLagerteil;
IB_Query_Faktuhead.SQLWhereItems.Add('aaw_l_Lagerteil.lagerort='''+Filt
er_Lagerort.Text+'''');
End;
//jetzt die Detailfilter
F1:='';
if Filter_ZeilenohnePreis.checked then
F1:=Add_or(F1)+'hatzeilenohnepreis=1';
if Filter_ZeilenalterPreis.checked then
F1:=Add_or(F1)+'hatzeilenalterpreis=1';
if Filter_nurfertig.checked then F1:=Add_or(F1)+'fertig=1';
if Filter_inArbeit.checked then F1:=Add_or(F1)+'fertig=0';
if Filter_nurgesperrt.checked then F1:=Add_or(F1)+'gesperrt=1';
if Filter_nurfrei.checked then F1:=Add_or(F1)+'gesperrt=0';
if Filter_geaendert_ungedruckt.checked then
F1:=Add_or(F1)+'geaendert=1';
if Filter_nurIntern.checked then F1:=Add_or(F1)+'intern=1';
if F1<>'' then Begin
F1:='('+F1+')';
IB_Query_Faktuhead.SQLWhereItems.add(F1);
End;
//jetzt noch den Belegartenfilter
F1:='';
For I:=0 to ErlaubteBelegArten.Items.Count-1 do
if ErlaubteBelegArten.Checked[i] then
F1:=F1+''''+IntToStr(ord(BelegArtTab[I]))+''',';
if F1<>'' then
Begin
Delete(F1,Length(F1),1); //letztes Comma wech
F1:='Belegart in ('+F1+')';
IB_Query_Faktuhead.SQLWhereItems.add(F1);
End;
end;
----------
Regards
Gunther
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
I have a complex OnPrepareSQL event, which is generating a longer
"where" statement depending on a number of radioboxes, tEdits and
checkboxes on a filterform.
It is working quite well, but I can't get a good re-prepare and refresh action
running. The user can modify the settings of the filter form and then press
the "refresh" button.
I've tried IB_query.unprepare, prepare and refresh, but this does not work
and gives an empty dataset after the first refresh (not on the initial run for
the query activation).
Doing a ib_query.active:=false; ib_query.prepare and ib_query.active:=true
again is working. I'd like to speed things up a little bit and avoid this query
activation triggering.
The PrepareSQL event is triggered on the refresh click.
Maybe I'm missing something here in my onprepareSQL event and it's not
directly related to the way to do a re-prepare?
Basically I'm just doing sqlwhereitems.add(' ...')
----------
procedure TForm_AAW_Main.IB_Query_FaktuheadPrepareSQL(
Sender: TIB_Statement);
VAR Join_AAW_Lines : Boolean;
Join_AAW_L_Lagerteil : Boolean;
Procedure Join_AAWLines;
Begin
If Join_AAW_Lines then exit;
IB_Query_Faktuhead.SQLFrom.Add('join aaw_lines on
aaw_main.ref=aaw_lines.ref0');
Join_AAW_Lines:=True;
End;
Procedure Join_AAWLLagerteil;
Begin
If Join_AAW_L_Lagerteil then exit;
IB_Query_Faktuhead.SQLFrom.Add('join aaw_L_Lagerteil on
aaw_Lines.ref=aaw_L_lagerteil.ref0');
Join_AAW_L_Lagerteil:=True;
End;
Function Add_Or(S:String) : String;
Begin
if S='' then result:=''
else result:=S+' or ';
End;
VAR F1, F2 : ShortString;
I : Smallint;
begin
inherited;
Join_aaw_Lines :=False;
Join_AAW_L_Lagerteil:=False;
if Radio_Datum_last3.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+AusgabeDatum(now-3*30)+''' and '''+AusgabeDatum(now)+'''');
if Radio_Datum_last18.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+AusgabeDatum(now-18*30)+''' and '''+AusgabeDatum(now)+'''');
if Radio_Datum_fromto.checked then
IB_Query_Faktuhead.SQLWhereItems.Add('Belegdatum between
'''+Datum_von.text+''' and '''+Datum_bis.text+'''');
if Radio_Summe_vonbis.checked then
Begin
Str(Summe_von.FloatValue:10:2,F1);
Str(Summe_bis.FloatValue:10:2,F2);
IB_Query_Faktuhead.SQLWhereItems.Add('Summebrutto between
'''+F1+''' and '''+F2+'''');
End;
if Filter_Kurzname.Text<>'' then
Begin
if EnthaeltWildcards(Filter_Kurzname.text) then
Begin //yop, Wildcards drin ...
F1:=Wildcard_to_FireBird (Filter_Kurzname.text);
IB_Query_Faktuhead.SQLWhereItems.Add('kurzname like
'''+F1+'''');
End
else // nur beginnend mit
Begin
IB_Query_Faktuhead.SQLWhereItems.Add('kurzname starting
with '''+Filter_Kurzname.text+'''');
End;
End;
if filter_AdressNr.text<>'' then
Begin
IB_Query_Faktuhead.SQLWhereItems.Add('adressnr starting with
'''+filter_adressnr.text+'''');
End;
if filter_belegtext.text<>'' then
Begin
F1:=Wildcard_to_FireBird (Filter_Belegtext.text);
Join_AAWLines;
IB_Query_Faktuhead.SQLWhereItems.Add('upper(aaw_lines.textzeile)
like '''+F1+'''');
End;
if Filter_Lagerort.text<>Filter_Lagerort.LeererText then
Begin
Join_AAWLines;
Join_AAWLLagerteil;
IB_Query_Faktuhead.SQLWhereItems.Add('aaw_l_Lagerteil.lagerort='''+Filt
er_Lagerort.Text+'''');
End;
//jetzt die Detailfilter
F1:='';
if Filter_ZeilenohnePreis.checked then
F1:=Add_or(F1)+'hatzeilenohnepreis=1';
if Filter_ZeilenalterPreis.checked then
F1:=Add_or(F1)+'hatzeilenalterpreis=1';
if Filter_nurfertig.checked then F1:=Add_or(F1)+'fertig=1';
if Filter_inArbeit.checked then F1:=Add_or(F1)+'fertig=0';
if Filter_nurgesperrt.checked then F1:=Add_or(F1)+'gesperrt=1';
if Filter_nurfrei.checked then F1:=Add_or(F1)+'gesperrt=0';
if Filter_geaendert_ungedruckt.checked then
F1:=Add_or(F1)+'geaendert=1';
if Filter_nurIntern.checked then F1:=Add_or(F1)+'intern=1';
if F1<>'' then Begin
F1:='('+F1+')';
IB_Query_Faktuhead.SQLWhereItems.add(F1);
End;
//jetzt noch den Belegartenfilter
F1:='';
For I:=0 to ErlaubteBelegArten.Items.Count-1 do
if ErlaubteBelegArten.Checked[i] then
F1:=F1+''''+IntToStr(ord(BelegArtTab[I]))+''',';
if F1<>'' then
Begin
Delete(F1,Length(F1),1); //letztes Comma wech
F1:='Belegart in ('+F1+')';
IB_Query_Faktuhead.SQLWhereItems.add(F1);
End;
end;
----------
Regards
Gunther
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de