diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 064adc2..00e2cbe 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -94,6 +94,13 @@ protected $transactionalDDLSupport = FALSE; /** + * Whether this database connection supports foreign key constraints + * + * @var bool + */ + protected $foreignKeyConstraintSupport = TRUE; + + /** * An index used to generate unique temporary table names. * * @var integer @@ -1128,6 +1135,21 @@ public function supportsTransactionalDDL() { } /** + * Determines if this driver supports foreign key constraints. + * + * Foreign key constraints ensure referential integrity is maintained, + * such as by cascading a deletion or causing it to fail if it would leave + * foreign key references to a non-existent record. + * + * @return + * TRUE if this connection supports foreign key constraints, FALSE + * otherwise. + */ + public function supportsForeignKeyConstraints() { + return $this->foreignKeyConstraintSupport; + } + + /** * Returns the name of the PDO driver for this connection. */ abstract public function databaseType(); diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php index 9e0e65f..d437dd7 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -45,6 +45,9 @@ public function __construct(PDO $connection, array $connection_options = array() // This driver defaults to transaction support, except if explicitly passed FALSE. $this->transactionSupport = !isset($connection_options['transactions']) || ($connection_options['transactions'] !== FALSE); + // This driver does not implement MySQL's foreign key constraint support + $this->foreignKeyConstraintSupport = FALSE; + // MySQL never supports transactional DDL. $this->transactionalDDLSupport = FALSE; diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index 30e9e01..e88de8a 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -43,6 +43,9 @@ public function __construct(PDO $connection, array $connection_options) { // This driver defaults to transaction support, except if explicitly passed FALSE. $this->transactionSupport = !isset($connection_options['transactions']) || ($connection_options['transactions'] !== FALSE); + // This driver does not implement PostgreSQL's foreign key constraint support + $this->foreignKeyConstraintSupport = FALSE; + // Transactional DDL is always available in PostgreSQL, // but we'll only enable it if standard transactions are. $this->transactionalDDLSupport = $this->transactionSupport; diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index 5aaf7da..23d2dab 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -77,6 +77,9 @@ public function __construct(PDO $connection, array $connection_options) { // This driver defaults to transaction support, except if explicitly passed FALSE. $this->transactionSupport = $this->transactionalDDLSupport = !isset($connection_options['transactions']) || $connection_options['transactions'] !== FALSE; + // This driver does not implement sqlite's foreign key constraint support + $this->foreignKeyConstraintSupport = FALSE; + $this->connectionOptions = $connection_options; // Attach one database for each registered prefix.