Scripts with & in sql

Riaan

Member
Is their a way to set the functionality off not to use variables? In example I have a script that needs to run but the data contains
 
There is currently no way to escape the & of substitution variables. You can only create a substitution variable (e.g. &amp) and set it to &.

------------------
Marco Kalter
Allround Automations
 
Thanks.

Herewith a work-a-round

In the "OnCommand" event of TOracleScript:

procedure TfrmMain.osrImportCommand(Sender: TOracleScript;
var Handled: Boolean);
begin

if pos('&', Sender.Commands.Items[Sender.CommandIndex].Text) > 0 then
begin
ConvertAmpersandToVariable(Sender.Commands.Items[Sender.CommandIndex].Text, Sender);
end;

end;
{==============================================================================}
procedure TfrmMain.ConvertAmpersandToVariable(const SQLCommand: String; DataSet: TOracleScript);
var
sTemp, sVar: String;
iPos, iLen, iResult: Integer;

function GetEndOfWord(AValue: String): Integer;
var iLoop: Integer;
begin
iResult := 0;
for iLoop := 1 to Length(AValue) do
begin
if (AValue[iLoop] = ' ') or
(AValue[iLoop] = ';') or
(AValue[iLoop] = '''') or
(AValue[iLoop] = '"') then
begin
Break;
end;
Inc(iResult);
end;
Result := iResult;
end;

begin

sTemp := SQLCommand;
while Pos('&', sTemp) 0 do
begin
iPos := Pos('&', sTemp);
iLen := GetEndOfWord(Copy(sTemp, iPos+1, Length(sTemp)));
sVar := Copy(sTemp, iPos+1, iLen);

DataSet.SetVariable(sVar, '&' + sVar);
sTemp := Copy(sTemp, iPos+iLen+1, Length(sTemp));
end;

end;
{==============================================================================}
 
Back
Top