Merge "Use RemexHtml as the tidy implementation for parser tests"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index ddc8df5..8ccccc3 100644 (file)
@@ -59,6 +59,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        const SLOW_WRITE_SEC = 0.500;
        const SMALL_WRITE_ROWS = 100;
 
+       /** @var string Whether lock granularity is on the level of the entire database */
+       const ATTR_DB_LEVEL_LOCKING = 'db-level-locking';
+
        /** @var string SQL query */
        protected $lastQuery = '';
        /** @var float|bool UNIX timestamp of last write query */
@@ -385,6 +388,21 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                return $conn;
        }
 
+       /**
+        * @param string $dbType A possible DB type (sqlite, mysql, postgres,...)
+        * @param string|null $driver Optional name of a specific DB client driver
+        * @return array Map of (Database::ATTRIBUTE_* constant => value) for all such constants
+        * @throws InvalidArgumentException
+        * @since 1.31
+        */
+       final public static function attributesFromType( $dbType, $driver = null ) {
+               static $defaults = [ self::ATTR_DB_LEVEL_LOCKING => false ];
+
+               $class = self::getClass( $dbType, $driver );
+
+               return call_user_func( [ $class, 'getAttributes' ] ) + $defaults;
+       }
+
        /**
         * @param string $dbType A possible DB type (sqlite, mysql, postgres,...)
         * @param string|null $driver Optional name of a specific DB client driver
@@ -441,6 +459,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                return $class;
        }
 
+       /**
+        * @return array Map of (Database::ATTRIBUTE_* constant => value
+        * @since 1.31
+        */
+       protected static function getAttributes() {
+               return [];
+       }
+
        /**
         * Set the PSR-3 logger interface to use for query logging. (The logger
         * interfaces for connection logging and error logging can be set with the
@@ -2132,8 +2158,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
 
                // We can't separate explicit JOIN clauses with ',', use ' ' for those
-               $implicitJoins = !empty( $ret ) ? implode( ',', $ret ) : "";
-               $explicitJoins = !empty( $retJOIN ) ? implode( ' ', $retJOIN ) : "";
+               $implicitJoins = $ret ? implode( ',', $ret ) : "";
+               $explicitJoins = $retJOIN ? implode( ' ', $retJOIN ) : "";
 
                // Compile our final table clause
                return implode( ' ', [ $implicitJoins, $explicitJoins ] );