How do I use Sqlite in a Cordova application?

Asked

Viewed 790 times

2

Gentlemen, I have a hybrid application that I built in HTML, CSS and Javascript (Jquery Mobile) using Cordova, and now I would like to access the device’s database. Unfortunately I don’t know where to start, because in the searches I did most of the material is in English (Google Dale Translate). I would like a simple example of CRUD to follow and tips for initiation like:

  1. I have to give permission to access the application to access the bank?

  2. The saved information remained permanently on the device?

1 answer

1

There is a native sqlite interface in Cordova/Phonegap

cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git

Example:

module.controller('MyCtrl', function($scope, $cordovaSQLite) {

      var db = $cordovaSQLite.openDB({ name: "my.db" });

      // for opening a background db:
      var db = $cordovaSQLite.openDB({ name: "my.db", bgType: 1 });

      $scope.execute = function() {
        var query = "INSERT INTO test_table (data, data_num) VALUES (?,?)";
        $cordovaSQLite.execute(db, query, ["test", 100]).then(function(res) {
          console.log("insertId: " + res.insertId);
        }, function (err) {
          console.error(err);
        });
      };

    });

http://ngcordova.com/docs/plugins/sqlite/

  • you are doing an insert in the table but have not created it before.... I tbm am looking for a good explanation on how to use Cordova/Sqlite, the tutorials I saw did not bring good solutions to basic things. If you can contribute a complete solution it would be great. Thank you

  • I wish I could chat with other devs who use Ionic/Cordova/Phonegap. If you can, you can contact me by Skype: [email protected]. Hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.