node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

Can't open a data base on disk

Open yuniers opened this issue 11 years ago • 3 comments

I'm new with sqlite3 and have some dudes whit him. When I try open a sqlite file this error is triggered to me:

{ open: false,
  filename: './datos_exportados(14-05-2015o).sqlite',
  mode: 65542 }

And the file exists, somebody can help me? It is my code:

var sqlite3 = require('sqlite3').verbose(),
    path = './datos_exportados(14-05-2015o).sqlite';
var sipac = new sqlite3.Database(path, 'OPEN_READONLY');
sipac.serialize(function(){
    var dat_act = sipac.run("SELECT * FROM dat_actividades")
    console.log(dat_act)
})
sipac.close()

yuniers avatar May 27 '15 18:05 yuniers

Probably a bit late but...

That isn't an error. If you check the documentation db.run returns a copy of the database so that you can chain another method if needed. That means console.log(dat_act) is actually console.log(sipac) so you are printing the representation of the db object to the console.

db.run is meant for running queries which don't return any results e.g. insertions. You need to use either db.all or db.get or db.each and pass them a callback function to handle the results:

var sqlite3 = require('sqlite3').verbose(),
    path = './datos_exportados(14-05-2015o).sqlite';
var sipac = new sqlite3.Database(path, 'OPEN_READONLY');
sipac.serialize(function(){
    sipac.each("SELECT * FROM dat_actividades", function(err, row) {
        if (err)
            console.log(err)
        else
            console.log(row)
    })
})
sipac.close()

Check out the api on the wiki if you haven't read it.

Graham--M avatar Jun 07 '15 22:06 Graham--M

This is so helpful! I had the same problem. I read the wiki first but nothing stood out to me.

linyi-xia avatar Oct 21 '15 18:10 linyi-xia

Closing as this appears to be resolved.

ErisDS avatar Nov 01 '15 14:11 ErisDS