From 85055ac97fa57ca339924cef719115d85bdf6c2e Mon Sep 17 00:00:00 2001 From: David M Date: Thu, 3 Jan 2008 17:00:40 +0000 Subject: oh boy... - Migrate code base to PHP 5.1+ git-svn-id: file:///svn/phpbb/trunk@8295 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index bb689a7394..0ac27023f3 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -82,21 +82,7 @@ class dbal_postgres extends dbal if ($this->db_connect_id) { // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ - if (version_compare(PHP_VERSION, '5.0.0', '>=')) - { - $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); - } - else - { - $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()'); - $row = @pg_fetch_assoc($query_id, null); - @pg_free_result($query_id); - - if (!empty($row['version'])) - { - $this->pgsql_version = substr($row['version'], 10); - } - } + $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') { @@ -172,7 +158,7 @@ class dbal_postgres extends dbal if ($this->query_result === false) { - if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false) + if (($this->query_result = pg_query($this->db_connect_id, $query)) === false) { $this->sql_error($query); } -- cgit v1.2.1 From af738dbc2a48713f59779410955282aa5760b741 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 4 Jan 2008 18:35:49 +0000 Subject: Ch-ch-ch-changes - Made us more DB independent by making many queries capability based instead of DB specific - Finished PHP5ifying of the acm_file class, now with some (hopefully) enhancements to its performance - Sped up viewforum considerably (also goes towards mcp_forum) I really hope I didn't explode CVS... git-svn-id: file:///svn/phpbb/trunk@8301 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 0ac27023f3..0f946c2d7c 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -27,7 +27,7 @@ class dbal_postgres extends dbal { var $last_query_text = ''; var $pgsql_version; - + /** * Connect to server */ @@ -84,9 +84,17 @@ class dbal_postgres extends dbal // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); - if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') + if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8') { - $this->multi_insert = true; + if ($this->pgsql_version[2] >= '1') + { + $this->multi_table_deletion = true; + } + + if ($this->pgsql_version[2] >= '2') + { + $this->multi_insert = true; + } } if ($schema !== '') @@ -331,6 +339,20 @@ class dbal_postgres extends dbal return @pg_escape_string($msg); } + /** + * Expose a DBMS specific function + */ + function sql_function($type, $col) + { + switch ($type) + { + case 'length_varchar': + case 'length_text': + return 'LENGTH(' . $col . ')'; + break; + } + } + /** * Build LIKE expression * @access private -- cgit v1.2.1 From 2928574ed46334bb8dbbb6612a62db3c3654ba12 Mon Sep 17 00:00:00 2001 From: David M Date: Mon, 7 Jan 2008 15:19:38 +0000 Subject: - a few tiny clean ups - a new MS SQL DBAL, it does not work so hot because of issues with the extension it depends on git-svn-id: file:///svn/phpbb/trunk@8313 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 0f946c2d7c..023a8fda1b 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -28,6 +28,8 @@ class dbal_postgres extends dbal var $last_query_text = ''; var $pgsql_version; + var $dbms_type = 'postgres'; + /** * Connect to server */ -- cgit v1.2.1 From 7b262babcd5c862c3068b08da8bba5f48bd5f36a Mon Sep 17 00:00:00 2001 From: David M Date: Sun, 3 Feb 2008 10:19:04 +0000 Subject: Alright, this should give some improved performance :) This is the end of random seek access to rows. If you have a compelling reason as to why they should stay, contact me. Else, they are gone forevermore... The following API calls are deprecated: acm::sql_rowseek() -> no replacement $db->sql_fetchfield($field, $rownum = false, $query_id = false) -> $db->sql_fetchfield($field, $query_id = false) Initial tests show that phpBB3 over four percent of memory against phpBB3.1 on an empty board. So far so good :) Other cool things: db2, MS SQL ODBC and MS SQL 2005 all use less memory because they do not need to reference the last executed query to handle random access seeks :) P.S. The crazy people using SVN: please report any issues with the new way we itterate through caches, I do not want to miss anything :) git-svn-id: file:///svn/phpbb/trunk@8372 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 023a8fda1b..0cce581558 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -256,27 +256,6 @@ class dbal_postgres extends dbal return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false; } - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false; - } - /** * Get last inserted id after insert statement */ -- cgit v1.2.1 From 2deee69e2f9ecd239e59bf651e73c6780227c824 Mon Sep 17 00:00:00 2001 From: David M Date: Wed, 2 Apr 2008 08:28:21 +0000 Subject: Some neat stuff, the new DBAL function has the potential of removing somewhere in the ballpark of 40% of all the DBAL code. It combines a few very common idioms into one statement, allowing us to implicitly use prepared statements. Short term advantages are the ability to remove the gross code that attempts to work around DB2, Oracle and Firebird. Long term advantages include removing the burden of sanitizing data (at least on input) from our end and placing it on shoulders of the backend PHP driver. Also included is a new posting API I am working on. It is not a real API in so much as it is a backend that a "nice" API could use. User submitted functions are welcome :) It represents a massive simplification in post and topic accounting and a generalization of concepts like "soft deletion" as it works across both topics and posts (yes, this has preliminary support for soft deletions). The only "interesting" problem left is global topics, this has yet to be solved. Enough talk, time for sleep. P.S. Sorry if I broke stuff, was not done on purpose :) git-svn-id: file:///svn/phpbb/trunk@8485 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 0cce581558..f4237999ff 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -334,6 +334,41 @@ class dbal_postgres extends dbal } } + function sql_handle_data($type, $table, $data, $where = '') + { + // for now, stmtname is an empty string, it might change to something more unique in the future + if ($type === 'INSERT') + { + $stmt = pg_prepare($this->dbms_type, '', "INSERT INTO $table (". implode(', ', array_keys($data)) . ") VALUES ($" . implode(', $', range(1, sizeof($data))) . ')'); + } + else + { + $query = "UPDATE $table SET "; + + $set = array(); + foreach (array_keys($data) as $key_id => $key) + { + $set[] = $key . ' = $' . $key_id; + } + $query .= implode(', ', $set); + + if ($where !== '') + { + $query .= $where; + } + + $stmt = pg_prepare($this->db_connect_id, '', $query); + } + + // add the stmtname to the top + array_unshift($data, ''); + + // add the connection resource + array_unshift($data, $this->db_connect_id); + + call_user_func_array('pg_execute', $data); + } + /** * Build LIKE expression * @access private -- cgit v1.2.1 From 2f4a618900e2c3b6ea14c68cbeb5897cd2ac1a04 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 May 2008 12:25:56 +0000 Subject: ok... i hope i haven't messed too much with the code and everything is still working. Changes: - Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed. - A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added. git-svn-id: file:///svn/phpbb/trunk@8572 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index f4237999ff..4c3e4729fa 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) exit; } -include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); /** * PostgreSQL Database Abstraction Layer -- cgit v1.2.1 From f2abefeaed267a405ae1ccafba7ce2a52794fadc Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 2 Sep 2008 13:36:48 +0000 Subject: Merge in r8758, r8807, r8808, r8809 git-svn-id: file:///svn/phpbb/trunk@8810 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 4c3e4729fa..8ac0fa8300 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -198,7 +198,7 @@ class dbal_postgres extends dbal return false; } - return ($this->query_result) ? $this->query_result : false; + return $this->query_result; } /** -- cgit v1.2.1 From 3a330753f413c3e024163f8f401f327bc2f9930c Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 4 Sep 2008 14:10:03 +0000 Subject: Get real dbms version instead of relying on php internal functions which only grab the local library version git-svn-id: file:///svn/phpbb/trunk@8821 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 8ac0fa8300..2f6b5613c5 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -26,7 +26,6 @@ include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); class dbal_postgres extends dbal { var $last_query_text = ''; - var $pgsql_version; var $dbms_type = 'postgres'; @@ -83,26 +82,17 @@ class dbal_postgres extends dbal if ($this->db_connect_id) { - // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ - $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); - - if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8') + if (version_compare($this->sql_server_info(true), '8.2', '>=')) { - if ($this->pgsql_version[2] >= '1') - { - $this->multi_table_deletion = true; - } - - if ($this->pgsql_version[2] >= '2') - { - $this->multi_insert = true; - } + $this->multi_table_deletion = true; + $this->multi_insert = true; } if ($schema !== '') { @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); } + return $this->db_connect_id; } @@ -111,10 +101,28 @@ class dbal_postgres extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'PostgreSQL ' . $this->pgsql_version; + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) + { + $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @pg_fetch_assoc($query_id, null); + @pg_free_result($query_id); + + $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; + + if (!empty($cache)) + { + $cache->put('pgsql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; } /** -- cgit v1.2.1 From d61459fce32d53926498ebc8d8d2274134fc5994 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 21 Jan 2009 17:06:54 +0000 Subject: PostgreSQL support git-svn-id: file:///svn/phpbb/trunk@9289 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 369 +++++++++++++++++------------------------ 1 file changed, 153 insertions(+), 216 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 2f6b5613c5..5074ce55f4 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -16,99 +16,128 @@ if (!defined('IN_PHPBB')) exit; } -include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); - /** * PostgreSQL Database Abstraction Layer -* Minimum Requirement is Version 7.3+ +* Minimum Requirement: 8.2+ * @package dbal */ -class dbal_postgres extends dbal +class phpbb_dbal_postgres extends phpbb_dbal { - var $last_query_text = ''; + /** + * @var string Database type. No distinction between versions or used extensions. + */ + public $dbms_type = 'postgres'; + + /** + * @var array Database type map, column layout information + */ + public $dbms_type_map = array( + 'INT:' => 'INT4', + 'BINT' => 'INT8', + 'UINT' => 'INT4', // unsigned + 'UINT:' => 'INT4', // unsigned + 'USINT' => 'INT2', // unsigned + 'BOOL' => 'INT2', // unsigned + 'TINT:' => 'INT2', + 'VCHAR' => 'varchar(255)', + 'VCHAR:' => 'varchar(%d)', + 'CHAR:' => 'char(%d)', + 'XSTEXT' => 'varchar(1000)', + 'STEXT' => 'varchar(3000)', + 'TEXT' => 'varchar(8000)', + 'MTEXT' => 'TEXT', + 'XSTEXT_UNI'=> 'varchar(100)', + 'STEXT_UNI' => 'varchar(255)', + 'TEXT_UNI' => 'varchar(4000)', + 'MTEXT_UNI' => 'TEXT', + 'TIMESTAMP' => 'INT4', // unsigned + 'DECIMAL' => 'decimal(5,2)', + 'DECIMAL:' => 'decimal(%d,2)', + 'PDECIMAL' => 'decimal(6,3)', + 'PDECIMAL:' => 'decimal(%d,3)', + 'VCHAR_UNI' => 'varchar(255)', + 'VCHAR_UNI:'=> 'varchar(%d)', + 'VARBINARY' => 'bytea', + ); - var $dbms_type = 'postgres'; + /** + * @var string PostgreSQL schema (if supplied with $database -> database.schema) + */ + public $schema = ''; /** - * Connect to server + * Connect to server. See {@link phpbb_dbal::sql_connect() sql_connect()} for details. */ - function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) + public function sql_connect($server, $user, $password, $database, $port = false, $persistency = false , $new_link = false) { + $this->persistency = $persistency; + $this->user = $user; + $this->server = $server; + $this->dbname = $database; + $this->port = $port; + $connect_string = ''; - if ($sqluser) + if ($this->user) { - $connect_string .= "user=$sqluser "; + $connect_string .= 'user=' . $this->user . ' '; } - if ($sqlpassword) + if ($password) { - $connect_string .= "password=$sqlpassword "; + $connect_string .= 'password=' . $password . ' '; } - if ($sqlserver) + if ($this->server) { - if (strpos($sqlserver, ':') !== false) + if (strpos($this->server, ':') !== false) { - list($sqlserver, $port) = explode(':', $sqlserver); + list($this->server, $this->port) = explode(':', $this->server, 2); } - if ($sqlserver !== 'localhost') + if ($this->server !== 'localhost') { - $connect_string .= "host=$sqlserver "; + $connect_string .= 'host=' . $this->server . ' '; } - - if ($port) + + if ($this->port) { - $connect_string .= "port=$port "; + $connect_string .= 'port=' . $this->port . ' '; } } - $schema = ''; + $this->schema = ''; - if ($database) + if ($this->dbname) { - $this->dbname = $database; - if (strpos($database, '.') !== false) + if (strpos($this->dbname, '.') !== false) { - list($database, $schema) = explode('.', $database); + list($this->dbname, $this->schema) = explode('.', $this->dbname, 2); } - $connect_string .= "dbname=$database"; + $connect_string .= 'dbname=' . $this->dbname; } - $this->persistency = $persistency; - - $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link); + $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, ($new_link) ? PGSQL_CONNECT_FORCE_NEW : false) : @pg_connect($connect_string, ($new_link) ? PGSQL_CONNECT_FORCE_NEW : false); - if ($this->db_connect_id) + if (!$this->db_connect_id) { - if (version_compare($this->sql_server_info(true), '8.2', '>=')) - { - $this->multi_table_deletion = true; - $this->multi_insert = true; - } - - if ($schema !== '') - { - @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); - } + return $this->sql_error(htmlspecialchars_decode(phpbb::$last_notice['message'])); + } - return $this->db_connect_id; + if ($this->schema) + { + @pg_query($this->db_connect_id, 'SET search_path TO ' . $this->schema); } - return $this->sql_error(''); + return $this->db_connect_id; } /** - * Version information about used database - * @param bool $raw if true, only return the fetched sql_server_version - * @return string sql server version + * Version information about used database. See {@link phpbb_dbal::sql_server_info() sql_server_info()} for details. */ - function sql_server_info($raw = false) + public function sql_server_info($raw = false) { - global $cache; - - if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) + if (!phpbb::registered('acm') || ($this->sql_server_version = phpbb::$acm->get('#pgsql_version')) === false) { $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); $row = @pg_fetch_assoc($query_id, null); @@ -116,9 +145,9 @@ class dbal_postgres extends dbal $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; - if (!empty($cache)) + if (phpbb::registered('acm')) { - $cache->put('pgsql_version', $this->sql_server_version); + phpbb::$acm->put('#pgsql_version', $this->sql_server_version); } } @@ -126,212 +155,128 @@ class dbal_postgres extends dbal } /** - * SQL Transaction - * @access private + * DB-specific base query method. See {@link phpbb_dbal::_sql_query() _sql_query()} for details. */ - function _sql_transaction($status = 'begin') + protected function _sql_query($query) { - switch ($status) - { - case 'begin': - return @pg_query($this->db_connect_id, 'BEGIN'); - break; - - case 'commit': - return @pg_query($this->db_connect_id, 'COMMIT'); - break; - - case 'rollback': - return @pg_query($this->db_connect_id, 'ROLLBACK'); - break; - } - - return true; + return @pg_query($this->db_connect_id, $query); } /** - * Base query method - * - * @param string $query Contains the SQL query which shall be executed - * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache - * @return mixed When casted to bool the returned value returns true on success and false on failure - * - * @access public + * Build LIMIT query and run it. See {@link phpbb_dbal::_sql_query_limit() _sql_query_limit()} for details. */ - function sql_query($query = '', $cache_ttl = 0) + protected function _sql_query_limit($query, $total, $offset, $cache_ttl) { - if ($query != '') - { - global $cache; - - // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('start', $query); - } - - $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; - $this->sql_add_num_queries($this->query_result); - - if ($this->query_result === false) - { - if (($this->query_result = pg_query($this->db_connect_id, $query)) === false) - { - $this->sql_error($query); - } - - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('stop', $query); - } - - if ($cache_ttl && method_exists($cache, 'sql_save')) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); - } - else if (strpos($query, 'SELECT') === 0 && $this->query_result) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - } - } - else if (defined('DEBUG_EXTRA')) - { - $this->sql_report('fromcache', $query); - } - } - else + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) { - return false; + $total = -1; } - return $this->query_result; + $query .= "\n LIMIT $total OFFSET $offset"; + return $this->sql_query($query, $cache_ttl); } /** - * Build db-specific query data - * @access private + * Close sql connection. See {@link phpbb_dbal::_sql_close() _sql_close()} for details. */ - function _sql_custom_build($stage, $data) + protected function _sql_close() { - return $data; + return @pg_close($this->db_connect_id); } /** - * Build LIMIT query + * SQL Transaction. See {@link phpbb_dbal::_sql_transaction() _sql_transaction()} for details. */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + protected function _sql_transaction($status) { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) + switch ($status) { - $total = -1; - } + case 'begin': + return @pg_query($this->db_connect_id, 'BEGIN'); + break; - $query .= "\n LIMIT $total OFFSET $offset"; + case 'commit': + return @pg_query($this->db_connect_id, 'COMMIT'); + break; - return $this->sql_query($query, $cache_ttl); + case 'rollback': + return @pg_query($this->db_connect_id, 'ROLLBACK'); + break; + } + + return true; } /** - * Return number of affected rows + * Return number of affected rows. See {@link phpbb_dbal::sql_affectedrows() sql_affectedrows()} for details. */ - function sql_affectedrows() + public function sql_affectedrows() { return ($this->query_result) ? @pg_affected_rows($this->query_result) : false; } /** - * Fetch current row + * Get last inserted id after insert statement. See {@link phpbb_dbal::sql_nextid() sql_nextid()} for details. */ - function sql_fetchrow($query_id = false) + public function sql_nextid() { - global $cache; - - if ($query_id === false) + if (!$this->db_connect_id) { - $query_id = $this->query_result; + return false; } - if (isset($cache->sql_rowset[$query_id])) + $query = "SELECT lastval() AS last_value"; + $temp_q_id = @pg_query($this->db_connect_id, $query); + + if (!$temp_q_id) { - return $cache->sql_fetchrow($query_id); + return false; } - return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false; + $temp_result = @pg_fetch_assoc($temp_q_id, NULL); + @pg_free_result($query_id); + + return ($temp_result) ? $temp_result['last_value'] : false; } /** - * Get last inserted id after insert statement + * Fetch current row. See {@link phpbb_dbal::_sql_fetchrow() _sql_fetchrow()} for details. */ - function sql_nextid() + protected function _sql_fetchrow($query_id) { - $query_id = $this->query_result; - - if ($query_id !== false && $this->last_query_text != '') - { - if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename)) - { - $query = "SELECT currval('" . $tablename[1] . "_seq') AS last_value"; - $temp_q_id = @pg_query($this->db_connect_id, $query); - - if (!$temp_q_id) - { - return false; - } - - $temp_result = @pg_fetch_assoc($temp_q_id, NULL); - @pg_free_result($query_id); - - return ($temp_result) ? $temp_result['last_value'] : false; - } - } - - return false; + return @pg_fetch_assoc($query_id, null); } /** - * Free sql result + * Free query result. See {@link phpbb_dbal::_sql_freeresult() _sql_freeresult()} for details. */ - function sql_freeresult($query_id = false) + protected function _sql_freeresult($query_id) { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_freeresult($query_id); - } - - if (isset($this->open_queries[(int) $query_id])) - { - unset($this->open_queries[(int) $query_id]); - return @pg_free_result($query_id); - } + return @pg_free_result($query_id); + } - return false; + /** + * Correctly adjust LIKE expression for special characters. See {@link phpbb_dbal::_sql_like_expression() _sql_like_expression()} for details. + */ + protected function _sql_like_expression($expression) + { + return $expression; } /** - * Escape string used in sql query + * Escape string used in sql query. See {@link phpbb_dbal::sql_escape() sql_escape()} for details. * Note: Do not use for bytea values if we may use them at a later stage */ - function sql_escape($msg) + public function sql_escape($msg) { return @pg_escape_string($msg); } /** - * Expose a DBMS specific function + * Expose a DBMS specific function. See {@link phpbb_dbal::sql_function() sql_function()} for details. */ - function sql_function($type, $col) + public function sql_function($type, $col) { switch ($type) { @@ -342,7 +287,10 @@ class dbal_postgres extends dbal } } - function sql_handle_data($type, $table, $data, $where = '') +/* + /** + * Handle data by using prepared statements. See {@link phpbb_dbal::sql_handle_data() sql_handle_data()} for details. + public function sql_handle_data($type, $table, $data, $where = '') { // for now, stmtname is an empty string, it might change to something more unique in the future if ($type === 'INSERT') @@ -364,7 +312,7 @@ class dbal_postgres extends dbal { $query .= $where; } - + $stmt = pg_prepare($this->db_connect_id, '', $query); } @@ -376,21 +324,20 @@ class dbal_postgres extends dbal call_user_func_array('pg_execute', $data); } +*/ /** - * Build LIKE expression - * @access private + * Build DB-specific query bits. See {@link phpbb_dbal::_sql_custom_build() _sql_custom_build()} for details. */ - function _sql_like_expression($expression) + protected function _sql_custom_build($stage, $data) { - return $expression; + return $data; } /** - * return sql error array - * @access private + * return sql error array. See {@link phpbb_dbal::_sql_error() _sql_error()} for details. */ - function _sql_error() + protected function _sql_error() { return array( 'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id), @@ -399,19 +346,9 @@ class dbal_postgres extends dbal } /** - * Close sql connection - * @access private - */ - function _sql_close() - { - return @pg_close($this->db_connect_id); - } - - /** - * Build db-specific report - * @access private + * Run DB-specific code to build SQL Report to explain queries, show statistics and runtime information. See {@link phpbb_dbal::_sql_report() _sql_report()} for details. */ - function _sql_report($mode, $query = '') + protected function _sql_report($mode, $query = '') { switch ($mode) { -- cgit v1.2.1 From e3d98fe77b1f2c60ceefa0ddf9091d08815d1f89 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 30 Mar 2009 10:44:52 +0000 Subject: fix LIMIT ALL in postgres layer git-svn-id: file:///svn/phpbb/trunk@9413 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 5074ce55f4..d74a8167e9 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -170,7 +170,7 @@ class phpbb_dbal_postgres extends phpbb_dbal // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { - $total = -1; + $total = 'ALL'; } $query .= "\n LIMIT $total OFFSET $offset"; -- cgit v1.2.1 From bf8ac19eaa8d74f9dfd6d597190f5664e7339382 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:13:59 +0000 Subject: Move trunk/phpBB to old_trunk/phpBB git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 409 ----------------------------------------- 1 file changed, 409 deletions(-) delete mode 100644 phpBB/includes/db/postgres.php (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php deleted file mode 100644 index d74a8167e9..0000000000 --- a/phpBB/includes/db/postgres.php +++ /dev/null @@ -1,409 +0,0 @@ - 'INT4', - 'BINT' => 'INT8', - 'UINT' => 'INT4', // unsigned - 'UINT:' => 'INT4', // unsigned - 'USINT' => 'INT2', // unsigned - 'BOOL' => 'INT2', // unsigned - 'TINT:' => 'INT2', - 'VCHAR' => 'varchar(255)', - 'VCHAR:' => 'varchar(%d)', - 'CHAR:' => 'char(%d)', - 'XSTEXT' => 'varchar(1000)', - 'STEXT' => 'varchar(3000)', - 'TEXT' => 'varchar(8000)', - 'MTEXT' => 'TEXT', - 'XSTEXT_UNI'=> 'varchar(100)', - 'STEXT_UNI' => 'varchar(255)', - 'TEXT_UNI' => 'varchar(4000)', - 'MTEXT_UNI' => 'TEXT', - 'TIMESTAMP' => 'INT4', // unsigned - 'DECIMAL' => 'decimal(5,2)', - 'DECIMAL:' => 'decimal(%d,2)', - 'PDECIMAL' => 'decimal(6,3)', - 'PDECIMAL:' => 'decimal(%d,3)', - 'VCHAR_UNI' => 'varchar(255)', - 'VCHAR_UNI:'=> 'varchar(%d)', - 'VARBINARY' => 'bytea', - ); - - /** - * @var string PostgreSQL schema (if supplied with $database -> database.schema) - */ - public $schema = ''; - - /** - * Connect to server. See {@link phpbb_dbal::sql_connect() sql_connect()} for details. - */ - public function sql_connect($server, $user, $password, $database, $port = false, $persistency = false , $new_link = false) - { - $this->persistency = $persistency; - $this->user = $user; - $this->server = $server; - $this->dbname = $database; - $this->port = $port; - - $connect_string = ''; - - if ($this->user) - { - $connect_string .= 'user=' . $this->user . ' '; - } - - if ($password) - { - $connect_string .= 'password=' . $password . ' '; - } - - if ($this->server) - { - if (strpos($this->server, ':') !== false) - { - list($this->server, $this->port) = explode(':', $this->server, 2); - } - - if ($this->server !== 'localhost') - { - $connect_string .= 'host=' . $this->server . ' '; - } - - if ($this->port) - { - $connect_string .= 'port=' . $this->port . ' '; - } - } - - $this->schema = ''; - - if ($this->dbname) - { - if (strpos($this->dbname, '.') !== false) - { - list($this->dbname, $this->schema) = explode('.', $this->dbname, 2); - } - $connect_string .= 'dbname=' . $this->dbname; - } - - $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, ($new_link) ? PGSQL_CONNECT_FORCE_NEW : false) : @pg_connect($connect_string, ($new_link) ? PGSQL_CONNECT_FORCE_NEW : false); - - if (!$this->db_connect_id) - { - return $this->sql_error(htmlspecialchars_decode(phpbb::$last_notice['message'])); - } - - if ($this->schema) - { - @pg_query($this->db_connect_id, 'SET search_path TO ' . $this->schema); - } - - return $this->db_connect_id; - } - - /** - * Version information about used database. See {@link phpbb_dbal::sql_server_info() sql_server_info()} for details. - */ - public function sql_server_info($raw = false) - { - if (!phpbb::registered('acm') || ($this->sql_server_version = phpbb::$acm->get('#pgsql_version')) === false) - { - $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); - $row = @pg_fetch_assoc($query_id, null); - @pg_free_result($query_id); - - $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; - - if (phpbb::registered('acm')) - { - phpbb::$acm->put('#pgsql_version', $this->sql_server_version); - } - } - - return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; - } - - /** - * DB-specific base query method. See {@link phpbb_dbal::_sql_query() _sql_query()} for details. - */ - protected function _sql_query($query) - { - return @pg_query($this->db_connect_id, $query); - } - - /** - * Build LIMIT query and run it. See {@link phpbb_dbal::_sql_query_limit() _sql_query_limit()} for details. - */ - protected function _sql_query_limit($query, $total, $offset, $cache_ttl) - { - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - $total = 'ALL'; - } - - $query .= "\n LIMIT $total OFFSET $offset"; - return $this->sql_query($query, $cache_ttl); - } - - /** - * Close sql connection. See {@link phpbb_dbal::_sql_close() _sql_close()} for details. - */ - protected function _sql_close() - { - return @pg_close($this->db_connect_id); - } - - /** - * SQL Transaction. See {@link phpbb_dbal::_sql_transaction() _sql_transaction()} for details. - */ - protected function _sql_transaction($status) - { - switch ($status) - { - case 'begin': - return @pg_query($this->db_connect_id, 'BEGIN'); - break; - - case 'commit': - return @pg_query($this->db_connect_id, 'COMMIT'); - break; - - case 'rollback': - return @pg_query($this->db_connect_id, 'ROLLBACK'); - break; - } - - return true; - } - - /** - * Return number of affected rows. See {@link phpbb_dbal::sql_affectedrows() sql_affectedrows()} for details. - */ - public function sql_affectedrows() - { - return ($this->query_result) ? @pg_affected_rows($this->query_result) : false; - } - - /** - * Get last inserted id after insert statement. See {@link phpbb_dbal::sql_nextid() sql_nextid()} for details. - */ - public function sql_nextid() - { - if (!$this->db_connect_id) - { - return false; - } - - $query = "SELECT lastval() AS last_value"; - $temp_q_id = @pg_query($this->db_connect_id, $query); - - if (!$temp_q_id) - { - return false; - } - - $temp_result = @pg_fetch_assoc($temp_q_id, NULL); - @pg_free_result($query_id); - - return ($temp_result) ? $temp_result['last_value'] : false; - } - - /** - * Fetch current row. See {@link phpbb_dbal::_sql_fetchrow() _sql_fetchrow()} for details. - */ - protected function _sql_fetchrow($query_id) - { - return @pg_fetch_assoc($query_id, null); - } - - /** - * Free query result. See {@link phpbb_dbal::_sql_freeresult() _sql_freeresult()} for details. - */ - protected function _sql_freeresult($query_id) - { - return @pg_free_result($query_id); - } - - /** - * Correctly adjust LIKE expression for special characters. See {@link phpbb_dbal::_sql_like_expression() _sql_like_expression()} for details. - */ - protected function _sql_like_expression($expression) - { - return $expression; - } - - /** - * Escape string used in sql query. See {@link phpbb_dbal::sql_escape() sql_escape()} for details. - * Note: Do not use for bytea values if we may use them at a later stage - */ - public function sql_escape($msg) - { - return @pg_escape_string($msg); - } - - /** - * Expose a DBMS specific function. See {@link phpbb_dbal::sql_function() sql_function()} for details. - */ - public function sql_function($type, $col) - { - switch ($type) - { - case 'length_varchar': - case 'length_text': - return 'LENGTH(' . $col . ')'; - break; - } - } - -/* - /** - * Handle data by using prepared statements. See {@link phpbb_dbal::sql_handle_data() sql_handle_data()} for details. - public function sql_handle_data($type, $table, $data, $where = '') - { - // for now, stmtname is an empty string, it might change to something more unique in the future - if ($type === 'INSERT') - { - $stmt = pg_prepare($this->dbms_type, '', "INSERT INTO $table (". implode(', ', array_keys($data)) . ") VALUES ($" . implode(', $', range(1, sizeof($data))) . ')'); - } - else - { - $query = "UPDATE $table SET "; - - $set = array(); - foreach (array_keys($data) as $key_id => $key) - { - $set[] = $key . ' = $' . $key_id; - } - $query .= implode(', ', $set); - - if ($where !== '') - { - $query .= $where; - } - - $stmt = pg_prepare($this->db_connect_id, '', $query); - } - - // add the stmtname to the top - array_unshift($data, ''); - - // add the connection resource - array_unshift($data, $this->db_connect_id); - - call_user_func_array('pg_execute', $data); - } -*/ - - /** - * Build DB-specific query bits. See {@link phpbb_dbal::_sql_custom_build() _sql_custom_build()} for details. - */ - protected function _sql_custom_build($stage, $data) - { - return $data; - } - - /** - * return sql error array. See {@link phpbb_dbal::_sql_error() _sql_error()} for details. - */ - protected function _sql_error() - { - return array( - 'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id), - 'code' => '' - ); - } - - /** - * Run DB-specific code to build SQL Report to explain queries, show statistics and runtime information. See {@link phpbb_dbal::_sql_report() _sql_report()} for details. - */ - protected function _sql_report($mode, $query = '') - { - switch ($mode) - { - case 'start': - - $explain_query = $query; - if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) - { - $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; - } - else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) - { - $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; - } - - if (preg_match('/^SELECT/', $explain_query)) - { - $html_table = false; - - if ($result = @pg_query($this->db_connect_id, "EXPLAIN $explain_query")) - { - while ($row = @pg_fetch_assoc($result, NULL)) - { - $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); - } - } - @pg_free_result($result); - - if ($html_table) - { - $this->html_hold .= ''; - } - } - - break; - - case 'fromcache': - $endtime = explode(' ', microtime()); - $endtime = $endtime[0] + $endtime[1]; - - $result = @pg_query($this->db_connect_id, $query); - while ($void = @pg_fetch_assoc($result, NULL)) - { - // Take the time spent on parsing rows into account - } - @pg_free_result($result); - - $splittime = explode(' ', microtime()); - $splittime = $splittime[0] + $splittime[1]; - - $this->sql_report('record_fromcache', $query, $endtime, $splittime); - - break; - } - } -} - -?> \ No newline at end of file -- cgit v1.2.1 From 2e17e448deed073f8614bb555a8ef20c57291c2a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:14:59 +0000 Subject: Copy 3.0.x branch to trunk git-svn-id: file:///svn/phpbb/trunk@10211 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 440 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 440 insertions(+) create mode 100644 phpBB/includes/db/postgres.php (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php new file mode 100644 index 0000000000..d117e8c948 --- /dev/null +++ b/phpBB/includes/db/postgres.php @@ -0,0 +1,440 @@ +dbname = $database; + if (strpos($database, '.') !== false) + { + list($database, $schema) = explode('.', $database); + } + $connect_string .= "dbname=$database"; + } + + $this->persistency = $persistency; + + $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link); + + if ($this->db_connect_id) + { + if (version_compare($this->sql_server_info(true), '8.2', '>=')) + { + $this->multi_insert = true; + } + + if ($schema !== '') + { + @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); + } + return $this->db_connect_id; + } + + return $this->sql_error(''); + } + + /** + * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version + */ + function sql_server_info($raw = false) + { + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) + { + $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @pg_fetch_assoc($query_id, null); + @pg_free_result($query_id); + + $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; + + if (!empty($cache)) + { + $cache->put('pgsql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; + } + + /** + * SQL Transaction + * @access private + */ + function _sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + return @pg_query($this->db_connect_id, 'BEGIN'); + break; + + case 'commit': + return @pg_query($this->db_connect_id, 'COMMIT'); + break; + + case 'rollback': + return @pg_query($this->db_connect_id, 'ROLLBACK'); + break; + } + + return true; + } + + /** + * Base query method + * + * @param string $query Contains the SQL query which shall be executed + * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache + * @return mixed When casted to bool the returned value returns true on success and false on failure + * + * @access public + */ + function sql_query($query = '', $cache_ttl = 0) + { + if ($query != '') + { + global $cache; + + // EXPLAIN only in extra debug mode + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('start', $query); + } + + $this->last_query_text = $query; + $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->sql_add_num_queries($this->query_result); + + if ($this->query_result === false) + { + if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false) + { + $this->sql_error($query); + } + + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('stop', $query); + } + + if ($cache_ttl && method_exists($cache, 'sql_save')) + { + $this->open_queries[(int) $this->query_result] = $this->query_result; + $cache->sql_save($query, $this->query_result, $cache_ttl); + } + else if (strpos($query, 'SELECT') === 0 && $this->query_result) + { + $this->open_queries[(int) $this->query_result] = $this->query_result; + } + } + else if (defined('DEBUG_EXTRA')) + { + $this->sql_report('fromcache', $query); + } + } + else + { + return false; + } + + return $this->query_result; + } + + /** + * Build db-specific query data + * @access private + */ + function _sql_custom_build($stage, $data) + { + return $data; + } + + /** + * 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) + { + $total = 'ALL'; + } + + $query .= "\n LIMIT $total OFFSET $offset"; + + return $this->sql_query($query, $cache_ttl); + } + + /** + * Return number of affected rows + */ + function sql_affectedrows() + { + return ($this->query_result) ? @pg_affected_rows($this->query_result) : false; + } + + /** + * Fetch current row + */ + function sql_fetchrow($query_id = false) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_fetchrow($query_id); + } + + return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false; + } + + /** + * Seek to given row number + * rownum is zero-based + */ + function sql_rowseek($rownum, &$query_id) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_rowseek($rownum, $query_id); + } + + return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false; + } + + /** + * Get last inserted id after insert statement + */ + function sql_nextid() + { + $query_id = $this->query_result; + + if ($query_id !== false && $this->last_query_text != '') + { + if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename)) + { + $query = "SELECT currval('" . $tablename[1] . "_seq') AS last_value"; + $temp_q_id = @pg_query($this->db_connect_id, $query); + + if (!$temp_q_id) + { + return false; + } + + $temp_result = @pg_fetch_assoc($temp_q_id, NULL); + @pg_free_result($query_id); + + return ($temp_result) ? $temp_result['last_value'] : false; + } + } + + return false; + } + + /** + * Free sql result + */ + function sql_freeresult($query_id = false) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_freeresult($query_id); + } + + if (isset($this->open_queries[(int) $query_id])) + { + unset($this->open_queries[(int) $query_id]); + return @pg_free_result($query_id); + } + + return false; + } + + /** + * Escape string used in sql query + * Note: Do not use for bytea values if we may use them at a later stage + */ + function sql_escape($msg) + { + return @pg_escape_string($msg); + } + + /** + * Build LIKE expression + * @access private + */ + function _sql_like_expression($expression) + { + return $expression; + } + + /** + * return sql error array + * @access private + */ + function _sql_error() + { + return array( + 'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id), + 'code' => '' + ); + } + + /** + * Close sql connection + * @access private + */ + function _sql_close() + { + return @pg_close($this->db_connect_id); + } + + /** + * Build db-specific report + * @access private + */ + function _sql_report($mode, $query = '') + { + switch ($mode) + { + case 'start': + + $explain_query = $query; + if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) + { + $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; + } + else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) + { + $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; + } + + if (preg_match('/^SELECT/', $explain_query)) + { + $html_table = false; + + if ($result = @pg_query($this->db_connect_id, "EXPLAIN $explain_query")) + { + while ($row = @pg_fetch_assoc($result, NULL)) + { + $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); + } + } + @pg_free_result($result); + + if ($html_table) + { + $this->html_hold .= ''; + } + } + + break; + + case 'fromcache': + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1]; + + $result = @pg_query($this->db_connect_id, $query); + while ($void = @pg_fetch_assoc($result, NULL)) + { + // Take the time spent on parsing rows into account + } + @pg_free_result($result); + + $splittime = explode(' ', microtime()); + $splittime = $splittime[0] + $splittime[1]; + + $this->sql_report('record_fromcache', $query, $endtime, $splittime); + + break; + } + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From af5b9a96409d788733fcb1ff367e0c7fb0583702 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 9 Nov 2010 08:59:25 +0100 Subject: [ticket/9556] Drop php closing tags, add trailing newline Closing tags converted using Oleg's script. remove-php-end-tags.py -a . Trailing newlines added using the following where $ext is file extension. find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s; Extensions: php, css, html, js, xml. PHPBB3-9556 --- phpBB/includes/db/postgres.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 4360c790a1..eb297b8db5 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -447,5 +447,3 @@ class dbal_postgres extends dbal } } } - -?> \ No newline at end of file -- cgit v1.2.1 From fb2642bbc6360dacfd4a3cc9f7e9447b02cb46a1 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 10 Jan 2011 02:27:18 +0100 Subject: [task/config-class] Implemented a config class to replace the global array. There is a phpbb_config class which simply holds an array and does not persist any data. It implements ArrayAccess, Countable and IteratorAggregate to allow regular use of configuration as if it was still an array. The phpbb_config_db class depends on an instance of the dbal and a cache driver. It obtains the configuration data from cache and database as necessary and persists data to the database. The functions set_config and set_config_count remain for backward compatability but they only call methods on the new config class now instead of directly manipulating the database and cache. PHPBB3-9988 --- phpBB/includes/db/postgres.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index eb297b8db5..424ce12245 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -365,6 +365,22 @@ class dbal_postgres extends dbal return $expression; } + /** + * @inheritdoc + */ + function cast_expr_to_bigint($expression) + { + return 'CAST(' . $expression . ' as DECIMAL(255, 0))'; + } + + /** + * @inheritdoc + */ + function cast_expr_to_string($expression) + { + return 'CAST(' . $expression . ' as VARCHAR(255))'; + } + /** * return sql error array * @access private -- cgit v1.2.1 From 7a04c9048c110f0bd21ea3e9e869e17b408d640e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/db/postgres.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 959d8df139..bf22cffafa 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -2,9 +2,8 @@ /** * * @package dbal -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From 90a957ad26f52e26c3979464c5ac15b1fd0fcc28 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 17:43:43 +0200 Subject: [ticket/11015] Make DBAL classes autoloadable PHPBB3-11015 This allows us to just create the object without having to include the driver first. However, it also means that users must specify the full class name in config.php --- phpBB/includes/db/postgres.php | 498 ----------------------------------------- 1 file changed, 498 deletions(-) delete mode 100644 phpBB/includes/db/postgres.php (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php deleted file mode 100644 index bf22cffafa..0000000000 --- a/phpBB/includes/db/postgres.php +++ /dev/null @@ -1,498 +0,0 @@ -dbname = $database; - if (strpos($database, '.') !== false) - { - list($database, $schema) = explode('.', $database); - } - $connect_string .= "dbname=$database"; - } - - $this->persistency = $persistency; - - if ($this->persistency) - { - if (!function_exists('pg_pconnect')) - { - $this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?'; - return $this->sql_error(''); - } - $collector = new phpbb_error_collector; - $collector->install(); - $this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW); - } - else - { - if (!function_exists('pg_connect')) - { - $this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?'; - return $this->sql_error(''); - } - $collector = new phpbb_error_collector; - $collector->install(); - $this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW); - } - - $collector->uninstall(); - - if ($this->db_connect_id) - { - if (version_compare($this->sql_server_info(true), '8.2', '>=')) - { - $this->multi_insert = true; - } - - if ($schema !== '') - { - @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); - } - return $this->db_connect_id; - } - - $this->connect_error = $collector->format_errors(); - return $this->sql_error(''); - } - - /** - * Version information about used database - * @param bool $raw if true, only return the fetched sql_server_version - * @param bool $use_cache If true, it is safe to retrieve the value from the cache - * @return string sql server version - */ - function sql_server_info($raw = false, $use_cache = true) - { - global $cache; - - if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) - { - $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); - $row = @pg_fetch_assoc($query_id, null); - @pg_free_result($query_id); - - $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; - - if (!empty($cache) && $use_cache) - { - $cache->put('pgsql_version', $this->sql_server_version); - } - } - - return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; - } - - /** - * SQL Transaction - * @access private - */ - function _sql_transaction($status = 'begin') - { - switch ($status) - { - case 'begin': - return @pg_query($this->db_connect_id, 'BEGIN'); - break; - - case 'commit': - return @pg_query($this->db_connect_id, 'COMMIT'); - break; - - case 'rollback': - return @pg_query($this->db_connect_id, 'ROLLBACK'); - break; - } - - return true; - } - - /** - * Base query method - * - * @param string $query Contains the SQL query which shall be executed - * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache - * @return mixed When casted to bool the returned value returns true on success and false on failure - * - * @access public - */ - function sql_query($query = '', $cache_ttl = 0) - { - if ($query != '') - { - global $cache; - - // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('start', $query); - } - - $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; - $this->sql_add_num_queries($this->query_result); - - if ($this->query_result === false) - { - if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false) - { - $this->sql_error($query); - } - - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('stop', $query); - } - - if ($cache_ttl && method_exists($cache, 'sql_save')) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); - } - else if (strpos($query, 'SELECT') === 0 && $this->query_result) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - } - } - else if (defined('DEBUG_EXTRA')) - { - $this->sql_report('fromcache', $query); - } - } - else - { - return false; - } - - return $this->query_result; - } - - /** - * Build db-specific query data - * @access private - */ - function _sql_custom_build($stage, $data) - { - return $data; - } - - /** - * 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) - { - $total = 'ALL'; - } - - $query .= "\n LIMIT $total OFFSET $offset"; - - return $this->sql_query($query, $cache_ttl); - } - - /** - * Return number of affected rows - */ - function sql_affectedrows() - { - return ($this->query_result) ? @pg_affected_rows($this->query_result) : false; - } - - /** - * Fetch current row - */ - function sql_fetchrow($query_id = false) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_fetchrow($query_id); - } - - return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false; - } - - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false; - } - - /** - * Get last inserted id after insert statement - */ - function sql_nextid() - { - $query_id = $this->query_result; - - if ($query_id !== false && $this->last_query_text != '') - { - if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename)) - { - $query = "SELECT currval('" . $tablename[1] . "_seq') AS last_value"; - $temp_q_id = @pg_query($this->db_connect_id, $query); - - if (!$temp_q_id) - { - return false; - } - - $temp_result = @pg_fetch_assoc($temp_q_id, NULL); - @pg_free_result($query_id); - - return ($temp_result) ? $temp_result['last_value'] : false; - } - } - - return false; - } - - /** - * Free sql result - */ - function sql_freeresult($query_id = false) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_freeresult($query_id); - } - - if (isset($this->open_queries[(int) $query_id])) - { - unset($this->open_queries[(int) $query_id]); - return @pg_free_result($query_id); - } - - return false; - } - - /** - * Escape string used in sql query - * Note: Do not use for bytea values if we may use them at a later stage - */ - function sql_escape($msg) - { - return @pg_escape_string($msg); - } - - /** - * Build LIKE expression - * @access private - */ - function _sql_like_expression($expression) - { - return $expression; - } - - /** - * @inheritdoc - */ - function cast_expr_to_bigint($expression) - { - return 'CAST(' . $expression . ' as DECIMAL(255, 0))'; - } - - /** - * @inheritdoc - */ - function cast_expr_to_string($expression) - { - return 'CAST(' . $expression . ' as VARCHAR(255))'; - } - - /** - * return sql error array - * @access private - */ - function _sql_error() - { - // pg_last_error only works when there is an established connection. - // Connection errors have to be tracked by us manually. - if ($this->db_connect_id) - { - $message = @pg_last_error($this->db_connect_id); - } - else - { - $message = $this->connect_error; - } - - return array( - 'message' => $message, - 'code' => '' - ); - } - - /** - * Close sql connection - * @access private - */ - function _sql_close() - { - return @pg_close($this->db_connect_id); - } - - /** - * Build db-specific report - * @access private - */ - function _sql_report($mode, $query = '') - { - switch ($mode) - { - case 'start': - - $explain_query = $query; - if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) - { - $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; - } - else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) - { - $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; - } - - if (preg_match('/^SELECT/', $explain_query)) - { - $html_table = false; - - if ($result = @pg_query($this->db_connect_id, "EXPLAIN $explain_query")) - { - while ($row = @pg_fetch_assoc($result, NULL)) - { - $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); - } - } - @pg_free_result($result); - - if ($html_table) - { - $this->html_hold .= ''; - } - } - - break; - - case 'fromcache': - $endtime = explode(' ', microtime()); - $endtime = $endtime[0] + $endtime[1]; - - $result = @pg_query($this->db_connect_id, $query); - while ($void = @pg_fetch_assoc($result, NULL)) - { - // Take the time spent on parsing rows into account - } - @pg_free_result($result); - - $splittime = explode(' ', microtime()); - $splittime = $splittime[0] + $splittime[1]; - - $this->sql_report('record_fromcache', $query, $endtime, $splittime); - - break; - } - } -} -- cgit v1.2.1 From 65bafb22810038fd51e22fd8168775afd86c2e74 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 18:08:40 +0200 Subject: [ticket/11015] Add BC files for the drivers PHPBB3-11015 --- phpBB/includes/db/postgres.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 phpBB/includes/db/postgres.php (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php new file mode 100644 index 0000000000..dc5e95ac57 --- /dev/null +++ b/phpBB/includes/db/postgres.php @@ -0,0 +1,19 @@ + Date: Mon, 12 Nov 2012 10:38:28 +0100 Subject: [ticket/11015] Remove old dbal classes PHPBB3-11015 --- phpBB/includes/db/postgres.php | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 phpBB/includes/db/postgres.php (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php deleted file mode 100644 index dc5e95ac57..0000000000 --- a/phpBB/includes/db/postgres.php +++ /dev/null @@ -1,19 +0,0 @@ -