Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda