I'm using Data to store some stuff and wanted to get a bunch of rows with various IDs without doing multiple calls to the load() method (which in turn would do multiple SQL calls); basically, I wanted to do a query with "WHERE x IN (y, z, …)." Since Data doesn't support this out-of-the-box, I initially went about it by extending the DataHandler class, but my coworker hefox suggested I implement it in Data and submit the patch instead. So here it is.

Usage is simple. If a value in the array passed to load() is itself an array, Data will format a clause with IN for that parameter. Example:

$table = data_get_table('my_table');
$data = $table->handler()->load(array('type' => 'foo', 'id' => array(4, 8, 9)));

With this patch, this will cause Data to build a query like: SELECT * FROM my_table WHERE type = "foo" AND id IN (4, 8, 9)

This hasn't been tested at all outside our project yet, so folks, please test this patch yourself if it might be of use to you and report back if it works.

CommentFileSizeAuthor
data_IN_query-D6.patch999 bytesGarrett Albright

Comments

Garrett Albright’s picture

Status: Active » Needs review

Whoops. Marking as need review.