执行'select count(distinct o0.id)as sclr\u 0 from order o0\u'时发生异常

hfsqlsce  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(261)

在symfony 3.4.8上使用sonataadminbundle时,我遇到了以下问题:
当我去查看我的表的列表时,我得到以下错误。
执行“select count(distinct o0\ id)as sclr\ U 0 from order o0\时发生异常:
sqlstate[42000]:语法错误或访问冲突:1064您的sql语法有错误;检查与mysql服务器版本相对应的手册,以获得在第1行“order o0\”附近使用的正确语法
我的实体\订单.php

<?php

namespace Gobusgo\GobusgoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Order
 *
 * @ORM\Table(name="Order")
 *  @ORM\Entity(repositoryClass="Gobusgo\GobusgoBundle\Repository\OrderRepository")
 */
class Order
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\User")
     */
    protected $userId;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Cargo")
     */
    protected $cargoId;

    /**
     * @var float
     *
     * @ORM\Column(type="float")
     */
    protected $price;

    /**
     * @var float
     *
     * @ORM\Column(name="quantity_of_cargo", type="float")
     */
    protected $quantityOfCargo;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $shippingAddress;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $deliveryAddress;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $additionalAddress1;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $additionalAddress2;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $additionalAddress3;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $additionalAddress4;

    /**
     * @ORM\ManyToOne(targetEntity="Gobusgo\GobusgoBundle\Entity\Address")
     *
     */
    protected $additionalAddress5;

    /**
     *
     *
     * @ORM\Column(type="datetime")
     */
    protected $dateOfOrder;

    /**
     * @var float
     *
     * @ORM\Column(type="float")
     */
    protected $status;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * @param mixed $userId
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    /**
     * @return mixed
     */
    public function getCargoId()
    {
        return $this->cargoId;
    }

    /**
     * @param mixed $cargoId
     */
    public function setCargoId($cargoId)
    {
        $this->cargoId = $cargoId;
    }

    /**
     * @return float
     */
    public function getPrice()
    {
        return $this->price;
    }

    /**
     * @param float $price
     */
    public function setPrice($price)
    {
        $this->price = $price;
    }

    /**
     * @return float
     */
    public function getQuantityOfCargo()
    {
        return $this->quantityOfCargo;
    }

    /**
     * @param float $quantityOfCargo
     */
    public function setQuantityOfCargo($quantityOfCargo)
    {
        $this->quantityOfCargo = $quantityOfCargo;
    }

    /**
     * @return mixed
     */
    public function getShippingAddress()
    {
        return $this->shippingAddress;
    }

    /**
     * @param mixed $shippingAddress
     */
    public function setShippingAddress($shippingAddress)
    {
        $this->shippingAddress = $shippingAddress;
    }

    /**
     * @return mixed
     */
    public function getDeliveryAddress()
    {
        return $this->deliveryAddress;
    }

    /**
     * @param mixed $deliveryAddress
     */
    public function setDeliveryAddress($deliveryAddress)
    {
        $this->deliveryAddress = $deliveryAddress;
    }

    /**
     * @return mixed
     */
    public function getAdditionalAddress1()
    {
        return $this->additionalAddress1;
    }

    /**
     * @param mixed $additionalAddress1
     */
    public function setAdditionalAddress1($additionalAddress1)
    {
        $this->additionalAddress1 = $additionalAddress1;
    }

    /**
     * @return mixed
     */
    public function getAdditionalAddress2()
    {
        return $this->additionalAddress2;
    }

    /**
     * @param mixed $additionalAddress2
     */
    public function setAdditionalAddress2($additionalAddress2)
    {
        $this->additionalAddress2 = $additionalAddress2;
    }

    /**
     * @return mixed
     */
    public function getAdditionalAddress3()
    {
        return $this->additionalAddress3;
    }

    /**
     * @param mixed $additionalAddress3
     */
    public function setAdditionalAddress3($additionalAddress3)
    {
        $this->additionalAddress3 = $additionalAddress3;
    }

    /**
     * @return mixed
     */
    public function getAdditionalAddress4()
    {
        return $this->additionalAddress4;
    }

    /**
     * @param mixed $additionalAddress4
     */
    public function setAdditionalAddress4($additionalAddress4)
    {
        $this->additionalAddress4 = $additionalAddress4;
    }

    /**
     * @return mixed
     */
    public function getAdditionalAddress5()
    {
        return $this->additionalAddress5;
    }

    /**
     * @param mixed $additionalAddress5
     */
    public function setAdditionalAddress5($additionalAddress5)
    {
        $this->additionalAddress5 = $additionalAddress5;
    }

    /**
     * @return mixed
     */
    public function getDateOfOrder()
    {
        return $this->dateOfOrder;
    }

    /**
     * @param mixed $dateOfOrder
     */
    public function setDateOfOrder($dateOfOrder)
    {
        $this->dateOfOrder = $dateOfOrder;
    }

    /**
     * @return float
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param float $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

}

我的管理员\orderadmin.php

<?php

namespace Gobusgo\GobusgoBundle\Admin;

use Gobusgo\GobusgoBundle\Entity\Cargo;
use Gobusgo\GobusgoBundle\Entity\User;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;

class OrderAdmin extends AbstractAdmin
{

    protected $baseRouteName = 'order_admin';
    protected $baseRoutePattern = 'order_admin';

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('userId', ModelType::class,[
                'class'=>User::class,
                'property'=>'fullName',
            ])
            ->add('cargoId', ModelType::class, [
                'class'=>Cargo::class,
                'property'=>'name'
            ])
        ;
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper->add('id');
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper->addIdentifier('id');
    }
}

myservices.yml包含以下代码

admin.order:
    class: Gobusgo\GobusgoBundle\Admin\OrderAdmin
    arguments: [~, Gobusgo\GobusgoBundle\Entity\Order, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, label: Заказ , group: "app.admin.group.admin" }
    public: true

拜托,帮帮我。。。

cnwbcb6i

cnwbcb6i1#

条令将您的表名按原样添加到查询中,没有反勾号。所以,mysql决定这是一个语法错误,因为 ORDER BY 是不区分大小写的保留sql关键字。
例如,要解决这个问题,可以在Map中重命名表

@ORM\Table(name="Order_postfix")

他们还说,您还可以通过在Map中使用反勾号来手动转义表名。这样地:

@ORM\Table(name="`Order`")

相关问题