I am opening a SQLite database in phonegap. This is my javascript code :
var myDB = null;
function onDeviceReady()
{
myDB = window.openDatabase("test", "1.0", "Test DB", 1000000);
//myDB = window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});
alert("yal");
myDB.transaction(PopulateDatabase,errorDB,successDB);
myDB.transaction(queryDB, errorCB, querySuccess);
}
function PopulateDatabase(tx)
{
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function errorDB(error)
{
alert("Error on Database creation : " + error);
}
function successDB()
{
alert("Database is created successfully");
}
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
alert("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
alert("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
alert("success");
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
This is work and I can get data from my database. My problem is that I can't found my database on my computer. Could someone tell me where can I found it ?
I tried this but it doesn't work for me.
myDB = window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});
I am using cordova-sqlite-storage plugin.
This is my config.xml file of the project :
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>yal</name>
<description>
A blank PhoneGap app.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
PhoneGap Team
</author>
<content src="index.html" />
<access origin="*" />
<plugin name="cordova-sqlite-ext" spec="~0.10.2" />