Click here to Skip to main content
15,072,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating a hybrid app by telerik app builder in visual studio. I am not able to access sqlite db which is created externally. But I can access the db which is created at run time. I referred some sites, those solutions are not worked for me. The following code will create db and access it while run time

JavaScript
var app = {};
app.db = null;

app.openDb = function () {
	var dbName = "Test.sqlite";

	//DB creation for Simulator
	if (window.navigator.simulator === true) {
		app.db = window.openDatabase(dbName, "1.0", "Test Database", 1073741824);
		console.log("Database Created!");
	}
	//DB creation for devices
	else {
		app.db = window.sqlitePlugin.openDatabase(dbName);
		console.log("Database Accessed!");
	}
}


I want to access the database which is present in the ~/data/Test.sqlite folder.

I Included the following scripts in my page

<script src="js/AosJS/common.js"></script>
<script src="js/vendor/jquery-2.1.0.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/AosJS/index.js"></script>
<script src="js/ng-cordova.min.js"></script>

What I have tried:

I tried to place the db in www folder and try to access it by the following code

JavaScript
app.db = window.sqlitePlugin.openDatabase({name: "Test.db", createFromLocation: 1});


It will give the following error

Uncaught TypeError: Cannot read property 'openDatabase' of undefined
Posted
Updated 5-May-16 19:18pm
v6
Comments
George Jonsson 5-May-16 10:41am
   
The error basically say that the object window.sqlitePlugin is undefined.
Where is this object initialized?
arunfromtmm 6-May-16 1:17am
   
Yes you are correct. I forgot to include the cordova.js in my page

1 solution

Actually I missed the js reference for cordova

You are correct, actually I missed to include the following cordova script <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900