Index: includes/database.mysql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysql.inc,v
retrieving revision 1.73
diff -u -p -r1.73 database.mysql.inc
--- includes/database.mysql.inc	25 May 2007 21:01:30 -0000	1.73
+++ includes/database.mysql.inc	29 May 2007 05:39:55 -0000
@@ -31,6 +31,11 @@ function db_status_report($phase) {
     $form['mysql']['severity'] = REQUIREMENT_ERROR;
     $form['mysql']['description'] = $t('Your MySQL Server is too old. Drupal requires at least MySQL %version.', array('%version' => DRUPAL_MINIMUM_MYSQL));
   }
+  
+  if (strpos(DRUPAL_BUGGY_MYSQL, $version) !== FALSE) {
+    $form['mysql']['severity'] = REQUIREMENT_ERROR;
+    $form['mysql']['description'] = $t('Your MySQL Server version has a known flaw that prevents Drupal from operating properly. Consider upgrading to at least MySQL version %version.', array('%version' => DRUPAL_NOT_BUGGY_MYSQL));
+  }
 
   return $form;
 }
@@ -250,11 +255,14 @@ function db_error() {
  * with table prefixes. For example, db_next_id('{node}_nid');
  */
 function db_next_id($name) {
-  global $active_db;
   $name = db_prefix_tables($name);
-  db_query('INSERT INTO {sequences} VALUES ("%s", LAST_INSERT_ID(1)) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name);
-
-  return mysql_insert_id($active_db);
+  // Reset LAST_INSERT_ID so it doesn't have a stale value if INSERT succeeds.
+  // The reset is necessary here because MySQL 4.1.21 cannot handle multiple
+  // LAST_INSERT_ID calls in a single query.
+  db_query('SELECT LAST_INSERT_ID(1)');
+  db_query('INSERT INTO {sequences} VALUES ("%s", 1) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name);
+  $id = db_result(db_query('SELECT LAST_INSERT_ID()'));
+  return $id;
 }
 
 /**
Index: includes/database.mysqli.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysqli.inc,v
retrieving revision 1.37
diff -u -p -r1.37 database.mysqli.inc
--- includes/database.mysqli.inc	25 May 2007 21:01:30 -0000	1.37
+++ includes/database.mysqli.inc	29 May 2007 05:39:56 -0000
@@ -36,6 +36,11 @@ function db_status_report($phase) {
     $form['mysql']['description'] = $t('Your MySQL Server is too old. Drupal requires at least MySQL %version.', array('%version' => DRUPAL_MINIMUM_MYSQL));
   }
 
+  if (strpos(DRUPAL_BUGGY_MYSQL, $version) !== FALSE) {
+    $form['mysql']['severity'] = REQUIREMENT_ERROR;
+    $form['mysql']['description'] = $t('Your MySQL Server version has a known flaw that prevents Drupal from operating properly. Consider upgrading to at least MySQL version %version.', array('%version' => DRUPAL_NOT_BUGGY_MYSQL));
+  }
+
   return $form;
 }
 
@@ -242,11 +247,14 @@ function db_error() {
  * with table prefixes. For example, db_next_id('{node}_nid');
  */
 function db_next_id($name) {
-  global $active_db;
   $name = db_prefix_tables($name);
-  db_query('INSERT INTO {sequences} VALUES ("%s", LAST_INSERT_ID(1)) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name);
-
-  return mysqli_insert_id($active_db);
+  // Reset LAST_INSERT_ID so it doesn't have a stale value if INSERT succeeds.
+  // The reset is necessary here because MySQL 4.1.21 cannot handle multiple
+  // LAST_INSERT_ID calls in a single query.
+  db_query('SELECT LAST_INSERT_ID(1)');
+  db_query('INSERT INTO {sequences} VALUES ("%s", 1) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name);
+  $id = db_result(db_query('SELECT LAST_INSERT_ID()'));
+  return $id;
 }
 
 /**
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.484
diff -u -p -r1.484 system.module
--- modules/system/system.module	28 May 2007 06:08:44 -0000	1.484
+++ modules/system/system.module	29 May 2007 05:39:58 -0000
@@ -8,10 +8,12 @@
 
 define('VERSION', '6.0-dev');
 
-define('DRUPAL_MINIMUM_PHP',    '4.3.3');
-define('DRUPAL_MINIMUM_MYSQL',  '4.1.0'); // If using MySQL
-define('DRUPAL_MINIMUM_PGSQL',  '7.4');   // If using PostgreSQL
-define('DRUPAL_MINIMUM_APACHE', '1.3');   // If using Apache
+define('DRUPAL_MINIMUM_PHP',     '4.3.3');
+define('DRUPAL_MINIMUM_MYSQL',   '4.1.0'); // If using MySQL
+define('DRUPAL_BUGGY_MYSQL',     '5.0.37,5.0.38,5.0.39');
+define('DRUPAL_NOT_BUGGY_MYSQL', '5.0.40');
+define('DRUPAL_MINIMUM_PGSQL',   '7.4');   // If using PostgreSQL
+define('DRUPAL_MINIMUM_APACHE',  '1.3');   // If using Apache
 
 /**
  * Implementation of hook_help().
