blob: 0fcd954e96715d0ce5c3820657f4e412c3c36c44 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Postgre Database Adapter Class
32 *
33 * Note: _DB is an extender class that the app controller
34 * creates dynamically based on whether the active record
35 * class is being used or not.
36 *
37 * @package CodeIgniter
38 * @subpackage Drivers
39 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050040 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000041 * @link http://codeigniter.com/user_guide/database/
42 */
43class CI_DB_postgre_driver extends CI_DB {
44
45 var $dbdriver = 'postgre';
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Allard2067d1a2008-11-13 22:59:24 +000047 var $_escape_char = '"';
48
Derek Jonese4ed5832009-02-20 21:44:59 +000049 // clause and character used for LIKE escape sequences
50 var $_like_escape_str = " ESCAPE '%s' ";
51 var $_like_escape_chr = '!';
52
Derek Allard2067d1a2008-11-13 22:59:24 +000053 /**
54 * The syntax to count rows is slightly different across different
55 * database engines, so this string appears in each driver and is
56 * used for the count_all() and count_all_results() functions.
57 */
58 var $_count_string = "SELECT COUNT(*) AS ";
59 var $_random_keyword = ' RANDOM()'; // database specific random keyword
60
61 /**
62 * Connection String
63 *
64 * @access private
65 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020066 */
Derek Allard2067d1a2008-11-13 22:59:24 +000067 function _connect_string()
68 {
69 $components = array(
70 'hostname' => 'host',
71 'port' => 'port',
72 'database' => 'dbname',
73 'username' => 'user',
74 'password' => 'password'
75 );
Barry Mienydd671972010-10-04 16:33:58 +020076
Derek Allard2067d1a2008-11-13 22:59:24 +000077 $connect_string = "";
78 foreach ($components as $key => $val)
79 {
80 if (isset($this->$key) && $this->$key != '')
81 {
82 $connect_string .= " $val=".$this->$key;
83 }
84 }
85 return trim($connect_string);
86 }
87
88 // --------------------------------------------------------------------
89
90 /**
91 * Non-persistent database connection
92 *
93 * @access private called by the base class
94 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020095 */
Derek Allard2067d1a2008-11-13 22:59:24 +000096 function db_connect()
Barry Mienydd671972010-10-04 16:33:58 +020097 {
Derek Allard2067d1a2008-11-13 22:59:24 +000098 return @pg_connect($this->_connect_string());
99 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Persistent database connection
105 *
106 * @access private called by the base class
107 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200108 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 function db_pconnect()
110 {
111 return @pg_pconnect($this->_connect_string());
112 }
Barry Mienydd671972010-10-04 16:33:58 +0200113
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 // --------------------------------------------------------------------
115
116 /**
Derek Jones87cbafc2009-02-27 16:29:59 +0000117 * Reconnect
118 *
119 * Keep / reestablish the db connection if no queries have been
120 * sent for a length of time exceeding the server's idle timeout
121 *
122 * @access public
123 * @return void
124 */
125 function reconnect()
126 {
127 if (pg_ping($this->conn_id) === FALSE)
128 {
129 $this->conn_id = FALSE;
130 }
131 }
132
133 // --------------------------------------------------------------------
134
135 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 * Select the database
137 *
138 * @access private called by the base class
139 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200140 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 function db_select()
142 {
143 // Not needed for Postgre so we'll return TRUE
144 return TRUE;
145 }
146
147 // --------------------------------------------------------------------
148
149 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 * Version number query string
151 *
152 * @access public
153 * @return string
154 */
155 function _version()
156 {
157 return "SELECT version() AS ver";
158 }
159
160 // --------------------------------------------------------------------
161
162 /**
163 * Execute the query
164 *
165 * @access private called by the base class
166 * @param string an SQL query
167 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200168 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 function _execute($sql)
170 {
171 $sql = $this->_prep_query($sql);
172 return @pg_query($this->conn_id, $sql);
173 }
Barry Mienydd671972010-10-04 16:33:58 +0200174
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 // --------------------------------------------------------------------
176
177 /**
178 * Prep the query
179 *
180 * If needed, each database adapter can prep the query string
181 *
182 * @access private called by execute()
183 * @param string an SQL query
184 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200185 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 function _prep_query($sql)
187 {
188 return $sql;
189 }
190
191 // --------------------------------------------------------------------
192
193 /**
194 * Begin Transaction
195 *
196 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200197 * @return bool
198 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 function trans_begin($test_mode = FALSE)
200 {
201 if ( ! $this->trans_enabled)
202 {
203 return TRUE;
204 }
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 // When transactions are nested we only begin/commit/rollback the outermost ones
207 if ($this->_trans_depth > 0)
208 {
209 return TRUE;
210 }
211
212 // Reset the transaction failure flag.
213 // If the $test_mode flag is set to TRUE transactions will be rolled back
214 // even if the queries produce a successful result.
215 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
216
217 return @pg_exec($this->conn_id, "begin");
218 }
219
220 // --------------------------------------------------------------------
221
222 /**
223 * Commit Transaction
224 *
225 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200226 * @return bool
227 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 function trans_commit()
229 {
230 if ( ! $this->trans_enabled)
231 {
232 return TRUE;
233 }
234
235 // When transactions are nested we only begin/commit/rollback the outermost ones
236 if ($this->_trans_depth > 0)
237 {
238 return TRUE;
239 }
240
241 return @pg_exec($this->conn_id, "commit");
242 }
243
244 // --------------------------------------------------------------------
245
246 /**
247 * Rollback Transaction
248 *
249 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200250 * @return bool
251 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 function trans_rollback()
253 {
254 if ( ! $this->trans_enabled)
255 {
256 return TRUE;
257 }
258
259 // When transactions are nested we only begin/commit/rollback the outermost ones
260 if ($this->_trans_depth > 0)
261 {
262 return TRUE;
263 }
264
265 return @pg_exec($this->conn_id, "rollback");
266 }
267
268 // --------------------------------------------------------------------
269
270 /**
271 * Escape String
272 *
273 * @access public
274 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000275 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 * @return string
277 */
Derek Jonese4ed5832009-02-20 21:44:59 +0000278 function escape_str($str, $like = FALSE)
279 {
280 if (is_array($str))
281 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500282 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200283 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000284 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200285 }
286
287 return $str;
288 }
Derek Jonese4ed5832009-02-20 21:44:59 +0000289
290 $str = pg_escape_string($str);
Barry Mienydd671972010-10-04 16:33:58 +0200291
Derek Jonese4ed5832009-02-20 21:44:59 +0000292 // escape LIKE condition wildcards
293 if ($like === TRUE)
294 {
295 $str = str_replace( array('%', '_', $this->_like_escape_chr),
296 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
297 $str);
298 }
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Jonese4ed5832009-02-20 21:44:59 +0000300 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 // --------------------------------------------------------------------
304
305 /**
306 * Affected Rows
307 *
308 * @access public
309 * @return integer
310 */
311 function affected_rows()
312 {
313 return @pg_affected_rows($this->result_id);
314 }
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 // --------------------------------------------------------------------
317
318 /**
319 * Insert ID
320 *
321 * @access public
322 * @return integer
323 */
324 function insert_id()
325 {
326 $v = $this->_version();
327 $v = $v['server'];
Barry Mienydd671972010-10-04 16:33:58 +0200328
Pascal Kriete8761ef52011-02-14 13:13:52 -0500329 $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
330 $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
Barry Mienydd671972010-10-04 16:33:58 +0200331
Pascal Kriete8761ef52011-02-14 13:13:52 -0500332 if ($table == NULL && $v >= '8.1')
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 {
334 $sql='SELECT LASTVAL() as ins_id';
335 }
Pascal Kriete8761ef52011-02-14 13:13:52 -0500336 elseif ($table != NULL && $column != NULL && $v >= '8.0')
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 {
338 $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
339 $query = $this->query($sql);
340 $row = $query->row();
341 $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
342 }
Pascal Kriete8761ef52011-02-14 13:13:52 -0500343 elseif ($table != NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 {
345 // seq_name passed in table parameter
346 $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
347 }
348 else
349 {
350 return pg_last_oid($this->result_id);
351 }
352 $query = $this->query($sql);
353 $row = $query->row();
354 return $row->ins_id;
355 }
356
357 // --------------------------------------------------------------------
358
359 /**
360 * "Count All" query
361 *
362 * Generates a platform-specific query string that counts all records in
363 * the specified database
364 *
365 * @access public
366 * @param string
367 * @return string
368 */
369 function count_all($table = '')
370 {
371 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000372 {
373 return 0;
374 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000375
Derek Allarde37ab382009-02-03 16:13:57 +0000376 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
377
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000379 {
380 return 0;
381 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000382
383 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500384 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000385 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 }
387
388 // --------------------------------------------------------------------
389
390 /**
391 * Show table query
392 *
393 * Generates a platform-specific query string so that the table names can be fetched
394 *
395 * @access private
396 * @param boolean
397 * @return string
398 */
399 function _list_tables($prefix_limit = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200400 {
401 $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
402
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
404 {
Greg Aker0d424892010-01-26 02:14:44 +0000405 $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 }
Barry Mienydd671972010-10-04 16:33:58 +0200407
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 return $sql;
409 }
Barry Mienydd671972010-10-04 16:33:58 +0200410
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 // --------------------------------------------------------------------
412
413 /**
414 * Show column query
415 *
416 * Generates a platform-specific query string so that the column names can be fetched
417 *
418 * @access public
419 * @param string the table name
420 * @return string
421 */
422 function _list_columns($table = '')
423 {
424 return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
425 }
426
427 // --------------------------------------------------------------------
428
429 /**
430 * Field data query
431 *
432 * Generates a platform-specific query so that the column data can be retrieved
433 *
434 * @access public
435 * @param string the table name
436 * @return object
437 */
438 function _field_data($table)
439 {
440 return "SELECT * FROM ".$table." LIMIT 1";
441 }
442
443 // --------------------------------------------------------------------
444
445 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200446 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200448 * Returns an array containing code and message of the last
449 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200451 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200453 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200455 return array('code' => '', 'message' => pg_last_error($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 }
457
458 // --------------------------------------------------------------------
459
460 /**
461 * Escape the SQL Identifiers
462 *
463 * This function escapes column and table names
464 *
465 * @access private
466 * @param string
467 * @return string
468 */
469 function _escape_identifiers($item)
470 {
471 if ($this->_escape_char == '')
472 {
473 return $item;
474 }
475
476 foreach ($this->_reserved_identifiers as $id)
477 {
478 if (strpos($item, '.'.$id) !== FALSE)
479 {
Barry Mienydd671972010-10-04 16:33:58 +0200480 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 // remove duplicates if the user already included the escape
483 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200484 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 }
Barry Mienydd671972010-10-04 16:33:58 +0200486
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 if (strpos($item, '.') !== FALSE)
488 {
Barry Mienydd671972010-10-04 16:33:58 +0200489 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 }
491 else
492 {
493 $str = $this->_escape_char.$item.$this->_escape_char;
494 }
Barry Mienydd671972010-10-04 16:33:58 +0200495
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 // remove duplicates if the user already included the escape
497 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
498 }
Barry Mienydd671972010-10-04 16:33:58 +0200499
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 // --------------------------------------------------------------------
501
502 /**
503 * From Tables
504 *
505 * This function implicitly groups FROM tables so there is no confusion
506 * about operator precedence in harmony with SQL standards
507 *
508 * @access public
509 * @param type
510 * @return type
511 */
512 function _from_tables($tables)
513 {
514 if ( ! is_array($tables))
515 {
516 $tables = array($tables);
517 }
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 return implode(', ', $tables);
520 }
521
522 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200523
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 /**
525 * Insert statement
526 *
527 * Generates a platform-specific insert string from the supplied data
528 *
529 * @access public
530 * @param string the table name
531 * @param array the insert keys
532 * @param array the insert values
533 * @return string
534 */
535 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200536 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
538 }
Barry Mienydd671972010-10-04 16:33:58 +0200539
Derek Allard2067d1a2008-11-13 22:59:24 +0000540 // --------------------------------------------------------------------
541
542 /**
Greg Aker60ef4ea2011-04-27 01:45:38 -0500543 * Insert_batch statement
544 *
545 * Generates a platform-specific insert string from the supplied data
546 *
547 * @access public
548 * @param string the table name
549 * @param array the insert keys
550 * @param array the insert values
551 * @return string
552 */
553 function _insert_batch($table, $keys, $values)
554 {
555 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
556 }
557
558 // --------------------------------------------------------------------
559
560 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 * Update statement
562 *
563 * Generates a platform-specific update string from the supplied data
564 *
565 * @access public
566 * @param string the table name
567 * @param array the update data
568 * @param array the where clause
569 * @param array the orderby clause
570 * @param array the limit clause
571 * @return string
572 */
573 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
574 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500575 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 {
577 $valstr[] = $key." = ".$val;
578 }
Barry Mienydd671972010-10-04 16:33:58 +0200579
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200581
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200583
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
585
586 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
587
588 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200589
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 return $sql;
591 }
592
593 // --------------------------------------------------------------------
594
595 /**
596 * Truncate statement
597 *
598 * Generates a platform-specific truncate string from the supplied data
599 * If the database does not support the truncate() command
600 * This function maps to "DELETE FROM table"
601 *
602 * @access public
603 * @param string the table name
604 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200605 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 function _truncate($table)
607 {
608 return "TRUNCATE ".$table;
609 }
Barry Mienydd671972010-10-04 16:33:58 +0200610
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 // --------------------------------------------------------------------
612
613 /**
614 * Delete statement
615 *
616 * Generates a platform-specific delete string from the supplied data
617 *
618 * @access public
619 * @param string the table name
620 * @param array the where clause
621 * @param string the limit clause
622 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200623 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
625 {
626 $conditions = '';
627
628 if (count($where) > 0 OR count($like) > 0)
629 {
630 $conditions = "\nWHERE ";
631 $conditions .= implode("\n", $this->ar_where);
632
633 if (count($where) > 0 && count($like) > 0)
634 {
635 $conditions .= " AND ";
636 }
637 $conditions .= implode("\n", $like);
638 }
639
640 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200641
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 return "DELETE FROM ".$table.$conditions.$limit;
643 }
644
645 // --------------------------------------------------------------------
646 /**
647 * Limit string
648 *
649 * Generates a platform-specific LIMIT clause
650 *
651 * @access public
652 * @param string the sql query string
653 * @param integer the number of rows to limit the query to
654 * @param integer the offset value
655 * @return string
656 */
657 function _limit($sql, $limit, $offset)
Barry Mienydd671972010-10-04 16:33:58 +0200658 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 $sql .= "LIMIT ".$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200660
Derek Allard2067d1a2008-11-13 22:59:24 +0000661 if ($offset > 0)
662 {
663 $sql .= " OFFSET ".$offset;
664 }
Barry Mienydd671972010-10-04 16:33:58 +0200665
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 return $sql;
667 }
668
669 // --------------------------------------------------------------------
670
671 /**
672 * Close DB Connection
673 *
674 * @access public
675 * @param resource
676 * @return void
677 */
678 function _close($conn_id)
679 {
680 @pg_close($conn_id);
681 }
682
683
684}
685
686
687/* End of file postgre_driver.php */
Andrey Andreev063f5962012-02-27 12:20:52 +0200688/* Location: ./system/database/drivers/postgre/postgre_driver.php */