Problem/Motivation

This module is currently incompatible with Drupal 10. The main issue stems from the policy decision that all databases must support JSON functionality (https://www.drupal.org/node/3192484). SQL Server itself does, but it uses different function names and the module/driver does not translate the commonly used JSON requests.

Is a solution actively being worked on?

Issue fork sqlsrv-3332118

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tevans created an issue. See original summary.

KenKodz’s picture

Looking at the Drupal 10.0.x code, the only thing I see JSON related is the check to see if the DB engine supports JSON.

In MySQL (default method):

  public function hasJson(): bool {
    try {
      return (bool) $this->query('SELECT JSON_TYPE(\'1\')');
    }
    catch (\Exception $e) {
      return FALSE;
    }
  }

In PgSQL:

  public function hasJson(): bool {
    try {
      return (bool) $this->query('SELECT JSON_TYPEOF(\'1\')');
    }
    catch (\Exception $e) {
      return FALSE;
    }
  }

For sqlsrv, this should accomplish the same thing:

  public function hasJson(): bool {
    try {
        return (bool) $this->query('SELECT ISJSON(\'[1]\')');
    }
    catch (\Exception $e) {
        return FALSE;
    }
  }

I'm still digging into the code to determine what other methods need to be added or changed. Anyone else wanting to work on this, we can discuss it here or in Slack.

KenKodz’s picture

Here's a patch for the change mentioned above.

tevans’s picture

I applied the patch, but was still seeing a warning on the Status Report that database support for JSON is not available. It looks like the syntax for the query wasn't quite right. Attaching a patch with the correct syntax that does appear to remove the warning.

KenKodz’s picture

Yeah, my code had a typo in it. Can confirm that #5 works.

pstewart’s picture

I ran into some trouble applying #5 as the file was formatted as UTF-16. This version of the patch is reformatted as UTF-8, but is otherwise identical to #5. Can confirm it works as expected talking to an SQL Server 2017 database.

As far as I can tell the hasJson method is the only thing we need to do at this stage, other stuff relating to json appears to be still active in core at the moment, such as mapping json data types in the schema API etc.

pstewart’s picture

pstewart’s picture

Version: 4.3.x-dev » 4.4.x-dev
Assigned: Unassigned » pstewart

  • pstewart committed fed0d542 on 4.4.x authored by KenKodz
    Issue #3332118 by KenKodz, pstewart, tevans: Database JSON support...
pstewart’s picture

I've now committed this to 4.4.x for inclusion in the next dev release. I've encountered no issues with this when running the Drupal 10 installer with an SQL Server database, and have confirmed the Status Report shows 'Database support for JSON' as being 'Available'. I think this is therefore all done, however I'll keep this issue at 'Needs Review' while the 4.4.x branch is in development and testing, and we'll move to 'Fixed' once we're ready to release 4.4.0 as stable.

.Kris.’s picture

Hello,

I have installed 4.4.x-dev, but I am still getting this error when I run update.php, and it is not allowing me to do the upgrade:

Requirements problem
Errors found
Database support for JSON
Not available
Is required in Drupal 10.0.

.Kris.’s picture

FileSize
129.26 KB

Here are the files in question (on left), compared to a clean install of Drupal 10.1 on the right:

pstewart’s picture

@.Kris. What version of SQL Server are you currently using? Note that JSON support is only available in SQL Server 2016 (13.x) and later.

pstewart’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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