diff --git a/fcl/db/db.pp b/fcl/db/db.pp index 04fee8e1c3..9b35756d77 100644 --- a/fcl/db/db.pp +++ b/fcl/db/db.pp @@ -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; diff --git a/fcl/db/dsparams.inc b/fcl/db/dsparams.inc index 49f5ca40da..292136e649 100644 --- a/fcl/db/dsparams.inc +++ b/fcl/db/dsparams.inc @@ -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; diff --git a/fcl/db/sqldb/sqldb.pp b/fcl/db/sqldb/sqldb.pp index 899d7f8857..6454c0276f 100644 --- a/fcl/db/sqldb/sqldb.pp +++ b/fcl/db/sqldb/sqldb.pp @@ -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