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

Request #11215 manager module: listTables & portability - bug or a feature?
Submitted: 2007-06-03 13:37 UTC
From: lukasfeiler Assigned: quipo
Status: Closed Package: MDB2 (version 2.4.1)
PHP Version: Irrelevant OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-06-03 13:37 UTC] lukasfeiler (Lukas Feiler)
Description: ------------ The manger module's listTables() method will by default convert all returned table names to lower case. If I wanted to run a "SELECT * FROM <table_name>" for each table I have to temporarily change the portability option: $mdb2->setOption('portability', MDB2_PORTABILITY_NONE); $tables = $mdb2->listTables(); $mdb2->setOption('portability', MDB2_PORTABILITY_ALL); for ($i = 0; $i < count($tables); $i++) { ... // run SELECT for each table } Is this a bug or a feature? Test script: --------------- <?php require_once 'MDB2.php'; // we assume there is just one table in test, and // that it contains an uppercase letter in its name $mdb2 = MDB2::factory('mysql://root@localhost/test'); $mdb2->loadModule('Manager'); $tables = $mdb2->listTables(); // currently prints ERROR if one of the table names // also contains uppercase letters for ($i = 0; $i < count($tables); $i++) { $result = $mdb2->queryAll('SELECT * FROM ' . $tables[$i]); echo PEAR::isError($result) ? 'ERROR' : 'OK'; echo "\n"; } ?> Expected result: ---------------- OK Actual result: -------------- ERROR

Comments

 [2007-06-09 15:42 UTC] quipo (Lorenzo Alberton)
By default, MDB2 has 'portability' = MDB2_PORTABILITY_ALL. If you want to remove the "fix case" feature, just call this method after the mdb2 object creation: $mdb2->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE);
 [2007-06-10 07:43 UTC] lukasfeiler (Lukas Feiler)
Maybe I'm mistaken here but if I use listTables() I want tables names I can actually work with in other SQL statements. As one might need the "fix case" feature in general - just not when calling some of the methods provided by the manager module, I suggest to implement additional methods within the manager module that will not do any case fixing by default. Otherwise some people will forget to temporarily change the portability option which will lead to nasty portability bugs. Having the tables Company, Employee and Department the following would work under Windows but fail under Linux: //developer forgets to change the portability option $tables = $mdb2->listTables(); for ($i = 0; $i < count($tables); $i++) { $result = $mdb2->query('SELECT * FROM ' . $tables[$i]); ... } Lower case table names will be returned by listTable(); this works under Windows because NTFS is case-insensitive while all common linux file systems are case sensitive.
 [2007-06-10 13:47 UTC] dufuz (Helgi Þormar)
Well it's up to the developer I'd think to use the proper options to get the tables in the case they need, or at least that's what I think
 [2007-06-10 15:24 UTC] lukasfeiler (Lukas Feiler)
Shouldn't the default behavior be what most people expect this method to do? IMHO most people will use listTables() to integrate the returned table names in an SQL statement. Please add at least a warning to the documentation of the manager module.
 [2007-06-10 19:29 UTC] lsmith (Lukas Smith)
Well MDB2 really likes people to play in the MDB2 portability best practices world and just smooths out all the kinks. If you do not like what MDB2 is doing, then disable the features. For your needs I would recommend creating an alternative module, that just overloads the existing module and wraps things with a change in options. Not sure, this might do the trick. Changing the behavior at this point is a no go, the only possible thing would be adding yet another option that would override the current option.