* the query-parser from sqldb now uses the dsparams-algorithm to handle comments and strings. (solves mantis issues #7599 and 6924)

git-svn-id: trunk@5007 -
This commit is contained in:
joost 2006-10-22 21:05:25 +00:00
parent b89cff5980
commit 88fd6f0727
3 changed files with 63 additions and 46 deletions

View File

@ -1895,6 +1895,8 @@ Function DateTimeToDateTimeRec(DT: TFieldType; Data: TDateTime): TDateTimeRec;
procedure DisposeMem(var Buffer; Size: Integer);
function BuffersEqual(Buf1, Buf2: Pointer; Size: Integer): Boolean;
function SkipComments(var p: PChar) : boolean;
implementation
uses dbconst,typinfo;

View File

@ -176,6 +176,63 @@ begin
Result := ParseSQL(SQL,DoCreate,ParameterStyle,ParamBinding, rs);
end;
function SkipComments(var p: PChar) : boolean;
begin
result := false;
case p^ of
'''': // single quote delimited string
begin
Inc(p);
Result := True;
while not (p^ in [#0, '''']) do
begin
if p^='\' then Inc(p,2) // make sure we handle \' and \\ correct
else Inc(p);
end;
if p^='''' then Inc(p); // skip final '
end;
'"': // double quote delimited string
begin
Inc(p);
Result := True;
while not (p^ in [#0, '"']) do
begin
if p^='\' then Inc(p,2) // make sure we handle \" and \\ correct
else Inc(p);
end;
if p^='"' then Inc(p); // skip final "
end;
'-': // possible start of -- comment
begin
Inc(p);
if p^='-' then // -- comment
begin
Result := True;
repeat // skip until at end of line
Inc(p);
until p^ in [#10, #0];
end
end;
'/': // possible start of /* */ comment
begin
Inc(p);
if p^='*' then // /* */ comment
begin
Result := True;
repeat
Inc(p);
if p^='*' then // possible end of comment
begin
Inc(p);
if p^='/' then Break; // end of comment
end;
until p^=#0;
if p^='/' then Inc(p); // skip final /
end;
end;
end; {case}
end;
Function TParams.ParseSQL(SQL: String; DoCreate: Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding; var ReplaceString : string): String;
type
@ -218,53 +275,8 @@ begin
p:=PChar(SQL);
BufStart:=p; // used to calculate ParamPart.Start values
repeat
SkipComments(p);
case p^ of
'''': // single quote delimited string
begin
Inc(p);
while not (p^ in [#0, '''']) do
begin
if p^='\' then Inc(p,2) // make sure we handle \' and \\ correct
else Inc(p);
end;
if p^='''' then Inc(p); // skip final '
end;
'"': // double quote delimited string
begin
Inc(p);
while not (p^ in [#0, '"']) do
begin
if p^='\' then Inc(p,2) // make sure we handle \" and \\ correct
else Inc(p);
end;
if p^='"' then Inc(p); // skip final "
end;
'-': // possible start of -- comment
begin
Inc(p);
if p='-' then // -- comment
begin
repeat // skip until at end of line
Inc(p);
until p^ in [#10, #0];
end
end;
'/': // possible start of /* */ comment
begin
Inc(p);
if p^='*' then // /* */ comment
begin
repeat
Inc(p);
if p^='*' then // possible end of comment
begin
Inc(p);
if p^='/' then Break; // end of comment
end;
until p^=#0;
if p^='/' then Inc(p); // skip final /
end;
end;
':','?': // parameter
begin
IgnorePart := False;

View File

@ -872,6 +872,9 @@ begin
repeat
begin
inc(CurrentP);
if SkipComments(CurrentP) then
if ParsePart = ppStart then PhraseP := CurrentP;
if CurrentP^ in [' ',#13,#10,#9,#0,'(',')',';'] then
begin