Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| mysql_base | |
0.00% |
0 / 26 |
|
0.00% |
0 / 6 |
272 | |
0.00% |
0 / 1 |
| sql_concatenate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| _sql_query_limit | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| get_estimated_row_count | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| get_row_count | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| get_table_status | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| _sql_custom_build | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\db\driver; |
| 15 | |
| 16 | /** |
| 17 | * Abstract MySQL Database Base Abstraction Layer |
| 18 | */ |
| 19 | abstract class mysql_base extends \phpbb\db\driver\driver |
| 20 | { |
| 21 | /** |
| 22 | * {@inheritDoc} |
| 23 | */ |
| 24 | public function sql_concatenate($expr1, $expr2) |
| 25 | { |
| 26 | return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * {@inheritDoc} |
| 31 | */ |
| 32 | protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) |
| 33 | { |
| 34 | $this->query_result = false; |
| 35 | |
| 36 | // if $total is set to 0 we do not want to limit the number of rows |
| 37 | if ($total == 0) |
| 38 | { |
| 39 | // MySQL 4.1+ no longer supports -1 in limit queries |
| 40 | $total = '18446744073709551615'; |
| 41 | } |
| 42 | |
| 43 | $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); |
| 44 | |
| 45 | return $this->sql_query($query, $cache_ttl); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * {@inheritDoc} |
| 50 | */ |
| 51 | function get_estimated_row_count($table_name) |
| 52 | { |
| 53 | $table_status = $this->get_table_status($table_name); |
| 54 | |
| 55 | if (isset($table_status['Engine'])) |
| 56 | { |
| 57 | if ($table_status['Engine'] === 'MyISAM') |
| 58 | { |
| 59 | return $table_status['Rows']; |
| 60 | } |
| 61 | else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000) |
| 62 | { |
| 63 | return '~' . $table_status['Rows']; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return parent::get_row_count($table_name); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * {@inheritDoc} |
| 72 | */ |
| 73 | function get_row_count($table_name) |
| 74 | { |
| 75 | $table_status = $this->get_table_status($table_name); |
| 76 | |
| 77 | if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM') |
| 78 | { |
| 79 | return $table_status['Rows']; |
| 80 | } |
| 81 | |
| 82 | return parent::get_row_count($table_name); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Gets some information about the specified table. |
| 87 | * |
| 88 | * @param string $table_name Table name |
| 89 | * |
| 90 | * @return array |
| 91 | * |
| 92 | * @access protected |
| 93 | */ |
| 94 | function get_table_status($table_name) |
| 95 | { |
| 96 | $sql = "SHOW TABLE STATUS |
| 97 | LIKE '" . $this->sql_escape($table_name) . "'"; |
| 98 | $result = $this->sql_query($sql); |
| 99 | $table_status = $this->sql_fetchrow($result); |
| 100 | $this->sql_freeresult($result); |
| 101 | |
| 102 | return $table_status; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * {@inheritDoc} |
| 107 | */ |
| 108 | protected function _sql_custom_build(string $stage, $data) |
| 109 | { |
| 110 | if ($stage === 'FROM' && is_string($data)) |
| 111 | { |
| 112 | $data = '(' . $data . ')'; |
| 113 | } |
| 114 | |
| 115 | return $data; |
| 116 | } |
| 117 | } |