Error creating oracle package caused by dbexp.FixParams

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for Oracle in Delphi and C++Builder
Post Reply
carlobar
Posts: 3
Joined: Tue 16 May 2006 09:37

Error creating oracle package caused by dbexp.FixParams

Post by carlobar » Fri 25 Nov 2011 17:51

DbExpress for Oracle driver 4.90.25 - 16 May 2011
During generation of package:
CREATE OR REPLACE PACKAGE BODY Test_FixParams IS
FUNCTION GetMessage RETURN VARCHAR2 AS
BEGIN
-- dbexp.FixParams's bad comment
RETURN 'Is dbexp.FixParams function Correct?';
END;
END Test_FixParams;

the package created into database is:
FUNCTION GetMessage RETURN VARCHAR2 AS
BEGIN
-- dbexp.FixParams's bad comment
RETURN 'Is dbexp.FixParams function Correct:1';
END;
The error is the substitution of:
...Correct?
with
...Correct:1

Debugging the driver we've notice that FixParams function fails because does not consider the presence of comments in package source, like:
-- dbexp.FixParams's bad comment
It consider the quote into the comment as a start of a literal, then the literal finished after:
RETURN '
and the ? char is consider outside any literal and it was substitutes by :1

We have fixed the Function considering the line comment and the section comment eventually present into source of package in this way:

function FixParams(const SQL: string; QuoteChar: Char = #0): string;
var
Start, Pos, NextPos: PChar;
InLiteral: Boolean;
InCommentLine: Boolean;
InCommentSection: Boolean;
ParamCount: integer;
l: integer;
begin
if (SQL '') then begin
ParamCount := 0;
case QuoteChar of
#0, ' ':
QuoteChar := '''';
end;
Pos := PChar(SQL);
Start := Pos;
Result := '';
InLiteral := False;
InCommentLine := False;
InCommentSection := False;
while Pos^ #0 do begin
NextPos := Pos+1;
if InCommentLine then
begin
//Test if comment line is finished
if (Pos^ = chr(10)) or (Pos^ = chr(13)) then
InCommentLine := False; //end of comment line
end
else if InCommentSection then
begin
//Test if comment section is finished
if (Pos^ = '*') and (NextPos^ = '/') then
InCommentSection := False; //end of comment section
end
else if not InLiteral and ((Pos^ = '-') and (NextPos^ = '-')) then
InCommentLine := True //start of comment line
else if not InLiteral and ((Pos^ = '/') and (NextPos^ = '*')) then
InCommentSection := True //start of comment section
else
Begin
//We aren't in any comments
if Pos^ = QuoteChar then
InLiteral := not InLiteral
else
if not InLiteral and (Pos^ = '?') then begin
if Pos > Start then begin
l := Length(Result);
SetLength(Result, l + (Pos - Start));
Move(Start^, Result[l + 1], (Pos - Start) * SizeOf(Char))
end;
Inc(ParamCount);
Result := Result + ':' + IntToStr(ParamCount);
Inc(Pos);
Start := Pos;
continue;
end;
end;
Inc(Pos);
end;
if Result = '' then
Result := SQL
else
Result := Result + Start;
end
else
Result := '';
end;

Do you agree?
Thanks
Carlo Barazzetta
Liscor SpA

carlobar
Posts: 3
Joined: Tue 16 May 2006 09:37

Why FixParams is called as implementation of ExecuteDirect ?

Post by carlobar » Mon 28 Nov 2011 09:09

Another possible mistake of the driver is the call of FixParams, when my Delphi program calls Connection.ExecuteDirect.
The help sais:
"Call ExecuteDirect to execute a single parameterless command": why the driver implements this call with a call to FixParams?
thank
Carlo Barazzetta

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 29 Nov 2011 07:10

Hello,

Thank you for the information.
We have reproduced the problem.
We will notify you as soon as we have any results.

Post Reply