hyperf / hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

Home Page:https://www.hyperf.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] updateOrInsert第二个参数使用默认值生成的sql有问题

lujihong opened this issue · comments

commented

Execute the command and paste the result below.

Command: uname -a && php -v && composer info | grep hyperf && php --ri swoole

PHP 8.3.7 (cli) (built: May 10 2024 22:11:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.7, Copyright (c), by Zend Technologies
hyperf/amqp                          v3.1.21            A amqplib for hyperf.
hyperf/async-queue                   v3.1.15            A async queue component for hyperf.
hyperf/cache                         v3.1.15            A cache component for hyperf.
hyperf/code-parser                   v3.1.15            A code parser component for Hyperf.
hyperf/codec                         v3.1.15            A codec component for Hyperf.
hyperf/collection                    v3.1.22            Hyperf Collection package which come from illuminate/collections
hyperf/command                       v3.1.22            Command for hyperf
hyperf/conditionable                 v3.1.15            Hyperf Macroable package which come from illuminate/conditionable
hyperf/config                        v3.1.15            An independent component that provides configuration container.
hyperf/constants                     v3.1.16            A constants component for hyperf.
hyperf/context                       v3.1.15            A coroutine/application context library.
hyperf/contract                      v3.1.15            The contracts of Hyperf.
hyperf/coordinator                   v3.1.21            Hyperf Coordinator
hyperf/coroutine                     v3.1.15            Hyperf Coroutine
hyperf/crontab                       v3.1.19            A crontab component for Hyperf.
hyperf/database                      v3.1.22            A flexible database library.
hyperf/database-pgsql                v3.1.22            A pgsql handler for hyperf/database.
hyperf/db-connection                 v3.1.15            A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v3.1.19            A Devtool for Hyperf.
hyperf/di                            v3.1.15            A DI for Hyperf.
hyperf/dispatcher                    v3.1.15            A HTTP Server for Hyperf.
hyperf/engine-contract               v1.10.1            Contract for Coroutine Engine
hyperf/engine-swow                   v2.11.0            Coroutine engine provided by swow.
hyperf/event                         v3.1.15            an event manager that implements PSR-14.
hyperf/exception-handler             v3.1.22            Exception handler for hyperf
hyperf/filesystem                    v3.1.15            flysystem integration for hyperf
hyperf/flysystem-oss                 v1.3.0            
hyperf/framework                     v3.1.15            A coroutine framework that focuses on hyperspeed and flexible, specifically use ...
hyperf/guzzle                        v3.1.15            Swoole coroutine handler for guzzle
hyperf/http-message                  v3.1.15            microservice framework base on swoole
hyperf/http-server                   v3.1.17            A HTTP Server for Hyperf.
hyperf/ide-helper                    v3.1.15            IDE help files for Hyperf.
hyperf/logger                        v3.1.15            A logger component for hyperf.
hyperf/macroable                     v3.1.15            Hyperf Macroable package which come from illuminate/macroable
hyperf/memory                        v3.1.15            An independent component that use to operate and manage memory.
hyperf/migration-generator           v3.1.15            Migration generator for Hyperf.
hyperf/model-cache                   v3.1.15            A model cache component for hyperf.
hyperf/model-listener                v3.1.15            A model listener for Hyperf.
hyperf/paginator                     v3.1.15            A paginator component for hyperf.
hyperf/phar                          v3.1.15            A component that supports pack Hyperf project as a Phar stand-alone package.
hyperf/pipeline                      v3.1.15            Hyperf Macroable package which come from illuminate/pipeline
hyperf/pool                          v3.1.15            An independent universal connection pool component.
hyperf/process                       v3.1.15            A process component for hyperf.
hyperf/redis                         v3.1.18            A redis component for hyperf.
hyperf/serializer                    v3.1.22            A serializer component for Hyperf.
hyperf/server                        v3.1.15            A base server library for Hyperf.
hyperf/signal                        v3.1.15            A signal library for Hyperf.
hyperf/snowflake                     v3.1.15            A snowflake library
hyperf/stdlib                        v3.1.15            A stdlib component for Hyperf.
hyperf/stringable                    v3.1.20            Hyperf Stringable package which come from illuminate/support
hyperf/support                       v3.1.15            A support component for Hyperf.
hyperf/tappable                      v3.1.15            Hyperf Macroable package which come from illuminate/tappable
hyperf/testing                       v3.1.21            Testing for hyperf
hyperf/translation                   v3.1.15            An independent translation component, forked by illuminate/translation.
hyperf/utils                         v3.1.0             A tools package that could help developer solved the problem quickly.
hyperf/validation                    v3.1.22            hyperf validation
hyperf/watcher                       v3.1.21            Hot reload watcher for Hyperf
hyperf/websocket-server              v3.1.17            A websocket server library for Hyperf.

Swow

Status => enabled
Author => Swow Team
Link => https://github.com/swow/swow
Contact => Twosee <twosee@php.net>
Version => 1.5.2 ( NTS RELEASE )
Built => May 14 2024 03:40:25
Context => boost-context
Scheduler => libuv-event
DebugLog => enabled

Optional dependencies => Version Info
Sanitizers => none
SSL => OpenSSL 3.1.4 24 Oct 2023
cURL => libcurl/8.5.0 OpenSSL/3.1.4 zlib/1.2.13 brotli/1.0.9 libidn2/2.3.4 nghttp2/1.57.0
PostgreSQL => none

Directive => Local Value => Master Value
swow.enable => On => On
swow.async_threads => 0 => 0
swow.async_file => On => On
swow.async_tty => On => On
curl.cainfo => no value => no value

Description:

第二个参数不传使用默认空数组时:

$this->labelMapper->model::query()->updateOrInsert(
  ['label' => $label, 'created_by' => $userId]
);

执行会报错:
Next Hyperf\Database\Exception\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where (label= ? andcreated_by= ?) limit 1' at line 1 (SQL: updatewechat_label set where (label= '测试' andcreated_by= 85) limit 1) in /opt/www/vendor/hyperf/dase/src/Connection.php:1146

改成这样就可以了:

 $this->labelMapper->model::query()->updateOrInsert(
  ['label' => $label, 'created_by' => $userId],
  ['created_by' => $userId]
);