Skip to content

Use Doctrine DBAL for multi-database support - #591

Merged
baimard merged 1 commit into
masterfrom
codex/issue-586
Aug 7, 2026
Merged

Use Doctrine DBAL for multi-database support#591
baimard merged 1 commit into
masterfrom
codex/issue-586

Conversation

@baimard

@baimard baimard commented Aug 7, 2026

Copy link
Copy Markdown
Owner

What changed

  • replaces direct prepared-statement/PDO-style access in Bdd with Nextcloud IDBConnection Doctrine DBAL execution
  • uses Nextcloud QueryBuilder for joins and operations involving the reserved order column
  • removes MySQL-specific backtick quoting and the hard-coded oc_ table prefix
  • replaces database NOW() with a PHP-generated ISO date
  • replaces database-specific year/month extraction with portable aggregation in PHP
  • aliases aggregate columns consistently across database engines
  • fixes the IBAN migration to use Nextcloud's logical table name so custom prefixes work

No translation catalogs or Transifex files are changed.

Why

The previous implementation obtained low-level prepared statements and embedded MySQL-specific SQL details. That could fail with PostgreSQL, SQLite, or a custom Nextcloud table prefix. Database access now goes through Nextcloud's Doctrine DBAL abstraction, with QueryBuilder used where identifier quoting is required.

Validation

  • PHP syntax checks across lib/
  • real Nextcloud DBAL smoke tests against the local database for configuration, customers, quotes, invoices, products, counters and turnover
  • real QueryBuilder smoke tests for quote details, product joins and product ordering
  • Nextcloud migration status reports no pending migration
  • static audit finds no direct PDO/prepare calls, MySQL backticks, NOW(), EXTRACT(...), or hard-coded oc_gestion identifiers in the database layer
  • git diff --check

The PHPUnit executable is not installed in this checkout (vendor/bin/phpunit is absent), so the PHPUnit suite could not be run locally.

@baimard
baimard marked this pull request as ready for review August 7, 2026 09:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc02917e63

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/Db/Bdd.php
return $data;
$result = $this->db->executeQuery($sql, $conditions);
$rows = iterator_to_array($result->iterateAssociative(), false);
$result->closeCursor();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Release DBAL results with the supported API

On supported Nextcloud versions, IDBConnection::executeQuery() and query-builder reads return a Doctrine DBAL Result, which has free() rather than the PDO closeCursor() method. Consequently, every legacy read routed through this helper fetches its rows and then throws an undefined-method error before returning; fetchAll() repeats the same invalid call. Use free() or omit the explicit release after exhausting the iterator.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

Comment thread lib/Db/Bdd.php
->where($query->expr()->eq('f.id_configuration', $query->createNamedParameter($id_configuration)));

$totals = [];
foreach ($this->fetchAll($query) as $row) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Aggregate turnover without materializing every line item

When a company has a large invoice history, this now fetches and retains every invoice line before grouping it in PHP, whereas the previous query performed SUM/GROUP BY in the database and returned only one row per month. The statistics request therefore scales in application memory and database transfer with the complete ledger and can time out or exhaust PHP's memory limit; use a portable database-side aggregation or at least stream the result instead of calling fetchAll().

Useful? React with 👍 / 👎.

@baimard
baimard merged commit 686841d into master Aug 7, 2026
3 checks passed
@baimard
baimard deleted the codex/issue-586 branch August 7, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant