MySQL插入重复密钥更新 - 基数违规

时间:2014-04-25 07:28:07

标签: mysql

我有一张桌子:

    CREATE TABLE `goodsXML` (
 `id` bigint(20) unsigned NOT NULL,
 `localID` int(6) NOT NULL,
 `dateCreated` datetime NOT NULL,
 `dateModified` datetime NOT NULL,
 `name` char(255) DEFAULT NULL,
 `groupName` char(255) DEFAULT NULL,
 `url` char(255) NOT NULL,
 `sourceUrl` char(255) NOT NULL,
 `categoryID` int(6) unsigned NOT NULL,
 `producerID` int(6) DEFAULT NULL,
 `shopID` int(6) NOT NULL,
 `XMLUrlOrder` tinyint(2) NOT NULL,
 `price` float(12,2) NOT NULL,
 `description` text,
 `descriptionHash` char(32) NOT NULL,
 `isRST` tinyint(1) NOT NULL DEFAULT '0',
 `isReplica` tinyint(1) NOT NULL DEFAULT '0',
 `status` tinyint(1) NOT NULL DEFAULT '0',
 `comment` char(255) NOT NULL,
 UNIQUE KEY `ixGroupNameCategoryIDShopIDProducerID` (`shopID`,`localID`),
 KEY `ixGroupNameCategoryID` (`groupName`,`categoryID`),
 KEY `ixDateModified` (`dateModified`),
 KEY `ixStatusShopID` (`status`,`shopID`),
 KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=133298 DEFAULT CHARSET=utf8

我有一个简单的查询:

INSERT goodsXML
                SET
                    localID='".$goodXML['localID']."',
                    dateCreated=NOW(),
                    dateModified=NOW(),
                    name='".mysql_escape_string($goodXML['name'])."',
                    groupName='".$groupName['groupName']."',
                    url='".$groupName['url']."',
                    sourceUrl='".$goodXML['sourceUrl']."',
                    categoryID=".$goodXML['categoryID'].",
                    producerID='".$goodXML['producerID']."',
                    shopID=".$this->shopID.",
                    XMLUrlOrder=".$this->XMLUrlOrder.",
                    price='".$goodXML['price']."',
                    description='".mysql_escape_string($goodXML['description'])."',
                    descriptionHash=MD5('".mysql_escape_string($goodXML['description'])."'),
                    isRST='".$goodXML['isRST']."',
                    isReplica='".$goodXML['isReplica']."',
                    status=".$status."
                ON DUPLICATE KEY UPDATE
                    #id=LAST_INSERT_ID(id),
                    dateModified=NOW(),
                    sourceUrl='".$goodXML['sourceUrl']."',
                    price='".$goodXML['price']."',
                    description='".mysql_escape_string($goodXML['description'])."',
                    descriptionHash=MD5('".mysql_escape_string($goodXML['description'])."'),
                    isRST='".$goodXML['isRST']."',
                    isReplica='".$goodXML['isReplica']."'

有时会出现以下错误

SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row in line 814

MySQL版本5.5.31-0。

请注意,我已经删除了所有其他唯一索引,并且还禁用了自动增量,但没有更改!

无法找到这里发生的事情。谢谢!

0 个答案:

没有答案