Sqlite Plugin Cordova

Hi All,

I have followed the guide at https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/ as well as the guide at ng cordova for installing sqlite into ionic.

Every time I try to call any function of sqlite with the calls or even reference Or inject sqlite into a controller/service/factory I get.

Unknown provider: $cordovaSQLiteProvider
The script is added in the index file for ng-cordova. As well as all code from the guide.

IE
angular.module(‘WebROE’, [‘ionic’, ‘ui.router’, “ui.utils”, ‘ngCordova’])

I have tested on the device, and on a browser. If anything else is needed for this let me know.

Hey @ioudas,

Did you remember to inject $cordovaSQLite to your controller? Sounds like that might be your issue, or you have a typing mistake. Happens to me all the time.

Regards,

Yes,

It is in the controller. I do not get an error until I add it to the controller…

If you need controller code let me know.

Which browser you have tested on and could you provide sample of code?

Boy that was a quick response. Ive tried testing on the device (samsung s4) and chrome.

Code is here

function CurrentOrderCtrl($scope, LimitChecks, $cordovaSQLite, $state, $ionicPopup, $ionicPopover, $ionicScrollDelegate, $rootScope, LoaderService, $ionicSideMenuDelegate, CurrOrderService, $q, $timeout, $filter) {
$scope.slsm = isSlsm;
if (isSlsm) {
$scope.CustCode = “(” + CustCode + “)”;
} else {
$scope.CustCode = “”;
}

$scope.execute = function() {
	var db = $cordovaSQLite.openDB({ name: "my.db" });
	var query = "INSERT INTO test_table (data, data_num) VALUES (?,?)";
	$cordovaSQLite.execute(db, query, ["test", 100]).then(function(res) {
	  console.log("insertId: " + res.insertId);
	}, function (err) {
	  console.error(err);
	});
};
$scope.CurrOrderLimits = [];
$scope.CurrOrderLimits = LimitChecks.checked;

// Function that we'll call once the promise is resolved
$scope.orderdata = [];
$scope.toggleLeftSideMenu = function() {
	$ionicSideMenuDelegate.toggleLeft();
};

$scope.toggleRightSideMenu = function() {
	$ionicSideMenuDelegate.toggleRight();
};

$scope.groups = [];
$scope.groupsleft = [];

if (typeof(navigator.connection) != 'undefined' && navigator.connection.type == 'none') {
		LoaderService.showAlert("There was a problem determing your network connection.");
		return;
	}
if (completedload==false){

	var canceller = $q.defer();
	LoaderService.show(canceller);
	
	CurrOrderService.OrderData(canceller).then(function (message) {
		// Anything to happen on success here
		LoaderService.hide()
		tempcurrorders = message.data;
		if (!message.data.result=="NoRecords") {
			$rootScope.FoundRecords = false;
		}
		else {
			$rootScope.FoundRecords = true;
		}
		if (angular.isArray(message.data['CurrentOrders']['CurrentOrdersItems'])) {
			tempcurrorders = message.data['CurrentOrders']['CurrentOrdersItems'];
		} else {
			tempcurrorders[0] = message.data['CurrentOrders']['CurrentOrdersItems'];
		}
		$scope.orderdata = tempcurrorders;
		console.log(CustCode);
		console.log($scope.orderdata);
		completedload = true;
	}, function (data, status) {
		LoaderService.hide()
		completedload = true;
		// Anything to happen on failure here
		LoaderService.showAlert("There was an error searching current orders. Error message: \n" + data.status);
	});
}

$scope.limitoptions = [
	{ limit: "PO Number"},
	{ limit: "Sidemark"},
	{ limit: "Ship To Address"},
	{ limit: "Special Instructions"}
];

$scope.limitOrder = function (data) {
	selectedOrder = data['result-work-order-num'];
	searchterm = data.SearchField1;
	
	if (typeof(navigator.connection) != 'undefined' && navigator.connection.type == 'none') {
		LoaderService.showAlert("There was a problem determing your network connection.");
		return;
	}
	var canceller = $q.defer();
	
};

$scope.RelatedOrder = function (data) {
	selectedOrder = data['result-work-order-num'];
	
	if (typeof(navigator.connection) != 'undefined' && navigator.connection.type == 'none') {
		LoaderService.showAlert("There was a problem determing your network connection.");
		return;
	}
	var canceller = $q.defer();
	LoaderService.show(canceller);
	StockSearchService.submitsearch(data, canceller).then(function (message) {
		// Anything to happen on success here
		LoaderService.hide()
		temp = message.data;
		if (angular.isArray(message.data['dyelot-records']['dyelot-recordsItems'])) {
			temp = message.data;
		} else {
			temp[0] = message.data['dyelot-records']['dyelot-recordsItems'];
		}
		$state.go("tabs.stockcheck");
	}, function (data, status) {
		LoaderService.hide()
		// Anything to happen on failure here
		LoaderService.showAlert("There was an error searching product stock. Error message: \n" + data.status);
	});
};

for (var i = 0; i < 10; i++) {
	$scope.groups[i] = {
		name: i,
		items: []
	};
	for (var j = 0; j < 3; j++) {
		$scope.groups[i].items.push(i + '-' + j);
	}
}

for (var i = 0; i < 10; i++) {
	$scope.groupsleft[i] = {
		name: i,
		items: []
	};
	for (var j = 0; j < 3; j++) {
		$scope.groupsleft[i].items.push(i + '-' + j);
	}
}

/*
 * if given group is the selected group, deselect it
 * else, select the given group
 */

$scope.toggleGroup = function (group) {
	if ($scope.isGroupShown(group)) {
		$scope.shownGroup = null;
	} else {
		$scope.shownGroup = group;
	}
};

$scope.isGroupShown = function (group) {
	return $scope.shownGroup === group;
};

$scope.toggleGroupLeft = function (group) {
	if ($scope.isGroupShown(group)) {
		$scope.shownGroupLeft = null;
	} else {
		$scope.shownGroupLeft = group;
	}
};

$scope.isGroupShownLeft = function (group) {
	return $scope.shownGroupLeft === group;
};

}

angular
.module(‘WebROE.controllers’, [])
.controller(‘HomeTabCtrl’, HomeTabCtrl)
.controller(‘ProductSearchCtrl’, ProductSearchCtrl)
.controller(‘PriceCtrl’, PriceCtrl)
.controller(‘ProdResultCtrl’, ProdResultCtrl)
.controller(‘StockCtrl’, StockCtrl)
.controller(‘CurrentOrderCtrl’, CurrentOrderCtrl)
.controller(‘AccountCtrl’, AccountCtrl)
.controller(‘AccessoriesInfoSearch’, AccessoriesInfoSearch)
.controller(‘SignInCtrl’, SignInCtrl);

var db = null;

angular.module(‘WebROE’).run(function ($cordovaSplashscreen, $cordovaSQLite, $ionicPlatform, $ionicConfigProvider, $templateCache) {
$cordovaSplashscreen.hide()
$ionicConfigProvider.platform.android.tabs.position(“bottom”);
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB(“my.db”);
$cordovaSQLite.execute(db, “CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)”);
});

});

This should be for sure onDeviceReady event maybe that causing the problem?

This is setup on the .run side of ionic. Which was copied from the site. I think .run $ionicPlatform.ready is ionics on device ready? No?

Hey all, ive put about a weeks worth of work. At this point Ive given up. Mods if you can delete this. Feel free.

Thanks.