Browse Source

--- Merging r26152 into '.':
U packages/fcl-db/src/base/dsparams.inc
U packages/fcl-db/src/sqldb/sqldb.pp
--- Merging r26412 into '.':
G packages/fcl-db/src/base/dsparams.inc
U packages/fcl-db/tests/testbasics.pas

# revisions: 26152,26412
r26152 | lacak | 2013-11-28 14:23:46 +0100 (Thu, 28 Nov 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-db/src/base/dsparams.inc
M /trunk/packages/fcl-db/src/sqldb/sqldb.pp

fcl-db: sqldb: add support for backtick "`" as identifier delimiter.
r26412 | lacak | 2014-01-08 20:59:18 +0100 (Wed, 08 Jan 2014) | 1 line
Changed paths:
M /trunk/packages/fcl-db/src/base/dsparams.inc
M /trunk/packages/fcl-db/tests/testbasics.pas

fcl-db: fix parameter parsing if form "-:param" is used. Do not confuse with simple line comment, which must start with "--". Bug #25505

git-svn-id: branches/fixes_2_6@26852 -

marco 11 years ago
parent
commit
0d2ada3eae

+ 6 - 10
packages/fcl-db/src/base/dsparams.inc

@@ -192,16 +192,12 @@ end;
 function SkipComments(var p: PChar; EscapeSlash, EscapeRepeat : Boolean) : Boolean;
 function SkipComments(var p: PChar; EscapeSlash, EscapeRepeat : Boolean) : Boolean;
 
 
 begin
 begin
-  result := false;
+  Result := False;
   case p^ of
   case p^ of
-    '''':
+    '''', '"', '`':
       begin
       begin
-        SkipQuotesString(p,'''',EscapeSlash,EscapeRepeat); // single quote delimited string
-        Result := True;
-      end;
-    '"':
-      begin
-        SkipQuotesString(p,'"',EscapeSlash,EscapeRepeat);  // double quote delimited string
+        // single quote, double quote or backtick delimited string
+        SkipQuotesString(p, p^, EscapeSlash, EscapeRepeat);
         Result := True;
         Result := True;
       end;
       end;
     '-': // possible start of -- comment
     '-': // possible start of -- comment
@@ -212,9 +208,9 @@ begin
           Result := True;
           Result := True;
           repeat // skip until at end of line
           repeat // skip until at end of line
             Inc(p);
             Inc(p);
-          until p^ in [#10, #0];
+          until p^ in [#10, #13, #0];
+          while p^ in [#10, #13] do Inc(p); // newline is part of comment
         end;
         end;
-        if p^<>#0 then Inc(p); // newline is part of comment
       end;
       end;
     '/': // possible start of /* */ comment
     '/': // possible start of /* */ comment
       begin
       begin

+ 1 - 1
packages/fcl-db/src/sqldb/sqldb.pp

@@ -1741,7 +1741,7 @@ begin
         until (CurrentP^ = #0) or (BracketCount = 0);
         until (CurrentP^ = #0) or (BracketCount = 0);
         if CurrentP^ <> #0 then inc(CurrentP);
         if CurrentP^ <> #0 then inc(CurrentP);
         end;
         end;
-      '"':
+      '"','`':
         if SkipComments(CurrentP, sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions) then
         if SkipComments(CurrentP, sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions) then
           Separator := sepDoubleQuote;
           Separator := sepDoubleQuote;
       else
       else

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

@@ -117,6 +117,14 @@ begin
   AssertEquals( StringReplace(SQLStr, ':par', '$', [rfReplaceAll]),
   AssertEquals( StringReplace(SQLStr, ':par', '$', [rfReplaceAll]),
     Params.ParseSQL(SQLStr, True, True, True, psPostgreSQL) );
     Params.ParseSQL(SQLStr, True, True, True, psPostgreSQL) );
 
 
+// Test comments:
+  // Simple comment
+  AssertEquals(     'select * from table where id= --comment :c'#10'$1-$2 or id= --:c'#13'-$3',
+    Params.ParseSQL('select * from table where id= --comment :c'#10':a-:b or id= --:c'#13'-:d', True, True, True, psPostgreSQL));
+  // Bracketed comment
+  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.Free;
   Params.Free;
 end;
 end;