Browse Source

* Use maximum scale if pqfmod doesnt return any.

git-svn-id: trunk@12570 -
joost 16 years ago
parent
commit
dd02d5ec61
1 changed files with 11 additions and 4 deletions
  1. 11 4
      packages/fcl-db/src/sqldb/postgres/pqconnection.pp

+ 11 - 4
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -379,7 +379,7 @@ begin
 end;
 
 function TPQConnection.TranslateFldType(res : PPGresult; Tuple : integer; var Size : integer) : TFieldType;
-
+var li : longint;
 begin
   Size := 0;
   case PQftype(res,Tuple) of
@@ -389,8 +389,11 @@ begin
                              size := PQfsize(Res, Tuple);
                              if (size = -1) then
                                begin
-                               size := (PQfmod(res,Tuple)-4) and $FFFF;
-                               if size = -5 then size := dsMaxStringSize;
+                               li := PQfmod(res,Tuple);
+                               if li = -1 then
+                                 size := dsMaxStringSize
+                               else
+                                 size := (li-4) and $FFFF;
                                end;
                              if size > dsMaxStringSize then size := dsMaxStringSize;
                              end;
@@ -409,10 +412,14 @@ begin
     Oid_Bool               : Result := ftBoolean;
     Oid_Numeric            : begin
                              Result := ftBCD;
+                             li := PQfmod(res,Tuple);
+                             if li = -1 then
+                               size := 4 // No information about the size available, use the maximum value
+                             else
                              // The precision is the high 16 bits, the scale the
                              // low 16 bits. Both with an offset of 4.
                              // In this case we need the scale:
-                             size := (PQfmod(res,Tuple)-4) and $FFFF;
+                               size := (li-4) and $FFFF;
                              end;
     Oid_Money              : Result := ftCurrency;
     Oid_Unknown            : Result := ftUnknown;