blob: 50f096b5d98e01007e49e92d970a45defe0e16d5 [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
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @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 /**
150 * Set client character set
151 *
152 * @access public
153 * @param string
154 * @param string
155 * @return resource
156 */
157 function db_set_charset($charset, $collation)
158 {
159 // @todo - add support if needed
160 return TRUE;
161 }
162
163 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200164
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 /**
166 * Version number query string
167 *
168 * @access public
169 * @return string
170 */
171 function _version()
172 {
173 return "SELECT version() AS ver";
174 }
175
176 // --------------------------------------------------------------------
177
178 /**
179 * Execute the query
180 *
181 * @access private called by the base class
182 * @param string an SQL query
183 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200184 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 function _execute($sql)
186 {
187 $sql = $this->_prep_query($sql);
188 return @pg_query($this->conn_id, $sql);
189 }
Barry Mienydd671972010-10-04 16:33:58 +0200190
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 // --------------------------------------------------------------------
192
193 /**
194 * Prep the query
195 *
196 * If needed, each database adapter can prep the query string
197 *
198 * @access private called by execute()
199 * @param string an SQL query
200 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200201 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 function _prep_query($sql)
203 {
204 return $sql;
205 }
206
207 // --------------------------------------------------------------------
208
209 /**
210 * Begin Transaction
211 *
212 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200213 * @return bool
214 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 function trans_begin($test_mode = FALSE)
216 {
217 if ( ! $this->trans_enabled)
218 {
219 return TRUE;
220 }
Barry Mienydd671972010-10-04 16:33:58 +0200221
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 // When transactions are nested we only begin/commit/rollback the outermost ones
223 if ($this->_trans_depth > 0)
224 {
225 return TRUE;
226 }
227
228 // Reset the transaction failure flag.
229 // If the $test_mode flag is set to TRUE transactions will be rolled back
230 // even if the queries produce a successful result.
231 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
232
233 return @pg_exec($this->conn_id, "begin");
234 }
235
236 // --------------------------------------------------------------------
237
238 /**
239 * Commit Transaction
240 *
241 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200242 * @return bool
243 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 function trans_commit()
245 {
246 if ( ! $this->trans_enabled)
247 {
248 return TRUE;
249 }
250
251 // When transactions are nested we only begin/commit/rollback the outermost ones
252 if ($this->_trans_depth > 0)
253 {
254 return TRUE;
255 }
256
257 return @pg_exec($this->conn_id, "commit");
258 }
259
260 // --------------------------------------------------------------------
261
262 /**
263 * Rollback Transaction
264 *
265 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200266 * @return bool
267 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 function trans_rollback()
269 {
270 if ( ! $this->trans_enabled)
271 {
272 return TRUE;
273 }
274
275 // When transactions are nested we only begin/commit/rollback the outermost ones
276 if ($this->_trans_depth > 0)
277 {
278 return TRUE;
279 }
280
281 return @pg_exec($this->conn_id, "rollback");
282 }
283
284 // --------------------------------------------------------------------
285
286 /**
287 * Escape String
288 *
289 * @access public
290 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000291 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 * @return string
293 */
Derek Jonese4ed5832009-02-20 21:44:59 +0000294 function escape_str($str, $like = FALSE)
295 {
296 if (is_array($str))
297 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500298 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200299 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000300 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200301 }
302
303 return $str;
304 }
Derek Jonese4ed5832009-02-20 21:44:59 +0000305
306 $str = pg_escape_string($str);
Barry Mienydd671972010-10-04 16:33:58 +0200307
Derek Jonese4ed5832009-02-20 21:44:59 +0000308 // escape LIKE condition wildcards
309 if ($like === TRUE)
310 {
311 $str = str_replace( array('%', '_', $this->_like_escape_chr),
312 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
313 $str);
314 }
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Jonese4ed5832009-02-20 21:44:59 +0000316 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 }
Barry Mienydd671972010-10-04 16:33:58 +0200318
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 // --------------------------------------------------------------------
320
321 /**
322 * Affected Rows
323 *
324 * @access public
325 * @return integer
326 */
327 function affected_rows()
328 {
329 return @pg_affected_rows($this->result_id);
330 }
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 // --------------------------------------------------------------------
333
334 /**
335 * Insert ID
336 *
337 * @access public
338 * @return integer
339 */
340 function insert_id()
341 {
342 $v = $this->_version();
343 $v = $v['server'];
Barry Mienydd671972010-10-04 16:33:58 +0200344
Pascal Kriete8761ef52011-02-14 13:13:52 -0500345 $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
346 $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
Barry Mienydd671972010-10-04 16:33:58 +0200347
Pascal Kriete8761ef52011-02-14 13:13:52 -0500348 if ($table == NULL && $v >= '8.1')
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 {
350 $sql='SELECT LASTVAL() as ins_id';
351 }
Pascal Kriete8761ef52011-02-14 13:13:52 -0500352 elseif ($table != NULL && $column != NULL && $v >= '8.0')
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 {
354 $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
355 $query = $this->query($sql);
356 $row = $query->row();
357 $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
358 }
Pascal Kriete8761ef52011-02-14 13:13:52 -0500359 elseif ($table != NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 {
361 // seq_name passed in table parameter
362 $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
363 }
364 else
365 {
366 return pg_last_oid($this->result_id);
367 }
368 $query = $this->query($sql);
369 $row = $query->row();
370 return $row->ins_id;
371 }
372
373 // --------------------------------------------------------------------
374
375 /**
376 * "Count All" query
377 *
378 * Generates a platform-specific query string that counts all records in
379 * the specified database
380 *
381 * @access public
382 * @param string
383 * @return string
384 */
385 function count_all($table = '')
386 {
387 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000388 {
389 return 0;
390 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000391
Derek Allarde37ab382009-02-03 16:13:57 +0000392 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000395 {
396 return 0;
397 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000398
399 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500400 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000401 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 }
403
404 // --------------------------------------------------------------------
405
406 /**
407 * Show table query
408 *
409 * Generates a platform-specific query string so that the table names can be fetched
410 *
411 * @access private
412 * @param boolean
413 * @return string
414 */
415 function _list_tables($prefix_limit = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200416 {
417 $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
418
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
420 {
Greg Aker0d424892010-01-26 02:14:44 +0000421 $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 +0000422 }
Barry Mienydd671972010-10-04 16:33:58 +0200423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 return $sql;
425 }
Barry Mienydd671972010-10-04 16:33:58 +0200426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 // --------------------------------------------------------------------
428
429 /**
430 * Show column query
431 *
432 * Generates a platform-specific query string so that the column names can be fetched
433 *
434 * @access public
435 * @param string the table name
436 * @return string
437 */
438 function _list_columns($table = '')
439 {
440 return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
441 }
442
443 // --------------------------------------------------------------------
444
445 /**
446 * Field data query
447 *
448 * Generates a platform-specific query so that the column data can be retrieved
449 *
450 * @access public
451 * @param string the table name
452 * @return object
453 */
454 function _field_data($table)
455 {
456 return "SELECT * FROM ".$table." LIMIT 1";
457 }
458
459 // --------------------------------------------------------------------
460
461 /**
462 * The error message string
463 *
464 * @access private
465 * @return string
466 */
467 function _error_message()
468 {
469 return pg_last_error($this->conn_id);
470 }
Barry Mienydd671972010-10-04 16:33:58 +0200471
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 // --------------------------------------------------------------------
473
474 /**
475 * The error message number
476 *
477 * @access private
478 * @return integer
479 */
480 function _error_number()
481 {
482 return '';
483 }
484
485 // --------------------------------------------------------------------
486
487 /**
488 * Escape the SQL Identifiers
489 *
490 * This function escapes column and table names
491 *
492 * @access private
493 * @param string
494 * @return string
495 */
496 function _escape_identifiers($item)
497 {
498 if ($this->_escape_char == '')
499 {
500 return $item;
501 }
502
503 foreach ($this->_reserved_identifiers as $id)
504 {
505 if (strpos($item, '.'.$id) !== FALSE)
506 {
Barry Mienydd671972010-10-04 16:33:58 +0200507 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
508
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 // remove duplicates if the user already included the escape
510 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200511 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 }
Barry Mienydd671972010-10-04 16:33:58 +0200513
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 if (strpos($item, '.') !== FALSE)
515 {
Barry Mienydd671972010-10-04 16:33:58 +0200516 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 }
518 else
519 {
520 $str = $this->_escape_char.$item.$this->_escape_char;
521 }
Barry Mienydd671972010-10-04 16:33:58 +0200522
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 // remove duplicates if the user already included the escape
524 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
525 }
Barry Mienydd671972010-10-04 16:33:58 +0200526
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 // --------------------------------------------------------------------
528
529 /**
530 * From Tables
531 *
532 * This function implicitly groups FROM tables so there is no confusion
533 * about operator precedence in harmony with SQL standards
534 *
535 * @access public
536 * @param type
537 * @return type
538 */
539 function _from_tables($tables)
540 {
541 if ( ! is_array($tables))
542 {
543 $tables = array($tables);
544 }
Barry Mienydd671972010-10-04 16:33:58 +0200545
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 return implode(', ', $tables);
547 }
548
549 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 /**
552 * Insert statement
553 *
554 * Generates a platform-specific insert string from the supplied data
555 *
556 * @access public
557 * @param string the table name
558 * @param array the insert keys
559 * @param array the insert values
560 * @return string
561 */
562 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200563 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000564 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
565 }
Barry Mienydd671972010-10-04 16:33:58 +0200566
Derek Allard2067d1a2008-11-13 22:59:24 +0000567 // --------------------------------------------------------------------
568
569 /**
Greg Aker60ef4ea2011-04-27 01:45:38 -0500570 * Insert_batch statement
571 *
572 * Generates a platform-specific insert string from the supplied data
573 *
574 * @access public
575 * @param string the table name
576 * @param array the insert keys
577 * @param array the insert values
578 * @return string
579 */
580 function _insert_batch($table, $keys, $values)
581 {
582 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
583 }
584
585 // --------------------------------------------------------------------
586
587 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 * Update statement
589 *
590 * Generates a platform-specific update string from the supplied data
591 *
592 * @access public
593 * @param string the table name
594 * @param array the update data
595 * @param array the where clause
596 * @param array the orderby clause
597 * @param array the limit clause
598 * @return string
599 */
600 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
601 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500602 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 {
604 $valstr[] = $key." = ".$val;
605 }
Barry Mienydd671972010-10-04 16:33:58 +0200606
Derek Allard2067d1a2008-11-13 22:59:24 +0000607 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200608
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200610
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
612
613 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
614
615 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200616
Derek Allard2067d1a2008-11-13 22:59:24 +0000617 return $sql;
618 }
619
620 // --------------------------------------------------------------------
621
622 /**
623 * Truncate statement
624 *
625 * Generates a platform-specific truncate string from the supplied data
626 * If the database does not support the truncate() command
627 * This function maps to "DELETE FROM table"
628 *
629 * @access public
630 * @param string the table name
631 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200632 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000633 function _truncate($table)
634 {
635 return "TRUNCATE ".$table;
636 }
Barry Mienydd671972010-10-04 16:33:58 +0200637
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 // --------------------------------------------------------------------
639
640 /**
641 * Delete statement
642 *
643 * Generates a platform-specific delete string from the supplied data
644 *
645 * @access public
646 * @param string the table name
647 * @param array the where clause
648 * @param string the limit clause
649 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200650 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
652 {
653 $conditions = '';
654
655 if (count($where) > 0 OR count($like) > 0)
656 {
657 $conditions = "\nWHERE ";
658 $conditions .= implode("\n", $this->ar_where);
659
660 if (count($where) > 0 && count($like) > 0)
661 {
662 $conditions .= " AND ";
663 }
664 $conditions .= implode("\n", $like);
665 }
666
667 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200668
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 return "DELETE FROM ".$table.$conditions.$limit;
670 }
671
672 // --------------------------------------------------------------------
673 /**
674 * Limit string
675 *
676 * Generates a platform-specific LIMIT clause
677 *
678 * @access public
679 * @param string the sql query string
680 * @param integer the number of rows to limit the query to
681 * @param integer the offset value
682 * @return string
683 */
684 function _limit($sql, $limit, $offset)
Barry Mienydd671972010-10-04 16:33:58 +0200685 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 $sql .= "LIMIT ".$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200687
Derek Allard2067d1a2008-11-13 22:59:24 +0000688 if ($offset > 0)
689 {
690 $sql .= " OFFSET ".$offset;
691 }
Barry Mienydd671972010-10-04 16:33:58 +0200692
Derek Allard2067d1a2008-11-13 22:59:24 +0000693 return $sql;
694 }
695
696 // --------------------------------------------------------------------
697
698 /**
699 * Close DB Connection
700 *
701 * @access public
702 * @param resource
703 * @return void
704 */
705 function _close($conn_id)
706 {
707 @pg_close($conn_id);
708 }
709
710
711}
712
713
714/* End of file postgre_driver.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000715/* Location: ./system/database/drivers/postgre/postgre_driver.php */