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

Request #4254 New DataSource driver (DB_Table)
Submitted: 2005-05-01 10:19 UTC
From: post at mark-wiesemann dot de Assigned: wiesemann
Status: Closed Package: Structures_DataGrid
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 44 + 45 = ?

 
 [2005-05-01 10:19 UTC] post at mark-wiesemann dot de
Description: ------------ I'd like to propose a new DataSource class which can handle DB_Table objects. Here is the code: http://www.markwiesemann.de/php/DB_Table.phps The code bases on the DB_Result DataSource class. As DB_Table can handle sorting in the select* functions the sort function of my class is not needed. At the moment a PEAR_Error object is returned if one calls this function. I don't know enough of the internals of Datagrid - maybe the function is not needed in every DataSource driver class and can be deleted. Usage of the new driver: (1) Assuming one has a DB_Table object called $c: require_once 'Structures/DataGrid/DataSource.php'; $dg =& new Structures_DataGrid(); $ds = Structures_DataGrid_DataSource::create($c, array('view' => 'all'), 'DB_Table'); $dg->bindDataSource($ds); $dg->render(); (2) Assuming the following lines were added in DataSource.php, function "_detectSourceType": // DB_Table case (strtolower(get_parent_class($source)) == 'db_table'): return 'DB_Table'; // to be replaced by a new constant break; you can use it this (common) way: $dg =& new Structures_DataGrid(); $dg->bind($c, array('view' => 'all')); $dg->render(); In both cases one has to specify a valid key from $c->sql in the option array (has to be a name of a predefined select option in DB_Table subclass). My bind function returns two times a PEAR_Error (DB_Result also returns one PEAR_Error on failure). Due to a bug (?) in DataGrid this will never be displayed or registered. This is because of line 179 of DataSource.php (current CVS version): $driver->bind($source, $options); ==> The returned PEAR_Error get's lost. It would be nice if the Datagrid team could add this new DataSource driver to their package.

Comments

 [2005-05-16 18:59 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-05-17 08:15 UTC] post at mark-wiesemann dot de
There is only little forgotten "_" in the new class: DBTable.php, line 74: function Structures_DataGrid_DataSource_DB_Table() ==> function Structures_DataGrid_DataSource_DBTable() (as you renamed the class the constructor has also to be renamed) Apart from that the class works as expected. And the errors are now returned as expected, too. Shortest version of using the new class is now: $dg =& new Structures_DataGrid(); $dg->bind($c, array('view' => 'all'), 'DBTable'); $dg->render(); If you add the suggested code to DataSource.php it will work without specifying the type: $dg =& new Structures_DataGrid(); $dg->bind($c, array('view' => 'all')); $dg->render(); Adjusted code for DataSource.php, function _detectSourceType: // DB_Table case (strtolower(get_parent_class($source)) == 'db_table'): return 'DBTable'; // to be replaced by a new constant break;
 [2005-05-17 17:41 UTC] post at mark-wiesemann dot de
An updated version of the header block for the bind function can be found here: http://www.markwiesemann.de/php/DBTable.txt Changes: - added variables ($object, $options) - removed "Nothing or" as it was wrong ($options['view'] is needed)
 [2005-05-22 14:50 UTC] post at mark-wiesemann dot de
http://www.markwiesemann.de/php/DBTable-new.phps contains the two changes described in the two comments above (typo with "_" and updated header block for bind()) and also a bugfix for empty database tables (line 144).
 [2005-05-27 14:51 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-05-27 15:10 UTC] post at mark-wiesemann dot de
You overlooked one little (but important) change: line 145 (current CVS version): if (!$this->_options['fields']) { has to be: if (!$this->_options['fields'] && count($recordSet)) { Otherwise one gets on emtpy results sets this warning: Warning: array_keys(): The first argument should be an array in [...]DBTable.php on line 145 (Next time I will provide a diff for such things instead of the files.)
 [2005-05-31 20:29 UTC] post at mark-wiesemann dot de
Here's the diff: http://www.markwiesemann.de/php/DBTable.patch.txt It adds the count call mentioned in last comment and also a new option 'where' which allows to filter the query. Usage example: $dg->bind($c, array('view' => 'all', 'where' => 'last_change > "2005-05-01"'), 'DBTable');
 [2005-12-13 12:17 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!