d7: to be inserted ID, is there a cleaner way?
I don't think there's a 100% reliable way to get the ID that will be used next. Even the method you've got won't work completely. Take this example:


Insert a node into the database (it has the new nid of 1 for arguments sake)
Insert another node into the database (it has the new nid of 2)
Then delete that second node
Add a new node to the database again. This time it will have a nid of 3, not 2 (as would be expected from your code).


The problem is that the MySQL AUTO_INCREMENT value exists completely independently of the primary key ids that are currently in the database; so unless you reset the auto increment counter each time there's no way to reliably determine the next id.

Also in a system with multiple simultaneous accessess to the database using code like that introduces potential race conditions.

It would be far simpler to perform this task when the node has been saved, perhaps in hook_node_save().

Oh and one other little thing, the vid you're inserting should not be 1, it'll be determined for you by the system. Using 1 for every node will link every single node to one revision in the node_revision table...probably not what you're looking for.