Android SQlite Problem


#1

Hi there,
im trying to implement $cordovaSQLite and open the database. Unfortunately it won’t work (sayed it cannot open the database).

My code:
var login = angular.module("login", ["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({name : "my.db"}); $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)"); }); })

Logcat prints the following error message:

[INFO:CONSOLE(174)] “OPEN database: my.db”, source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (174)

[INFO:CONSOLE(195)] “OPEN database: my.db failed, aborting any pending transactions”, source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (195)

[INFO:CONSOLE(82)] “Could not open database”, source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (82)

Can anybody help me with this?

Sincerly

Alex


#2

did you added the sqlite cordova plugin first?


#3

yes i did but it it seems like it just wont work :confused:


#4

You probably are missing the third parameter

db = $cordovaSQLite.openDB({name : "my.db"});
var query = "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text)
$cordovaSQLite.execute(db, query, []).then(function(res) {
   console.log(res);
}, function (err) {
   console.error(err);
});

If you want to test it also in your browser check this out: https://gist.github.com/ilgianfra/9b3c4f1492745d818618
Let me know if it hepls!


#5

if you are not using any prepared params the last parameter can be omitted.
@Baklizki
could you remove the table creation code? --> only try to oopen your database.

Does the error also occurs?


#6

Thank @gianfra_ for your reply,
i tried your code and undortunatly, it won’t call either the success nor the error callbacks :confused:


#7

Hi @bengtler,
i tried your advice and the error is still alive.
Could it maybe be a thing of permissions? I tried to grant every possible permission in the AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE" />


#8

Thanks to @bengtler and @gianfra_ for your help,
finally i found the problem (and i dont know why it work in that way, because in all tutorials they do it different).

My problem was that i include the “ng-cordova.min.js” before i include the “cordova.js” file (how i saw in the tutorial).

Unfortunately my Logcat doesnt displayed the errors, that it could not find angularjs. Just when i created a seperate project and tried it with it, it displayed me the error messages and i could correct it.

Thanks for your help,

Alex


#9

nice you got it working!

and letting us know, that you solved your problem :blush:


#10

Thanks a lot for providing your solution :slight_smile:


#12

Hello!
I’m having the same issue here. I made a question at stackoverflow.com

I tried putting the .min script before and after cordova.js but no luck. Also tried with the android manifest xml.
The thing is that this was working 4 days ago and I don’t know what happened.

Thanks in advance!