summaryrefslogtreecommitdiffstats
path: root/system/drivers
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-09-06 03:55:56 +0200
committeradmin <devnull@localhost>2006-09-06 03:55:56 +0200
commit1066dcb279e26de29fd663d61957dfcd1f939f9a (patch)
tree5b82e2855a20145221a49ce2d0945d4005e5d924 /system/drivers
parent5ffcde80fe0c37015c5383da6e53389ad6f4d6f0 (diff)
Diffstat (limited to 'system/drivers')
-rw-r--r--system/drivers/DB_postgre.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php
index f0be3c0b1..aa7ec7020 100644
--- a/system/drivers/DB_postgre.php
+++ b/system/drivers/DB_postgre.php
@@ -154,7 +154,35 @@ class CI_DB_postgre extends CI_DB {
*/
function insert_id()
{
- return pg_last_oid($this->result_id);
+ $v = pg_version($this->conn_id);
+ $v = $v['server'];
+
+ $table = func_num_args() > 0 ? func_get_arg(0) : null;
+ $column = func_num_args() > 1 ? func_get_arg(1) : null;
+
+ if ($table == null && $v >= '8.1')
+ {
+ $sql='SELECT LASTVAL() as ins_id';
+ }
+ elseif ($table != null && $column != null && $v >= '8.0')
+ {
+ $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
+ $query = $this->query($sql);
+ $row = $query->row();
+ $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
+ }
+ elseif ($table != null)
+ {
+ // seq_name passed in table parameter
+ $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
+ }
+ else
+ {
+ return pg_last_oid($this->result_id);
+ }
+ $query = $this->query($sql);
+ $row = $query->row();
+ return $row->ins_id;
}
// --------------------------------------------------------------------