Menu

#420 loads of notices generated during search

closed-fixed
PHP errors (22)
5
2008-09-26
2008-09-15
Mike Newton
No

Line 952 (2.11.9) or line 906 (trunk) of relation.lib.php tries to reference an associative array element that might not always exist. So for every field in the database a PHP notice is generated (undefined index.) Here's what I did to fix it:

foreach ($disp_row as $relrow) {
+ if (!isset($relrow[$foreign_field])) {
+ $value = '';
+ } else {
$key = $relrow[$foreign_field];

// if the display field has been defined for this foreign table
if ($foreign_display) {
$value = $relrow[$foreign_display];
} else {
$value = '';
} // end if ($foreign_display)
+ } // end if
$foreign[$key] = $value;
} // end foreach

Discussion

  • Marc Delisle

    Marc Delisle - 2008-09-16
    • labels: 438951 --> PHP errors
     
  • Marc Delisle

    Marc Delisle - 2008-09-16

    Moved to patches.

     
  • Marc Delisle

    Marc Delisle - 2008-09-18
    • assigned_to: nobody --> lem9
     
  • Marc Delisle

    Marc Delisle - 2008-09-18

    Please tell me how to reproduce the case where the element does not exist.

     
  • Mike Newton

    Mike Newton - 2008-09-19

    I'm not sure what I'm doing to cause it. I'm using the InnoDB engine on my database, lots of foreign keys but none of the pma_* tables are configured or anything.

     
  • Marc Delisle

    Marc Delisle - 2008-09-19

    Ok, I tried with InnoDB and cannot see any notices.

    Could you paste here some of the notices?

    These appear when you click Search?

     
  • Marc Delisle

    Marc Delisle - 2008-09-24
    • status: open --> pending
     
  • Mike Newton

    Mike Newton - 2008-09-24
    • status: pending --> open
     
  • Mike Newton

    Mike Newton - 2008-09-24

    Here it is; seems to be triggered by the interplay between the three tables; if there's no data in table1 then the error does not occur. After this database is created, go to table2 and click search to replicate the problem. I think the focus of this bug should actually be the fact that it's trying to generate a select box when it shouldn't; something I hadn't noticed before now.

    CREATE DATABASE `test2112871`;
    USE `test2112871`;

    SET FOREIGN_KEY_CHECKS=0;
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    CREATE TABLE `table1` (`t1_id` int(10) unsigned NOT NULL auto_increment, `t1_data` varchar(64) collate latin1_general_ci NOT NULL, PRIMARY KEY (`t1_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
    INSERT INTO `table1` (`t1_id`, `t1_data`) VALUES (1, 'data'), (2, 'other data'), (3, 'third data');

    CREATE TABLE IF NOT EXISTS `table2` (`t2_id` int(10) unsigned NOT NULL auto_increment, `t1_id` int(10) unsigned NOT NULL, `t3_id` int(10) unsigned default NULL, PRIMARY KEY (`t2_id`), KEY `fk_t1_id` (`t1_id`), KEY `fk_t3_id` (`t3_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

    CREATE TABLE IF NOT EXISTS `table3` (`t3_id` int(10) unsigned NOT NULL auto_increment, `t1_id` int(10) unsigned NOT NULL, `up_desc` varchar(64) collate latin1_general_ci NOT NULL, PRIMARY KEY (`t3_id`), KEY `fk_t1_id` (`t1_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

    ALTER TABLE `table2` ADD CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `table1` (`t1_id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `table2_ibfk_2` FOREIGN KEY (`t3_id`) REFERENCES `table3` (`t3_id`) ON DELETE CASCADE ON UPDATE CASCADE;

    ALTER TABLE `table3` ADD CONSTRAINT `table3_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `table1` (`t1_id`) ON DELETE CASCADE ON UPDATE CASCADE;

    SET FOREIGN_KEY_CHECKS=1;

     
  • Marc Delisle

    Marc Delisle - 2008-09-26

    I hate to reply that but with your test case I cannot reproduce the problem (tested with trunk).
    Modifying the code like this:

    foreach ($disp_row as $relrow) {
    echo 'trace ' . $foreign_field . ' ' . $relrow[$foreign_field] . "\n";
    $key = $relrow[$foreign_field];

    Going to table2 and clicking Search, I get (with PHP 5.2.6):
    trace t1_id 1
    trace t1_id 2
    trace t1_id 3

     
  • Mike Newton

    Mike Newton - 2008-09-26

    Just checked out SVN trunk and I don't see the error either. The search page shows a textbox for t3_id search field, as it should, not a corrupted select box like 2.11.9 does.

    I'll close this; I assume it's not worth the trouble to fix this on the 2.11 branch. Sorry to take your time!

     
  • Mike Newton

    Mike Newton - 2008-09-26
    • status: open --> closed-fixed
     
  • Marc Delisle

    Marc Delisle - 2008-09-27

    Mike,
    thanks anyway for your good work!

     
MongoDB Logo MongoDB