[firebase-br] IBO - erro ao abrir tib_query pela segunda vez
Marcelo
marcelo em magnosystem.com.br
Seg Out 31 13:40:24 -03 2016
Dê um open na query antes de passar os parâmetros.
Em 31/10/2016 00:00, Andrei Luís escreveu:
> Boa noite,
>
> IBO 4.9.9
> Delphi 2006
> Firebird 2.5.6
>
> Estou com um problema aqui que não entendo o que acontece. Num módulo
> financeiro, tenho vários checks e edits para filtrar, ao clicar num botão
> vou montando a SQL, abaixo parte do código que está no botão filtrar, onde
> o problema acontece.
>
> procedure TfFinanceiroFiltro.bFiltraClick(Sender: TObject);
> var wWhere:string;
> begin
> wWhere:='where ';
> with dm.qrFinanceiro do
> begin
> if Active then
> begin
> Close;
> Unprepare;
> IB_Transaction.CommitRetaining;
> end;
> SQL.Clear;
> SQL.Text:='SELECT f.REGISTRO_ID, e.razaosocial, f.NR_DOCUMENTO,
> f.SACADO' +
> ', f.CLIENTE_ID, f.DATAEMISSAO, f.OBSERVACAO1,
> f.OBSERVACAO2'+
> ', f.VALOR, f.DATAVENCIMENTO, f.datapagamento,
> f.planocontas_id ' +
> ', f.BAIXA_BOLETO, f.DATADABAIXA, f.TIPOBOLETO_ID,
> f.BASETERRITORIAL_ID' +
> ', tb.tipoboleto, f.marcado, e.endereco, e.cep, c.cidade,
> f.baixa_obs, f.contafinanceiro_id,' +
> ' f.meiopagamento, f.nr_cheque '+
> ', f.valor_pago, pc.tipo credito_debito, ' +
> ' case when pc.tipo=''C'' then ''CRÉDITO''' +
> ' when pc.tipo=''D'' then ''DÉBITO'' ' +
> 'end credito_debito_desc ' +
> 'FROM Financeiro f';
> SQL.Add('left join empresas e on (e.registro_id=f.cliente_id)');
> SQL.Add('left join tipoboleto tb on
> (tb.registro_id=f.tipoboleto_id)');
> SQL.Add('join cidades c on (c.registro_id=e.cidade_id)');
> SQL.Add('left join plano_contas pc on
> (pc.registro_id=f.planocontas_id)');
>
> wWhere:='where ';
> ParamCheck := True;
>
> bFiltra.tag := 0 ;
>
>
> if (checkCredito.Checked) and (not checkDebito.Checked) then
> begin
> Sql.Add(wwhere + '(pc.tipo=''C'')');
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
> if (not checkCredito.Checked) and (checkDebito.Checked) then
> begin
> Sql.Add(wwhere + '(pc.tipo=''D'')');
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
>
> if checkQuitadas.checked then
> Begin
> if checkEmAberto.checked then
> begin
> SQL.Add(wwhere + ' ((f.baixa_boleto = '+QuotedStr('T')+')
> or (f.baixa_boleto ='+QuotedStr('F')+') or (f.datapagamento is not null))');
>
> end
> else
> begin
> SQL.Add(wwhere + ' ((f.baixa_boleto = '+QuotedStr('T')
> +') or (f.datapagamento is not null))');
>
> end;
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
> if checkEmAberto.checked then
> Begin
> if not checkQuitadas.checked then
> begin
> SQL.Add(wwhere + ' ((f.baixa_boleto = '+QuotedStr('F')
> +') and (f.datapagamento is null))');
>
> end;
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
> if (checkDataEmissao.Checked) then
> Begin
> SQL.Add(wwhere + ' (f.dataEmissao between :wdataEmissaoInicial
> and :wdataEmissaoFinal)');
>
>
> ParamByName('wDataEmissaoInicial').asDate:=editDataEmissaoInicial.Date;
>
> ParamByName('wDataEmissaoFinal').asDate:=editDataEmissaoFinal.Date;
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
>
> if (checkDataVencimento.Checked) then
> Begin
> SQL.Add(wwhere + ' (f.dataVencimento between
> :wdataVencimentoInicial and :wdataVencimentoFinal) ');
>
> ParamByName('wDataVencimentoInicial').asDate:=editDataVencimentoInicial.Date;
>
> ParamByName('wDataVencimentoFinal').asDate:=editDataVencimentoFinal.Date;
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
>
>
> if (checkRazao.Checked) and (editRazao.text<>'') then
> Begin
> SQL.Add(wwhere + ' (e.razaoSocial containing :wRazao)');
> ParamByName('wRazao').asString:=editRazao.Text;
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
>
> if (checkNrDoc.Checked) and (editNrDoc.text<>'') then
> Begin
> SQL.Add(wwhere + ' (f.Nr_Documento containing :wNrDoc)');
> ParamByName('wNrDoc').asString:=editNrDoc.Text;
>
> wWhere:='and ';
> bFiltra.tag := 1 ;
> end;
>
> Open;
> end;
> StatusBar1.Panels[0].Text := inttostr(dm.qrFinanceiro.RecordCount) +'
> registros filtrados';
> StatusBar1.Panels[1].Text := 'Valor total: ' +
> FormatFloat('###,###,###.00',
> qry_tmp.FieldByName('valor_total').AsCurrency);
> label1.Caption:=inttostr(dm.qrFinanceiro.RecordCount) +' registros
> filtrados';
>
> gbDbGrid.Show;
> gbFiltro.Hide;
> end;
>
>
> Quando executa esse código, dou um hide nas opções do filtro
> (gbFiltro.Hide) e mostro o grid com o resultado da query, estou usando
> TIB_Query. Nesse ponto apresento alguns botões, e um deles volta para o
> filtro com o seguinte código:
>
> gbDbGrid.Hide;
> gbFiltro.Show;
> dm.qrFinanceiro.Close;
> dm.qrFinanceiro.Unprepare;
> dm.qrFinanceiro.IB_Transaction.CommitRetaining;
> dm.qrFinanceiro.params.CleanupInstance;
>
>
> O problema está agora, se tento filtrar uma segunda vez, com mais campos.
> Por exemplo, acabo de fazer um teste da seguinte forma:
>
> Primeira pesquisa, checks marcados: checkQuitadas, checkCredito e
> checkRazao. Roda redondo. Volto e desmarco checkRazao e marco checkNrDoc:
> tudo certo, sem problema. Volto e marco checkRazao novamente, ficando dessa
> vez marcados checkQuitadas, checkCredito, checkRazao e checkNrDoc, aí
> aparece o erro isc error code 335544572 invalid cursor reference no
> momento em que dou open no TIB_Query. Aí preciso fechar o sistema e abrir
> novamente para poder abrir essa query. Já troquei o CommitRetaining por
> Commit e deu na mesma.
>
> Mais um fato curioso, se eu abro o sistema, e filtro por todos os campos
> que mencionei, não dá erro na primeira vez, mas se altero algum parametros,
> o erro acontece.
>
> Alguém tem uma luz pra me dar? Trata-se de um sistema que roda a bastante
> tempo, e de repente começou isso. Provável que eu tenha mudado alguma
> propriedade que está ocasionando isso.Tenho um módulo semelhante em outro
> sistema que não está acontecendo isso.
>
> []s
> Andrei
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
> Para saber como gerenciar/excluir seu cadastro na lista, use: http://www.firebase.com.br/fb/artigo.php?id=1107
> Para consultar mensagens antigas: http://www.firebase.com.br/pesquisa_lista.html
>
Mais detalhes sobre a lista de discussão lista