]> 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 9c3c3a52e5c4890ed7926c0683a0da4a195d016b..f3edf52be5f1e973f940402db42ff6cc90b5d16b 100644 (file)
@@ -648,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
         */
@@ -665,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) . ", ";
                                }
@@ -741,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.
         *