The docblock for Connection::query() has the return definition set to @return \Drupal\Core\Database\StatementInterface|int|null. However, there is also the statement return $this->connection->lastInsertId($sequence_name);. $this->connection is defined as @var \PDO and php.org defines the function as public PDO::lastInsertId ([ string $name = NULL ] ) : string.

The return definition should be changed to @return \Drupal\Core\Database\StatementInterface|int|string|null.

This error was flagged by the mglaman/drupal-check tool.

The entire original return section is as follows:

    * @return \Drupal\Core\Database\StatementInterface|int|null
   *   This method will return one of the following:
   *   - If either $options['return'] === self::RETURN_STATEMENT, or
   *     $options['return'] is not set (due to self::defaultOptions()),
   *     returns the executed statement.
   *   - If $options['return'] === self::RETURN_AFFECTED,
   *     returns the number of rows affected by the query
   *     (not the number matched).
   *   - If $options['return'] === self::RETURN_INSERT_ID,
   *     returns the generated insert ID of the last query.
   *   - If either $options['return'] === self::RETURN_NULL, or
   *     an exception occurs and $options['throw_exception'] evaluates to FALSE,
   *     returns NULL. 

We will update one section to:

  *   - If $options['return'] === self::RETURN_INSERT_ID,
   *     returns the generated insert ID of the last query as a string.
CommentFileSizeAuthor
#10 3125391-9.patch1.28 KBbeakerboy
#3 3125391-3.patch778 bytesbeakerboy

Comments

Beakerboy created an issue. See original summary.

beakerboy’s picture

Issue summary: View changes
beakerboy’s picture

Assigned: beakerboy » Unassigned
Status: Active » Needs review
StatusFileSize
new778 bytes

Please review this patch.

daffie’s picture

Status: Needs review » Needs work

Hi @Beakerboy: Your documention change looks good. What I am missing is that the next line is saying "This method will return one of the following". Could you add your possibility to that list. Also can you update the issue summery with the appropriate links. That way people can check what you are saying. Thanks for your the issue and the patch.

beakerboy’s picture

@daffie, the RETURN_INSERT_ID option is already in the list so I think it’s good.

beakerboy’s picture

Issue summary: View changes
beakerboy’s picture

Status: Needs work » Needs review
daffie’s picture

Issue summary: View changes
Status: Needs review » Needs work

Can we add to the string "returns the generated insert ID of the last query" the words " as a string".

prabha1997’s picture

Assigned: Unassigned » prabha1997
beakerboy’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

Clearly stating the return type of the RETURN_INSERT_ID case is a string in the docblock.

beakerboy’s picture

Issue summary: View changes
beakerboy’s picture

Issue summary: View changes
daffie’s picture

Assigned: prabha1997 » Unassigned
Status: Needs review » Reviewed & tested by the community

Looks good to me.
This issue is a documentation improvement.
For me it is RTBC.

prabha1997’s picture

Status: Reviewed & tested by the community » Needs review

I apologize by mistakly added patch.

prabha1997’s picture

Status: Needs review » Reviewed & tested by the community
daffie’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b67ddac362 to 9.1.x and 9fcad9365d to 9.0.x. Thanks!

Backported to 9.0.x as a docs change.

  • alexpott committed b67ddac on 9.1.x
    Issue #3125391 by Beakerboy, daffie: Connection::query() return types...

  • alexpott committed 9fcad93 on 9.0.x
    Issue #3125391 by Beakerboy, daffie: Connection::query() return types...
alexpott’s picture

Version: 9.0.x-dev » 8.9.x-dev

Decided to go back to 8.9.x to keep the docs in sync. Makes and changes for bugfixes easier later on and is still true.

  • alexpott committed d7fa684 on 8.9.x
    Issue #3125391 by Beakerboy, daffie: Connection::query() return types...
drumm’s picture

Version: 9.0.x-dev » 8.9.x-dev

There was some sort of race condition with the simultaneously-posted comments. 8.9.x-dev was in Drupal.org’s field cache, but the field data & revision tables had 9.0.x-dev stored.

Status: Fixed » Closed (fixed)

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