logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Sql_Script in Delphi: msg#00205

Subject: Sql_Script in Delphi
I Tried translate a example by Carlos Guzman ( in VB.net I think )
for to create a function to execute a SQL script using .net provider
Firebird in Delphi 2006.  
But always the except in W_BatchExecution.Execute() is raise.  
Someone have ideia what is happening. Where is my mistake 
 
Thank a lot
 
Marcelo
 
I am using Delphi 2006 and provider 1.7.0b
 
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);
 
// It Does not accept command below. The compiler give the error
// [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;
 
***********************************************
My Script file content is
-------------------------
 

/* 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 ; !!
 

 
<Prev in Thread] Current Thread [Next in Thread>