Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.6

Bug #14082 DB_Table_Manager::getIndexes() misbehaviour
Submitted: 2008-06-05 10:25 UTC Modified: 2008-06-06 07:36 UTC
From: ggramlich Assigned: wiesemann
Status: Closed Package: DB_Table (version 1.5.2)
PHP Version: 5.2.3 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2008-06-05 10:25 UTC] ggramlich (Gregor Gramlich)
Description: ------------ DB_Table_Manager::getIndexes() makes a call to MDB2_Driver_Reverse_mysql::getTableConstraintDefinition() in line 1594 of DB/Table/Manager.php $index_fields = $reverse->getTableConstraintDefinition($table, $table_idx_tmp); The result is interpreted in line 1603: $index_type = current(array_keys($index_fields)); Thus, we expect the first key of $index_fields to be the index_type. Actually what is returned by getTableConstraintDefinition() is a hash that looks like Array ( [primary] => [unique] => 1 [foreign] => [check] => [fields] => Array ( [schluessel] => Array ( [position] => 1 [sorting] => ascending ) ) [references] => Array ( [table] => [fields] => Array ( ) ) [onupdate] => [ondelete] => [match] => [deferrable] => [initiallydeferred] => ) So in this case we get 'primary' instead of 'unique'. A patch is attached that works for me, but I don't know, whether this is also correct for the DB backend and others than the mysql driver. It is a rather severe problem, since it makes every DB_Table::verify() call on tables with unique indexes return a PEAR_Error. Best Gregor Test script: --------------- class SomeTable extends DB_Table { ... var $idx = array( 'primary_index' => array( 'type' => 'primary', 'cols' => 'id' ), 'key_unique' => array( 'type' => 'unique', 'cols' => 'schluessel', ) ); } $table = new SomeTable(...) $res = $table->verify(); if (PEAR::isError($res)) { echo $res->getMessage() . "\n"; } else { echo "OK\n"; } $res = DB_Table_Manager::getIndexes($table->db, $tablename); print_r($res); Expected result: ---------------- OK Array ( [normal] => Array ( ) [primary] => Array ( [PRIMARY] => Array ( [0] => id ) ) [unique] => Array ( [tablename_key_unique_idx] => Array ( [0] => schluessel ) ) ) Actual result: -------------- Verification failed: index does not exist 'key_unique' ('tablename_key_unique_idx') Array ( [normal] => Array ( ) [primary] => Array ( [PRIMARY] => Array ( [0] => id ) [tablename_key_unique_idx] => Array ( [0] => schluessel ) ) [unique] => Array ( ) )

Comments

 [2008-06-05 14:28 UTC] wiesemann (Mark Wiesemann)
Gregor, thanks for the report. Unfortunately I cannot reproduce this problem. I've taken your example code and have added some columns. It returns the expected result. My test script can be found here: http://tmp.markwiesemann.eu/dbt-bug-14082b.phps Can you please test this script on your system? Do you see anything that is missing to reproduce the problem?
 [2008-06-05 15:22 UTC] ggramlich (Gregor Gramlich)
Hello Mark, thanks for the quick response. I used your script and got what happened before: DB_TABLE Error - Verification failed: index does not exist 'key_unique' ('test_14082b_key_unique_idx') <pre>Array ( [normal] => Array ( ) [primary] => Array ( [primary] => Array ( [0] => id ) [test_14082b_key_unique_idx] => Array ( [0] => feld1 ) ) [unique] => Array ( ) ) php --version PHP 5.2.3-1ubuntu6.3 (cli) (built: Jan 10 2008 09:38:37) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies mysql --version mysql Ver 14.12 Distrib 5.0.45, for pc-linux-gnu (i486) using readline 5.2 mysqld --version mysqld Ver 5.0.45-Debian_1ubuntu3.3-log for pc-linux-gnu on i486 (Debian etch distribution) DB 1.7.14RC1 beta DB_Table 1.5.1 stable MDB2 2.5.0b1 beta MDB2_Driver_mysql 1.5.0b1 beta MDB2_Schema 0.8.2 beta I also reinstalled the packages to make sure, that I did not have any patches in there. If you confirm that you cannot reproduce, I will setup a xampp system and start a test setup from scratch. (You can mail also me.) Thanks Gregor
 [2008-06-06 07:26 UTC] wiesemann (Mark Wiesemann)
MDB2 introduced default values for the array that getTableConstraintDefinition() returns, see here: http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mysql.php?r1=1.70&r2=1.71
 [2008-06-06 07:36 UTC] wiesemann (Mark Wiesemann)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/DB_Table --- I've used your patch slightly modified to make clear that we need to search for boolean true.