Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdo_firebird] float, double value is incorrect #13119

Closed
SakiTakamachi opened this issue Jan 10, 2024 · 7 comments
Closed

[pdo_firebird] float, double value is incorrect #13119

SakiTakamachi opened this issue Jan 10, 2024 · 7 comments

Comments

@SakiTakamachi
Copy link
Member

Description

The following code:

<?php

$db = new PDO(/* firebird */);

$db->exec('CREATE TABLE test (f_val FLOAT, d_val DOUBLE PRECISION)');
$db->exec('INSERT INTO test VALUES (0.0000001, 0.00000001)');
$stmt = $db->query('select * from test');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));

Resulted in this output:

array(1) {
  [0]=>
  array(2) {
    ["F_VAL"]=>
    string(8) "0.000000"
    ["D_VAL"]=>
    string(8) "0.000000"
  }
}

But I expected this output instead:

array(1) {
  [0]=>
  array(2) {
    ["F_VAL"]=>
    string(8) "0.0000001"
    ["D_VAL"]=>
    string(8) "0.00000001"
  }
}

After trying various things, it seems that the fraction part is displayed as a fixed 6 digits. e.g. 12.000000001 => 12.000000
It's late today, so I'll try again tomorrow.

(In the first place, I think I want the value to be a native type, but I won't consider that for now.)

PHP Version

= PHP8.2

Operating System

Ubuntu20.04(docker)

@SakiTakamachi
Copy link
Member Author
SakiTakamachi commented Jan 10, 2024
ZVAL_STR(result, zend_strpprintf(0, "%F", php_get_double_from_sqldata(var->sqldata)));
{gc = {refcount = 1, u = {type_info = 22}}, h = 0, len = 8, val = "0"}

php_get_double_from_sqldata is fine, so maybe there's something with zend...

@SakiTakamachi
Copy link
Member Author
SakiTakamachi commented Jan 11, 2024

Since the process was similar to sprintf, I referred to the documentation.

https://www.php.net/manual/en/function.sprintf.php#refsect1-function.sprintf-parameters

For e, E, f and F specifiers: this is the number of digits to be printed after the decimal point (by default, this is 6).

It was by design, not a bug in zend. However, this specification is inappropriate for obtaining fetched values, so I should consider other methods.

@SakiTakamachi
Copy link
Member Author
SakiTakamachi commented Jan 11, 2024

@nielsdos
It seems to start using zend_strpprintf after #10920, is there any reason why the fraction part has a fixed number of digits?

If there is no particular reason, I think it would be better to use zend_gcvt.
(Indeed, zend_gcvt is used to convert float to double in mysqlnd)

@SakiTakamachi
Copy link
Member Author
SakiTakamachi commented Jan 11, 2024

TBH, it may be simpler to make it a native type.

However, since changing the type is a BC break, it may be a good idea to leave 8.2 and 8.3 as string type, and make master a native type.

@nielsdos
Copy link
Member

@SakiTakamachi the zend_strpprintf function was already used prior to my PR.
But I agree that zend_gcvt is probably right, and that on master native types would be preferable (but would at the very least require a mail to the ML due to BC break)

@SakiTakamachi
Copy link
Member Author

@nielsdos
Oops, I'm very sorry! I missreaded that.
Thank you for checking.

@SakiTakamachi
Copy link
Member Author
SakiTakamachi commented Jan 11, 2024

BTW, strangely, firebird's float type can be saved as is in the DB even with a number of digits like 12.345678.

SakiTakamachi added a commit that referenced this issue Jan 16, 2024
SakiTakamachi added a commit that referenced this issue Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants