Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mapper::query() method to pass param types. #208

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/QuerySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down