Zend_Db-Examples icon indicating copy to clipboard operation
Zend_Db-Examples copied to clipboard

In example missing - think passing an array is broken?

Open intellix opened this issue 12 years ago • 0 comments

Hey, sorry if this is the wrong place to put this. I've been trying to use IN but I'm thinking that it's not working correctly.

Code: $idList = array('1', '2', '3', '4', '5'); // Get adapter set before $adapter = $this->getAdapter();

    // Grab squares between
    $select = new Select;
    $select
        ->from($this->getTableName())
        ->join(
            'map_types', 
            'map_types.map_id = map.id',
            array('map_types.type')
        )
        ->where->in('map.id', $idList);

    $statement = $adapter->createStatement();
    $select->prepareStatement($adapter, $statement);

    $resultSet = new ResultSet();
    $resultSet->setDataSource($statement->execute());

    return $resultSet;

I'm thinking that I'm passing in the list of ID's within the IN parameter correctly. The next piece of dump should illustrate:

["sql":protected] => string(141) "SELECT *, map_types.map_types.type FROM map INNER JOIN map_types ON map_types.map_id = map.id WHERE map.id IN (:where1)" ["isQuery":protected] => NULL ["parameterContainer":protected] => object(Zend\Db\Adapter\ParameterContainer)#479 (2) { ["data":protected] => array(5) { ["where1"] => string(1) "1" ["where2"] => string(1) "2" ["where3"] => string(1) "3" ["where4"] => string(1) "4" ["where5"] => string(1) "5" } ["errata":protected] => array(5) { ["where1"] => NULL ["where2"] => NULL ["where3"] => NULL ["where4"] => NULL ["where5"] => NULL } }

I tried to pass in the imploded array but then it says that it requires an array. Went through the code and I guess this is the bit that only lets it have the first value:

Zend\Db\Sql\Where->prepareStatement()

$wherePart .= vsprintf($part[0], $values);

If I'm doing it wrong then it would be great to see an example of its correct usage :)

Thanks and thanks for making it easier to debug the SQL output!

intellix avatar Mar 09 '12 00:03 intellix