Quote column name aliases
authorRyan Schmidt <skizzerz@skizzerz.net>
Mon, 2 May 2016 18:04:47 +0000 (13:04 -0500)
committerLegoktm <legoktm.wikipedia@gmail.com>
Mon, 2 May 2016 21:22:59 +0000 (21:22 +0000)
Sometimes, a column name alias is chosen that is a reserved word or is
otherwise invalid (such as an alias named "user" on postgres or mssql).
Let's unconditionally quote the alias so that no matter what the user
specifies, it will not cause the query to error out.

Bug: T118973
Change-Id: If3ea7324980355e78afcdb3bf2596d23bb96412d

includes/db/Database.php

index c36cfdb..8807e13 100644 (file)
@@ -1847,7 +1847,7 @@ abstract class DatabaseBase implements IDatabase {
                if ( !$alias || (string)$alias === (string)$name ) {
                        return $name;
                } else {
-                       return $name . ' AS ' . $alias; // PostgreSQL needs AS
+                       return $name . ' AS ' . $this->addIdentifierQuotes( $alias ); // PostgreSQL needs AS
                }
        }