Using TOracleScript's OnData event

nwgarside

Member²
Hello,

I'm using DOA 4.0.7.1 with Delphi 2007 on Windows 7 x64. I'm using a TOracleScript component to execute a script containing both DML and DDL commands such as the following:


-- Name = "type_dml Disabling triggers"
SELECT 'ALTER TABLE '||LOWER(table_name)||' DISABLE ALL TRIGGERS;'
FROM tabs
WHERE table_name LIKE 'AUTH%';

-- Name = "type_ddl Truncating dbo.callcycles table"
TRUNCATE TABLE dbo.callcycles;

-- Name = "type_ddl Analysing dbo.callcycles table"
ANALYZE TABLE dbo.callcycles COMPUTE STATISTICS;


The first statement in the script returns 9 ALTER TABLE
DISABLE ALL TRIGGERS;
statements, but I'm struggling to 'capture' these 9 statements and run them.

I'm using the TOracleScript's OnData event to output the statements to a memo:
procedure TfrmMain.scrSimmerDownData(Sender: TOracleScript);
begin
mmoOutput.Lines.Add(Sender.Query.FieldAsString(0));
end;
How can I execute the 9 ALTER TABLE statements that are being generated?

Thanks!

/Neil
 
I would personally use a TOracleQuery instance to first execute the query that generates the disable statements. Add the results to a script, append the truncate/analyze statements, and execute it.
 
Hi Marco,

Thanks for the prompt response.

Okay...I will try using a TOracleQuery as you suggest.

One related question I was hoping you could respond to...using the same TOracleScript as in my original post, I am getting a count of commands in the script, and then running each command step-by-step:

iCommand is initially set to 0.


01 procedure TfrmMain.bbnExecuteClick(Sender: TObject);
02 begin
03 try
04 scrSimmerDown.Commands[iCommand].Execute;
05 Inc(iCommand);
06 except
07 on EListError do MessageDlg('No more commands to run!', mtInformation, [mbOK], 0);
08 end;
09 end;


When I run the commands in the script this way, the OnCommand and AfterCommand events do not fire! But if I run the entire script (with scrSimmerDown.Execute as line 04 above) the events do fire.

Why don't the OnCommand and AfterCommand events fire when the script's commands are run one-by-one?

Kind regards,

/Neil
 
The OnCommand and AfterCommand events will indeed only be triggered as a result of a script execution, and not as a result of individual Command.Execute calls.
 
Back
Top