#25 Trim leading whitespace from queries

Patches
closed
Jan Pedersen
9
2012-09-25
2004-03-23
Dave Lerner
No

Suggestion: If leading whitespace is allowed in
queries, then the queries can (optionally) be formatted
more nicely, e.g.:

$result = $db->query("
SELECT a,b
FROM x
WHERE z
");

(The lines of the query are indented above, but that
may not show up here.)

I think this is more readable for long or complex queries.

Suggested change:

Insert at beginning of XoopsMySQLDatabaseProxy::query()
in class/database/mysqldatabase.php:

$sql = ltrim($sql);

An equivalent solution would be to revert to using
preg_match, rather than substr, and allow leading
whitespace in the regex pattern:

preg_match("/^\sSELECT./i", $sql)

Discussion

  • Skalpa Keo
    Skalpa Keo
    2004-05-12

    Logged In: YES
    user_id=882380

    Changed to accepted and ok for 2.0.7 release.

     
  • Jan Pedersen
    Jan Pedersen
    2004-05-13

    Logged In: YES
    user_id=841117

    Fixed, ready for review