Skip to content

Commit 42e2f4f

Browse files
authored
Merge pull request #162 from homersimpsons/fix/sql-count-array-to-string
SQLCountWithArray - ArrayToString conversion
2 parents ee3fde7 + ba53a0a commit 42e2f4f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/InnerResultIterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ public function count()
124124

125125
/**
126126
* Makes a separate SQL query to compute the row count.
127-
* (not needed in MySQL)
127+
* (not needed in MySQL if fetch is already done)
128128
*/
129129
private function getRowCountViaSqlQuery(): int
130130
{
131131
$countSql = 'SELECT COUNT(1) FROM ('.$this->getQuery().') c';
132132

133133
$this->logger->debug('Running count SQL request: '.$countSql);
134134

135-
$this->count = (int) $this->tdbmService->getConnection()->fetchColumn($countSql, $this->parameters);
135+
$this->count = (int) $this->tdbmService->getConnection()->fetchColumn($countSql, $this->parameters, 0, DbalUtils::generateArrayTypes($this->parameters));
136136
return $this->count;
137137
}
138138

tests/TDBMDaoGeneratorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,4 +2169,19 @@ public function testMethodNameConflictsBetweenRegularAndAutoPivotProperties()
21692169
$artist->getChildrenByArtistsRelations(); // auto-pivot relationship
21702170
$this->assertEquals(1, 1);
21712171
}
2172+
2173+
/**
2174+
* @depends testDaoGeneration
2175+
*/
2176+
public function testSQLCountWithArray(): void
2177+
{
2178+
$userDao = new TestUserDao($this->tdbmService);
2179+
$countryDao = new CountryDao($this->tdbmService);
2180+
2181+
$country = $countryDao->getById(2);
2182+
2183+
// Let's test filter bags by bean and filter bag with many values.
2184+
$users = $userDao->getUsersByComplexFilterBag($country, ['John Doe', 'John Smith'])->take(0, 1);
2185+
$this->assertEquals(1, $users->count());
2186+
}
21722187
}

0 commit comments

Comments
 (0)