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" />
Storage Location of databases using window.openDatabase
When using
window.openDatabase
, you use "Web SQL". This functionality is provided by the browser directly. Where the data is stored depends on what browser you use. The storage space available in Web SQL is limited by default. Depending on what browser you use, you can increase the amount of storage space allowed.In Chrome, for example, you can access the databases via the developer tools:
Using SQLite with Phonegap Desktop
Using SQLite does not work with the setup you currently use. When opening the app served by Phonegap Desktop in a normal browser, you don't have access to the local computer/device. In order to use plugins that need to access the device, you must open the app served by Phonegap Desktop in "Phonegap Developer App" on your mobile device.
See this doc page for instructions.