You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MySqlTools.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }