Issues

ZF-2322: Multiple Inserts / Updates from rowsets

Issue Type: New Feature Created: 2007-12-17T23:04:30.000+0000 Last Updated: 2013-02-13T12:05:10.000+0000 Status: Open Fix version(s): Reporter: Ken Chau (lqqkout4elfy) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

  • Zend_Db_Table

Related issues: Attachments: - zf-2322.diff

Description

Currently, the Zend_DB way to bulk insert (to my knowledge):

$tb = new Table;

for ($i = 0; $i < 500; $i++) { $row = $tb->createRow(); $row->blah = 'blah'; $row->save(); }

// I propose something like this

$count = 5; // count of rows $tb = new Table;

$rowset = $tb->createRowSet($count); $rowset->save();

/** To update **/

$tb = new Table; $rowset = $tb->fetchAll($condition);

// Modify $rowset

$rowset->save(); // This will be saved for rows where $condition is met

Comments

Posted by Wil Sinclair (wil) on 2008-03-25T20:43:52.000+0000

Please categorize/fix as needed.

Posted by Wil Sinclair (wil) on 2009-01-06T10:56:15.000+0000

This issue has gone unaddressed for too long. I'm reassigning this to Ralph for re-evaluation and categorization.

Posted by Ken Chau (lqqkout4elfy) on 2009-02-05T14:06:50.000+0000

Rather than making it too big of a problem - what if we simply added some functionality to Zend_Db_Adapter ?

So given an array of hash :

$db->insert('tablename', $data); // (or multipleInsert or bulkInsert, what have you)

Posted by Jack Tanner (jacktanner) on 2009-08-09T11:24:33.000+0000

If/when this should get fixed ... it'd be nice to have bulk insert-or-update functionality, too, i.e., INSERT INTO... ON DUPLICATE KEY UPDATE.

Posted by Hector Virgen (djvirgen) on 2009-10-20T10:36:56.000+0000

Patch that allows support for bulk inserts for MySQL PDO adapter.

Posted by Ralph Schindler (ralph) on 2009-12-31T10:20:30.000+0000

The patch supplied has the same method name defined twice. Also, this seems to be heavily MySQL specific and the usage is not portable across database vendors. Shouldn't this be done in userspace since the application is taking advantage of database specific functionality?

Posted by Hector Virgen (djvirgen) on 2009-12-31T10:41:13.000+0000

My mistake, the second method should have been named "insertOrUpdateMultiple". It takes advantage of MySQL's ON DUPLICATE KEY UPDATE feature.

The patch is for the MySQL PDO adapter -- other adapters would need to implement their own versions of these methods, even if that means looping through the data and performing separate inserts.

Adding new methods to the adapters that other classes (like Zend_Db_Table) would rely on means we may need to update the Zend_Db_Adapter_Abstract. Maybe we can add a simple cross-database version of this that other adapters can override with their own version.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts