[firebase-br] Fw: Firebird via ADO.NET

Marcelo marcelo em inovacao.inf.br
Ter Abr 25 09:56:44 -03 2006


Caros amigos estou tentando utilizar algumas funções do provider ADO criado pelo
Sr. Carlos Guzman. Encontrei um exemplo feito pelo Sr. Carlos ( acho que em VB.net )
e tentei traduzi-lo para o Delphi 2006 mas não tive sucesso. Gostaria de ver se 
alguém tem alguma idéia de onde estou errando.

Estou usando o Delphi 2006 e o provider 1.7.0b para FireBird 1.5.2.

Objetivo : Criar uma rotina para executar script SQL via provider ADO.Net para 
FireBird. Rotina essa que sera ativada de dentro de um webform.

Problema : Sempre esta dando except no Try que tento utilizar o metodo     W_BatchExecution.Execute(); e não roda o Script.

Também não consegui fazer a segte atribuição direta [//  W_BatchExecution.SqlStatements := W_Script.Results;] conforme esta descrito abaixo.

Obs: Já testei meu script no Firebird e funciona perfeitamente.

Muito obrigado.

Marcelo

*************************************************
Rotina para execução do script.

procedure TAIGI9020.Button4_Click(sender: System.Object; e: System.EventArgs);
var
  W_Connection     : FbConnection;
  W_Command        : FbCommand;
  W_NomeArquivo    : String;
  W_Script         : FbScript;
  W_BatchExecution : FbBatchExecution;
  W_Ind            : SmallInt;

begin


// HFU_NomeArquivo = HTML File upload component

  if Trim(HFU_NomeArquivo.Value) = '' then
    begin
      Response.Write('Missing file name');
      Exit;
    end;

  W_NomeArquivo := HFU_NomeArquivo.Value;

  W_Connection  := FbConnection.Create(ConfigurationSettings.AppSettings.Item['ConnectionString']);
  W_Command     := FbCommand.Create();
  W_Command.Connection := W_Connection;
  W_Connection.Open();


  W_Script      := FbScript.Create(W_NomeArquivo);

  try
    W_Script.Parse;
  except
    Response.Write('There are erro in script');
    W_Script.Free;
    W_Command.Free;
    W_Connection.Free;
    Exit;
  end;

  W_BatchExecution := FbBatchExecution.Create(W_Connection);

// O Compilador Delphi não aceita o comando abaixao. O segte erro é retornado
// [Pascal Error] aigi9020.pas(134): E2129 Cannot assign to a read-only property
//  W_BatchExecution.SqlStatements := W_Script.Results;
//
// Then I have created loop to initialize W_BatchExecution.SqlStatament
  for W_Ind := 0 to W_Script.Results.count - 1 do
    begin
      Response.Write((W_Ind).ToString);
      W_BatchExecution.SqlStatements.Add(W_Script.Results[W_Ind]);
      Response.Write(W_BatchExecution.SqlStatements[W_Ind]);
    end;

  try
    W_BatchExecution.Execute();
  except
    Response.Write('                       There are error in script - II');
    W_Script.Free;
    W_BatchExecution.Free;
    W_Command.Free;
    W_Connection.Free;
    Exit;
  end;

  W_Script.Free;
  W_BatchExecution.Free;
  W_Command.Free;
  W_Connection.Free;

end;

***********************************************
Conteúdo do meu script
----------------------


/* xxxx                           Estruturas do AIGI */

CREATE TABLE FilialII
           ( FIL_CDII                             SMALLINT      NOT NULL,
             FIL_NMII                             VARCHAR(35)   NOT NULL,
             FIL_DT_LKII                          TIMESTAMP     NOT NULL,
             CONSTRAINT PK_FIL_CDII               PRIMARY KEY (FIL_CDII)
           );

SET TERM !! ;
create trigger T_FILIALII_01 for FilialII
before insert position 1 as
begin

  NEW.FIL_Dt_LkII = 'now';

end !!
SET TERM ; !!

create trigger T_FILIALII_02 for FilialII
before update position 2 as
begin

  NEW.FIL_Dt_LkII = 'now';

end !!
SET TERM ; !!


 


Mais detalhes sobre a lista de discussão lista