0

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

batMan007
  • 551
  • 1
  • 10
  • 24
  • Possible duplicate of [Reading info from sqlite database, Syntax? How do I use it in html5 webapp?](http://stackoverflow.com/questions/3122057/reading-info-from-sqlite-database-syntax-how-do-i-use-it-in-html5-webapp) – Pyromonk Apr 21 '17 at 04:39
  • i tried that but i'm getting 'db.transaction' not defined – batMan007 Apr 21 '17 at 04:41
  • first c my question how i inserted and what method i have been used based on that give me solution – batMan007 Apr 21 '17 at 04:44
  • I see no `db.transaction` in your code. Please check the scope of your `db` variable. – Pyromonk Apr 21 '17 at 04:50
  • i already tried that above example which u mentioned above – batMan007 Apr 21 '17 at 06:04

2 Answers2

1

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);  
  });  
Kushan
  • 10,657
  • 4
  • 37
  • 41
  • i'm getting this error on my console "Uncaught TypeError: Cannot read property 'First_Name' of undefined" – batMan007 Apr 21 '17 at 06:02
0

finally i found the solution

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

this code works

batMan007
  • 551
  • 1
  • 10
  • 24