swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

task 里面执行sql语句的更新操作问题 #162

Closed aprchen closed 6 years ago

aprchen commented 6 years ago
Q A
Bug report? yes
Feature request? yes/no
Swoft version x.y.z
Swoole version 2.1.1 (by php --ri swoole)
PHP version 7.1.4 (by php -v)
Runtime environment Win10/Mac/CentOS 7/Ubuntu/Docker etc.

Details 看了下出错的原因是因为sql语句是更新操作,而在Swoft\Db\Driver\Mysql\QueryBuilder 中 image 这部分判断没有生效,执行了fetch方法,而产生的语法错误问题

Describe what you are trying to achieve and what goes wrong.

2018/03/21 14:26:01 [error] [book] [logid:] [spanid:0] trace[TaskEventListener.php:46,Swoft\Task\Bootstrap\Listeners\TaskEventListener->onTask] TaskExecutor->run SQLSTATE[HY000]: General error file=/Users/sl/Code/swoft/vendor/swoft/db/src/Driver/Mysql/SyncMysqlConnection.php line=157 

Provide minimal script to reproduce the issue

/**
     * @Scheduled(cron="* * * * * *")
     * @throws \Swoft\Db\Exception\DbException
     */
    public function test(){
        $sql = "UPDATE sl_template_task SET send_state = CASE id WHEN 45 THEN 1 WHEN 44 THEN 1 END WHERE id IN (45,44)";
        $em = EntityManager::create();
        $query = $em->createQuery($sql);
        $query->execute();
        $em->close();
        echo "1\n";
    }
stelin commented 6 years ago

更新代码已修复