batMan007
batMan007

Reputation: 589

How to get sqlite database Values in javascript

i need how to get values from sqlite Database for particular columns records in Javascript, i successfully inserted values in DB but do no how to fetch the values from db

Here my sample code how i inserted :

var newPath1 = __dirname + path.sep+'schedule.sqlite'
var bfr = fs.readFileSync(newPath1)
var db = new sql.Database(bfr)
db.run("INSERT into 
profile_id(SNo,visit_id,date,time,profile_url,First_Name,Last_Name) VALUES 
(?,?,?,?,?,?,?)",
[result,result1,date1,time1,sampleUrl,first_Name,last_Name])
var data = db.export();
var buffer = new Buffer(data);
fs.writeFileSync(newPath1, buffer);

i need a solution from this DB i need to fetch all values from First_Name

Upvotes: 0

Views: 2633

Answers (2)

batMan007
batMan007

Reputation: 589

finally i found the solution

var fName =  db.exec("SELECT First_Name FROM profile_id")

this code works

Upvotes: 0

Kushan
Kushan

Reputation: 10703

Try like this,

var stmt = db.prepare("INSERT into 
profile_id(SNo,visit_id,date,time,profile_url,First_Name,Last_Name) VALUES 
(?,?,?,?,?,?,?)");  

  stmt.run(result,result1,date1,time1,sampleUrl,first_Name,last_Name);  

  stmt.finalize();  

  db.each("SELECT First_Name FROM profile_id", function(err, row) {  
      console.log("First Name : "+row.First_Name);  
  });  

Upvotes: 1

Related Questions