Problem/Motivation

We have a defacto interface on Statements but the methods where commented out because of a bug in php 5.2. Since we require a more recent version we can put them back on the interface.

Proposed resolution

Uncomment the methods.

Remaining tasks

User interface changes

API changes

I guess its almost an API change because they were not strictly enforced. However, since they were implemented and expected to be implemented it isn't really a change.

Beta phase evaluation

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul’s picture

Status: Active » Needs review
FileSize
2.22 KB

Lets see what testbot says.

neclimdul’s picture

FileSize
4.57 KB

I assumed our code was following our psuedo interface but it is not.

This fixes the classes to be consistent.
http://3v4l.org/bTuOC

The last submitted patch, 1: uncomment-2521832-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: uncomment-2521832-2.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
2.97 KB
5.02 KB
2.45 KB

We apparently are not very good about following this interface so this is good for catching some inconsistencies.

This fixes some argument names for some of the statement implementations and PDO is picky about arguments on fetchAll in some cases so this conditionally provides the exact number of arguments given in Statement.php

Note: I implemented proxy methods here similar to other proxy methods on Statement because the argument names do not match \PDOStatement which triggers strict warnings.

Crell’s picture

Category: Task » Bug report

Sounds like this is actually a bug then, found by enforcing the interface.

+++ b/core/lib/Drupal/Core/Database/Statement.php
@@ -127,4 +127,30 @@ public function rowCount() {
+  public function setFetchMode($mode, $a1 = NULL, $a2 = array()) {
+    // Call \PDOStatement::setFetchMode to set fetch mode.
+    return parent::setFetchMode($mode);
+  }

Wait, why are we dropping the other two parameters? Don't they serve some purpose in the world?

Status: Needs review » Needs work

The last submitted patch, 5: uncomment-2521832-5.patch, failed testing.

neclimdul’s picture

FileSize
1.25 KB
5.42 KB

I have no idea...

Tests turned up another bug, fetchall can take 0 arguments.

neclimdul’s picture

Status: Needs work » Needs review
Crell’s picture

Status: Needs review » Reviewed & tested by the community

Huzzah! Thanks, neclimdul.

alexpott’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +API change, +Needs change record
  1. Given that we are now enforcing expectations through an interface I think we should have a small CR telling people this.
  2. +++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php
    @@ -438,14 +438,14 @@ public function fetchAssoc() {
     
    -  public function fetchAll($fetch_style = NULL, $fetch_column = NULL, $constructor_args = NULL) {
    -    $this->fetchStyle = isset($fetch_style) ? $fetch_style : $this->defaultFetchStyle;
    +  public function fetchAll($mode = NULL, $column_index = NULL, $constructor_arguments = NULL) {
    

    Missing {@inheritdoc} - in fact I think we should fix all the implementations to use the {inheritdoc} now that the interface has the methods.

  3.   /**
       * @see \PDOStatement::setFetchMode()
       */
      public function setFetchMode($fetchStyle, $a2 = NULL, $a3 = NULL) {
    

    In core/lib/Drupal/Core/Database/StatementPrefetch.php can inheritdoc plus the args don't match.

neclimdul’s picture

everything except the CR

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Change notice: https://www.drupal.org/node/2539326

Thanks, neclimdul!

amateescu’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs change record
+++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php
@@ -268,14 +261,7 @@ public function setFetchMode($fetchStyle, $a2 = NULL, $a3 = NULL) {
-   * This is the core method of this class. It grabs the value at the current
-   * array position in $this->data and format it according to $this->fetchStyle
-   * and $this->fetchMode.

We shouldn't lose this comment, we can either put it back below @inheritdoc or in the function body. Since dreditor context is not helpful, the comment was in the docblock of the current() method.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
731 bytes
14.41 KB

Oh, yeah this is actually from \Iterator not our Interfaces so we sort of need that documentation.

neclimdul’s picture

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Bot should be OK.

amateescu’s picture

Cool :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 42c26e2 and pushed to 8.0.x. Thanks!

  • alexpott committed 42c26e2 on 8.0.x
    Issue #2521832 by neclimdul, Crell, amateescu: Uncomment...
chx’s picture

I think ... the change record might be slightly misleading? Statements still implements StatementInterface, we just added a few new methods do it so that it mirrors PDOStatement 100% but we do not actually require to implement / extend / whatever PDO itself.

neclimdul’s picture

Drupal 8 StatementInterface requires all of the methods of PDOStatement explicitly.

That sounds a lot like what you're saying. Can you help me understand how we could clarify it and I will update it.

chx’s picture

I rewrote the CR from ground up from the viewpoint of someone who actually wrote DB drivers :) and changed the title too because the title was very confusing (since PDOStatement doesn't have an interface)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.