android - Cordova sqlite does not create DB on $cordovaSQLite.openDB or window.openDatabase -
i'm trying store data in sqlite db @ ionic app. i'm creating db , 1 table following code:
var db = null; angular.module('starter', ['ionic', 'starter.controllers', 'ngcordova', 'slick']) .run(function($ionicplatform, $cordovasqlite) { $ionicplatform.ready(function() { if (window.cordova && window.cordova.plugins.keyboard) { cordova.plugins.keyboard.hidekeyboardaccessorybar(true); cordova.plugins.keyboard.disablescroll(true); } if (window.statusbar) { statusbar.styledefault(); } if (window.cordova) { db = $cordovasqlite.opendb({ name: "kog.db" }); $cordovasqlite.execute(db, "create table if not exists teams (id integer, title text, day text, fromtime text, totime text, location text)"); console.log("android"); } else { db = window.opendatabase("kog.db", '1', 'kog', 1024 * 1024 * 100); // browser db.transaction(function (tx) { tx.executesql('create table if not exists teams (id integer, title text, day text, fromtime text, totime text, location text)'); }); console.log("browser"); } }); })
when i'm testing app, db not created. neither on mobile device sqlite plugin, nor testing app in chrome window.opendatabase.
any advice, i'm doing wrong?
thanks help! cara
try use : cordova-sqlite-ext
after adding plugin app write following code in app index.html file , test it.
<script type="text/javascript" charset="utf-8" src="lawnchair.js"></script> <script type="text/javascript" charset="utf-8"> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { var db = window.sqliteplugin.opendatabase({ name: "dbtesting.db", location: 'default' }); db.transaction(function(tx) { tx.executesql('create table if not exists test_table (id integer primary key autoincrement, data text, data_num integer)'); tx.executesql("insert test_table (data, data_num) values (?,?)", ["sinorise 2", 100], function(tx, res) { alert("insertid: " + res.insertid + " -- should valid"); db.transaction(function(tx) { tx.executesql("select data test_table;", [], function(tx, res) { console.log("res.rows.length: " + res.rows.length + " -- should > 1"); window.external.notify("res.rows.item(0).data: " + res.rows.item(0).data + " -- should text"); }, function(e) { window.external.notify("error: " + json.stringify(e) + " : " + e.message); console.log("error: " + json.stringify(e) + e.message); }); }); }, function (e) { window.external.notify("error: " + json.stringify(e) + " : " + e.message); console.log("error: " + json.stringify(e) + e.message); }); }, function (e) { console.log("error index: " + json.stringify(e)); }); } </script>
Comments
Post a Comment