Index: trunk/core/kernel/application.php =================================================================== diff -u -r3066 -r3075 --- trunk/core/kernel/application.php (.../application.php) (revision 3066) +++ trunk/core/kernel/application.php (.../application.php) (revision 3075) @@ -1276,15 +1276,22 @@ * * @return int * @access public - * @author Eduard + * @author Alex */ function NextResourceId() { - $this->DB->Query('LOCK TABLES '.TABLE_PREFIX.'IdGenerator WRITE'); - $this->DB->Query('UPDATE '.TABLE_PREFIX.'IdGenerator SET lastid = lastid+1'); - $id = $this->DB->GetOne("SELECT lastid FROM ".TABLE_PREFIX."IdGenerator"); + $table_name = TABLE_PREFIX.'IdGenerator'; + + $this->DB->Query('LOCK TABLES '.$table_name.' WRITE'); + $this->DB->Query('UPDATE '.$table_name.' SET lastid = lastid + 1'); + $id = $this->DB->GetOne('SELECT lastid FROM '.$table_name); + if($id === false) + { + $this->DB->Query('INSERT INTO '.$table_name.' (lastid) VALUES (2)'); + $id = 2; + } $this->DB->Query('UNLOCK TABLES'); - return $id; + return $id - 1; } /**