Problem/Motivation

In SQL SERVER, the implementation of the GREATEST function doesn't handle data types other than 'real'. This is causing an issue as noted in https://drupal.org/node/1598924#comment-7495746.

Steps to reproduce

Set up a views that uses any of the affected comment field handlers.

Proposed resolution

For the reasons given in #40 no code changes are to be made.

Documentation updated, https://www.drupal.org/docs/8/api/database-api/dynamic-queries/expressio...

Some handlers in the Views Comment submodule should be rewritten not to use GREATEST and use the universally compatible CASE WHEN clausule.

Remaining tasks

Review
RTBC
Commit

User interface changes

None.

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug: feature is broken on SQL Server.
Prioritized changes The main goal of this issue is compatiblity.
Disruption Non disruptive, change is very isolated.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

omegamonk’s picture

Title: The implementation of GREATEST in sqlsrv doesn't handle numbers other than 'real'. » The implementation of GREATEST in sqlsrv doesn't handle data types other than 'real'.

Corrected title for clarity.

david_garcia’s picture

FileSize
622 bytes

This worked for me to remove the warnings in referenced POST:

ALTER FUNCTION [dbo].[GREATEST](@op1 sql_variant, @op2 sql_variant) RETURNS sql_variant AS
BEGIN
DECLARE @result sql_variant
SET @result = CASE WHEN @op1 >= @op2 THEN @op1 ELSE @op2 END
RETURN @result
END

I changed INSTALL.inc to create the funcition in the new way.

The patch is not GIT ready, I'm still struggling to learn GIT and am on a project deadline right now.

omegamonk’s picture

@david_garcia_garcia, this is similar to the way I intended on handling it. Thanks for the patch.

The MySQL function of the same name handles multiple parameters and so I am working on a solution to that problem, as well.

david_garcia’s picture

I think there is no way to accomplish that except for using CLR.

In SQL Server a UDF cannot have optional parameters (it does have optional parameter values, wich is not the same thing).

Anyways, if you come up with something, let us know!

thorsten.’s picture

Thx 4 the patch!

br, thorsten

david_garcia’s picture

FileSize
1.57 KB

DANGER!!! The use of this patch breaks (silently) Views Module when using the content field handler "Node Last Update or Comment" wich ironically is used in the Views used by Advanced Forum Module (the motivation of the patch was to solve warnings in the Forum Module).

I am attaching the modified handlers in Views Module if anyone comes across this crazy issue that took me ages to solve. What happens is that, whenever a View is using the affected field type, it will silently show no results at all.

thorsten.’s picture

thx 4 the update @david_garcia_garcia

br, thorsten

david_garcia’s picture

I am starting to think that to solve all compatibility issues with SQL Server Driver we need 100% compatible CLR implementation of functions such as GREATEST, WS_CONCAT, CONCAT, GROUP_CONCAT, but I am not sure of making the effort because it looks as though CLR functions will never make it into the module due to security reasons.

david_garcia’s picture

Title: The implementation of GREATEST in sqlsrv doesn't handle data types other than 'real'. » GREATEST function does not behave equally in all database engines
Project: Drupal driver for SQL Server and SQL Azure » Views (for Drupal 7)
Version: 7.x-1.x-dev » 8.x-3.x-dev
Issue summary: View changes
FileSize
3.07 KB
david_garcia’s picture

Status: Active » Needs review
david_garcia’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
FileSize
3.07 KB
david_garcia’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.0.x-dev
Component: Code » comment.module
Priority: Normal » Major
FileSize
3.01 KB

Ported to D8.

david_garcia’s picture

david_garcia’s picture

--

david_garcia’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 13: 2013028-replace-greatest-with-for-case-when-D8.patch, failed testing.

TolliSysDev’s picture

Hi,

Is there a fix or workaround for this? I have followed several threads regarding this and can't seem to get advanced forum views comment working with MSSQL.

Any suggestions are greatly appreciated.

EDIT to add that I found fix here: http://cgit.drupalcode.org/drupal/commit/?id=b4858c7

I am getting the previously mentioned date_time errors, but I am happy that I am able to use the Advanced Forums module now. Thanks for working on this...

david_garcia’s picture

Is there a fix or workaround for this?

There is: review, propose patches and/or donate to projects.

This issue needs a follow-up with something like "Remove all uses of GREATEST in core".

I've rerolled the D8 patch, but if no one reviews, this will never make it into D8 (and into D7 because the backport policy states that for something to get into D7, first must be solved in D8).

david_garcia’s picture

Status: Needs work » Needs review
david_garcia’s picture

Not that bad, there is only one additional place in core where greatest is used:

\core\modules\comment\src\Plugin\views\field\NodeNewComments.php (1 hit)
Line 136: AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp1), :timestamp2) AND c.status = :status GROUP BY n.nid", array(

daffie’s picture

SQLite also does not support GREATEST. In the SQLite driver there is a file called core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php and in that file there is a helper function called sqlFunctionGreatest that fixes the problem for SQLite.

david_garcia’s picture

Unluckily that workaround will not do the job for MSSQL.

The thing is that core shoud be as database agnostic as possible and CASE WHEN is a more universally equaly implemented SQL specification.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markdorison’s picture

Version: 8.1.x-dev » 8.3.x-dev

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

larowlan’s picture

Status: Needs review » Needs work

Looking good, but as per #21, there is still one instance to go?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative, +Needs issue summary update

Is this still an issue

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

I asked about this issue in #bugsmash, and pinged daffie. daffie responded saying that MySQL/MariaDB and PostgreSQL having a different opinions on how to handle NULL values in combination with the "GREATEST" functionality. The SQL Server has yet another opinion how to do the functionality And finished by saying that this something we cannot fix.

I am not sure if this should be documented somewhere and I left a question about that in #bugsmash.

As for this issue, we can close this as won't fix.

quietone’s picture

Category: Bug report » Task
Priority: Major » Normal
Issue summary: View changes
Status: Closed (won't fix) » Fixed

I just heard from @daffie in slack who told me they updated the documentation to explain GREATEST and LEAST, etc. I have added that to the Issue Summary.

Based on that I am changing this to a Task and marking it Fixed, and updating credit.

Thanks!

quietone’s picture

Cleaning up tags.

Status: Fixed » Closed (fixed)

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