简体   繁体   English

尝试将新记录插入firebird数据库时如何解决[错误:查询时 - 字符串“待处理”的转换错误]?

[英]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.

相关问题 尝试将查询从 nodejs 插入 postgresql 数据库时出错 - Getting error trying to insert query from nodejs to postgresql database 尝试将数据库与 postgress 连接时如何修复错误? - How to fix error when trying to connect database with postgress? 如何在从数据库中获取数据时修复错误 - how to fix the error while fetching the data from the database 尝试在 mongodb 数据库中创建和添加新数据时响应错误 - Error in response while trying to create and add new data in mongodb database 如何解决“承诺{ <pending> }”从influxdb-query返回值时? - How to fix “Promise { <pending>}” when returning values from influxdb-query? 尝试访问本地主机中的数据库时如何解决“错误:服务器不支持 SSL 连接”? - How to fix "Error: The server does not support SSL connections" when trying to access database in localhost? 尝试执行 POST 方法时如何修复此 Sequelize 数据库错误? - How Do I Fix this Sequelize Database Error when trying to do a POST method? 尝试连接到MongoDB Atlas时如何解决密码错误? - How to fix password error when trying to connect to MongoDB Atlas? 如何修复:在迁移中,原始查询在 varchar 中对广告反斜杠转义进行续集,这会在将该值插入数据库时导致错误 - How to fix : In Migration, a raw query sequelize ad backslash escape in varchar which cause error while inserting that value in database 尝试执行时如何修复 node.js 错误? - How to fix node.js error when trying to execute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM