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

191
Visualizações
I don't know Why I'm getting Sqlite Busy Error

I successfully updated sql data by following codes.

app.get('/courtInfo/:courtName',async function(req,res){
    let db = await getDBConnection();
    let rows = await db.all('select * from courts');   
    
    const name = req.params.courtName;

    const newPlayerNum = req.query.playerUpdated;
    const newIsPickup = req.query.isPickup;

    if(typeof newPlayerNum!=='undefined'&&newPlayerNum!=''){
        var newsql = 'UPDATE courts SET currentNum = ? WHERE court_name = ?';
        db.run(newsql,[newPlayerNum,name],function(err){
            if(err) return console.log(err);
        });        
    }

    if(typeof newIsPickup!=='undefined'&&newIsPickup!=''){
        var newsql = 'UPDATE courts SET is_pickup = ? WHERE court_name =?';
        db.run(newsql,[newIsPickup,name],function(err){
            if(err) return console.log(err);
        });   
    }
    await db.close();

..... 

But when I tried like this, I got Sqlite Busy error.

app.post('/newCourtAdded', upload.single('courtImg'),async function(req,res){
    let db = await getDBConnection();
    let rows = await db.all('select * from courts'); 
    const newCourtId = rows[rows.length-1]+1;
    const newCourtName = req.body.courtName;
    const newCourtNum = req.body.courtNum;
    const newCourtIsWater = req.body.isWater;
    const newImagePath = req.file.originalname;
    
    console.log(newCourtName, newCourtNum, newCourtIsWater, newImagePath);
    var newSqlite = 'INSERT INTO courts (court_id, court_name, court_image, is_water, is_pickup, court_num, currentNum) VALUES (?,?,?,?,?,?,?)';
    var newValue = [];

    newValue.push(newCourtId);
    newValue.push(newCourtName);
    newValue.push('/image/'+newImagePath);
    newValue.push(newCourtIsWater);
    newValue.push(0);
    newValue.push(newCourtNum);
    newValue.push(0);

    db.run(newSqlite,newValue,function(err){
        if(err){
            return console.log(err);
        }else{
            db.close();         
        } 
    });
    
     
    res.redirect("http://localhost:3000");
   
});

I think they have same logic, I mean, open database -> make dataSet -> change and save database -> close database.

I don't know Why the former one is successful and the other is not. Could you please teach me why?

about 4 years ago · Juan Pablo Isaza
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