I'm trying to understand why I want to use db_next_id instead of just letting a table with an autoincrement do its thing. Drupal docs says "for compatibility reasons" but I'm not sure what incompatibilities there might be. Granted I only know mysql, and only enough to get me by...
Here is an example from aggregator.module ( vrs 1.213.2.3)
$edit['fid'] = db_next_id('{aggregator_feed}_fid');
db_query('INSERT INTO {aggregator_feed} (fid, title, url, refresh, block) VALUES (%d, \'%s\', \'%s\', %d, %d)',
$edit['fid'],$edit['title'], $edit['url'], $edit['refresh'], $edit['block']);
The aggregator fid column is autoincrement, so why not just pass it a NULL or 0?
The reason I ask is I'm playing with some ideas for a per user RSS feeds module, and I would like to reuse some of the aggregator functions. However, trying to get at the last ID added to the aggregator table without using something like LAST_INSERT_ID() is troublesome and slow. Since LAST_INSERT_ID only stores the last id when the autoincrement is allowed to 'go off' and do it's thing, using db_next_id and inserting the returned value directly doesn't register anything with LAST_INSERT_ID...
I'm thinking this is a postgre versus mysql thing...
Looking at db_next_id it uses nextval() to get the id - i thought I might be able to use currval() to do the same thing as LAST_INSERT_ID() but that didn't work out...