1
0

MySqlTools.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 ownCloud GmbH
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OC\DB;
  7. use OCP\IDBConnection;
  8. /**
  9. * Various MySQL specific helper functions.
  10. */
  11. class MySqlTools {
  12. /**
  13. * @param IDBConnection $connection
  14. * @return bool
  15. */
  16. public function supports4ByteCharset(IDBConnection $connection) {
  17. $variables = ['innodb_file_per_table' => 'ON'];
  18. if (!$this->isMariaDBWithLargePrefix($connection)) {
  19. $variables['innodb_file_format'] = 'Barracuda';
  20. $variables['innodb_large_prefix'] = 'ON';
  21. }
  22. foreach ($variables as $var => $val) {
  23. $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
  24. $row = $result->fetch();
  25. $result->closeCursor();
  26. if ($row === false) {
  27. return false;
  28. }
  29. if (strcasecmp($row['Value'], $val) !== 0) {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
  35. protected function isMariaDBWithLargePrefix(IDBConnection $connection) {
  36. $result = $connection->executeQuery('SELECT VERSION()');
  37. $row = strtolower($result->fetchColumn());
  38. $result->closeCursor();
  39. if ($row === false) {
  40. return false;
  41. }
  42. return str_contains($row, 'maria') && version_compare($row, '10.3', '>=') ||
  43. !str_contains($row, 'maria') && version_compare($row, '8.0', '>=');
  44. }
  45. }