Problem/Motivation

I tried to upgrade a 9.3.15 site to 9.4.0.

It went fine until I tried "drush updatedb -y". This is the error that was the result:

 [warning] Undefined array key "return" Connection.php:748
Error: Call to a member function fetchField() on null in Drupal\sqlsrv\Driver\Database\sqlsrv\Schema->tableExists() (line 733 of C:\ApacheSites\arr_dr9_devp9\web\modules\contrib\sqlsrv\src\Driver\Database\sqlsrv\Schema.php).
 [warning] Drush command terminated abnormally.

Steps to reproduce

  • composer require drupal/core-recommended:^9.4.0 drupal/core-dev:^9.4.0 drupal/core-composer-scaffold:^9.4.0 drupal/core-project-message:^9.4.0 drupal/core-vendor-hardening:^9.4.0 drush/drush drupal/devel composer/installers --update-with-dependencies
  • drush updatedb -y

My configuration

  • Windows
  • MS SQL Server - 2017 Enterprise
  • Apache 2.4
  • PHP 8.0
  • Drupal 9.3.15
  • Drupal driver for SQL Server and SQL Azure 4.3.1

Comments

ARRC-Drupal-Chick created an issue. See original summary.

freelock’s picture

I got a similar error after upgrading to Drupal 9.4. We don't use SQL Server for the primary Drupal database -- we use it as a data source for an ongoing migration, so we end up with a long backtrace, starting with:

Error: Call to a member function fetchField() on null in modules/contrib/sqlsrv/src/Driver/Database/sqlsrv/Schema.php on line 765 #0 modules/contrib/sqlsrv/src/Driver/Database/sqlsrv/Connection.php(790): Drupal\sqlsrv\Driver\Database\sqlsrv\Schema->getDefaultSchema()

Error: Call to a member function fetchField() on null in Drupal\sqlsrv\Driver\Database\sqlsrv\Schema->getDefaultSchema() (line 765 of /var/www/html/downtoearthdistributors.com/modules/contrib/sqlsrv/src/Driver/Database/sqlsrv/Schema.php)

I'm guessing the internal database API changed...

freelock’s picture

I just tracked this down to a change record that did more than deprecate functionality -- it removed a default 'return' option - #3185520: Introduced a Connection::lastInsertId method, deprecating the 'return' query option and the Database::RETURN_* constants.

The specific change is in core/lib/Drupal/Core/Database/Connection.php . In 9.3.x, this function returned an option 'return' => Database::RETURN_STATEMENT. In 9.4.x, this option was removed from default options.

freelock’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

The core Connection Class query method has been changed between 9.3 to 9.4 to make the return option optional. I applied the same change to the \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection class, to the query() and queryDirect() methods, which appears to fix this issue, and should be backward compatible.

ARRC-Drupal-Chick’s picture

Status: Needs review » Active

I just noticed that I listed my "Drupal driver for SQL Server and SQL Azure" version as 4.1.3 and it should be 4.3.1. (Lysdexia strikes again.)

@freelock, thank you. It is always good to find out that I am not the only one to experience an issue.

Can I safely assume that your patch works with 4.3.1? I'm willing to try and see if it fixes my issue.

ARRC-Drupal-Chick’s picture

I attempted to apply the patch using composer (both from this site and locally downloaded) and it timed out.

So, I manually changed the two lines and Drupal 9.4.0 is now happy.

I copied the updated file to a 9.3.16 site and it worked just fine.

@freelock, thank you very much.

ARRC-Drupal-Chick’s picture

Issue summary: View changes
solideogloria’s picture

Version: 4.3.1 » 4.3.x-dev
Status: Active » Reviewed & tested by the community

I applied #4 successfully with Composer on Drupal 9.4.1. This fixed my issue.

I had been unable to select from a database using code like this:

      $result = $this->database->select('table')
        ->fields('table', ['id', 'description'])
        ->condition('id', $ids, 'IN')
        ->execute();
IngJheyner’s picture

I confirm, patch #4 worked for me.

On the other hand, I have a site with drupal 9 and sqlserver, but I have had performance problems and I saw that it was solved with wincache but this module has not worked again, I appreciate if you give me some documentation where I can improve this, thanks

Dudelinos’s picture

I had the same error and #4 fixed it for me also. Thanks

ysamoylenko’s picture

#4 fixes the problem on Drupal core 9.4.2.

dmlb2000’s picture

Fixed errors for me moving to 9.4 from 9.3.

mjmorley’s picture

Fixed error for me after upgrading to drupal 9.4

jumpsuitgreen’s picture

@freelock, thanks for posting. Patch #4 fixed the error for me as well. v9.4

calmforce’s picture

This bug makes the module completely useless on Drupal 9.4 - it generates fatal errors upon connection to MSSQL DB. The patch #4 fixes the problem, so why the maintainers do not include it into the released code? The project looks abandoned, it has not been updated in a year and has the fatal error that makes it incompatible with the latest released version of Drupal.

gngn’s picture

Priority: Normal » Major

Rasising to 'major'

hitesh.koli’s picture

#4 fixes the problem on Drupal core 9.4.12 . This patch need to go in next release

solideogloria’s picture

Patch #4 works in Drupal 9.5 as well.

robertoperuzzo’s picture

Patch #4 works in my Drupal 9.5.7 new installation.

pstewart’s picture

Patch #4 working for me upgrading to D9.5.7, so another upvote for RTBC here.

pstewart’s picture

Just noting this issue is a side-effect from 3185269, which removed the default value from the options array. THe patch copies over the relevant change that was made in the parent class, so is good to go.

  • pstewart committed acf89a33 on 4.3.x authored by freelock
    Issue #3291199 by freelock, ARRC-Drupal-Chick, solideogloria: Call to a...
pstewart’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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