mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 21:10:11 +02:00
* 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:
parent
b89cff5980
commit
88fd6f0727
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user