1

I have a SQLite database I am trying to add data to with the sqlite3 package. My query is as follows, and works in the SQLite command line.

'INSERT INTO `EVENTS`(`ID`,`EventName`,`EventSociety`,`BookerName`,`BookerEmail`,`BookerStudentID`,`BookerPhone`,`TimeStart`,`TimeEnd`,`EquipmentList`,`EventSearchYear`,`EventSearchMonth`,`EventSearchDay`) VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);';

And I'm using this code to insert to the database in node.

    db.run("begin transaction");
    let sql = 'INSERT INTO `EVENTS`(`ID`,`EventName`,`EventSociety`,`BookerName`,`BookerEmail`,`BookerStudentID`,`BookerPhone`,`TimeStart`,`TimeEnd`,`EquipmentList`,`EventSearchYear`,`EventSearchMonth`,`EventSearchDay`) VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);';
    console.log(sql);
    db.run(sql,(err) => {
        res.send('ok');
    });
    db.run("commit");

Trying this in node hard crashes, with a Illegal instruction: 4. However, it is only happening on two tables, both with over 5 fields, in my database, and not any other smaller ones. Is there a character limit I'm unaware of?

02380b
  • 11
  • 1

1 Answers1

0

To avoid crash, we need to handle error as below:

Example

The line db.run(sql, params, function (err) { in below example:

  let sql = `INSERT INTO Users(id,firstName,lastName,email,password,permissionLevel) VALUES (?,?,?, ?,?,?)`;
  let params = [uuid4(), "fn1", "ln1", "a@a2.com", "pwd1", 0];
  db.run(sql, params, function (err) {
    if (err) {
      console.error("Error: Insert failed: ", err.message);
      console.error("Error: Full error: ", err);
      return;
    }
    console.log("insert success");
  });
Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140