Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change MSSQL query if no limit or offset is set #4870

Closed
wants to merge 1 commit into from

Conversation

Bakual
Copy link
Contributor

@Bakual Bakual commented Oct 21, 2014

Issue

Currently, MSSQL creates an error for each database query where no limit is set. Like for inserts, updates and the like.
See #3602 and #4869 for the issue reports.

Solution

Add a check to the sqlsrv query class in the processLimit() method. Similar to what we already do in MySQL and PostgreSQL.

Testing

@sovainfo can you explain how to reproduce the issue? As far as I understood one sees that on first page after updating?

@sovainfo
Copy link
Contributor

According to me the issue is that the limit is applied while there is no need:

  • It is called several times by $db->setQuery($query, 0, 1); while result of the query is always no row or 1 row.
  • It is called for statements other than type SELECT
  • It is called even when both limit and offset are 0

This is independent of MSSQL, it applies to MySQL and PostgreSQL as well.

Don't mind that the function returns when both are not set. But that doesn't stop the errors on #__session deleting 1 row !

As explained in #4869 the update from J336 when set to test fails.

@Bakual
Copy link
Contributor Author

Bakual commented Oct 21, 2014

This is independent of MSSQL, it applies to MySQL and PostgreSQL as well.

I'm not aware of any issues like this in MySQL and PostgreSQL. And judging from code, there should be any issues since they have a similar check already in their processLimit() method.

Don't mind that the function returns when both are not set. But that doesn't stop the errors on #__session deleting 1 row !

That may be a different issue. I don't know how you have to apply limits to a DELETE on MSSQL. Maybe the processLimit method needs to be adjusted to take care of that special case.

@sovainfo
Copy link
Contributor

I thought the purpose of Joomla was to be independent of RDBMS. That means you need to do the right thing for all, not just one!. Calling routines when they shouldn't is still wrong. It doesn't make it right when it doesn't give problems in certain situations.

Just because PHP and MySQL allows sloppy programming, it doesn't means you should do it!
Specially if want to support other environments as well. Better to remove MSSQL and PostgreSQL from Joomla. They are never going to work as MySQL. And that seems to be the requirement here!

@Bakual
Copy link
Contributor Author

Bakual commented Oct 21, 2014

Just to be clear: This PR just adds a behavior to MSSQL which is already present in PostgreSQL and MySQL query classes.
It makes it consistent on where it is checked and leaves the responsibility in the database specific query class. Which imho is correct.

@Bakual Bakual mentioned this pull request Oct 22, 2014
@jbultena
Copy link

finnaly this bug gonna get fixed.

@@ -260,6 +260,11 @@ public function dateAdd($date, $interval, $datePart)
*/
public function processLimit($query, $limit, $offset = 0)
{
if (!$limit && !$offset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bakual Shouldn't we do the same here as in other drivers:

if ($limit > 0 && $offset > 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places we have the code to apply the limit within the if clause.
I went the other way around and bail out if the checks are not successful. I prefer this way in this case because the actual code has another if clause and is quite a few lines long.
I think it's easier to read this way.
Also PostgreSQL has yet another way

        if ($limit > 0)
        {
            $query .= ' LIMIT ' . $limit;
        }

        if ($offset > 0)
        {
            $query .= ' OFFSET ' . $offset;
        }

So there is not really a standard anyway 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably dependent on the database type on how to handle these values.

@Bakual
Copy link
Contributor Author

Bakual commented Dec 3, 2014

Closing as fixed with #5293

@Bakual Bakual closed this Dec 3, 2014
@Bakual Bakual deleted the FixMSSQLQueryLimit branch December 3, 2014 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants