我见过许多以该消息开头的主题,但找不到与我的问题相关的主题。
以下是创建异常的代码,并显示错误消息:“SQLSTATE[HY000]:一般错误”。我的问题是:除了“一般错误”之外我什么也没有。 实际上,没有错误:据我所知,我要删除的行已正确删除。 如果我在 phpMyAdmin 中使用查询,则不会出现错误。 我想知道为什么我在一切似乎都正常的情况下却出现了这个错误。
public function deleteAllUnused() {
try {
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata("\Entity\CataloguePrixDetailProduit", "cpdp");
$sqlRequest = $this->buildDeleteAllUnusedRequest();
return $this->getEntityManager()
->createNativeQuery($sqlRequest, $rsm)
->execute();
} catch (Exception $exc) {
throw new Exception($exc->getMessage());
}
}
private function buildDeleteAllUnusedRequest() {
return
"DELETE cpdp.*\n"
. "FROM CataloguePrixDetailProduit cpdp JOIN (\n"
. "SELECT cpdp2.idCataloguePrixDetailProduit\n"
. "FROM CataloguePrixDetailProduit cpdp2\n"
. "WHERE cpdp2.idCataloguePrixDetailProduit NOT IN (\n"
. "SELECT DISTINCT(cpdp3.idCataloguePrixDetailProduit)\n"
. "FROM CataloguePrixDetailProduit cpdp3\n"
. "INNER JOIN CatalogueExploitantFournisseur cef ON cpdp3.idCatalogueExploitantFournisseur = cef.idCatalogueExploitantFournisseur\n"
. "INNER JOIN CatalogueExploitant ce ON cef.idCatalogueExploitant = ce.idCatalogueExploitant\n"
. "INNER JOIN DetailProduitCommandeServiceValide dpcsv \n"
. "ON dpcsv.idDetailProduit = cpdp3.idDetailProduit\n"
. "AND dpcsv.idFournisseur = cef.idFournisseur\n"
. "AND dpcsv.idExploitant = ce.idExploitant\n"
. ")\n"
. ") r ON r.idCataloguePrixDetailProduit = cpdp.idCataloguePrixDetailProduit";
}
我不明白出了什么问题。我无法保留无缘无故发送错误消息的应用程序。
编辑: 这是异常堆栈:
[10:02:38][Repository\CataloguePrixDetailProduitRepository][deleteAllUnused] : SQLSTATE[HY000]: General error
#0 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\library\DoctrineOrm\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(148): PDOStatement->fetch(2)
#1 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\library\DoctrineOrm\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(111): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
#2 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\library\DoctrineOrm\Doctrine\ORM\AbstractQuery.php(747): Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(Object(Doctrine\DBAL\Driver\PDOStatement), Object(Doctrine\ORM\Query\ResultSetMappingBuilder), Array)
#3 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\model\Repository\CataloguePrixDetailProduitRepository.php(107): Doctrine\ORM\AbstractQuery->execute()
#4 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\controller\CataloguePrixDetailProduitController.php(196): Repository\CataloguePrixDetailProduitRepository->deleteAllUnused()
#5 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\library\Dispatcher.php(60): CataloguePrixDetailProduitController->ajaxLoadedFlushPrixUnused()
#6 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\library\Dispatcher.php(11): Dispatcher->callAction(Object(CataloguePrixDetailProduitController))
#7 C:\xampp\htdocs\projects\Sogesa\applications\SogesaWeb\webroot\index.php(21): Dispatcher->__construct()
#8 {main}
感谢您的宝贵时间。
最佳答案
To Fix this general issue use DQL statement
createQuery Instead of using createNativeQuery
当我尝试使用 createNativeQuery 执行删除查询时,我遇到了此错误,但在阅读此 link 后我们将其更改为 createQuery,它对我有用。
关于mysql - SQLSTATE[HY000] : General error with doctrine2 and no error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24733577/