Welcome Guest, Not a member yet? Register   Sign In
Igniting Code with Code Igniter
#1

[eluser]Unknown[/eluser]
Igniting Code with Code Igniter


modified system/database/driver/postgre/postgre_driver.php
Code:
function insert_id()
{
$v = pg_version($this->conn_id);
if (isset($v[’server’])) $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);
}
/**
* another insert id Hack for PostgreSQL
* @author : Hasin Hayder
* @since : March 09, 2007
*/
elseif(is_null($v))
{
$sql=’SELECT (LASTVAL()) as ins_id’;
}
/**
* End Hack
*/
else
{
return pg_last_oid($this->result_id);
}
$query = $this->query($sql);
$row = $query->row();
return $row->ins_id;
}

[mod edit: added code tags]
#2

[eluser]Grahack[/eluser]
I'm not a PostG user but I have few things to say.
'code' tags are great to display source code, makes it more readable.
Also, you thread title is quite unclear.
Cheers!

EDIT: the same for this one




Theme © iAndrew 2016 - Forum software by © MyBB