瀏覽代碼

fcl-db: fix parameter parsing in case, when in SQL follows two comments, where in 2nd commend is embeded quote char. Bug #22463

git-svn-id: trunk@31155 -
lacak 10 年之前
父節點
當前提交
2f97bc7f60
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 3 3
      packages/fcl-db/src/base/dsparams.inc
  2. 3 0
      packages/fcl-db/tests/testbasics.pas

+ 3 - 3
packages/fcl-db/src/base/dsparams.inc

@@ -235,9 +235,9 @@ begin
   case p^ of
   case p^ of
     '''', '"', '`':
     '''', '"', '`':
       begin
       begin
+        Result := True;
         // single quote, double quote or backtick delimited string
         // single quote, double quote or backtick delimited string
         SkipQuotesString(p, p^, EscapeSlash, EscapeRepeat);
         SkipQuotesString(p, p^, EscapeSlash, EscapeRepeat);
-        Result := True;
       end;
       end;
     '-': // possible start of -- comment
     '-': // possible start of -- comment
       begin
       begin
@@ -315,7 +315,7 @@ begin
   p:=PChar(SQL);
   p:=PChar(SQL);
   BufStart:=p; // used to calculate ParamPart.Start values
   BufStart:=p; // used to calculate ParamPart.Start values
   repeat
   repeat
-    SkipComments(p,EscapeSlash,EscapeRepeat);
+    while SkipComments(p,EscapeSlash,EscapeRepeat) do ;
     case p^ of
     case p^ of
       ':','?': // parameter
       ':','?': // parameter
         begin
         begin
@@ -403,7 +403,7 @@ begin
             Dec(NewQueryLength,p-ParamNameStart);
             Dec(NewQueryLength,p-ParamNameStart);
           end;
           end;
         end;
         end;
-      #0:Break;
+      #0:Break; // end of SQL
     else
     else
       Inc(p);
       Inc(p);
     end;
     end;

+ 3 - 0
packages/fcl-db/tests/testbasics.pas

@@ -145,6 +145,9 @@ begin
   // Bracketed comment
   // Bracketed comment
   AssertEquals(     'select * from table where id=/*comment :c*/$1-$2',
   AssertEquals(     'select * from table where id=/*comment :c*/$1-$2',
     Params.ParseSQL('select * from table where id=/*comment :c*/:a-:b', True, True, True, psPostgreSQL));
     Params.ParseSQL('select * from table where id=/*comment :c*/:a-:b', True, True, True, psPostgreSQL));
+  // Consecutive comments, with quote in second comment
+  AssertEquals(     '--c1'#10'--c'''#10'select '':a'' from table where id=$1',
+    Params.ParseSQL('--c1'#10'--c'''#10'select '':a'' from table where id=:id', True, True, True, psPostgreSQL));
 
 
   Params.Free;
   Params.Free;
 end;
 end;