Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
(part 1) #3265086 Implement statement classes using \Iterator (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake authored Mar 30, 2023
1 parent 72e4c43 commit de50e82
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 122 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ env:
SIMPLETEST_BASE_URL: "http://localhost:8080"
PHPUNIT_SKIP_CLASS: '[
"Drupal\\KernelTests\\Core\\Cache\\ApcuBackendTest",
"Drupal\\Tests\\file\\Functional\\FileAddPermissionsUpdateTest",
"Drupal\\Tests\\file\\Functional\\DownloadTest"
"Drupal\\Tests\\file\\Functional\\FileAddPermissionsUpdateTest"
]'

jobs:

#################################

sqlite-pdo:
name: "SQLite with PDO"
runs-on: ubuntu-20.04
mysql-pdo:
name: "MySql"
runs-on: ubuntu-latest
env:
DRUDBAL_ENV: "dbal/sqlite/file"
DBAL_URL: "sqlite://localhost/sites/drudbal.sqlite"
SIMPLETEST_DB: "dbal://localhost/sites/drudbal.sqlite?module=drudbal&dbal_driver=pdo_sqlite"
DRUDBAL_ENV: "dbal/mysql"
DBAL_URL: "mysql://root:@0.0.0.0:3306/drudbal"
SIMPLETEST_DB: "dbal://root:@0.0.0.0:3306/drudbal?module=drudbal&dbal_driver=pdo_mysql"

strategy:
fail-fast: false
matrix:
php-version:
- "8.1"
# - "8.2"
test-args:
- "--group Database"
# - "--group Entity"
Expand All @@ -40,12 +38,22 @@ jobs:
# - "--group file"
# - "--group views"

services:
mysql:
image: "mysql:5.7"
options: >-
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes
-e MYSQL_DATABASE=drudbal
ports:
- "3306:3306"

steps:
- name: Install PHP
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
extensions: "pdo_mysql"
ini-values: "zend.assertions=1"

- name: Checkout Drupal
Expand All @@ -62,6 +70,7 @@ jobs:
- name: Install Composer dependencies
run: |
composer install --no-progress --ansi
composer config --no-plugins allow-plugins.composer/package-versions-deprecated true
- name: Composer require DruDbal from local staging
run: |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ Issue | Description
tbd | Add tests for Upsert with default values |
tbd | Ensure that when INSERTing a NULL value in a database column, SELECTing it back returns NULL and not empty string - for all fetch modes |
tbd | UpdateTestBase::runUpdate should reset database schema after updating |
[2992274](https://www.drupal.org/project/drupal/issues/2992274) | Installer tests fail if contrib driver hides database credentials form fields |
[3256642](https://www.drupal.org/project/drupal/issues/3256642) | Autoload classes of database drivers modules' dependencies |
[#2992274](https://www.drupal.org/project/drupal/issues/2992274) | Installer tests fail if contrib driver hides database credentials form fields |
[#3256642](https://www.drupal.org/project/drupal/issues/3256642) | Autoload classes of database drivers modules' dependencies |
[#3347497](https://www.drupal.org/project/drupal/issues/3347497) | Introduce a FetchModeTrait to allow emulating PDO fetch modes |
4 changes: 0 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ parameters:
- src
- drush
- tests

ignoreErrors:
# \PDO::sqliteCreateCollation not identified by PHPStan.
- "#^Call to an undefined method PDO::sqliteCreateCollation\\(\\)#"
28 changes: 23 additions & 5 deletions src/Driver/Database/dbal/Statement/PrefetchingStatementWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Doctrine\DBAL\Statement as DbalStatement;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Event\StatementExecutionEndEvent;
use Drupal\Core\Database\Event\StatementExecutionStartEvent;
use Drupal\Core\Database\RowCountException;
use Drupal\Core\Database\StatementInterface;
use Drupal\drudbal\Driver\Database\dbal\Connection as DruDbalConnection;
Expand Down Expand Up @@ -254,8 +256,17 @@ public function execute($args = [], $options = []) {
}
}

$logger = $this->connection()->getLogger();
$query_start = microtime(TRUE);
if ($this->connection()->isEventEnabled(StatementExecutionStartEvent::class)) {
$startEvent = new StatementExecutionStartEvent(
spl_object_id($this),
$this->connection()->getKey(),
$this->connection()->getTarget(),
$this->getQueryString(),
$args ?? [],
$this->connection()->findCallerFromDebugBacktrace()
);
$this->connection()->dispatchEvent($startEvent);
}

try {
$this->dbalResult = $this->dbalStatement->executeQuery($args);
Expand Down Expand Up @@ -290,9 +301,16 @@ public function execute($args = [], $options = []) {
// Initialize the first row in $this->currentRow.
$this->next();

$query_end = microtime(TRUE);
if (!empty($logger)) {
$logger->log($this, $args, $query_end - $query_start, $query_start);
if (isset($startEvent) && $this->connection()->isEventEnabled(StatementExecutionEndEvent::class)) {
$this->connection()->dispatchEvent(new StatementExecutionEndEvent(
$startEvent->statementObjectId,
$startEvent->key,
$startEvent->target,
$startEvent->queryString,
$startEvent->args,
$startEvent->caller,
$startEvent->time
));
}

return TRUE;
Expand Down
Loading

0 comments on commit de50e82

Please sign in to comment.