-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Incorrect NUMERIC value returned from Firebird PDO query in PHP 8.1 #9971
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
Comments
Hmm, there is https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt, which queries a Can you please specify the exact table definition – ideally having a complete script which creates and fills the table, and then does the query, printing the resulting row via |
Test Results for the script at https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt Additional comment added 19/11/2022: My apologies, I neglected to mention that I had to use "dialect=1;" to get the test to work in either PHP7.4 or 8.1.12. My previous scripts in PHP7.4 were only ever doing selects. PHP 7.4 string(5) "-1.00" PHP 8.1.12 (php8.1-interbase 8.1.12-1+ubuntu20.04.1+deb.sury.org+1) string(4) "0.00" |
Hi @clarumedia please Test phpt code use pdo_firebird extension installed and enabled not interbase extension the fix seems to me never came for the shortstop extension please @cmb69 can you confirm if you are not busy? Thank you |
This is seriously screwed. What's the version of your database server? |
print $dbh->getAttribute(PDO::ATTR_SERVER_INFO); PHP 7.4 Server Version: Firebird/Windows/Intel/i386 (access method), version "WI-V2.0.1.12855 Firebird 2.0" Firebird/Windows/Intel/i386 (remote server), version "WI-V2.0.1.12855 Firebird 2.0/tcp (DBSERVERHOSTNAME)/P10" Firebird/Linux/AMD/Intel/x64 (remote interface), version "LI-V3.0.5.33220 Firebird 3.0/tcp (arm-lnx-1)/P10" on disk structure version 11.0 PHP 8.1 Server Version: Firebird/Windows/Intel/i386 (access method), version "WI-V2.0.1.12855 Firebird 2.0" Firebird/Windows/Intel/i386 (remote server), version "WI-V2.0.1.12855 Firebird 2.0/tcp (DBSERVERHOSTNAME)/P10" Firebird/Linux/AMD/Intel/x64 (remote interface), version "LI-V3.0.5.33220 Firebird 3.0/tcp (arm-lnx-1)/P10" on disk structure version 11.0 |
@hormus Am I missing something on setting up pdo_firebird on Ubuntu 20.04 ? I had installed php8.1-interbase because it was all that was listed ? apt-cache search php firebird PDO Connection My PDO connection string is like this: "firebird:dbname=DBSERVERHOSTNAME:c:\ProgramData\Db\mydatabase.FDB;dialect=1;" The incorrect numeric values occur whether dialect=1 is used or not, but using dialect=1 is the only way to get the above test script to work in either PHP7.4 or PHP8.1 "Metadata update statement is not allowed by the current database SQL dialect 1" https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt |
Test results for https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt without using dialect=1 PHP 7.4 Warning: PDO::exec(): SQLSTATE[HY000]: General error: -817 Dynamic SQL Error SQL error code = -817 Metadata update statement is not allowed by the current database SQL dialect 1 in /opt/firebird_test.php on line 16 Warning: PDO::exec(): SQLSTATE[HY000]: General error: -204 Dynamic SQL Error SQL error code = -204 Table unknown PRICE At line 1, column 13 in /opt/firebird_test.php on line 17 Warning: PDO::exec(): SQLSTATE[HY000]: General error: -204 Dynamic SQL Error SQL error code = -204 Table unknown PRICE At line 1, column 13 in /opt/firebird_test.php on line 18 Warning: PDO::exec(): SQLSTATE[HY000]: General error: -204 Dynamic SQL Error SQL error code = -204 Table unknown PRICE At line 1, column 13 in /opt/firebird_test.php on line 19 Warning: PDO::prepare(): SQLSTATE[HY000]: General error: -204 Dynamic SQL Error SQL error code = -204 Table unknown PRICE At line 1, column 21 in /opt/firebird_test.php on line 24 Fatal error: Uncaught Error: Call to a member function execute() on bool in /opt/firebird_test.php:25 PHP 8.1 PHP Fatal error: Uncaught Error: Call to a member function execute() on bool in /opt/firebird_test.php:25 |
That looks like a Firebird 2.0 server, but that version is discontinued since 12 Apr 2012. Please try with a Firebird 3.0 or 4.0 server (at least for testing purposes). |
Test results for firebird3.0-server on Ubuntu 20.04 https://unixcop.com/install-firebird-ubuntu/ SET SQL DIALECT 1; chmod 777 /var/lib/firebird/3.0/data/second_database.fdb Dialect 1Test Script: https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt PHP 7.4 string(5) "-1.00" PHP 8.1 string(4) "0.00" No DialectTest Script: https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt PHP 7.4 and PHP 8.1 PHP Warning: PDO::exec(): SQLSTATE[HY000]: General error: -817 Dynamic SQL Error SQL error code = -817 Metadata update statement is not allowed by the current database SQL dialect 1 in /home/chris/x.php on line 16 |
Thanks! This way I can reproduce the issue. |
Well, not necessarily the exact issue you've reported, but at least I have some ideas. First, dialect 1 stores ext/pdo_firebird/firebird_statement.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c
index d2b0a720b6..a4fea65c95 100644
--- a/ext/pdo_firebird/firebird_statement.c
+++ b/ext/pdo_firebird/firebird_statement.c
@@ -382,6 +382,9 @@ static int firebird_stmt_get_col(
case SQL_INT64:
n = *(ISC_INT64*)var->sqldata;
break;
+ case SQL_DOUBLE:
+ n = 0;
+ break;
EMPTY_SWITCH_DEFAULT_CASE()
} However, I doubt that this fixes the issue for you, but if possible, give it a try.
|
@cmb69 It's been a very long time since I've compiled PHP. I'd be very grateful of any pointers for testing your fix ? |
Basically, you need to
Maybe you need to specify the installation dir of Firebird ( |
@cmb69 Which branch are you on ? |
I tested with |
@cmb69 Apologies for the delay. Test results after compiling PHP branch 8.1 with your modification (above) to ext/pdo_firebird/firebird_statement.c and then running the test script with the compiled PHP in php-src/sapi/cli/php Connecting with:firebird:dbname=localhost:/var/lib/firebird/3.0/data/second_database.fdb;dialect=1 Looks like that's fixed it. :-) |
Dialect 1 databases store and transfer `NUMERIC(15,2)` values as doubles, which we need to cater to in `firebird_stmt_get_col()` to avoid `ZEND_ASSUME(0)` to ever be triggered, since that may result in undefined behavior. Since adding a regression test would require to create a dialect 1 database, we go without it.
Thanks for checking, @clarumedia!
Interesting! So apparently the issue was "only" the |
Test results for your simplified fix: https://github.com/php/php-src/pull/10021/files Connecting with:firebird:dbname=localhost:/var/lib/firebird/3.0/data/second_database.fdb;dialect=1 Looking good :-) |
* PHP-8.1: Fix GH-9971: Incorrect NUMERIC value returned from PDO_Firebird
* PHP-8.2: Fix GH-9971: Incorrect NUMERIC value returned from PDO_Firebird
Thank you @cmb69 :-) |
Description
The following code:
Resulted in this output in PHP 8.1.12 :
But I expected this output instead as per PHP 7.4:
Both report LI-V6.3.5.33220 Firebird 3.0 from a call to
$pdo->getAttribute(PDO::ATTR_CLIENT_VERSION)
Makes no difference if I set
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
PHP Version
PHP 8.1.12
Operating System
Ubuntu 20.04
The text was updated successfully, but these errors were encountered: