Software Archive
Read-only legacy content
17061 Discussions

How to call a .db file with Intel XDK?

Denis_J_
Beginner
1,721 Views
  1. I created a database using SQLite
  2. I export the database .db format
  3. Then I save the database files in the www folder on Intel XDK
  4. How to call the database ??

please help me,.,

0 Kudos
20 Replies
Swati_S_Intel1
Employee
1,705 Views

You have to import your db when you start up the app and then use where required. You can create a simple app with one of our sample apps or templates and write your import script in deviceready or document.ready depending on whether you are using webapp or cordova app. 

Swati

 

0 Kudos
Davide_M_
Beginner
1,705 Views

I have some problems to open the .db file, could you share with me the few lines of code to connect to the database?
​Thanks a lot
Davide

 

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
1,705 Views

Are you using an plugin?

I am using com.brodysoft.sqlitePlugin. With this one I open the db with this command> db = window.sqlitePlugin.openDatabase({name: wNomeDB, location: 2});

 

 

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
1,705 Views

Unfortunately, to test any app with plugins, you need to test on device. The emulator does not run yet.

0 Kudos
John_H_Intel2
Employee
1,705 Views

You can also build a custom app preview. This will build an app preview that contains your plugins.

This functionality can be found on the debug tab of the XDK.

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
1,705 Views

Yes, it is true. I do the same.

I am waiting very anxious this new tool in XDK, not only for this plugin, but all.

0 Kudos
Denis_J_
Beginner
1,705 Views

checkout my simple project :
https://www.dropbox.com/s/2u1l4eh3x734h1m/intel_XDK_%28programsederhana%29.zip?dl=0

*note : create database using "sqlite browser"

0 Kudos
Lisa_P_
Beginner
1,705 Views

Hi,

i have some problem to read a sqlLite db.

I add in my Intel xdk project the plugin  cordova-sqlite-storage and i have add my .db file in www folder.

In index.html I use this code:

document.addEventListener("deviceready", onDeviceReady, false);
 
function successCallback(db) {
    alert("successo : "+db);
}
function errorCallback(db) {
    alert("error : "+db);
}
      function onDeviceReady() {
        var db = window.sqlitePlugin.openDatabase({name: "consiglinonna.db", createFromLocation: 1, androidLockWorkaround: 1}); //, function(db) {
        db.transaction(function(tx) {
            alert('ciao');
            //tx.executeSql("SELECT * FROM 'categorie'", [], function(tx, res) {
            tx.executeSql("SELECT * FROM categorie", [], function(tx, res) {
                alert("res: " + JSON.stringify(res));
                alert("res1: " + res.rows[0]);
            }, function(error) {
                alert('SELECT error: ' + error.message);
            });

        }, function(err,a,b,c) {
            alert('Open database ERROR: ' + JSON.stringify(err));
           // alert(err+"\n"+a+"\n"+b+"\n"+c);
        });
  }

On device test i read thi alert: 

Open database ERROR: code:0

but in console I can read 'DB opened: consiglinonna.db'

what does it means? what am I doing wrong?

please, please help me!!!

thanks

0 Kudos
Denis_J_
Beginner
1,705 Views

Lisa P. wrote:

Hi,

i have some problem to read a sqlLite db.

I add in my Intel xdk project the plugin  cordova-sqlite-storage and i have add my .db file in www folder.

In index.html I use this code:

document.addEventListener("deviceready", onDeviceReady, false);
 
function successCallback(db) {
    alert("successo : "+db);
}
function errorCallback(db) {
    alert("error : "+db);
}
      function onDeviceReady() {
        var db = window.sqlitePlugin.openDatabase({name: "consiglinonna.db", createFromLocation: 1, androidLockWorkaround: 1}); //, function(db) {
        db.transaction(function(tx) {
            alert('ciao');
            //tx.executeSql("SELECT * FROM 'categorie'", [], function(tx, res) {
            tx.executeSql("SELECT * FROM categorie", [], function(tx, res) {
                alert("res: " + JSON.stringify(res));
                alert("res1: " + res.rows[0]);
            }, function(error) {
                alert('SELECT error: ' + error.message);
            });

        }, function(err,a,b,c) {
            alert('Open database ERROR: ' + JSON.stringify(err));
           // alert(err+"\n"+a+"\n"+b+"\n"+c);
        });
  }

On device test i read thi alert: 

Open database ERROR: code:0

but in console I can read 'DB opened: consiglinonna.db'

what does it means? what am I doing wrong?

please, please help me!!!

thanks

include "SQLitePlugin.js" to index.html

<script src="../plugins/cordova-sqlite-storage/www/SQLitePlugin.js"></script>

sql.PNG

or you can check my simple project :

https://www.dropbox.com/s/2u1l4eh3x734h1m/intel_XDK_%28programsederhana%29.zip?dl=0

0 Kudos
Lisa_P_
Beginner
1,705 Views

Hi,

thanks for your answer.

I add the js call in this way (src="plugins/cordova-sqlite-storage/www/SQLitePlugin.js"), but notthing is change (Attention: i used 'plugins' and not '../plugins' because  '../plugins' gives error that can't read the file...).

I think that the db is opened, but the select query (SELECT * from categorie) fail, because i can see the alert 'ciao', but not the alert 'res' and 'res1'.

I opened your project in my intel xdk yesterday but I think to have the same problem...in console I can read 'DB opened', but the table that prints the result is empty.

I add in your code some alert and data.rows.length il 0, like in my case...

function data_m(){
db_mahasiswa.transaction(function(tx) {
        alert('pippo');
    tx.executeSql("SELECT * FROM data_mahasiswa", null, function(tx, data) {
        alert('pluto '+data.rows.length);

Sorry form my bad english...

 

0 Kudos
Denis_J_
Beginner
1,705 Views

Lisa P. wrote:

Hi,

thanks for your answer.

I add the js call in this way (src="plugins/cordova-sqlite-storage/www/SQLitePlugin.js"), but notthing is change (Attention: i used 'plugins' and not '../plugins' because  '../plugins' gives error that can't read the file...).

I think that the db is opened, but the select query (SELECT * from categorie) fail, because i can see the alert 'ciao', but not the alert 'res' and 'res1'.

I opened your project in my intel xdk yesterday but I think to have the same problem...in console I can read 'DB opened', but the table that prints the result is empty.

I add in your code some alert and data.rows.length il 0, like in my case...

function data_m(){
db_mahasiswa.transaction(function(tx) {
        alert('pippo');
    tx.executeSql("SELECT * FROM data_mahasiswa", null, function(tx, data) {
        alert('pluto '+data.rows.length);

Sorry form my bad english...

 

 

Don't test application in emulator, it's not works,.. but you must try your application on your device,.,

I also had problems when I test the application in the emulator, but when I tried it on my device, it's worked,.,

0 Kudos
Lisa_P_
Beginner
1,705 Views

Don't test application in emulator, it's not works,.. but you must try your application on your device,.,

I also had problems when I test the application in the emulator, but when I tried it on my device, it's worked,.,

Hi,

I tested always on my device connected with USB cable (emulator tab alert me "Unimplemented API Emulation").

0 Kudos
Denis_J_
Beginner
1,705 Views
Lisa P. wrote:

Hi,

I tested always on my device connected with USB cable (emulator tab alert me "Unimplemented API Emulation").

no, that's not who I mean. but you must build your application & install your application on your device,.. not test with connected by usb,.. it's just like you test in the emulate,..
0 Kudos
Davide_M_
Beginner
1,705 Views

Exactly.
You always have to build and really install on the device. If you like, you can use googledrive, dropbox or other services like that to upload from the computer and download (and install) from the mobile.
Until now, no way to test in emulator

0 Kudos
Adri_v_
Beginner
1,705 Views

FWIW : I can confirm that this works when debugging from the XDK on an USB connected Android device - which obviously allows for faster testing than building the app/installing it on your device

(just wondering where the actual DB file is created on the device - but that's another issue)

0 Kudos
Ruben_D_
Beginner
1,705 Views

posiblemente ya lo resolvieron, pero en este momento logre instalar el plugin desde la siguiente dirección:

https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free

Saludos,

0 Kudos
Роман_Б_
Beginner
1,705 Views

I can not add plugin cordova-sqlite-storage because  it exists this error:

Uh oh! "/media/destructor/Documents/Projects/IntelXDK/Temp/plugins/cordova-sqlite-storage/node_modules/cordova-sqlite-storage-dependencies/libs/sqlite-connector.jar" not found!

0 Kudos
Giselle_G_Intel
Employee
1,705 Views

Are you using the git repo mentioned in the above comment to add the plugin in the way this article outlines for third-party plugins? >https://software.intel.com/en-us/xdk/docs/add-manage-project-plugins< this should provide a good step-by-step to adding it to your project. If you are not using the git repo option, how are you attempting to add it?

0 Kudos
PaulF_IntelCorp
Employee
1,539 Views

Роман Б. wrote:

I can not add plugin cordova-sqlite-storage because  it exists this error:

Uh oh! "/media/destructor/Documents/Projects/IntelXDK/Temp/plugins/cordova-sqlite-storage/node_modules/cordova-sqlite-storage-dependencies/libs/sqlite-connector.jar" not found!

That plugin is not compatible with either the XDK cloud build system or with the PhoneGap Build system. It can only be used with Cordova CLI. This is due to the use of "hooks scripts" which is described in the README.md file > https://github.com/litehelpers/Cordova-sqlite-storage#status < and is directly related to the error you are seeing.

The last version of that plugin that can be used with the XDK or with PhoneGap Build is 1.2.2. After that release of the plugin the author added the "before_plugin_install" hooks script.

0 Kudos
Reply