This patch enables pager_query() sql to span multiple lines, which is my preferred way of writing long sql queries as they're more readable. Without this patch, those using multiline (as in with line breaks in them) sql will find that theme_pager() returns the wrong number of pages.

This patch just solves this issue for pager_query, though there may be many other places in the drupal code where multiline sql isn't supported. Indeed, Drupal coding style says to keep sql to one line. But for usability, I believe the coding style should be changed.

The patch simply changes two . in a preg_replace to (.|\n) to enable line returns to return true as well.

before:

$count_query = preg_replace(array('/SELECT.*?FROM/As', '/ORDER BY .*/'), array('SELECT COUNT(*) FROM', ''), $query);

after:

$count_query = preg_replace(array('/SELECT(.|\n)*?FROM/As', '/ORDER BY (.|\n)*/'), array('SELECT COUNT(*) FROM', ''), $query);
CommentFileSizeAuthor
multiline_sql.patch734 bytesjakeg

Comments

jakeg’s picture

Project: Paging » Drupal core
Version: 6.x-1.x-dev » x.y.z
Component: Code » database system

changing what project it refers to

ax’s picture

pager_query() sql should be able to span multiple lines because of the s modifier ('/SELECT.*?FROM/As', last char). could you please provide an example where multiline sql makes it fail? i'd guess there is another reason ...

LAsan’s picture

Version: x.y.z » 7.x-dev

Any news about this?

Moving to cvs.

moshe weitzman’s picture

Status: Needs work » Closed (duplicate)
damien tournoud’s picture

Version: 7.x-dev » 6.x-dev
Status: Closed (duplicate) » Active

Reassigned to D6.

dpearcefl’s picture

At this point, no new features will be added to D6. If you think Drupal 8 needs this feature, please assign this issue to D8.

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.