Bug #69590 [Com]: OCI extension: oci_field_scale returns 0 for float expression

From: Date: Mon, 11 May 2015 10:36:32 +0000
Subject: Bug #69590 [Com]: OCI extension: oci_field_scale returns 0 for float expression
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192615@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69590&edit=1

 ID:                 69590
 Comment by:         vavra at 602 dot cz
 Reported by:        vavra at 602 dot cz
 Summary:            OCI extension: oci_field_scale returns 0 for float
                     expression
 Status:             Not a bug
 Type:               Bug
 Package:            OCI8 related
 Operating System:   Windows7 32bit
 PHP Version:        5.6.8
 Assigned To:        sixd
 Block user comment: N
 Private report:     N

 New Comment:

Shall I understand this that this is OCI (Oracle) bug and I should create a new issue for Oracle?

You are quoting "When precision is 0, NUMBER(precision, scale) can be represented simply as
NUMBER."

Well, when the NUMBER is without precision, the Oracle doc says: "The absence of precision and
scale designators specifies the maximum range and
precision for an Oracle number." So the operands are floats.

Even if the operands would have been integers (NUMBER(x)), the division should result to
oci_field_scale(.) with nonzero. And I got the same bad result 0 for table with integers with same
values as above:


Previous Comments:
------------------------------------------------------------------------
[2015-05-07 18:21:59] sixd@php.net

By 'same results', I mean precision is always 0 so the rule I quoted applies.

------------------------------------------------------------------------
[2015-05-07 18:16:51] sixd@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

- This isn't specific to PHP.  Try 'CREATE TABLE testtab as select a, b, a/b division,
21/2 constant_division from test_division' and change your PHP code to query testtab. You will
see the same result.

- The columns are of type NUMBER.  Check oci_field_precision(). It is zero in all cases.  From Table
6-8 in the OCI manual https://docs.oracle.com/database/121/LNOCI/oci06des.htm#LNOCI16458
it says "When precision is 0, NUMBER(precision, scale) can be represented simply as
NUMBER."

- It seems a semi-interesting quirk that the runtime/compile time evaluation is returning different
scales.

------------------------------------------------------------------------
[2015-05-07 06:55:02] vavra at 602 dot cz

Description:
------------
Lets consider this table
 create table test_division(a number, b number);
with values
 insert into test_division values (21, 2);  
and this query
 select a, b, a/b division, 21/2 constant_division from test_division
leads to result in our system
{
  'A' =>
  double(21)
  'B' =>
  double(2)
  'DIVISION' =>
  int(10)
  'CONSTANT_DIVISION' =>
  double(10.5)
}

The problem is that oci_field_scale(., 'DIVISION') returns 0. (Note: for
'CONSTANT_DIVISION' returns -127). In our system we decide according to the
oci_field_scale result, if to call intval or floatval on column value. OCI driver returns always
string values and we need to convert them.

Oracle version is Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production,
Windows.

Expected result:
----------------
oci_field_scale(., 'DIVISION') should return 1, or -127 (as says documentation: For FLOAT
columns, precision is nonzero and scale is -127.)

Actual result:
--------------
0


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69590&edit=1


Thread (4 messages)

« previous php.bugs (#192615) next »