javascript - Using Cordova-sqlite-storage plugin -
i using cordova-sqlite plugin in order select , insert data database embedded in android device. in case create database native code , trying read data javascript source. but, think javascript not reading same location android do.
this js file :
var db = window.sqliteplugin.opendatabase({name: 'db',iosdatabaselocation: 'library'}); var session = this._sessioninfoservice.getsessioninfo(); db.transaction(function (tx) { var firstname = session.firstname; var lastname = session.lastname; var userid = session.id; tx.executesql("create table if not exists user (user_id integer, firstname varchar, lastname varchar)"); tx.executesql('select * user', [], function (tx, results) { var len = results.rows.length, i; console.log(len); (i = 0; < len; i++){ var id =results.rows.item(i).user_id; console.log(results.rows.item(i).user_id ); if(id!=userid){ var dialogtitle = "another user registred device"; var dialogtext = "do want override "; wl.simpledialog.show(dialogtitle, dialogtext, [ { text : 'override', handler : function(){ db = window.sqliteplugin.opendatabase({name: 'db',iosdatabaselocation: 'library'}); db.transaction(function (tx) { tx.executesql("update user set user_id =?, firstname=?, lastname=?", [userid,firstname,lastname]); } } }, { text : 'no', handler : function(){ db = window.sqliteplugin.opendatabase({name: 'db',iosdatabaselocation: 'library'}); db.transaction(function (tx) { tx.executesql("insert user (user_id,firstname, lastname) values(?,?,?)", [userid,firstname,lastname]); } } } ]); } else{ } } }, null); } }); }
and java file in native source
@override public void onstart(intent intent, int startid) { final sqlitedatabase db = openorcreatedatabase("db", context.mode_private, null); db.execsql("create table if not exists user (user_id int, firstname varchar, lastname varchar);"); log.i("e2", "yes"); db.execsql("insert user (user_id,firstname,lastname) values(91,'ess','ess');"); thread thread = new thread(new runnable() { @override public void run() { try { string query = "select * user"; cursor c = db.rawquery(query, null); if (c != null && c.movetofirst()) { int userid=c.getint(1); system.out.println("userid"+userid); log.i("userid",string.valueof(userid)); } } catch(e){} } }); thread.start(); }
when try create database , user table javascript , select java file facing exception : table user unknown , when select users js empty list . that's why think code creates 2 databases same name in 2 different locations.
Comments
Post a Comment