db_last_insert_id

View: New views
5 Messages — Rating Filter:   Alert me  

db_last_insert_id

by Jeff Greenberg-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm confused with the db_last_insert_id function in
database.mysql-common.inc.


The function is:


function db_last_insert_id($table, $field) {
  return db_result(db_query('SELECT LAST_INSERT_ID()'));
}


and I see no reason whatsoever for there to be any parameters, let alone
required ones.


Re: db_last_insert_id

by Joe Pletcher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The postgres version is:

function db_last_insert_id($table, $field) {
   return db_result(db_query("SELECT CURRVAL('{". db_escape_table
($table) ."}_". db_escape_table($field) ."_seq')"));
}

Joe

On Nov 4, 2009, at 7:07 PM, Jeff Greenberg wrote:

> I'm confused with the db_last_insert_id function in database.mysql-
> common.inc.
>
>
> The function is:
>
>
> function db_last_insert_id($table, $field) {
> return db_result(db_query('SELECT LAST_INSERT_ID()'));
> }
>
>
> and I see no reason whatsoever for there to be any parameters, let  
> alone required ones.
>


Re: db_last_insert_id

by Mlen-Too Wesley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It works differently in PostgreSQL, see database.pgsql.inc, or here:
http://api.drupal.org/api/function/db_last_insert_id

On Wed, Nov 4, 2009 at 7:07 PM, Jeff Greenberg <jeff@...> wrote:
I'm confused with the db_last_insert_id function in database.mysql-common.inc.


The function is:


function db_last_insert_id($table, $field) {
 return db_result(db_query('SELECT LAST_INSERT_ID()'));
}


and I see no reason whatsoever for there to be any parameters, let alone required ones.



Re: db_last_insert_id

by Jamie Holly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not for MySQL, but that function needs to be the same for the other
databases. Look at database.pgsql.inc:

function db_last_insert_id($table, $field) {
  return db_result(db_query("SELECT CURRVAL('{". db_escape_table($table)
."}_". db_escape_table($field) ."_seq')"));
}


Jamie Holly
http://www.intoxination.net 
http://www.hollyit.net



Jeff Greenberg wrote:

> I'm confused with the db_last_insert_id function in
> database.mysql-common.inc.
>
>
> The function is:
>
>
> function db_last_insert_id($table, $field) {
>   return db_result(db_query('SELECT LAST_INSERT_ID()'));
> }
>
>
> and I see no reason whatsoever for there to be any parameters, let alone
> required ones.
>
>
>  

Re: db_last_insert_id

by Jeff Greenberg-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah, makes complete sense now. I need to become more 'culturally' aware!  
Thanks!