Sunday, 15 February 2015

javascript - how can share sqlite database in android native and android phonegap of same project -



javascript - how can share sqlite database in android native and android phonegap of same project -

in android phonegap application have written plugin phone call native code.in native code creating sqlite database,creating table, , inserting data.here trying open same database , fetching info javascript file using phonegap storage api. native android code open database , create table

enter code here private void opendatabase(string dbname, string password) { file dbfile = this.cordova.getactivity().getdatabasepath("theteamscore"+ ".db"); mydb = sqlitedatabase.openorcreatedatabase(dbfile, null); } private void createtableandinsert() { seek { this.opendatabase(dbname, null); mydb.execsql("create table if not exists contacts(id integer not null,name text not null, selectedemail text, selectedphone text)"); string sql ="insert contacts (id,name,selectedemail,selectedphone) values (1,'saranga','saranga@gmail.com', '7620765783')"; mydb.execsql(sql); } catch(exception e) { log.e("error", "error", e); } }

javascript file contains code open same database(databasename="theteamscore") , select info created table

enter code here function open_db() { homecoming window.opendatabase("theteamscore", "1.0", "theteamscore db", 200000); } function query_db(tx) { if (dbquery == "select"){ tx.executesql('select * contacts', [], select_emailsuccess, error_cbforselect); } }

but above code unable fetch info contacts table , showing error no table found contacts .how open same database , utilize table using phonegap

both using different database,in situation request used next plug-in...

github link

sqlite single-user database. if go "copy database" route, risk losing data. if desktop user added info , ios user added data, someone's info lost when re-create file.

you can implement own "syncing" algorithm identifies changes between databases , keeps them in sync. can pain, mutual solution , recommend. i've done way desktop/ios app.

you can take utilize database server, require network access connect it. from here

javascript android cordova

No comments:

Post a Comment