Browse Source

* some code-cleanup
* check for fieldname removed, since it slows down a lot and has no real use
* Store/cache the fieldnumber also in PQConnection

git-svn-id: trunk@5819 -

joost 18 years ago
parent
commit
4424835ba4
2 changed files with 23 additions and 13 deletions
  1. 9 5
      fcl/db/sqldb/interbase/ibconnection.pp
  2. 14 8
      fcl/db/sqldb/postgres/pqconnection.pp

+ 9 - 5
fcl/db/sqldb/interbase/ibconnection.pp

@@ -597,6 +597,7 @@ begin
     begin
     begin
     FreeSQLDABuffer(SQLDA);
     FreeSQLDABuffer(SQLDA);
     FreeSQLDABuffer(in_SQLDA);
     FreeSQLDABuffer(in_SQLDA);
+    SetLength(FieldBinding,0);
     end;
     end;
 end;
 end;
 
 
@@ -757,7 +758,6 @@ var
   x          : integer;
   x          : integer;
   VarcharLen : word;
   VarcharLen : word;
   CurrBuff     : pchar;
   CurrBuff     : pchar;
-  b            : longint;
   c            : currency;
   c            : currency;
 
 
 begin
 begin
@@ -766,8 +766,13 @@ begin
 {$R-}
 {$R-}
     x := FieldBinding[FieldDef.FieldNo-1];
     x := FieldBinding[FieldDef.FieldNo-1];
 
 
-    if SQLDA^.SQLVar[x].AliasName <> FieldDef.Name then
-      DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self);
+    // Joost, 5 jan 2006: I disabled the following, since it's usefull for
+    // debugging, but it also slows things down. In principle things can only go
+    // wrong when FieldDefs is changed while the dataset is opened. A user just
+    // shoudn't do that. ;) (The same is done in PQConnection)
+
+    // if SQLDA^.SQLVar[x].AliasName <> FieldDef.Name then
+    // DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self);
     if assigned(SQLDA^.SQLVar[x].SQLInd) and (SQLDA^.SQLVar[x].SQLInd^ = -1) then
     if assigned(SQLDA^.SQLVar[x].SQLInd) and (SQLDA^.SQLVar[x].SQLInd^ = -1) then
       result := false
       result := false
     else
     else
@@ -796,8 +801,7 @@ begin
           end;
           end;
         ftInteger :
         ftInteger :
           begin
           begin
-            b := 0;
-            Move(b, Buffer^, sizeof(longint));
+            FillByte(buffer^,sizeof(Longint),0);
             Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
             Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
           end;
           end;
         ftLargeint :
         ftLargeint :

+ 14 - 8
fcl/db/sqldb/postgres/pqconnection.pp

@@ -23,11 +23,12 @@ type
 
 
   TPQCursor = Class(TSQLCursor)
   TPQCursor = Class(TSQLCursor)
     protected
     protected
-    Statement : string;
-    tr        : TPQTrans;
-    res       : PPGresult;
-    CurTuple  : integer;
-    Nr        : string;
+    Statement    : string;
+    tr           : TPQTrans;
+    res          : PPGresult;
+    CurTuple     : integer;
+    Nr           : string;
+    FieldBinding : array of integer;
   end;
   end;
 
 
   { TPQConnection }
   { TPQConnection }
@@ -585,6 +586,7 @@ begin
   with cursor as TPQCursor do
   with cursor as TPQCursor do
     begin
     begin
     nFields := PQnfields(Res);
     nFields := PQnfields(Res);
+    setlength(FieldBinding,nFields);
     for i := 0 to nFields-1 do
     for i := 0 to nFields-1 do
       begin
       begin
       size := PQfsize(Res, i);
       size := PQfsize(Res, i);
@@ -600,7 +602,8 @@ begin
       else if fieldtype = ftblob then
       else if fieldtype = ftblob then
         size := 0;
         size := 0;
 
 
-      TFieldDef.Create(FieldDefs, PQfname(Res, i), fieldtype,size, False, (i + 1));
+      with TFieldDef.Create(FieldDefs, PQfname(Res, i), fieldtype,size, False, (i + 1)) do
+        FieldBinding[FieldNo-1] := i;
       end;
       end;
     CurTuple := -1;
     CurTuple := -1;
     end;
     end;
@@ -645,11 +648,14 @@ var
 begin
 begin
   with cursor as TPQCursor do
   with cursor as TPQCursor do
     begin
     begin
-    for x := 0 to PQnfields(res)-1 do
-      if PQfname(Res, x) = FieldDef.Name then break;
 
 
+    // Joost, 5 jan 2006: I disabled the following, since it's usefull for
+    // debugging, but it also slows things down. In principle things can only go
+    // wrong when FieldDefs is changed while the dataset is opened. A user just
+    // shoudn't do that. ;) (The same is done in IBConnection)
     if PQfname(Res, x) <> FieldDef.Name then
     if PQfname(Res, x) <> FieldDef.Name then
       DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self);
       DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self);
+    x := FieldBinding[FieldDef.FieldNo-1];
 
 
     if pqgetisnull(res,CurTuple,x)=1 then
     if pqgetisnull(res,CurTuple,x)=1 then
       result := false
       result := false