X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FDatabase%2FSchema.php;h=4bd0a9bdf391b600b5a1299668059e4e5651330a;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=80a68f6e5acc8dd4a16430a520318249aee317fb;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Database/Schema.php b/web/core/lib/Drupal/Core/Database/Schema.php index 80a68f6e5..4bd0a9bdf 100644 --- a/web/core/lib/Drupal/Core/Database/Schema.php +++ b/web/core/lib/Drupal/Core/Database/Schema.php @@ -19,6 +19,8 @@ abstract class Schema implements PlaceholderInterface { /** * The placeholder counter. + * + * @var int */ protected $placeholder = 0; @@ -30,6 +32,8 @@ abstract class Schema implements PlaceholderInterface { * method. * * @see DatabaseSchema::getPrefixInfo() + * + * @var string */ protected $defaultSchema = 'public'; @@ -195,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])) { @@ -404,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. * @@ -658,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."); + } + } + } + }