MySqlTools.php 1.9 KB

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