Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Database / Schema.php
index aafe1756ba392d056d2769c82c209d53b8635a12..4bd0a9bdf391b600b5a1299668059e4e5651330a 100644 (file)
@@ -199,7 +199,7 @@ abstract class Schema implements PlaceholderInterface {
     // couldn't use db_select() here because it would prefix
     // information_schema.tables and the query would fail.
     // Don't use {} around information_schema.tables table.
-    $results = $this->connection->query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments());
+    $results = $this->connection->query("SELECT table_name as table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments());
     foreach ($results as $table) {
       // Take into account tables that have an individual prefix.
       if (isset($individually_prefixed_tables[$table->table_name])) {
@@ -408,6 +408,26 @@ abstract class Schema implements PlaceholderInterface {
    */
   abstract public function dropPrimaryKey($table);
 
+  /**
+   * Finds the primary key columns of a table, from the database.
+   *
+   * @param string $table
+   *   The name of the table.
+   *
+   * @return string[]|false
+   *   A simple array with the names of the columns composing the table's
+   *   primary key, or FALSE if the table does not exist.
+   *
+   * @throws \RuntimeException
+   *   If the driver does not override this method.
+   */
+  protected function findPrimaryKeyColumns($table) {
+    if (!$this->tableExists($table)) {
+      return FALSE;
+    }
+    throw new \RuntimeException("The '" . $this->connection->driver() . "' database driver does not implement " . __METHOD__);
+  }
+
   /**
    * Add a unique key.
    *
@@ -662,4 +682,25 @@ abstract class Schema implements PlaceholderInterface {
     return is_string($value) ? $this->connection->quote($value) : $value;
   }
 
+  /**
+   * Ensures that all the primary key fields are correctly defined.
+   *
+   * @param array $primary_key
+   *   An array containing the fields that will form the primary key of a table.
+   * @param array $fields
+   *   An array containing the field specifications of the table, as per the
+   *   schema data structure format.
+   *
+   * @throws \Drupal\Core\Database\SchemaException
+   *   Thrown if any primary key field specification does not exist or if they
+   *   do not define 'not null' as TRUE.
+   */
+  protected function ensureNotNullPrimaryKey(array $primary_key, array $fields) {
+    foreach (array_intersect($primary_key, array_keys($fields)) as $field_name) {
+      if (!isset($fields[$field_name]['not null']) || $fields[$field_name]['not null'] !== TRUE) {
+        throw new SchemaException("The '$field_name' field specification does not define 'not null' as TRUE.");
+      }
+    }
+  }
+
 }