X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FDatabase%2FSchema.php;h=4bd0a9bdf391b600b5a1299668059e4e5651330a;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=aafe1756ba392d056d2769c82c209d53b8635a12;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Database/Schema.php b/web/core/lib/Drupal/Core/Database/Schema.php index aafe1756b..4bd0a9bdf 100644 --- a/web/core/lib/Drupal/Core/Database/Schema.php +++ b/web/core/lib/Drupal/Core/Database/Schema.php @@ -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."); + } + } + } + }