Browse Source

+ fixed some memory issues when using parameters

git-svn-id: trunk@1396 -
joost 20 years ago
parent
commit
908cf4c7e2
1 changed files with 12 additions and 7 deletions
  1. 12 7
      fcl/db/sqldb/postgres/pqconnection.pp

+ 12 - 7
fcl/db/sqldb/postgres/pqconnection.pp

@@ -466,9 +466,9 @@ end;
 
 
 procedure TPQConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;AParams : TParams);
 procedure TPQConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;AParams : TParams);
 
 
-var ar : array of pchar;
-    i  : integer;
-    s  : string;
+var ar  : array of pointer;
+    i   : integer;
+    s   : string;
 
 
 begin
 begin
   with cursor as TPQCursor do
   with cursor as TPQCursor do
@@ -479,13 +479,18 @@ begin
         begin
         begin
         setlength(ar,Aparams.count);
         setlength(ar,Aparams.count);
         for i := 0 to AParams.count -1 do
         for i := 0 to AParams.count -1 do
+          begin
           case AParams[i].DataType of
           case AParams[i].DataType of
-            ftdatetime : ar[i] := pchar(formatdatetime('YYYY-MM-DD',AParams[i].AsDateTime));
+            ftdatetime : s := formatdatetime('YYYY-MM-DD',AParams[i].AsDateTime);
           else
           else
-            ar[i] := pchar(AParams[i].asstring);
-          writeln(ar[i]);
+            s := AParams[i].asstring;
+          end; {case}
+          GetMem(ar[i],length(s)+1);
+          StrMove(PChar(ar[i]),Pchar(s),Length(S)+1);
           end;
           end;
-        res := PQexecPrepared(tr,pchar('prepst'+nr),Aparams.count,@Ar[0],nil,nil,0)
+        res := PQexecPrepared(tr,pchar('prepst'+nr),Aparams.count,@Ar[0],nil,nil,0);
+        for i := 0 to AParams.count -1 do
+          FreeMem(ar[i]);
         end
         end
       else
       else
         res := PQexecPrepared(tr,pchar('prepst'+nr),0,nil,nil,nil,0);
         res := PQexecPrepared(tr,pchar('prepst'+nr),0,nil,nil,nil,0);