Browse Source

+ some fixes for ParseSQL

git-svn-id: trunk@3793 -
joost 19 years ago
parent
commit
04bb467b2f
1 changed files with 10 additions and 32 deletions
  1. 10 32
      fcl/db/dsparams.inc

+ 10 - 32
fcl/db/dsparams.inc

@@ -170,14 +170,12 @@ end;
 
 
 Function TParams.ParseSQL(SQL: String; DoCreate: Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding): String;
 Function TParams.ParseSQL(SQL: String; DoCreate: Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding): String;
 
 
-var pb : TParamBinding;
-    rs : string;
+var rs : string;
 
 
 begin
 begin
-  Result := ParseSQL(SQL,DoCreate,ParameterStyle,pb, rs);
+  Result := ParseSQL(SQL,DoCreate,ParameterStyle,ParamBinding, rs);
 end;
 end;
 
 
-
 Function TParams.ParseSQL(SQL: String; DoCreate: Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding; var ReplaceString : string): String;
 Function TParams.ParseSQL(SQL: String; DoCreate: Boolean; ParameterStyle : TParamStyle; var ParamBinding: TParambinding; var ReplaceString : string): String;
 
 
 type
 type
@@ -201,20 +199,22 @@ var
   NewQueryLength:integer;
   NewQueryLength:integer;
   NewQuery:string;
   NewQuery:string;
   NewQueryIndex,BufIndex,CopyLen,i:integer;    // Parambinding will have length ParamCount in the end
   NewQueryIndex,BufIndex,CopyLen,i:integer;    // Parambinding will have length ParamCount in the end
-  SimStrCount,b:integer;                         // in psSimulated mode this is the counter with the amount of repeating '$' signs
+  b:integer;
   tmpParam:TParam;
   tmpParam:TParam;
 
 
 begin
 begin
   if DoCreate then Clear;
   if DoCreate then Clear;
   // Parse the SQL and build ParamBinding
   // Parse the SQL and build ParamBinding
   ParamCount:=0;
   ParamCount:=0;
-  SimStrCount := 1;
-  ReplaceString := '';
   NewQueryLength:=Length(SQL);
   NewQueryLength:=Length(SQL);
   SetLength(ParamPart,ParamAllocStepSize);
   SetLength(ParamPart,ParamAllocStepSize);
   SetLength(Parambinding,ParamAllocStepSize);
   SetLength(Parambinding,ParamAllocStepSize);
   QuestionMarkParamCount:=0; // number of ? params found in query so far
   QuestionMarkParamCount:=0; // number of ? params found in query so far
 
 
+  ReplaceString := '$';
+  if ParameterStyle = psSimulated then
+    while pos(ReplaceString,SQL) > 0 do ReplaceString := ReplaceString+'$';
+
   p:=PChar(SQL);
   p:=PChar(SQL);
   BufStart:=p; // used to calculate ParamPart.Start values
   BufStart:=p; // used to calculate ParamPart.Start values
   repeat
   repeat
@@ -339,20 +339,6 @@ begin
             Dec(NewQueryLength,p-ParamNameStart);
             Dec(NewQueryLength,p-ParamNameStart);
           end;
           end;
         end;
         end;
-      '$':
-        if ParameterStyle = psSimulated then
-          begin
-          b := 1;
-          while p^='$' do
-            begin
-            inc(p);
-            inc(b);
-            end;
-          if b > SimStrCount then SimStrCount := b;
-          end
-        else
-          Inc(p);
-        
       #0:Break;
       #0:Break;
     else
     else
       Inc(p);
       Inc(p);
@@ -366,16 +352,8 @@ begin
   begin
   begin
     // replace :ParamName by ? for interbase and by $x for postgresql/psSimulated
     // replace :ParamName by ? for interbase and by $x for postgresql/psSimulated
     // (using ParamPart array and NewQueryLength)
     // (using ParamPart array and NewQueryLength)
-    if (ParameterStyle = psSimulated) then
-      begin
-      if (SimStrCount > 1) then
-        begin
-        inc(NewQueryLength,(paramcount)*(SimStrCount-1));
-        for b := 1 to SimStrCount do ReplaceString := ReplaceString+'$';
-        end
-      else
-        ReplaceString := '$';
-      end;
+    if (ParameterStyle = psSimulated) and (length(ReplaceString) > 1) then
+      inc(NewQueryLength,(paramcount)*(length(ReplaceString)-1));
 
 
     SetLength(NewQuery,NewQueryLength);
     SetLength(NewQuery,NewQueryLength);
     NewQueryIndex:=1;
     NewQueryIndex:=1;
@@ -390,7 +368,7 @@ begin
         psPostgreSQL,
         psPostgreSQL,
         psSimulated : begin
         psSimulated : begin
                         ParamName := IntToStr(ParamBinding[i]+1);
                         ParamName := IntToStr(ParamBinding[i]+1);
-                        for b := 1 to SimStrCount do
+                        for b := 1 to length(ReplaceString) do
                           begin
                           begin
                           NewQuery[NewQueryIndex]:='$';
                           NewQuery[NewQueryIndex]:='$';
                           Inc(NewQueryIndex);
                           Inc(NewQueryIndex);