How to fix [Error: While query - conversion error from string "pending" ] when trying to insert a new record into firebird database?
How to fix [Error: While query - conversion error from string "pending" ] when trying to insert a new record into firebird database?
我创建了具有以下架构的 table:
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)
);
但是,当我尝试使用 node.js 应用程序将新数据插入 table 时,出现以下错误:
Console output
生成的查询对我来说没问题:
INSERT INTO orders VALUES (793771, 'pending', '1612387572153', 590931, 3923, 0);
申请代码:
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');
});
}
}
当我在插入期间指定列列表时,问题已解决。谢谢,@Mark Rotteveel。
我创建了具有以下架构的 table:
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)
);
但是,当我尝试使用 node.js 应用程序将新数据插入 table 时,出现以下错误: Console output
生成的查询对我来说没问题:
INSERT INTO orders VALUES (793771, 'pending', '1612387572153', 590931, 3923, 0);
申请代码:
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');
});
}
}
当我在插入期间指定列列表时,问题已解决。谢谢,@Mark Rotteveel。