diff --git a/lib/Mapper.php b/lib/Mapper.php index 1e90a27..53cf517 100644 --- a/lib/Mapper.php +++ b/lib/Mapper.php @@ -559,10 +559,11 @@ public function create(array $data, array $options = []) * * @param string $sql Raw query or SQL to run against the datastore * @param array Optional $conditions Array of binds in column => value pairs to use for prepared statement + * @param array Optional $types Array of DBAL column types (e.g. to specify custom type for IN () condition) */ - public function query($sql, array $params = []) + public function query($sql, array $params = [], array $types = []) { - $result = $this->connection()->executeQuery($sql, $params); + $result = $this->connection()->executeQuery($sql, $params, $types); if ($result) { return $this->collection($result); } diff --git a/tests/QuerySql.php b/tests/QuerySql.php index 17a2fd9..234898e 100644 --- a/tests/QuerySql.php +++ b/tests/QuerySql.php @@ -404,6 +404,29 @@ public function testCustomQueryWithSqlAndNamedParams() $this->assertSame($postCount, $i); } + public function testCustomQueryWithSqlAndIndexedParamTypes() + { + $mapper = test_spot_mapper('SpotTest\Entity\Tag'); + $names = ['Tag 1', 'Tag 2']; + + $tags = $mapper->query( + "SELECT * FROM " . $mapper->table() . " WHERE name IN (?)", + [$names], + [\Doctrine\DBAL\Connection::PARAM_STR_ARRAY] + ); + $this->assertInstanceOf('Spot\Entity\Collection', $tags); + $tagCount = count($tags); + + $i = 0; + foreach ($tags as $tag) { + $i++; + $this->assertInstanceOf('SpotTest\Entity\Tag', $tag); + $this->assertContains($tag->getName(), $names); + } + + $this->assertSame($tagCount, $i); + } + /** * @dataProvider identifierProvider */