diff core/lib/Drupal/Core/Database/Schema.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Database/Schema.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/core/lib/Drupal/Core/Database/Schema.php	Thu Feb 28 13:11:55 2019 +0000
@@ -199,7 +199,7 @@
     // 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])) {
@@ -409,6 +409,26 @@
   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.
    *
    * @param $table
@@ -662,4 +682,25 @@
     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.");
+      }
+    }
+  }
+
 }