Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nicolas_r_
Beginner
97 Views

cordova-sqlite-legacy Plugin

Hi im using cordoba-sql-legacy plugin ver 0.7.18, and i follow a tutorial but i don't know if is working because the emulator console didn't give me any information, i also try adding a "alert" but it shows nothing so maybe is something wrong on my code i really don't know. as framework im  using Ionic with angularJS. any info about i will appreciate a lot thanks =)

My app.js

var db = null;

var example = angular.module('myApp', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $cordovaSQLite) {
        $ionicPlatform.ready(function() {
            if(window.cordova && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            }
            if(window.StatusBar) {
                StatusBar.styleDefault();
            }
            db = $cordovaSQLite.openDB("my.db");
            $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
        });
    });

example.controller("ExampleController", function($scope, $cordovaSQLite) {
 
    $scope.insert = function(firstname, lastname) {
        var query = "INSERT INTO people (firstname, lastname) VALUES (?,?)";
        $cordovaSQLite.execute(db, query, [firstname, lastname]).then(function(result) {
            console.log("INSERT ID -> " + result.insertId);
            alert("result.insertId");
        }, function(error) {
            console.log(error);
        });
    };
 
    $scope.select = function(lastname) {
        var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
        $cordovaSQLite.execute(db, query, [lastname]).then(function(result) {
            if(result.rows.length > 0) {
                console.log("SELECTED -> " + result.rows.item(0).firstname + " " + result.rows.item(0).lastname);
                
            } else {
                console.log("No results found");
            }
        }, function(error) {
            console.log(error);
        });
    };
 
});

My index.html

 <div id="campa_de_sangre" class="upage-content vertical-col left hidden"></div>
                <div id="consejos" class="upage-content vertical-col left hidden">

                    <ion-content ng-controller="ExampleController">
                        <button class="button" ng-click="insert('nic','rad')">Insertar</button>
                        <button class="button" ng-click="select('rad')">Selecet</button>
                    </ion-content>

                </div>

Tags (2)
0 Kudos
6 Replies
Elroy_A_Intel
Employee
97 Views

Intel XDK Emulate Tab only support the standard Cordova plugins. You will need to test any other plugins on a physical device. 

0 Kudos
nicolas_r_
Beginner
97 Views

but the alert in the could should apear even when the pluging do nothing?

 

0 Kudos
Elroy_A_Intel
Employee
97 Views

The alert is contained within your sqllite code block so it will not execute if the plugin or functionality isn't accessible.

0 Kudos
PaulF_IntelCorp
Employee
97 Views

Nicolas -- please use the Debug tab to test an app that contains non-core plugins.

0 Kudos
nicolas_r_
Beginner
97 Views

i test on real device and not event the alert show 

0 Kudos
PaulF_IntelCorp
Employee
97 Views

Might have to use the CDT panel to see what is happening. > https://developers.google.com/web/tools/chrome-devtools/

0 Kudos