Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Database/Schema.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 7a779792577d |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
197 // Normally, we would heartily discourage the use of string | 197 // Normally, we would heartily discourage the use of string |
198 // concatenation for conditionals like this however, we | 198 // concatenation for conditionals like this however, we |
199 // couldn't use db_select() here because it would prefix | 199 // couldn't use db_select() here because it would prefix |
200 // information_schema.tables and the query would fail. | 200 // information_schema.tables and the query would fail. |
201 // Don't use {} around information_schema.tables table. | 201 // Don't use {} around information_schema.tables table. |
202 $results = $this->connection->query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments()); | 202 $results = $this->connection->query("SELECT table_name as table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments()); |
203 foreach ($results as $table) { | 203 foreach ($results as $table) { |
204 // Take into account tables that have an individual prefix. | 204 // Take into account tables that have an individual prefix. |
205 if (isset($individually_prefixed_tables[$table->table_name])) { | 205 if (isset($individually_prefixed_tables[$table->table_name])) { |
206 $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->table_name])); | 206 $prefix_length = strlen($this->connection->tablePrefix($individually_prefixed_tables[$table->table_name])); |
207 } | 207 } |
405 * @return | 405 * @return |
406 * TRUE if the primary key was successfully dropped, FALSE if there was no | 406 * TRUE if the primary key was successfully dropped, FALSE if there was no |
407 * primary key on this table to begin with. | 407 * primary key on this table to begin with. |
408 */ | 408 */ |
409 abstract public function dropPrimaryKey($table); | 409 abstract public function dropPrimaryKey($table); |
410 | |
411 /** | |
412 * Finds the primary key columns of a table, from the database. | |
413 * | |
414 * @param string $table | |
415 * The name of the table. | |
416 * | |
417 * @return string[]|false | |
418 * A simple array with the names of the columns composing the table's | |
419 * primary key, or FALSE if the table does not exist. | |
420 * | |
421 * @throws \RuntimeException | |
422 * If the driver does not override this method. | |
423 */ | |
424 protected function findPrimaryKeyColumns($table) { | |
425 if (!$this->tableExists($table)) { | |
426 return FALSE; | |
427 } | |
428 throw new \RuntimeException("The '" . $this->connection->driver() . "' database driver does not implement " . __METHOD__); | |
429 } | |
410 | 430 |
411 /** | 431 /** |
412 * Add a unique key. | 432 * Add a unique key. |
413 * | 433 * |
414 * @param $table | 434 * @param $table |
660 return 'NULL'; | 680 return 'NULL'; |
661 } | 681 } |
662 return is_string($value) ? $this->connection->quote($value) : $value; | 682 return is_string($value) ? $this->connection->quote($value) : $value; |
663 } | 683 } |
664 | 684 |
685 /** | |
686 * Ensures that all the primary key fields are correctly defined. | |
687 * | |
688 * @param array $primary_key | |
689 * An array containing the fields that will form the primary key of a table. | |
690 * @param array $fields | |
691 * An array containing the field specifications of the table, as per the | |
692 * schema data structure format. | |
693 * | |
694 * @throws \Drupal\Core\Database\SchemaException | |
695 * Thrown if any primary key field specification does not exist or if they | |
696 * do not define 'not null' as TRUE. | |
697 */ | |
698 protected function ensureNotNullPrimaryKey(array $primary_key, array $fields) { | |
699 foreach (array_intersect($primary_key, array_keys($fields)) as $field_name) { | |
700 if (!isset($fields[$field_name]['not null']) || $fields[$field_name]['not null'] !== TRUE) { | |
701 throw new SchemaException("The '$field_name' field specification does not define 'not null' as TRUE."); | |
702 } | |
703 } | |
704 } | |
705 | |
665 } | 706 } |