pear / DB

http://pear.php.net/package/DB
9 stars 33 forks source link

PHP 8.0 testcase failure #23

Closed ashnazg closed 6 months ago

ashnazg commented 7 months ago

Testcase tests/driver/16tableinfo.phpt encounters a failure when run on PHP 8.0, as seen below. The behavior differences appear to be in how the queried table characteristics are interpreted by DB. The paste below is the runtime output of the testcase... you can visually compare it to the --EXPECT-- section in the PHPT to see what's different.

As best I can tell, some flags are interpreted differently on 8.0 as compared to PHP7 and PHP5, e.g. flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

while also some column characteristics show up differently, e.g. type ... was 'varchar' but we expected 'string'

I thought at first that maybe the PHP 8.0 behavior should be different based on that test platform's database version (newer?) as compared to the PHP7 and PHP5 platforms, but I don't know that for sure.

@schengawegga , if you are able to research this testcase, see how it acts on your various PHP8 platforms. If you become convinced that the runtime behavior as seen below is correct, then I can adjust this testcase to only run itself against PHP7 and older... and create a sister testcase just for PHP8 and up, that is written to --EXPECT-- these flag and type differences.

RUNTIME OUTPUT FROM THE BUILD:

tests/driver/16tableinfo.out

==========================================

Passing result OBJECT to method in DB_<type>.

Output = default.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

~~~~~~~~

column 9:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => d

type ... was 'varchar' but we expected 'string'

len ... matched expected value

flags ... matched expected value

~~~~~~~~

==========================================

Passing result ID to method in DB_<type>.

Output = DB_TABLEINFO_ORDER.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

~~~~~~~~

column 3:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key' but we expected 'not_null multiple_key binary'

~~~~~~~~

num_fields: matched expected result

order:

matched expected result

==========================================

Passing DB_TABLEINFO_ORDERTABLE to method in DB_result.

Output = DB_TABLEINFO_ORDERTABLE.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

~~~~~~~~

column 3:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key' but we expected 'not_null multiple_key binary'

~~~~~~~~

num_fields: matched expected result

ordertable[phptest]: matched expected result

ordertable[phptest_fk]: matched expected result

==========================================

Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.

Output = default.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

~~~~~~~~

column 1:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => fk

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => fk

type ... matched expected value

len ... matched expected value

flags ... was 'not_null primary_key group_by' but we expected 'not_null primary_key'

~~~~~~~~

column 2:

matched expected result

column 3:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => d

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key' but we expected 'not_null multiple_key binary'

~~~~~~~~

column 4:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => e

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => e

type ... was 'char' but we expected 'string'

len ... matched expected value

flags ... matched expected value

~~~~~~~~

column 5:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => f

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => f

type ... was 'decimal' but we expected 'real'

len ... matched expected value

flags ... matched expected value

~~~~~~~~

==========================================

Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.

Output = DB_TABLEINFO_FULL.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'

~~~~~~~~

order:

matched expected result

ordertable[phptest_fk]:

matched expected result

==========================================

Passing TABLE NAME 'phptest_fk' to method in DB_<driver> AGAIN.

Output = DB_TABLEINFO_FULL, lowercasing turned off.

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

column 0:

DIDN'T match expected values...

~~~~~~~~

Expected:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... matched expected value

~~~~

Actual:

table ... matched expected value

name => a

type ... matched expected value

len ... matched expected value

flags ... was 'not_null multiple_key group_by' but we expected 'not_null multiple_key'
schengawegga commented 7 months ago

@ashnazg i think found the problem.

i´ve done an var_dump($dbh->tableInfo('phptest_fk')); in PHP 7.4.29 and PHP 8.1.12, and the output is exactly the same.

It is a bug in the tests since it is written.

In examineArrayData is a comparison if ($value == 0 && !$quirks[$quirk_key]['size_from_table']). https://github.com/pear/DB/blob/4efd340ec9eb1da23fa2df60d387c274e9c1100b/tests/driver/16tableinfo.phpt#L147 The problem is, that $value == 0 is always true in PHP7 if $value is a string. So this test will always pass, if $value is a string, no matter what is written in $value.

This has changed in PHP8 https://www.php.net/releases/8.0/en.php#saner-string-to-number-comparisons In PHP8 $value == 0 is false if $value is a string.

So i think, this test was always not showing the correct result before PHP8, because it always passes if $value was a string.

What do you think?

I will do an PR in the next days. But now, it is to late and i go to sleep a little bit. I think, we should fix this before the 1.12.0 release.

schengawegga commented 7 months ago

Created pull request PHP 8.0 testcase failure #24 @ashnazg

ashnazg commented 6 months ago

PR looks good to me... ok to close this issue once it merges.