SQLite not create DB in Web SQL


#1

Hi,
Currently I have done in Hybrid Apps. It is SQLite compatible in Hybrid Apps.
I’m having problem in creating DB in Web SQL.

Above is my codes,

app.js

(function () {

function mycarCtrl ($rootScope, $state) {
var vm = this;
var db;
var app = angular.module(‘app’, [‘ionic’, ‘ngCordova’])

app.run(function ($ionicPlatform, $cordovaSQLite) {
    $ionicPlatform.ready(function () {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

            cordova.plugins.Keyboard.disableScroll(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
        db = window.openDatabase("car", "1.0", "My Proton", 2000);
        $cordovaSQLite.execute(db, "CREATE TABLE listcar (id integer primary key, carmodel text, carregister text)");
    });
})
app.controller('mycarCtrl', function ($scope, $cordovaSQLite) {
    var vm = this;
    vm.addInfo = function(){
        var query ="INSERT INTO listcar (carmodel, carregister) VALUES (?,?)";
        $cordovaSQLite.execute (db,query, [vm.carmodel, vm.carregister]);
        vm.load();
    }

    vm.load = function (){
        vm.alldata=[];
        $cordovaSQLite.execute(db,"SELECT * FROM listcar"). then (function(result){
            if (result.rows.length){
                
                for(var i=0; i<result.rows.length;i++){

                vm.alldata.push(result.rows.items(i));

                }
            } else {
                console.log("No data found");
            }
        }, 
        function (error){
            console.log("error"+err);
        });
        }

})();

car.html

{{items.carmodel}}

{{items.carregister}}

    <div>
      <a class="button button-outline button-dark" href = "#/add">Add More Car</a>
    </div>

Anybody can solve this?
Thanks.


#2

Take a look at this: https://github.com/jdnichollsc/Ionic-Starter-Template

A good starting point for working with SQLite and WebSQL.


#3

Thanks. I will. But it’s for native or hybrid apps?