Browse Source

fcl-db: postgresql: fixes loading of field data of type FLOAT4
(revealed by test TestSQLReal)

git-svn-id: trunk@23064 -

lacak 12 years ago
parent
commit
f6e23e07f1
1 changed files with 16 additions and 12 deletions
  1. 16 12
      packages/fcl-db/src/sqldb/postgres/pqconnection.pp

+ 16 - 12
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -780,7 +780,7 @@ type TNumericRecord = record
      end;
 
 var
-  x,i,j         : integer;
+  x,i           : integer;
   s             : string;
   li            : Longint;
   CurrBuff      : pchar;
@@ -814,18 +814,22 @@ begin
       result := true;
 
       case FieldDef.DataType of
-        ftInteger, ftSmallint, ftLargeInt, ftFloat :
-          begin
-          i := PQfsize(res, x);
-          case i of               // postgres returns big-endian numbers
-            sizeof(int64) : pint64(buffer)^ := BEtoN(pint64(CurrBuff)^);
-            sizeof(integer) : pinteger(buffer)^ := BEtoN(pinteger(CurrBuff)^);
-            sizeof(smallint) : psmallint(buffer)^ := BEtoN(psmallint(CurrBuff)^);
-          else
-            for j := 1 to i do
-              pchar(Buffer)[j-1] := CurrBuff[i-j];
+        ftInteger, ftSmallint, ftLargeInt :
+          case PQfsize(res, x) of  // postgres returns big-endian numbers
+            sizeof(int64) : pint64(buffer)^ := BEtoN(pint64(CurrBuff)^); // INT8
+            sizeof(integer) : pinteger(buffer)^ := BEtoN(pinteger(CurrBuff)^); // INT4
+            sizeof(smallint) : psmallint(buffer)^ := BEtoN(psmallint(CurrBuff)^); // INT2
+          end; {case}
+        ftFloat :
+          case PQfsize(res, x) of  // postgres returns big-endian numbers
+            sizeof(int64) :  // FLOAT8
+              pint64(buffer)^ := BEtoN(pint64(CurrBuff)^);
+            sizeof(integer) :  // FLOAT4
+              begin
+              li := BEtoN(pinteger(CurrBuff)^);
+              pdouble(buffer)^ := psingle(@li)^
+              end;
           end; {case}
-          end;
         ftString, ftFixedChar :
           begin
           case PQftype(res, x) of