[英]How to fix [Error: While query - conversion error from string “pending” ] when trying to insert a new record into firebird database?
I've created a table with the following schema:我创建了一个具有以下架构的表:
CREATE TABLE orders (
id INTEGER NOT NULL PRIMARY KEY,
status VARCHAR(30) NOT NULL CHECK(status IN('ordered', 'paid', 'pending', 'complete')),
order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
delivery_id INTEGER,
client_id INTEGER,
operator_id INTEGER,
FOREIGN KEY(delivery_id)
REFERENCES delivery_info(id) ON DELETE CASCADE,
FOREIGN KEY(client_id) REFERENCES client(id) ON DELETE CASCADE,
FOREIGN KEY(operator_id) REFERENCES operator(id)
);
However, when I'm trying to insert new data into the table using a node.js application, I get the following error: Console output但是,当我尝试使用 node.js 应用程序将新数据插入表中时,出现以下错误:控制台 output
Generated query looks okay to me:生成的查询对我来说看起来不错:
INSERT INTO orders VALUES (793771, 'pending', '1612387572153', 590931, 3923, 0);
Application code:申请代码:
class Order {
static DEFAULT_OPERATOR_ID = 0;
constructor(id, status, time, delivery, client,
operatorId = Order.DEFAULT_OPERATOR_ID)
{
this.id = id;
this.status = status;
this.time = time;
this.delivery = delivery;
this.client = client;
this.operatorId = operatorId
}
save() {
console.log(this);
const insertQuery = `
INSERT INTO orders
VALUES (${this.id}, '${this.status}', '${this.time}', ${this.delivery.id}, ${this.client.id}, ${this.operatorId});
`;
console.log(insertQuery);
dbConnection.query(insertQuery, (error, result) => {
if (error) throw error;
console.log('Inserted new order');
});
}
}
Issue is fixed when I specify the column list during insertion.当我在插入期间指定列列表时,问题已得到修复。 Thanks, @Mark Rotteveel .
谢谢, @Mark Rotteveel 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.