sql-js / sql.js

A javascript library to run SQLite on the web.
http://sql.js.org
Other
12.38k stars 1.05k forks source link

Update database not working #198

Open vnzlogin opened 7 years ago

vnzlogin commented 7 years ago

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.

lovasoa commented 7 years ago

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

6 мая 2017 г. 5:23:42 GMT+03:00, phamvansy notifications@github.com пишет:

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.

ganggoo commented 6 years ago

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)

NENCAO commented 3 years ago

Me too Has anyone solved the problem?

askmewhat commented 3 years ago

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);
lovasoa commented 3 years ago

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