sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Update database not working

Open bluedoctorhazan opened this issue 8 years ago • 5 comments

I try:

xhr.onload = function(e) {
          var uInt8Array = new Uint8Array(this.response);
          var db = new SQL.Database(uInt8Array);
          var contents = db.exec("SELECT * FROM drugs WHERE id="+idDrug+"");

          var viewed = parseInt(contents[0]['values'][0][6])+1;
          
          var stmt = db.prepare("update drugs set viewed=? where id=?");
          stmt.bind([viewed, idDrug]);
}

But row not update, please help me.

bluedoctorhazan avatar May 06 '17 02:05 bluedoctorhazan

Did you read the README? Especially the fact about the database not being persistent.

6 мая 2017 г. 5:23:42 GMT+03:00, phamvansy [email protected] пишет:

I try:

xhr.onload = function(e) {
         var uInt8Array = new Uint8Array(this.response);
         var db = new SQL.Database(uInt8Array);
    var contents = db.exec("SELECT * FROM drugs WHERE id="+idDrug+"");

         var viewed = parseInt(contents[0]['values'][0][6])+1;
         
        var stmt = db.prepare("update drugs set viewed=? where id=?");
         stmt.bind([viewed, idDrug]);
}

But row not update, please help me.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/kripken/sql.js/issues/198

-- Простите за краткость, создано в K-9 Mail.

lovasoa avatar May 06 '17 08:05 lovasoa

Hoi i have a similar Problem . Update doesent work I do => var sqlstr = "UPDATE content SET content_parent=-1 WHERE content_lfd=" + parentFolderLFD + ";" ; db.exec(sqlstr); db.run(sqlstr); both does not Update the value of the content Table

what am i doin wrong ?

when i use a statement var stmt = window.db.prepare("UPDATE content SET content_parent=-1 WHERE content_lfd = ? ;"); stmt.run([parentFolderLFD,]);

i get this Exception: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (:2:14)

ganggoo avatar Nov 23 '17 13:11 ganggoo

Me too Has anyone solved the problem?

NENCAO avatar Jul 18 '20 08:07 NENCAO

ALL of the operation about data changes(eg: UPDATE、INSERT..) NEED do this process:

var data = dbinstance.export();
var buffer = Buffer.from(data, "binary");
fs.writeFileSync(dblocate, buffer);

askmewhat avatar Oct 17 '20 12:10 askmewhat

@askmewhat: If you are using node.js, you probably want to use a native sqlite3 binding, and not sql.js. Updates will just work.

lovasoa avatar Oct 17 '20 12:10 lovasoa