问题描述
我正在尝试从nodejs插入到MysqL数据库中的标准ISO日期中,并出现以下错误:
\b
StackOverflow上的所有其他问题似乎是人们没有正确格式化日期。
如果我手动运行查询,则在进行一些修改后它可以工作-它的nodejs给我不好的预检吗?还是我发送数据有误?
首先创建表:
/**
* Creates a new {@link CustomTarget} that will attempt to load the resource in its original size.
*
* <p>This constructor can cause very memory inefficient loads if the resource is large and can
* cause OOMs. It's provided as a convenience for when you'd like to specify dimensions with
* {@link com.bumptech.glide.request.RequestOptions#override(int)}. In all other cases,prefer
* {@link #CustomTarget(int,int)}.
*/
public CustomTarget() {
this(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL);
}
然后插入条目:
ER_TruncATED_WRONG_VALUE: Incorrect date value: '0' for column 'lastmod' at row 1
在console.log中,插入语句如下所示:
CREATE TABLE IF NOT EXISTS urls (
id int(6) unsigned NOT NULL AUTO_INCREMENT,url varchar(255) NOT NULL,lastmod date NOT NULL,updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (url),UNIQUE KEY id (id)
);
并产生以下错误:const MysqL = require('MysqL2')
const pool = MysqL.createPool(settings);
async function upsert(entries){
// entries = [{url,lastmod},{url,lastmod}]
const query = `
INSERT INTO urls (
url,lastmod )
VALUES (?)
ON DUPLICATE KEY UPDATE
url=VALUES(url),lastmod=VALUES(lastmod)
`
let q = pool.format(query,entries)
console.log(q);
let result;
try{
result = await pool.query(query,entries)
} catch ( err ){
console.log("Error in upsert",err)
} finally {
return result
}
}
有趣的是,如果我删除
INSERT INTO urls (
url,lastmod
)
VALUES (
`url` = 'https://test.com',`lastmod` = '2020-12-30'
)
ON DUPLICATE KEY UPDATE
url=VALUES(url),lastmod=VALUES(lastmod),
从我的VALUES列表中,仅将其设置为“ value”而不是ER_TruncATED_WRONG_VALUE: Incorrect date value: '0' for column 'lastmod' at row 1
='value',我可以手动运行insert-为什么节点MysqL这样准备值?我在做错什么吗?
谢谢!
解决方法
我发现错误是VALUES (?)
应该写为VALUES ?
不确定是什么区别,但解决了我的问题:-)