From 614711ff2189b20f06104848554ff5a3087b82a2 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 25 Feb 2019 18:51:49 -0800 Subject: [PATCH] Database: Prevent gaps in PRIMARY index when using DUPLICATE_KEY_UPDATE with insert() method. --- e107_handlers/e_db_pdo_class.php | 2 ++ e107_handlers/mysql_class.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/e107_handlers/e_db_pdo_class.php b/e107_handlers/e_db_pdo_class.php index 88375b962..70830f370 100644 --- a/e107_handlers/e_db_pdo_class.php +++ b/e107_handlers/e_db_pdo_class.php @@ -856,6 +856,8 @@ class e_db_pdo implements e_db elseif($this->mySQLresult === 2 || $this->mySQLresult === true) // updated { $result = true; + // reset auto-increment to prevent gaps. + $this->db_Query("ALTER TABLE ".$this->mySQLPrefix.$table." AUTO_INCREMENT=1", NULL, 'db_Insert', $debug, $log_type, $log_remark); } elseif($this->mySQLresult === 0) // updated (no change) { diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index cd1a60357..ecad1804a 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -1018,6 +1018,9 @@ class e_db_mysql elseif($this->mySQLresult === 2 || $this->mySQLresult === true) // updated { $result = true; + // reset auto-increment to prevent gaps. + $this->db_Query("ALTER TABLE ".$this->mySQLPrefix.$table." AUTO_INCREMENT=1", NULL, 'db_Insert', $debug, $log_type, $log_remark); + } elseif($this->mySQLresult === 0) // updated (no change) {