]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBA.php
Merge pull request #8946 from annando/fix-fatal
[friendica.git] / src / Database / DBA.php
index f4d4bb11dd1907b644873899cf6daf621906491c..f3edf52be5f1e973f940402db42ff6cc90b5d16b 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Database;
 
@@ -10,8 +29,6 @@ use PDO;
 use PDOStatement;
 
 /**
- * @class MySQL database class
- *
  * This class is for the low level database stuff that does driver specific things.
  */
 class DBA
@@ -631,6 +648,20 @@ class DBA
        /**
         * Returns the SQL parameter string built from the provided parameter array
         *
+        * Expected format for each key:
+        *
+        * group_by:
+        *  - list of column names
+        *
+        * order:
+        *  - numeric keyed column name => ASC
+        *  - associative element with boolean value => DESC (true), ASC (false)
+        *  - associative element with string value => 'ASC' or 'DESC' literally
+        *
+        * limit:
+        *  - single numeric value => count
+        *  - list with two numeric values => offset, count
+        *
         * @param array $params
         * @return string
         */
@@ -648,7 +679,11 @@ class DBA
                                if ($order === 'RAND()') {
                                        $order_string .= "RAND(), ";
                                } elseif (!is_int($fields)) {
-                                       $order_string .= self::quoteIdentifier($fields) . " " . ($order ? "DESC" : "ASC") . ", ";
+                                       if ($order !== 'DESC' && $order !== 'ASC') {
+                                               $order = $order ? 'DESC' : 'ASC';
+                                       }
+
+                                       $order_string .= self::quoteIdentifier($fields) . " " . $order . ", ";
                                } else {
                                        $order_string .= self::quoteIdentifier($order) . ", ";
                                }
@@ -724,6 +759,17 @@ class DBA
                return DI::dba()->processlist();
        }
 
+       /**
+        * Fetch a database variable
+        *
+        * @param string $name
+        * @return string content
+        */
+       public static function getVariable(string $name)
+       {
+               return DI::dba()->getVariable($name);
+       }
+
        /**
         * Checks if $array is a filled array with at least one entry.
         *