惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
B
Blog
博客园 - Franky
小众软件
小众软件
Recorded Future
Recorded Future
B
Blog RSS Feed
爱范儿
爱范儿
宝玉的分享
宝玉的分享
L
LangChain Blog
博客园 - 【当耐特】
The Register - Security
The Register - Security
P
Proofpoint News Feed
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
aimingoo的专栏
aimingoo的专栏
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog

博客园 - 代码小伙

gin框架使用zap,在日志中加入trace_id gorm使用gen自动生成模型和查询文件 Go使用base64Captcha生成字母验证码 GoFrame框架查询数据表时对字段取别名 GoFrame框架使用BindHandler设置路由失效的原因 GoFrame框架WebServer默认端口号是什么 GoFrame框架SetFileServerEnabled关闭静态服务不生效 vite修改端口号 用路由方式写一个通用的微信小程序校验文件验证 手机网页通过微信deeplink实现wap支付 position:sticky失效原因分析 mysql把一个表的字段赋值到另一张表 基于jquery的countdown插件实现毫秒倒计时 Vue打包代码如何部署在ThinkPHP项目里 保姆级教程,centos7安装erlang和rabbitmq Element Plus表单resetFields重置表单无效 thinkphp6通过中间件设置跨域 centos7安装jdk vue3中使用swiper6实现轮播
GoFrame框架使用WherePri报错原因
代码小伙 · 2025-08-21 · via 博客园 - 代码小伙

在使用模型的WherePri方法中,发现有时会出现SQL报错的情况,比如在做update时,有如下报错信息

there should be WHERE condition statement for UPDATE operation

表面意思是更新操作需要有where条件,说明我们通过WherePri并没有帮我们拼接以主键查询的条件。
比如我通过模型的One方法查询出一条数据,直接使用他查到的结果去做一个更新操作,就会出现这个问题,原因在于同意One方法查询到的结果是gdb.Record类型,而gdb.Record类型本质是map[string]Value的别名,gdb.Value类型是个指针,在gdb包的gdb.go文件,约666-684行有定义,所以需要将gdb.Value通过gvar包的string或者intint64等方法转化类型后,再带进WherePri方法中,才能正常拼接出where条件

type (
	// Raw is a raw sql that will not be treated as argument but as a direct sql part.
	Raw string

	// Value is the field value type.
	Value = *gvar.Var

	// Record is the row record of the table.
	Record map[string]Value

	// Result is the row record array.
	Result []Record

	// Map is alias of map[string]interface{}, which is the most common usage map type.
	Map = map[string]interface{}

	// List is type of map array.
	List = []Map
)