TOraScript and Macros

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jrunyan
Posts: 7
Joined: Fri 28 Sep 2007 21:50

TOraScript and Macros

Post by jrunyan » Wed 13 Jan 2010 17:20

I'm unsig ODAC (5.10.4.12) TOraScript and load the script at runtime. I assign a value to a macro but when I execute the script the macro is not substituted.

Sample Script:

CREATE OR REPLACE DIRECTORY AS &P1
/

Sample Code:

for i := 0 to OraScript.Macros.Count - 1 do
begin
MacroName := 'P' + IntToStr(i + 1);
OraScript.FindMacro(MacroName).Value := MainFrm.Macro;
end;

Application.ProcessMessages;

// execute the script
try
OraScript.Execute;
except
on e: Exception do
begin
MainFrm.AddMessage(e.Message);
end;
end;

The documentation states theat the substitution occurs "In time of opening Query..."

There is no Open for TOraScript and when I execute the script the substitution does not occur and I get an oracle error becuase it can't create a directory named &P1.

How can I force the macro substitution at runtime?

John

jrunyan
Posts: 7
Joined: Fri 28 Sep 2007 21:50

Re: TOraScript and Macros

Post by jrunyan » Wed 13 Jan 2010 17:40

I found out that it was the Oracle statment that was in error, however I have connected an OraQuery to capture the individual statements to echo the command to the user and the Text of the OraQuery.SQL.Text still shows the Macro not the substituted text.

Is there a wa to update the Query with the macro substitution?

John

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 14 Jan 2010 08:38

Use the following code:

Code: Select all

var
  SQL: string;
...
  SQL := OraQuery.SQL.Text;
  OraQuery.Macros.Expand(SQL);

Post Reply