From 3c0f6f85fefad182b13f56d2a3cb38467dd36ab1 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 16 Oct 2005 19:50:03 +0000 Subject: [PATCH] Merged revisions 1374,1389,1396 via svnmerge from svn+ssh://peter@www.freepascal.org/FPC/svn/fpc/trunk r1374 (marco) * TUpdatestatusset (kbmmw port missed this) r1389 (joost) + Fix bug #4376, varchar without size specification r1396 (joost) + fixed some memory issues when using parameters git-svn-id: branches/fixes_2_0@1430 - --- fcl/db/db.pp | 1 + fcl/db/sqldb/postgres/pqconnection.pp | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fcl/db/db.pp b/fcl/db/db.pp index a5db72e73a..c77257896e 100644 --- a/fcl/db/db.pp +++ b/fcl/db/db.pp @@ -53,6 +53,7 @@ type deParentScroll); TUpdateStatus = (usUnmodified, usModified, usInserted, usDeleted); + TUpdateStatusSet = SET OF TUpdateStatus; TUpdateMode = (upWhereAll, upWhereChanged, upWhereKeyOnly); diff --git a/fcl/db/sqldb/postgres/pqconnection.pp b/fcl/db/sqldb/postgres/pqconnection.pp index 0d049e63b4..b737960596 100644 --- a/fcl/db/sqldb/postgres/pqconnection.pp +++ b/fcl/db/sqldb/postgres/pqconnection.pp @@ -466,9 +466,9 @@ end; 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 with cursor as TPQCursor do @@ -479,13 +479,18 @@ begin begin setlength(ar,Aparams.count); for i := 0 to AParams.count -1 do + begin 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 - 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; - 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 else res := PQexecPrepared(tr,pchar('prepst'+nr),0,nil,nil,nil,0); @@ -539,7 +544,10 @@ begin fieldtype := TranslateFldType(PQftype(BaseRes, i)); if (fieldtype = ftstring) and (size = -1) then + begin size := pqfmod(baseres,i)-3; + if size = -4 then size := dsMaxStringSize; + end; if fieldtype = ftdate then size := sizeof(double);