flarum/framework · error · Exception

Unsupported database driver

Error message

Unsupported database driver

What it means

An exhaustiveness/compatibility error in the timed-counts query builder: getTimedCounts branches on the connection driver name (pgsql, sqlite, mysql/mariadb default). It is thrown when the database driver is none of the handled ones, so no SQL date-format expression can be generated for hourly/daily grouping.

Solutions

  1. Run statistics on a supported driver: MySQL/MariaDB, PostgreSQL, or SQLite.
  2. Add a match arm for the new driver with its date-formatting SQL before upgrading the database.
  3. Catch the error and fall back to lifetime statistics if timed grouping is unavailable.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at extensions/statistics/src/Api/Controller/ShowStatisticsData.php:146 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/5e7fb00e23fcab1b. Report an issue: GitHub.

Appendix: source

Thrown at extensions/statistics/src/Api/Controller/ShowStatisticsData.php:146

        }

        if (! isset($endDate)) {
            $endDate = new DateTime();
        }

        $formats = match ($query->getConnection()->getDriverName()) {
            'pgsql' => ['YYYY-MM-DD HH24:00:00', 'YYYY-MM-DD'],
            default => ['%Y-%m-%d %H:00:00', '%Y-%m-%d'],
        };

        // if within the last 24 hours, group by hour
        $format = "CASE WHEN $column > ? THEN '$formats[0]' ELSE '$formats[1]' END";

        $dbFormattedDatetime = match ($query->getConnection()->getDriverName()) {
            'sqlite' => "strftime($format, $column)",
            'pgsql' => "TO_CHAR($column, $format)",
            'mysql', 'mariadb' => "DATE_FORMAT($column, $format)",
            default => throw new Exception('Unsupported database driver'),
        };

        $results = $query
            ->selectRaw(
                $dbFormattedDatetime.' as time_group',
                [new DateTime('-25 hours')]
            )
            ->selectRaw('COUNT(id) as count')
            ->where($column, '>', $startDate)
            ->where($column, '<=', $endDate)
            ->groupBy('time_group')
            ->pluck('count', 'time_group');

        $timed = [];

        $results->each(function ($count, $time) use (&$timed) {
            $time = new DateTime($time);
            $timed[$time->getTimestamp()] = (int) $count;

View on GitHub (pinned to 4b939f6853)