Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

336
Visualizações
Express.js ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: '' for column 'id' at row 1

In my main.js file the string is "hello,0,,0,0" (empty at 2nd position if u read it in array) it need to be able to pass NULL into the database.
FYI: it will work if the 2nd position is a 0 and not empty
I am trying to split the string "," into var as shown below.

var Val = req.body.string.split(","); 
var one = Val[0];
var two = Val[1];
var three = Val[2];
var four = Val[3];
var five = Val[4];
let sqlquery = "INSERT INTO TESTING (one, two, three, four, five) VALUES (?,?,?,?,?)";

let newrecord = [one, two, three, four, five];  
db.query(sqlquery, newrecord, (err, result) => {
if (err) {
return console.error(err.message);
} else
res.send("Added in database");

and i got this error
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: '' for column 'three' at row 1

The table i created: CREATE TABLE TESTING (one VARCHAR(50), two BOOLEAN, three INT(4), four INT(4), five BOOLEAN ,PRIMARY KEY(name));
fields are all NULL
No auto increment in the table above, there is another table i created using the exact same way but with auto increment id but still throws the same error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you know that parameter three is a number, you could write

var three = Val[2] || null;

I assume you later execute a command like

db.query(sqlquery, [one, two, three, four, five]);

Then, if Val[2] = "0", you get three = "0", and this string value is accepted by the database for a numeric 0.

But Val[2] = "" is a falsy value, therefore you get three = null, and this is hopefully accepted by the database for a NULL value.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda