Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!