MySqlTools.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017, ownCloud GmbH
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\DB;
  25. use OCP\IDBConnection;
  26. /**
  27. * Various MySQL specific helper functions.
  28. */
  29. class MySqlTools {
  30. /**
  31. * @param IDBConnection $connection
  32. * @return bool
  33. */
  34. public function supports4ByteCharset(IDBConnection $connection) {
  35. $variables = ['innodb_file_per_table' => 'ON'];
  36. if (!$this->isMariaDBWithLargePrefix($connection)) {
  37. $variables['innodb_file_format'] = 'Barracuda';
  38. $variables['innodb_large_prefix'] = 'ON';
  39. }
  40. foreach ($variables as $var => $val) {
  41. $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
  42. $row = $result->fetch();
  43. $result->closeCursor();
  44. if ($row === false) {
  45. return false;
  46. }
  47. if (strcasecmp($row['Value'], $val) !== 0) {
  48. return false;
  49. }
  50. }
  51. return true;
  52. }
  53. protected function isMariaDBWithLargePrefix(IDBConnection $connection) {
  54. $result = $connection->executeQuery('SELECT VERSION()');
  55. $row = strtolower($result->fetchColumn());
  56. $result->closeCursor();
  57. if ($row === false) {
  58. return false;
  59. }
  60. return strpos($row, 'maria') && version_compare($row, '10.3', '>=') ||
  61. strpos($row, 'maria') === false && version_compare($row, '8.0', '>=');
  62. }
  63. }