* 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 -
This commit is contained in:
joost 2007-01-05 15:29:17 +00:00
parent 1d96dcc50d
commit 4424835ba4
2 changed files with 23 additions and 13 deletions

View File

@ -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 // Joost, 5 jan 2006: I disabled the following, since it's usefull for
DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self); // 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; FillByte(buffer^,sizeof(Longint),0);
Move(b, Buffer^, sizeof(longint));
Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen); Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
end; end;
ftLargeint : ftLargeint :

View File

@ -23,11 +23,12 @@ type
TPQCursor = Class(TSQLCursor) TPQCursor = Class(TSQLCursor)
protected protected
Statement : string; Statement : string;
tr : TPQTrans; tr : TPQTrans;
res : PPGresult; res : PPGresult;
CurTuple : integer; CurTuple : integer;
Nr : string; 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