Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Postgre Database Adapter Class |
| 31 | * |
| 32 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 33 | * creates dynamically based on whether the query builder |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 34 | * class is being used or not. |
| 35 | * |
| 36 | * @package CodeIgniter |
| 37 | * @subpackage Drivers |
| 38 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 39 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | * @link http://codeigniter.com/user_guide/database/ |
| 41 | */ |
| 42 | class CI_DB_postgre_driver extends CI_DB { |
| 43 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 44 | /** |
| 45 | * Database driver |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 49 | public $dbdriver = 'postgre'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 50 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 51 | /** |
Andrey Andreev | 3e9d2b8 | 2012-10-27 14:28:51 +0300 | [diff] [blame] | 52 | * Database schema |
| 53 | * |
| 54 | * @var string |
Andrey Andreev | 485a348 | 2012-10-27 03:22:43 +0300 | [diff] [blame] | 55 | */ |
| 56 | public $schema = 'public'; |
| 57 | |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 58 | // -------------------------------------------------------------------- |
| 59 | |
Andrey Andreev | 485a348 | 2012-10-27 03:22:43 +0300 | [diff] [blame] | 60 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 61 | * ORDER BY random keyword |
| 62 | * |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 63 | * @var array |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 64 | */ |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 65 | protected $_random_keyword = array('RANDOM()', 'RANDOM()'); |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 66 | |
| 67 | // -------------------------------------------------------------------- |
| 68 | |
| 69 | /** |
| 70 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | * |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 72 | * Creates a DSN string to be used for db_connect() and db_pconnect() |
| 73 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 74 | * @param array $params |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 75 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | */ |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 77 | public function __construct($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | { |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 79 | parent::__construct($params); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 80 | |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 81 | if ( ! empty($this->dsn)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | { |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
| 86 | $this->dsn === '' OR $this->dsn = ''; |
| 87 | |
| 88 | if (strpos($this->hostname, '/') !== FALSE) |
| 89 | { |
| 90 | // If UNIX sockets are used, we shouldn't set a port |
| 91 | $this->port = ''; |
| 92 | } |
| 93 | |
Andrey Andreev | ab1d568 | 2012-04-03 20:48:32 +0300 | [diff] [blame] | 94 | $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' '; |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 95 | |
| 96 | if ( ! empty($this->port) && ctype_digit($this->port)) |
| 97 | { |
Andrey Andreev | ab1d568 | 2012-04-03 20:48:32 +0300 | [diff] [blame] | 98 | $this->dsn .= 'port='.$this->port.' '; |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | if ($this->username !== '') |
| 102 | { |
Andrey Andreev | ab1d568 | 2012-04-03 20:48:32 +0300 | [diff] [blame] | 103 | $this->dsn .= 'user='.$this->username.' '; |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 104 | |
| 105 | /* An empty password is valid! |
| 106 | * |
| 107 | * $db['password'] = NULL must be done in order to ignore it. |
| 108 | */ |
| 109 | $this->password === NULL OR $this->dsn .= "password='".$this->password."' "; |
| 110 | } |
| 111 | |
| 112 | $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' '; |
| 113 | |
| 114 | /* We don't have these options as elements in our standard configuration |
| 115 | * array, but they might be set by parse_url() if the configuration was |
| 116 | * provided via string. Example: |
| 117 | * |
| 118 | * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1 |
| 119 | */ |
| 120 | foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key) |
| 121 | { |
| 122 | if (isset($this->$key) && is_string($this->key) && $this->key !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | { |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 124 | $this->dsn .= $key."='".$this->key."' "; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
Andrey Andreev | 6192bc0 | 2012-03-26 12:32:32 +0300 | [diff] [blame] | 127 | |
| 128 | $this->dsn = rtrim($this->dsn); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------- |
| 132 | |
| 133 | /** |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 134 | * Database connection |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | * |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 136 | * @param bool $persistent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 138 | */ |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 139 | public function db_connect($persistent = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 140 | { |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 141 | if ($persistent === TRUE |
Andrey Andreev | c07c485 | 2012-12-03 16:42:10 +0200 | [diff] [blame^] | 142 | && ($this->conn_id = @pg_pconnect($this->dsn)) |
| 143 | && pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD |
| 144 | && pg_ping($this->conn_id) === FALSE |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 145 | ) |
| 146 | { |
| 147 | return FALSE; |
| 148 | } |
| 149 | else |
| 150 | { |
Andrey Andreev | c07c485 | 2012-12-03 16:42:10 +0200 | [diff] [blame^] | 151 | $this->conn_id = @pg_connect($this->dsn); |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Andrey Andreev | c07c485 | 2012-12-03 16:42:10 +0200 | [diff] [blame^] | 154 | if ($this->conn_id && ! empty($this->schema)) |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 155 | { |
| 156 | $this->simple_query('SET search_path TO '.$this->schema.',public'); |
| 157 | } |
| 158 | |
Andrey Andreev | c07c485 | 2012-12-03 16:42:10 +0200 | [diff] [blame^] | 159 | return $this->conn_id; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // -------------------------------------------------------------------- |
| 163 | |
| 164 | /** |
| 165 | * Persistent database connection |
| 166 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 169 | public function db_pconnect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | { |
Andrey Andreev | 0259d12 | 2012-12-03 14:55:56 +0200 | [diff] [blame] | 171 | return $this->db_connect(TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 173 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | // -------------------------------------------------------------------- |
| 175 | |
| 176 | /** |
Derek Jones | 87cbafc | 2009-02-27 16:29:59 +0000 | [diff] [blame] | 177 | * Reconnect |
| 178 | * |
| 179 | * Keep / reestablish the db connection if no queries have been |
| 180 | * sent for a length of time exceeding the server's idle timeout |
| 181 | * |
Derek Jones | 87cbafc | 2009-02-27 16:29:59 +0000 | [diff] [blame] | 182 | * @return void |
| 183 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 184 | public function reconnect() |
Derek Jones | 87cbafc | 2009-02-27 16:29:59 +0000 | [diff] [blame] | 185 | { |
| 186 | if (pg_ping($this->conn_id) === FALSE) |
| 187 | { |
| 188 | $this->conn_id = FALSE; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // -------------------------------------------------------------------- |
| 193 | |
| 194 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | * Set client character set |
| 196 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 197 | * @param string $charset |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 198 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | */ |
Andrey Andreev | 8e89df8 | 2012-03-03 03:48:12 +0200 | [diff] [blame] | 200 | protected function _db_set_charset($charset) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | { |
Andrey Andreev | 8e89df8 | 2012-03-03 03:48:12 +0200 | [diff] [blame] | 202 | return (pg_set_client_encoding($this->conn_id, $charset) === 0); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 206 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 208 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 210 | * @return string |
| 211 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 212 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 213 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 214 | if (isset($this->data_cache['version'])) |
| 215 | { |
| 216 | return $this->data_cache['version']; |
| 217 | } |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 218 | elseif ( ! $this->conn_id) |
| 219 | { |
| 220 | $this->initialize(); |
| 221 | } |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 222 | |
Andrey Andreev | 2b73037 | 2012-11-05 17:01:11 +0200 | [diff] [blame] | 223 | if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE) |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 224 | { |
| 225 | return FALSE; |
| 226 | } |
| 227 | |
| 228 | /* If PHP was compiled with PostgreSQL lib versions earlier |
| 229 | * than 7.4, pg_version() won't return the server version |
| 230 | * and so we'll have to fall back to running a query in |
| 231 | * order to get it. |
| 232 | */ |
| 233 | return isset($pg_version['server']) |
| 234 | ? $this->data_cache['version'] = $pg_version['server'] |
| 235 | : parent::version(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // -------------------------------------------------------------------- |
| 239 | |
| 240 | /** |
| 241 | * Execute the query |
| 242 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 243 | * @param string $sql an SQL query |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 245 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 246 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 247 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | return @pg_query($this->conn_id, $sql); |
| 249 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 250 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | // -------------------------------------------------------------------- |
| 252 | |
| 253 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 254 | * Begin Transaction |
| 255 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 256 | * @param bool $test_mode |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 257 | * @return bool |
| 258 | */ |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 259 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 262 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | { |
| 264 | return TRUE; |
| 265 | } |
| 266 | |
| 267 | // Reset the transaction failure flag. |
| 268 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 269 | // even if the queries produce a successful result. |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 270 | $this->_trans_failure = ($test_mode === TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 271 | |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 272 | return (bool) @pg_query($this->conn_id, 'BEGIN'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // -------------------------------------------------------------------- |
| 276 | |
| 277 | /** |
| 278 | * Commit Transaction |
| 279 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 280 | * @return bool |
| 281 | */ |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 282 | public function trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 285 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | { |
| 287 | return TRUE; |
| 288 | } |
| 289 | |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 290 | return (bool) @pg_query($this->conn_id, 'COMMIT'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | // -------------------------------------------------------------------- |
| 294 | |
| 295 | /** |
| 296 | * Rollback Transaction |
| 297 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 298 | * @return bool |
| 299 | */ |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 300 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | a19beb0 | 2012-03-03 04:20:50 +0200 | [diff] [blame] | 303 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | { |
| 305 | return TRUE; |
| 306 | } |
| 307 | |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 308 | return (bool) @pg_query($this->conn_id, 'ROLLBACK'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // -------------------------------------------------------------------- |
| 312 | |
| 313 | /** |
| 314 | * Escape String |
| 315 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 316 | * @param string $str |
| 317 | * @param bool $like Whether or not the string will be used in a LIKE condition |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | * @return string |
| 319 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 320 | public function escape_str($str, $like = FALSE) |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 321 | { |
| 322 | if (is_array($str)) |
| 323 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 324 | foreach ($str as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 325 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 326 | $str[$key] = $this->escape_str($val, $like); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | return $str; |
| 330 | } |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 331 | |
| 332 | $str = pg_escape_string($str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 333 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 334 | // escape LIKE condition wildcards |
| 335 | if ($like === TRUE) |
| 336 | { |
Andrey Andreev | 55201ac | 2012-03-20 14:20:39 +0200 | [diff] [blame] | 337 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
| 338 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
| 339 | $str); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 340 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 341 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 342 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 344 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | // -------------------------------------------------------------------- |
| 346 | |
| 347 | /** |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 348 | * "Smart" Escape String |
| 349 | * |
| 350 | * Escapes data based on type |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 351 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 352 | * @param string $str |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 353 | * @return mixed |
| 354 | */ |
| 355 | public function escape($str) |
| 356 | { |
Soesapto Joeni Hantoro | dabeaa1 | 2012-05-15 16:37:46 +0700 | [diff] [blame] | 357 | if (is_bool($str)) |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 358 | { |
Soesapto Joeni Hantoro | d2574db | 2012-05-15 16:28:16 +0700 | [diff] [blame] | 359 | return ($str) ? 'TRUE' : 'FALSE'; |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 360 | } |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 361 | |
Soesapto Joeni Hantoro | dabeaa1 | 2012-05-15 16:37:46 +0700 | [diff] [blame] | 362 | return parent::escape($str); |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 363 | } |
Andrey Andreev | 242925b | 2012-05-15 13:03:51 +0300 | [diff] [blame] | 364 | |
Soesapto Joeni Hantoro | f25b929 | 2012-05-15 08:10:31 +0700 | [diff] [blame] | 365 | // -------------------------------------------------------------------- |
| 366 | |
| 367 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | * Affected Rows |
| 369 | * |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 370 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 372 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 373 | { |
| 374 | return @pg_affected_rows($this->result_id); |
| 375 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 376 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | // -------------------------------------------------------------------- |
| 378 | |
| 379 | /** |
| 380 | * Insert ID |
| 381 | * |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 382 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 384 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | { |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 386 | $v = pg_version($this->conn_id); |
| 387 | $v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4 |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 388 | |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 389 | $table = (func_num_args() > 0) ? func_get_arg(0) : NULL; |
| 390 | $column = (func_num_args() > 1) ? func_get_arg(1) : NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 392 | if ($table === NULL && $v >= '8.1') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 393 | { |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 394 | $sql = 'SELECT LASTVAL() AS ins_id'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | } |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 396 | elseif ($table !== NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 397 | { |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 398 | if ($column !== NULL && $v >= '8.0') |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 399 | { |
| 400 | $sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq"; |
| 401 | $query = $this->query($sql); |
| 402 | $query = $query->row(); |
| 403 | $seq = $query->seq; |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | // seq_name passed in table parameter |
| 408 | $seq = $table; |
| 409 | } |
| 410 | |
| 411 | $sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | } |
| 413 | else |
| 414 | { |
| 415 | return pg_last_oid($this->result_id); |
| 416 | } |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 417 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 418 | $query = $this->query($sql); |
Andrey Andreev | 214583f | 2012-01-26 16:39:09 +0200 | [diff] [blame] | 419 | $query = $query->row(); |
| 420 | return (int) $query->ins_id; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | // -------------------------------------------------------------------- |
| 424 | |
| 425 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | * Show table query |
| 427 | * |
| 428 | * Generates a platform-specific query string so that the table names can be fetched |
| 429 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 430 | * @param bool $prefix_limit |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | * @return string |
| 432 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 433 | protected function _list_tables($prefix_limit = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 434 | { |
Andrey Andreev | 485a348 | 2012-10-27 03:22:43 +0300 | [diff] [blame] | 435 | $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 437 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | { |
Andrey Andreev | 58803fb | 2012-06-24 00:45:37 +0300 | [diff] [blame] | 439 | return $sql.' AND "table_name" LIKE \'' |
| 440 | .$this->escape_like_str($this->dbprefix)."%' " |
| 441 | .sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 443 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 444 | return $sql; |
| 445 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 446 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 447 | // -------------------------------------------------------------------- |
| 448 | |
| 449 | /** |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 450 | * List column query |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | * |
| 452 | * Generates a platform-specific query string so that the column names can be fetched |
| 453 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 454 | * @param string $table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | * @return string |
| 456 | */ |
Andrey Andreev | 738497c | 2012-03-20 14:12:25 +0200 | [diff] [blame] | 457 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | { |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 459 | return 'SELECT "column_name" |
| 460 | FROM "information_schema"."columns" |
| 461 | WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | // -------------------------------------------------------------------- |
| 465 | |
| 466 | /** |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 467 | * Returns an object with field data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 469 | * @param string $table |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 470 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | */ |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 472 | public function field_data($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | { |
Andrey Andreev | 4658307 | 2012-11-16 16:44:31 +0200 | [diff] [blame] | 474 | if ($table === '') |
| 475 | { |
| 476 | return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; |
| 477 | } |
| 478 | |
| 479 | $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" |
| 480 | FROM "information_schema"."columns" |
| 481 | WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); |
| 482 | |
| 483 | if (($query = $this->query($sql)) === FALSE) |
| 484 | { |
| 485 | return FALSE; |
| 486 | } |
| 487 | $query = $query->result_object(); |
| 488 | |
| 489 | $retval = array(); |
| 490 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 491 | { |
| 492 | $retval[$i] = new stdClass(); |
| 493 | $retval[$i]->name = $query[$i]->column_name; |
| 494 | $retval[$i]->type = $query[$i]->data_type; |
| 495 | $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; |
| 496 | $retval[$i]->default = $query[$i]->column_default; |
| 497 | } |
| 498 | |
| 499 | return $retval; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | // -------------------------------------------------------------------- |
| 503 | |
| 504 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 505 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 507 | * Returns an array containing code and message of the last |
| 508 | * database error that has occured. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 510 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 512 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 513 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 514 | return array('code' => '', 'message' => pg_last_error($this->conn_id)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | // -------------------------------------------------------------------- |
| 518 | |
| 519 | /** |
Andrey Andreev | 98e46cf | 2012-11-13 03:01:42 +0200 | [diff] [blame] | 520 | * ORDER BY |
| 521 | * |
| 522 | * @param string $orderby |
| 523 | * @param string $direction ASC or DESC |
| 524 | * @param bool $escape |
| 525 | * @return object |
| 526 | */ |
| 527 | public function order_by($orderby, $direction = '', $escape = NULL) |
| 528 | { |
| 529 | $direction = strtoupper(trim($direction)); |
| 530 | if ($direction === 'RANDOM') |
| 531 | { |
| 532 | if ( ! is_float($orderby) && ctype_digit((string) $orderby)) |
| 533 | { |
| 534 | $orderby = ($orderby > 1) |
| 535 | ? (float) '0.'.$orderby |
| 536 | : (float) $orderby; |
| 537 | } |
| 538 | |
| 539 | if (is_float($orderby)) |
| 540 | { |
| 541 | $this->simple_query('SET SEED '.$orderby); |
| 542 | } |
| 543 | |
| 544 | $orderby = $this->_random_keyword[0]; |
| 545 | $direction = ''; |
| 546 | $escape = FALSE; |
| 547 | } |
| 548 | |
| 549 | return parent::order_by($orderby, $direction, $escape); |
| 550 | } |
| 551 | |
| 552 | // -------------------------------------------------------------------- |
| 553 | |
| 554 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 555 | * Update statement |
| 556 | * |
| 557 | * Generates a platform-specific update string from the supplied data |
| 558 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 559 | * @param string $table |
| 560 | * @param array $values |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | * @return string |
| 562 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 563 | protected function _update($table, $values) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 565 | $this->qb_limit = FALSE; |
| 566 | $this->qb_orderby = array(); |
| 567 | return parent::_update($table, $values); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 568 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 569 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 570 | // -------------------------------------------------------------------- |
| 571 | |
| 572 | /** |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 573 | * Update_Batch statement |
| 574 | * |
| 575 | * Generates a platform-specific batch update string from the supplied data |
| 576 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 577 | * @param string $table Table name |
| 578 | * @param array $values Update data |
| 579 | * @param string $index WHERE key |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 580 | * @return string |
| 581 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 582 | protected function _update_batch($table, $values, $index) |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 583 | { |
| 584 | $ids = array(); |
| 585 | foreach ($values as $key => $val) |
| 586 | { |
| 587 | $ids[] = $val[$index]; |
| 588 | |
| 589 | foreach (array_keys($val) as $field) |
| 590 | { |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 591 | if ($field !== $index) |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 592 | { |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 593 | $final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field]; |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | $cases = ''; |
| 599 | foreach ($final as $k => $v) |
| 600 | { |
aroche | 7f875b7 | 2012-07-16 18:22:08 +0300 | [diff] [blame] | 601 | $cases .= $k.' = (CASE '.$index."\n" |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 602 | .implode("\n", $v)."\n" |
| 603 | .'ELSE '.$k.' END), '; |
| 604 | } |
| 605 | |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 606 | $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); |
| 607 | |
Andrey Andreev | d40459d | 2012-07-18 16:46:39 +0300 | [diff] [blame] | 608 | return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); |
Andrey Andreev | d06acd8 | 2012-05-25 00:29:09 +0300 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | // -------------------------------------------------------------------- |
| 612 | |
| 613 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | * Delete statement |
| 615 | * |
| 616 | * Generates a platform-specific delete string from the supplied data |
| 617 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 618 | * @param string $table |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 619 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 620 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 621 | protected function _delete($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 623 | $this->qb_limit = FALSE; |
| 624 | return parent::_delete($table); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | // -------------------------------------------------------------------- |
Andrey Andreev | 82e88b9 | 2012-04-06 21:18:59 +0300 | [diff] [blame] | 628 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 629 | /** |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 630 | * LIMIT |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 631 | * |
| 632 | * Generates a platform-specific LIMIT clause |
| 633 | * |
Andrey Andreev | a24e52e | 2012-11-02 03:54:12 +0200 | [diff] [blame] | 634 | * @param string $sql SQL Query |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | * @return string |
| 636 | */ |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 637 | protected function _limit($sql) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 638 | { |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame] | 639 | return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | // -------------------------------------------------------------------- |
| 643 | |
| 644 | /** |
| 645 | * Close DB Connection |
| 646 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 647 | * @return void |
| 648 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 649 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 651 | @pg_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 656 | /* End of file postgre_driver.php */ |
Andrey Andreev | 242925b | 2012-05-15 13:03:51 +0300 | [diff] [blame] | 657 | /* Location: ./system/database/drivers/postgre/postgre_driver.php */ |