MySqlTools.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 str_contains($row, 'maria') && version_compare($row, '10.3', '>=') ||
  61. !str_contains($row, 'maria') && version_compare($row, '8.0', '>=');
  62. }
  63. }