diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-05-12 22:41:00 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-05-12 22:41:00 +0200 |
commit | 7e70eec5a37ddfe112e12b976821c5b944128d32 (patch) | |
tree | bc5c4b8d279474dc78207f72d65915d2b4ff1064 /phpBB/includes/db/driver/mysql_base.php | |
parent | f90ed6c3cb9e1b8baeb352a07b81608fa7c067b5 (diff) | |
parent | fe13b89dd4bd6d808d81c903e66fe869ccd43050 (diff) | |
download | forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.gz forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.bz2 forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.xz forums-7e70eec5a37ddfe112e12b976821c5b944128d32.zip |
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11465
Diffstat (limited to 'phpBB/includes/db/driver/mysql_base.php')
-rw-r--r-- | phpBB/includes/db/driver/mysql_base.php | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/phpBB/includes/db/driver/mysql_base.php b/phpBB/includes/db/driver/mysql_base.php new file mode 100644 index 0000000000..ba44ea61aa --- /dev/null +++ b/phpBB/includes/db/driver/mysql_base.php @@ -0,0 +1,145 @@ +<?php +/** +* +* @package dbal +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Abstract MySQL Database Base Abstraction Layer +* @package dbal +*/ +abstract class phpbb_db_driver_mysql_base extends phpbb_db_driver +{ + /** + * {@inheritDoc} + */ + public function sql_concatenate($expr1, $expr2) + { + return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; + } + + /** + * Build LIMIT query + */ + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + { + $this->query_result = false; + + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) + { + // MySQL 4.1+ no longer supports -1 in limit queries + $total = '18446744073709551615'; + } + + $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $cache_ttl); + } + + /** + * Gets the estimated number of rows in a specified table. + * + * @param string $table_name Table name + * + * @return string Number of rows in $table_name. + * Prefixed with ~ if estimated (otherwise exact). + * + * @access public + */ + function get_estimated_row_count($table_name) + { + $table_status = $this->get_table_status($table_name); + + if (isset($table_status['Engine'])) + { + if ($table_status['Engine'] === 'MyISAM') + { + return $table_status['Rows']; + } + else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000) + { + return '~' . $table_status['Rows']; + } + } + + return parent::get_row_count($table_name); + } + + /** + * Gets the exact number of rows in a specified table. + * + * @param string $table_name Table name + * + * @return string Exact number of rows in $table_name. + * + * @access public + */ + function get_row_count($table_name) + { + $table_status = $this->get_table_status($table_name); + + if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM') + { + return $table_status['Rows']; + } + + return parent::get_row_count($table_name); + } + + /** + * Gets some information about the specified table. + * + * @param string $table_name Table name + * + * @return array + * + * @access protected + */ + function get_table_status($table_name) + { + $sql = "SHOW TABLE STATUS + LIKE '" . $this->sql_escape($table_name) . "'"; + $result = $this->sql_query($sql); + $table_status = $this->sql_fetchrow($result); + $this->sql_freeresult($result); + + return $table_status; + } + + /** + * Build LIKE expression + * @access private + */ + function _sql_like_expression($expression) + { + return $expression; + } + + /** + * Build db-specific query data + * @access private + */ + function _sql_custom_build($stage, $data) + { + switch ($stage) + { + case 'FROM': + $data = '(' . $data . ')'; + break; + } + + return $data; + } +} |