Skip to content

Commit

Permalink
[BUGFIX] Fix query for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Nov 1, 2024
1 parent 4497a3a commit 720aeab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/core12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ jobs:
- name: Functional Tests with postgres
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -d postgres -s functional

# @todo disabled, due cross dbmns issues in code. Should be fixed first
# - name: Functional Tests with sqlite
# run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -d sqlite -s functional
- name: Functional Tests with sqlite
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -d sqlite -s functional
16 changes: 12 additions & 4 deletions Classes/Domain/Repository/NewsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace GeorgRinger\News\Domain\Repository;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use GeorgRinger\News\Domain\Model\DemandInterface;
use GeorgRinger\News\Domain\Model\News;
use GeorgRinger\News\Service\CategoryService;
Expand Down Expand Up @@ -359,14 +360,21 @@ public function countByDate(DemandInterface $demand): array
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_news_domain_model_news');
$isPostgres = $connection->getDatabasePlatform() instanceof PostgreSQLPlatform;
$isSqlite = $connection->getDatabasePlatform() instanceof SQLitePlatform;
if ($isPostgres) {
$sql = 'SELECT count(*), date_trunc(\'year\', to_timestamp(' . $field . '/1)::date) as _year, date_trunc(\'month\', to_timestamp(' . $field . '/1)::date) as _MONTH
from tx_news_domain_model_news ' . substr($sql, strpos($sql, 'WHERE '));
} elseif ($isSqlite) {
$sql = 'SELECT strftime(\'%m\', ' . $field . ', \'unixepoch\') AS "_month",' .
' strftime(\'%Y\', ' . $field . ', \'unixepoch\') AS "_year", ' .
' count(strftime(\'%m\', ' . $field . ', \'unixepoch\')) as count_month,' .
' count(strftime(\'%Y\', ' . $field . ', \'unixepoch\')) as count_year' .
' FROM tx_news_domain_model_news ' . substr($sql, strpos($sql, 'WHERE '));
} else {
$sql = 'SELECT MONTH(FROM_UNIXTIME(0) + INTERVAL ' . $field . ' SECOND ) AS "_month",' .
' YEAR(FROM_UNIXTIME(0) + INTERVAL ' . $field . ' SECOND) AS "_year" ,' .
' count(MONTH(FROM_UNIXTIME(0) + INTERVAL ' . $field . ' SECOND )) as count_month,' .
' count(YEAR(FROM_UNIXTIME(0) + INTERVAL ' . $field . ' SECOND)) as count_year' .
$sql = 'SELECT MONTH(FROM_UNIXTIME(' . $field . ')) AS "_month",' .
' YEAR(FROM_UNIXTIME(' . $field . ')) AS "_year", ' .
' count(MONTH(FROM_UNIXTIME(' . $field . '))) as count_month,' .
' count(YEAR(FROM_UNIXTIME(' . $field . '))) as count_year' .
' FROM tx_news_domain_model_news ' . substr($sql, strpos($sql, 'WHERE '));
}

Expand Down

0 comments on commit 720aeab

Please sign in to comment.