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