Fórum Exemplo Metódo Pessimista com componetes IBX #51964
04/08/2005
0
Componentes que colocoquei
//Botão Gravar procedure TForm1.btGravarClick(Sender: TObject); begin try IBDataSet1.Post; ibtransaction1.CommitRetaining; except ShowMessage(´ERRO: ao gravar o registo´); end; IBDataSet1.Close; IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(´select * from MENU´); IBDataSet1.Prepare; IBDataSet1.Open; end; //Botão Editar procedure TForm1.bteditarClick(Sender: TObject); var strsql:string; begin strsql := ´select * from MENU where codigo = ´ + dbcodigo.Text + ´ with lock´; IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(strsql); try IBDataSet1.Prepare; IBDataSet1.Open; IBDataSet1.Edit; except strsql := stringreplace(strsql,´with lock´,´´,[rfReplaceAll]); IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(strsql); IBDataSet1.Prepare; IBDataSet1.Open; showmessage(´Registro Bloqueado´); end; end;
[color=green:9b4dd1964d]Movido de Delphi para Interbase/Firebird[/color:9b4dd1964d]
Porty
Curtir tópico
+ 0Posts
04/08/2005
Porty
procedure TForm1.btGravarClick(Sender: TObject); var codigo: integer; begin if IBDataSet1.State in dseditmodes then try codigo := IBDataSet1Codigo.Value; IBDataSet1.Post; ibtransaction1.CommitRetaining; except ShowMessage(´ERRO: ao gravar o registo´); end; IBDataSet1.Close; IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(´select * from MENU´); IBDataSet1.Prepare; IBDataSet1.Open; IBDataSet1.Locate(´CODIGO´, CODIGO, []); end; procedure TForm1.bteditarClick(Sender: TObject); var strsql:string; var codigo: integer; begin codigo := IBDataSet1Codigo.Value; strsql := ´select * from MENU where codigo = ´ + dbcodigo.Text + ´ with lock´; try if ibtransaction1.InTransaction then ibtransaction1.Commit; except ibtransaction1.Rollback; end; IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(strsql); try ibtransaction1.StartTransaction; IBDataSet1.Prepare; IBDataSet1.Open; IBDataSet1.Edit; except ibtransaction1.Rollback; //strsql := stringreplace(strsql,´with lock´,´´,[rfReplaceAll]); strsql := ´select * from menu´; IBDataSet1.Close; IBDataSet1.SelectSQL.Clear; IBDataSet1.SelectSQL.Add(strsql); IBDataSet1.Prepare; IBDataSet1.Open; IBDataSet1.Locate(´CODIGO´, CODIGO, []); showmessage(´Registro Bloqueado´); end; end; //botão cancelar procedure TForm1.btCancelarClick(Sender: TObject); begin if IBDataSet1.state in dseditmodes then begin IBDataSet1.cancel; ibtransaction1.Rollback; end; end;
Gostei + 0
22/08/2005
Porty
Cumprimentos
Gostei + 0
24/08/2005
Mordred
Qual é a diferença entre eu simplesmente dar um Open na tabela e eu dar um Open usando Prepare antes? Qual a vantagem de trabalhar nessa segunda forma?
Gostei + 0
24/08/2005
Afarias
|dar um Open usando Prepare antes?
Usando IBX?? Nenhuma mesmo!
T+
Gostei + 0
24/08/2005
Mordred
Gostei + 0
24/08/2005
Beppe
Gostei + 0
25/08/2005
Comodelphi
Gostei + 0
25/08/2005
Afarias
O banco sempre prepara a consulta antes de ser executada.
Um PREPARE só tem sentido ser explicitamente chamado quando um determinado SQL (parametrizado) será executado repetidas vezes, no mais o prepare (e unprepare) é automaticamente realizado.
Quando chamado o prepare explicitamente, é boa prática chamar o unprepare ao final do processo.
Um prepare não ´sobrevive´ em situações como a alteração do texto do SQL ou o commit/rollback da transação.
T+
Gostei + 0
26/08/2005
Mordred
Gostei + 0
26/08/2005
Porty
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)