Added support for get_last_insert_id($table, $field). pgsql is currently the only class making use of the params since it returns the unique OID for the system. The params are required so pgsql compatibility is forcibly maintained.

This commit is contained in:
mdean 2001-08-08 03:14:05 +00:00
parent ea40a2ac06
commit af6d27da68
3 changed files with 56 additions and 2 deletions

View File

@ -256,6 +256,28 @@
}
/* public: table locking */
function get_last_insert_id($table, $field)
{
/* This will get the last insert ID created on the current connection. Should only be called
* after an insert query is run on a table that has an auto incrementing field. Of note, table
* and field are required for pgsql compatiblity. MSSQL uses a query to retrieve the last
* identity on the connection, so table and field are ignored here as well.
*/
if (!isset($table) || $table == '' || !isset($field) || $field == '')
return -1;
$result = @mssql_query("select @@identity", $this->Link_ID);
if (!$result)
return -1;
$Record = @mssql_fetch_row(0);
@mssql_free_result($result);
if (!is_array($Record)) /* no identity? */
return -1;
return $Record[0];
}
function lock($table, $mode="write")
{
return 1; // FIXME: fill it in!

View File

@ -289,12 +289,17 @@
return True;
}
function get_last_insert_id()
function get_last_insert_id($table, $field)
{
/* This will get the last insert ID created on the current connection. Should only be called
* after an insert query is run on a table that has an auto incrementing field.
* after an insert query is run on a table that has an auto incrementing field. $table and
* $field are required, but unused here since it's unnecessary for mysql. For compatibility
* with pgsql, the params must be supplied.
*/
if (!isset($table) || $table == '' || !isset($field) || $field == '')
return -1;
return @mysql_insert_id($this->Link_ID);
}

View File

@ -273,6 +273,33 @@
return pg_Exec($this->Link_ID,'rollback');
}
function get_last_insert_id($table, $field)
{
/* This will get the last insert ID created on the current connection. Should only be called
* after an insert query is run on a table that has an auto incrementing field. Of note, table
* and field are required because pgsql returns the last inserted OID, which is unique across
* an entire installation. These params allow us to retrieve the sequenced field without adding
* conditional code to the apps.
*/
if (!isset($table) || $table == '' || !isset($field) || $field == '')
return -1;
$oid = pg_getlastoid($this->Query_ID);
if ($oid == -1)
return -1;
$result = @pg_Exec($this->Link_ID, "select $field from $table where oid=$oid");
if (!$result)
return -1;
$Record = @pg_fetch_array($result, 0);
@pg_freeresult($result);
if (!is_array($Record)) /* OID not found? */
return -1;
return $Record[0];
}
function lock($table, $mode = 'write')
{
$result = $this->transaction_begin();