Cordova sqlite plugin not working in device


#1

i installed cordova sqlite plugin followed below tutorial

it is working when im doing

ionic serve

but it is not working after i install apk in mobile. please tell me the solution.


#2

Cordova plugins won’t work on browser (ionic serve) so it may not be working at all for you.

Can you verify the plugin libraries are included in your android build? How are you testing whether or not it’s working?


#3

Hi,

i created apk. and install in my mobile. data in not able to insert in table. so i guess database is not creating…
please suggest how to test this and debug… this database.

libraries are here… i checked

platforms\android\ant-build\classes\net\orworks\cordovaplugins\cordovasqlite


#4

any errors while debugging?


#5

no errors showing,

here is my code.
app.js

var db = null;
angular.module(‘starter’, [‘ionic’, ‘starter.controllers’,‘ngCordova’])

.run(function($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}

if (window.cordova) {
db = window.sqlitePlugin.openDatabase({ name: “iautocount.db”, location: 1 }); //device
}else{
db = window.openDatabase(“iautocount.db”, ‘1’, ‘auto’, 1024 * 1024 * 100); // browser

}

});
})

and here is my controller.js

.controller(‘SettingsCtrl’, function($scope, $http,$ionicLoading,$cordovaSQLite) {

  	$cordovaSQLite.execute(db, "drop table profile");
  				$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS profile (id integer primary key, profiledata text)");
  				proquery = "INSERT INTO profile (profiledata) VALUES (?)";
  				$cordovaSQLite.execute(db, proquery, ["testdatahere"]).then(function(res) {
  					//console.log("INSERT ID -> " + res.insertId);
  					//alert(res.insertId);
  						//window.alert(res.insertId)
  				  });

var que = “SELECT profiledata FROM profile” ;
$cordovaSQLite.execute(db, que, []).then(function(res) {
if(res.rows.length > 0) {
$scope.profdata=res.rows.item(0).profiledata;
//window.alert($scope.profdata)
}
});

})


#6

i m waiting can you please give me solution…


#7

The SQL lite plugin will spit out logs showing that the DB was created. To see the logs you can do 1 of 2 things…

  1. Install the app using ionic livereload (ionic run -l, or ionic emulate -lc if running on ios sim), to enable console logs from ionics livereload server. If this is unfamiliar to you then you may need to look at the ionic CLI README here .

  2. for ios, build the app on the ios simulator using Xcode, then you can trace the logs for the Sqllite log output.

Once you get some logs going paste them here.


#8

@djett

i m trying in emulator , app is not loading in emulator. is it any other way to test. or what is wrong in my code… can you tell me so i can fix it.


#9

@jswebtech .If you using Sqlite Plugin.this is solutions you have to.Please follow the solution


#10

@Thamil

i checked where to create db not understand.

below is my code can u tell me what is wrong what i will do to create db.

var db = null;
angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])
.run(function($ionicPlatform,$cordovaSQLite) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
	if (window.cordova) 
	{
		db = window.sqlitePlugin.openDatabase({ name: "iautocount.db", location: 1 }); //device
		window.alert("Trying DB...")
    }
	else
	{
		db = window.openDatabase("iautocount.db", '1', 'auto', 1024 * 1024 * 100); // browser
	}
  });
})

#11

Hi, just to point out that you can see the code provided in Quizionic App Template here: http://codecanyon.net/item/quizionic-a-quiz-app-template-for-ionic-framework-with-sqlite-database/14205904, that uses a pre-populated SQLite database file and also works on Ionic Serve under Chrome browser.


#12

See the best starter with SQLite using ngCordova and services: https://github.com/jdnichollsc/Ionic-Starter-Template

Regards, Nicholls


#13

Hi.

Did you find a solution? I’m facing this exactly problem and I can’t understand what is happening.

Thanks


#14

give me full code of Create and insert code for angular 2

Thanks,