# Code Not Being Executed

**URL:** <https://forum.ionicframework.com/t/code-not-being-executed/46967>\
**Category:** ionic-v1\
**Created:** [March 20, 2016, 5:24pm UTC](https://forum.ionicframework.com/t/code-not-being-executed/46967 "2016-03-20T17:24:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harilall](https://avatars.discourse-cdn.com/v4/letter/h/ac8455/32.png) [@Harilall](https://forum.ionicframework.com/u/Harilall)\
**Post date:** [March 20, 2016, 5:24pm UTC](https://forum.ionicframework.com/t/code-not-being-executed/46967/1 "2016-03-20T17:24:36Z")

</div>

I was having problems with the SQLite database but managed to solve that error by placing the code within a deviceready listener function, the problem now is although I don’t get the same prior errors my code in the deviceready function isn’t getting hit. I have tried debugging in Chrome and it just skips over the code - please advise, here’s my function code below

```
$scope.saveExpense = function(expenseItem){
		if(angular.isDefined(expenseItem) && angular.isDefined(expenseItem.detail) && angular.isDefined(expenseItem.amount))
		{
			var dateInDb = $filter('date')(expenseItem.myDate, 'yyyy-MM-dd');			
			
				document.addEventListener('deviceready', function(){ 
				
					//db = $cordovaSQLite.openDB({name: "expenseApp.db"});
					var query = "insert into expenses (date, detail, amount) values(?,?,?)";
					$cordovaSQLite.execute(db, query, [dateInDb, expenseItem.detail, expenseItem.amount])
					.then(function(res){
						console.log("res = " + res);
						if (res.rows.length > 0)
						{
							var iAlert = $ionicPopup.alert({
								title: 'Item added to database',
								template: 'expenseItem.date = ' + expenseItem.date + '<br/>' + 'expenseItem.detail = ' + expenseItem.detail + '<br/>' +
											'expenseItem.amount = ' + expenseItem.amount,
							});
						}
					}), function(error){
						$ionicPopup.alert({
							title: 'Error',
							template: 'Something went wrong <br/>' + error.message
						});
					}
				
				});

			$state.reload();
		}
	}
```

---

<div class="post-metadata">

**Author:** ![A\_Burgess](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/a_burgess/32/102501_2.png) [@A\_Burgess](https://forum.ionicframework.com/u/A_Burgess)\
**Post date:** [March 21, 2016, 2:18pm UTC](https://forum.ionicframework.com/t/code-not-being-executed/46967/2 "2016-03-21T14:18:42Z")

</div>

```
 ionic.Platform.ready(function () {
    ...
});
```
