Standard db_last_insert_id instead of VBTODRUPAL_ADD_TO_IDS

juan_g - October 29, 2009 - 14:53
Project:vBulletin to Drupal
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Instead of:

define('VBTODRUPAL_ADD_TO_IDS', 1000000);

which gives IDs such as 1000001, etc., the standard way for vbtodrupal -and all D6 modules- would be to use the db_last_insert_id API function for each table.

For example, comment_save uses it in this way:

$edit['cid'] = db_last_insert_id('comments', 'cid');

#1

smk-ka - November 27, 2009 - 16:39

vBulletin to Drupal doesn't create rows one by one, hence this approach won't work.

It should work, however, to read out the current auto_increment counters for all affected tables, determine the maximum value and use it as offset:
SELECT MAX(Auto_increment) FROM information_schema.tables WHERE table_schema = 'drupal_database_name' AND table_name IN ('node', 'node_revisions', 'comment', 'user', etc...);
This doesn't save us from "holes" in index numbers, but at least keeps the holes as small as possible. And it's limited to MySQL 5 (or whichever version introduced the information_schema).

 
 

Drupal is a registered trademark of Dries Buytaert.