diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php old mode 100644 new mode 100755 index 668a44f8cfd0c..f83d8196a368b --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -39,6 +39,7 @@ public function update($installer) $this->updateAssets(); $this->clearStatsCache(); $this->convertTablesToUtf8mb4(true); + $this->convertTablesToNewNullDate(); $this->cleanJoomlaCache(); // VERY IMPORTANT! THIS METHOD SHOULD BE CALLED LAST, SINCE IT COULD @@ -1683,6 +1684,109 @@ public function flushSessions() return true; } + + /** + * Converts the site's database tables to the new null Date of mySQL 5.7. Can also be used as reverter + * + * @param string $newNull the old null date string + * @param string $oldNull the new null date string + * + * @return void + * + * @since 12.2 + */ + public function convertTablesToNewNullDate($newNull=null,$oldNull=null) + { + $db = JFactory::getDbo(); + + // This is only required for MySQL databases + $serverType = $db->getServerType(); + + if ($serverType != 'mysql') + { + return; + } + + if (!method_exists($db, 'serverUsesNewNullDate')) + { + return; + } + + // Possible Convert Back + if ($db->serverUsesNewNullDate()) + { + if (is_null($newNull)) + { + $newNull='1000-01-01 00:00:00'; + } + + if (is_null($oldNull)) + { + $oldNull = '0000-00-00 00:00:00'; + } + } + else + { + if (is_null($oldNull)) + { + $oldNull = '1000-01-01 00:00:00'; + } + + if (is_null($newNull)) + { + $newNull = '0000-00-00 00:00:00'; + } + } + + // Check conversion status in database + $db->setQuery('SELECT ' . $db->quoteName('converted') + . ' FROM ' . $db->quoteName('#__nullDate_conversion') + ); + + $convertedDB = '0000-00-00 00:00:00'; + + try + { + $convertedDB = $db->loadResult(); + } + catch (Exception $e) + { + // Render the error message from the Exception object + JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + return; + } + + if ($convertedDB == $newNull) + { + // Already updated - nothing to do + return; + } + + $fileName = JPATH_ROOT . "/administrator/components/com_admin/sql/others/mysql/nullDate-conversion.sql"; + + if (is_file($fileName)) + { + $fileContents = @file_get_contents($fileName); + $queries = $db->splitSql($fileContents); + + if (!empty($queries)) + { + foreach ($queries as $query) + { + $query = str_replace(array('#O#', '#T#'), array($oldNull, $newNull), $query); + try + { + $db->setQuery($query)->execute(); + } + catch (Exception $e) + { + JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } + } + } + } + } + /** * Converts the site's database tables to support UTF-8 Multibyte. * diff --git a/administrator/components/com_admin/sql/others/mysql/nullDate-conversion.sql b/administrator/components/com_admin/sql/others/mysql/nullDate-conversion.sql new file mode 100644 index 0000000000000..4cef7e4e0d87e --- /dev/null +++ b/administrator/components/com_admin/sql/others/mysql/nullDate-conversion.sql @@ -0,0 +1,176 @@ +ALTER TABLE `#__nullDate_conversion` CHANGE `converted` `converted` datetime NOT NULL DEFAULT $T$; +UPDATE `#__nullDate_conversion` SET `converted` = $T$; + +ALTER TABLE `#__banners` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__banners` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__banners` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__banners` CHANGE `reset` `reset` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `reset` = $T$ WHERE `reset` = $O$; + +ALTER TABLE `#__banners` CHANGE `created` `created` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `created` = $T$ WHERE `created` = $O$; + +ALTER TABLE `#__banners` CHANGE `modified` `modified` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banners` SET `modified` = $T$ WHERE `modified` = $O$; + +ALTER TABLE `#__banner_clients` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__banner_clients` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__categories` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__categories` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__categories` CHANGE `created_time` `created_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__categories` SET `created_time` = $T$ WHERE `created_time` = $O$; + +ALTER TABLE `#__categories` CHANGE `modified_time` `modified_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__categories` SET `modified_time` = $T$ WHERE `modified_time` = $O$; + +ALTER TABLE `#__contact_details` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__contact_details` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__contact_details` CHANGE `created` `created` datetime NOT NULL DEFAULT $T$; +UPDATE `#__contact_details` SET `created` = $T$ WHERE `created` = $O$; + +ALTER TABLE `#__contact_details` CHANGE `modified` `modified` datetime NOT NULL DEFAULT $T$; +UPDATE `#__contact_details` SET `modified` = $T$ WHERE `modified` = $O$; + +ALTER TABLE `#__contact_details` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__contact_details` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__contact_details` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__contact_details` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__content` CHANGE `created` `created` datetime NOT NULL DEFAULT $T$; +UPDATE `#__content` SET `created` = $T$ WHERE `created` = $O$; + +ALTER TABLE `#__content` CHANGE `modified` `modified` datetime NOT NULL DEFAULT $T$; +UPDATE `#__content` SET `modified` = $T$ WHERE `modified` = $O$; + +ALTER TABLE `#__content` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__content` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__content` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__content` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__content` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__content` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__menu` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__menu` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__extensions` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__extensions` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__finder_filters` CHANGE `created` `created` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_filters` SET `created` = $T$ WHERE `created` = $O$; + +ALTER TABLE `#__finder_filters` CHANGE `modified` `modified` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_filters` SET `modified` = $T$ WHERE `modified` = $O$; + +ALTER TABLE `#__finder_filters` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_filters` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__finder_links` CHANGE `indexdate` `indexdate` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_links` SET `indexdate` = $T$ WHERE `indexdate` = $O$; + +ALTER TABLE `#__finder_links` CHANGE `publish_start_date` `publish_start_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_links` SET `publish_start_date` = $T$ WHERE `publish_start_date` = $O$; + +ALTER TABLE `#__finder_links` CHANGE `publish_end_date` `publish_end_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_links` SET `publish_end_date` = $T$ WHERE `publish_end_date` = $O$; + +ALTER TABLE `#__finder_links` CHANGE `start_date` `start_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_links` SET `start_date` = $T$ WHERE `start_date` = $O$; + +ALTER TABLE `#__finder_links` CHANGE `end_date` `end_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__finder_links` SET `end_date` = $T$ WHERE `end_date` = $O$; + +ALTER TABLE `#__messages` CHANGE `date_time` `date_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__messages` SET `date_time` = $T$ WHERE `date_time` = $O$; + +ALTER TABLE `#__modules` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__modules` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__modules` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__modules` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__modules` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__modules` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__newsfeeds` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__newsfeeds` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__newsfeeds` CHANGE `created` `created` datetime NOT NULL DEFAULT $T$; +UPDATE `#__newsfeeds` SET `created` = $T$ WHERE `created` = $O$; + +ALTER TABLE `#__newsfeeds` CHANGE `modified` `modified` datetime NOT NULL DEFAULT $T$; +UPDATE `#__newsfeeds` SET `modified` = $T$ WHERE `modified` = $O$; + +ALTER TABLE `#__newsfeeds` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__newsfeeds` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__newsfeeds` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__newsfeeds` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__redirect_links` CHANGE `created_date` `created_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__redirect_links` SET `created_date` = $T$ WHERE `created_date` = $O$; + +ALTER TABLE `#__redirect_links` CHANGE `modified_date` `modified_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__redirect_links` SET `modified_date` = $T$ WHERE `modified_date` = $O$; + +ALTER TABLE `#__tags` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__tags` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__tags` CHANGE `created_time` `created_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__tags` SET `created_time` = $T$ WHERE `created_time` = $O$; + +ALTER TABLE `#__tags` CHANGE `modified_time` `modified_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__tags` SET `modified_time` = $T$ WHERE `modified_time` = $O$; + +ALTER TABLE `#__tags` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__tags` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__tags` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__tags` SET `publish_down` = $T$ WHERE `publish_down` = $O$; + +ALTER TABLE `#__ucm_content` CHANGE `core_created_time` `core_created_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__ucm_content` SET `core_created_time` = $T$ WHERE `core_created_time` = $O$; + +ALTER TABLE `#__ucm_content` CHANGE `core_modified_time` `core_modified_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__ucm_content` SET `core_modified_time` = $T$ WHERE `core_modified_time` = $O$; + +ALTER TABLE `#__ucm_history` CHANGE `save_date` `save_date` datetime NOT NULL DEFAULT $T$; +UPDATE `#__ucm_history` SET `save_date` = $T$ WHERE `save_date` = $O$; + +ALTER TABLE `#__users` CHANGE `registerDate` `registerDate` datetime NOT NULL DEFAULT $T$; +UPDATE `#__users` SET `registerDate` = $T$ WHERE `registerDate` = $O$; + +ALTER TABLE `#__users` CHANGE `lastvisitDate` `lastvisitDate` datetime NOT NULL DEFAULT $T$; +UPDATE `#__users` SET `lastvisitDate` = $T$ WHERE `lastvisitDate` = $O$; + +ALTER TABLE `#__users` CHANGE `lastResetTime` `lastResetTime` datetime NOT NULL DEFAULT $T$; +UPDATE `#__users` SET `lastResetTime` = $T$ WHERE `lastResetTime` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `checked_out_time` = $T$ WHERE `checked_out_time` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `created_time` `created_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `created_time` = $T$ WHERE `created_time` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `modified_time` `modified_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `modified_time` = $T$ WHERE `modified_time` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `review_time` `review_time` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `review_time` = $T$ WHERE `review_time` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `publish_up` `publish_up` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `publish_up` = $T$ WHERE `publish_up` = $O$; + +ALTER TABLE `#__user_notes` CHANGE `publish_down` `publish_down` datetime NOT NULL DEFAULT $T$; +UPDATE `#__user_notes` SET `publish_down` = $T$ WHERE `publish_down` = $O$; \ No newline at end of file diff --git a/administrator/components/com_admin/sql/updates/mysql/3.6.3-2016-08-10.sql b/administrator/components/com_admin/sql/updates/mysql/3.6.3-2016-08-10.sql new file mode 100755 index 0000000000000..5b389c20953b9 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/3.6.3-2016-08-10.sql @@ -0,0 +1 @@ +ALTER TABLE `#__menu` CHANGE `checked_out_time` `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'; \ No newline at end of file diff --git a/administrator/components/com_admin/sql/updates/mysql/3.7.0-2016-06-08.sql b/administrator/components/com_admin/sql/updates/mysql/3.7.0-2016-06-08.sql new file mode 100755 index 0000000000000..3c25c7401558c --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/3.7.0-2016-06-08.sql @@ -0,0 +1,13 @@ +-- +-- Table structure for table `#__nullDate_conversion` +-- + +CREATE TABLE IF NOT EXISTS `#__nullDate_conversion` ( + `converted` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +-- +-- Dumping data for table `#__nullDate_conversion` +-- + +INSERT INTO `#__nullDate_conversion` (`converted`) VALUES ('0000-00-00 00:00:00'); \ No newline at end of file diff --git a/administrator/components/com_installer/models/database.php b/administrator/components/com_installer/models/database.php old mode 100644 new mode 100755 index b4dc2e3ec3a88..24a88ca068627 --- a/administrator/components/com_installer/models/database.php +++ b/administrator/components/com_installer/models/database.php @@ -66,6 +66,7 @@ public function fix() $this->fixUpdateVersion(); $installer = new JoomlaInstallerScript; $installer->deleteUnexistingFiles(); + $installer->convertTablesToNewNullDate(); $this->fixDefaultTextFilters(); /* diff --git a/installation/model/database.php b/installation/model/database.php old mode 100644 new mode 100755 index a7fea7473faf5..ba12c0e46cb75 --- a/installation/model/database.php +++ b/installation/model/database.php @@ -652,6 +652,8 @@ public function createTables($options) } } + + // Handle default backend language setting. This feature is available for localized versions of Joomla. $app = JFactory::getApplication(); $languages = $app->getLocaliseAdmin($db); @@ -1022,7 +1024,16 @@ public function populateDatabase($db, $schema) * necessary, so there's no need to check the conditions in JInstaller. */ $query = $db->convertUtf8mb4QueryToUtf8($query); - + + /** + * If the Driver has set a nullDate which differs from the default (oldschool) nullDate + * replace it in the query + */ + if ($db->getNullDate()) + { + $query = $db->convertNullDate($query, $db->getNullDate()); + } + /** * This is a query which was supposed to convert tables to utf8mb4 charset but the server doesn't * support utf8mb4. Therefore we don't have to run it, it has no effect and it's a mere waste of time. diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql old mode 100644 new mode 100755 index 5fbfe52d4586f..a48783be62341 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -1469,6 +1469,23 @@ CREATE TABLE IF NOT EXISTS `#__newsfeeds` ( KEY `idx_xreference` (`xreference`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; +-- -------------------------------------------------------- + +-- +-- Table structure for table `#__nullDate_conversion` +-- + +CREATE TABLE IF NOT EXISTS `#__nullDate_conversion` ( + `converted` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +-- +-- Dumping data for table `#__nullDate_conversion` +-- + +INSERT INTO `#__nullDate_conversion` (`converted`) VALUES ('0000-00-00 00:00:00'); + + -- -------------------------------------------------------- -- diff --git a/libraries/cms/schema/changeitem/mysql.php b/libraries/cms/schema/changeitem/mysql.php index 673a5c65289d9..fdfb4e2d6c099 100644 --- a/libraries/cms/schema/changeitem/mysql.php +++ b/libraries/cms/schema/changeitem/mysql.php @@ -60,10 +60,12 @@ protected function buildCheckQuery() $command = strtoupper($wordArray[0] . ' ' . $wordArray[1]); // Check for special update statement to reset utf8mb4 conversion status - if (($command == 'UPDATE `#__UTF8_CONVERSION`' + if ((($command == 'UPDATE `#__UTF8_CONVERSION`' || $command == 'UPDATE #__UTF8_CONVERSION') && strtoupper($wordArray[2]) == 'SET' && strtolower(substr(str_replace('`', '', $wordArray[3]), 0, 9)) == 'converted') + || (($command == 'INSERT INTO `#__nullDate_conversion`') + && strtolower(substr(str_replace('`', '', $wordArray[3]), 0, 9)) == 'converted')) { // Statement is special statement to reset conversion status $this->queryType = 'UTF8CNV'; diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php old mode 100644 new mode 100755 index 8c5c5f12fb77d..17d15c0407498 --- a/libraries/joomla/database/driver.php +++ b/libraries/joomla/database/driver.php @@ -873,7 +873,26 @@ public function getAlterTableCharacterSet($tableName) return $queries; } - + + /** + * Automatically changes the null date in the Query File + * + * @param string $query The query to convert + * + * @param string $nullDate The used nullDate + * + * @return string The converted query + */ + public function convertNullDate($query,$nullDate) + { + if ($nullDate != '0000-00-00 00:00:00') + { + $query = str_replace('0000-00-00 00:00:00', $nullDate, $query); + } + + return $query; + } + /** * Automatically downgrade a CREATE TABLE or ALTER TABLE query from utf8mb4 (UTF-8 Multibyte) to plain utf8. Used * when the server doesn't support UTF-8 Multibyte. diff --git a/libraries/joomla/database/driver/mysqli.php b/libraries/joomla/database/driver/mysqli.php index b26e8423ee0a4..77125f357b8e6 100644 --- a/libraries/joomla/database/driver/mysqli.php +++ b/libraries/joomla/database/driver/mysqli.php @@ -194,6 +194,12 @@ public function connect() // Pre-populate the UTF-8 Multibyte compatibility flag based on server version $this->utf8mb4 = $this->serverClaimsUtf8mb4Support(); + + // Use different NullTime + if ($this->serverUsesNewNullDate()) + { + $this->nullDate = '1000-01-01 00:00:00'; + } // Set the character set (needed for MySQL 4.1.2+). $this->utf = $this->setUtf(); @@ -974,6 +980,21 @@ private function serverClaimsUtf8mb4Support() } } } + + /** + * Does the database server uses the new null time (1000-01-01 00:00:00) instead of the old one (0000-00-00 00:00:00) + * + * libmysql uses the new null time since 5.7 (same version as the MySQL server). + * + * @return boolean + * + * @since 12.2 + */ + public function serverUsesNewNullDate() + { + $server_version = $this->getVersion(); + return version_compare($server_version, '5.7.0', '>='); + } /** * Return the actual SQL Error number diff --git a/libraries/joomla/database/driver/pdomysql.php b/libraries/joomla/database/driver/pdomysql.php index 024b1e97578b2..e2a135e728989 100644 --- a/libraries/joomla/database/driver/pdomysql.php +++ b/libraries/joomla/database/driver/pdomysql.php @@ -45,21 +45,21 @@ class JDatabaseDriverPdomysql extends JDatabaseDriverPdo protected $nameQuote = '`'; /** - * The null or zero representation of a timestamp for the database driver. This should be - * defined in child classes to hold the appropriate value for the engine. + * The minimum supported database version. * * @var string * @since 3.4 */ - protected $nullDate = '0000-00-00 00:00:00'; + protected static $dbMinimum = '5.0.4'; /** - * The minimum supported database version. + * The null or zero representation of a timestamp for the database driver. This should be + * defined in child classes to hold the appropriate value for the engine. * * @var string * @since 3.4 */ - protected static $dbMinimum = '5.0.4'; + protected $nullDate = '0000-00-00 00:00:00'; /** * Constructor. @@ -130,15 +130,16 @@ public function connect() parent::connect(); } + $serverVersion = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); if ($this->utf8mb4) { /* * At this point we know the client supports utf8mb4. Now * we must check if the server supports utf8mb4 as well. */ - $serverVersion = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); + $this->utf8mb4 = version_compare($serverVersion, '5.5.3', '>='); - + if (!$this->utf8mb4) { // Reconnect with the utf8 character set. @@ -148,6 +149,14 @@ public function connect() } } + /* + * checking if the new null type format of myaql 5.7.0 is used + */ + if (version_compare($serverVersion, '5.7.0', '>=')) + { + $this->nullDate = '1000-01-01 00:00:00'; + } + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); @@ -166,6 +175,21 @@ public static function isSupported() { return class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers()); } + + /** + * Does the database server uses the new null time (1000-01-01 00:00:00) instead of the old one (0000-00-00 00:00:00) + * + * libmysql uses the new null time since 5.7 (same version as the MySQL server). + * + * @return boolean + * + * @since 12.2 + */ + public function serverUsesNewNullDate() + { + return ($this->nullDate == "1000-01-01 00:00:00"); + } + /** * Drops a table from the database.