storesafe / cordova-sqlcipher-adapter

A Cordova/PhoneGap plugin to create and access encrypted databases on Android, iOS, and Windows with API similar to HTML5/Web SQL API
Other
89 stars 55 forks source link

Coming across the error 'database not open' in SQLitePlugin.js #28

Open manishm77 opened 8 years ago

manishm77 commented 8 years ago

On trying to open database with the prescribed command, I am getting an error and it navigates to the following line (114) in SQLitePlugin.js

error(newSQLError('database not open'));

My code is as below:

function onDeviceReady() { /console.log(navigator.notification);/ alert("inside onDeviceReady of login.js"); var dbObj = window.sqlitePlugin.openDatabase({name: DB_NAME, key: 'sdtaylor', location: 1}, dataStorage.successcb, dataStorage.errorcb);

... other code .............. };

$(document).on("pagebeforeshow","#loginPage", function() { window.sessionStorage.clear(); document.addEventListener("deviceready", onDeviceReady, false); });

brodycj commented 8 years ago

This may happen if there was an error opening the database.

manishm77 commented 8 years ago

Sure, but where do I look for the problem.

brodycj commented 8 years ago

Please add an error callback to the openDatabase call.

manishm77 commented 8 years ago

Okay, modified the errorcb as follows:

errorcb: function(error){
    alert("errorcb: "+error);
},

I simply get an alert with message: "errorcb: Error: Could not open database"

Any other way get more elaborate error message?

brodycj commented 8 years ago

Which platform are you using?

manishm77 commented 8 years ago

We are building solution for Android and iOS. But at the moment I am developing using the browser of cordova (which gets added under the platforms). We first develop the functionalities and test on the browser, then create apk and ipa and test. So I can say currently I am facing issue on the cordova browser.

brodycj commented 8 years ago

The browser platform is not supported by this plugin. I will document this more clearly when I get a chance.

manishm77 commented 8 years ago

Okay, thanks. So I have to change the code, build an apk and then test.

But I wanted to make sure that the data is getting encrypted into the sqlite. I hope there are apps that allow me to browse sqlite database.

brodycj commented 8 years ago

But I wanted to make sure that the data is getting encrypted into the sqlite.

The best way to test this is to try making an encrypted database (with a valid key) then try opening it:

and then try to read an existing table. Of course you should be able to read the data if and only if you opened the database with the correct password.

There is a corner case, through. If you create/open a database with a password for the first time without writing any data, the database file may be completely empty (size of zero bytes) and opening the database with an incorrect password (or no password) would work in this case.

I hope there are apps that allow me to browse sqlite database.

The sqlite project itself comes with a sqlite3 command line tool, and SQLCipher (which is based off SQLite) also has the sqlite3 command-line tool. If you use the sqlite3 command line tool from SQLCipher you would use the 'key' PRAGMA to unlock an encrypted database.

There are also open-source, "freeware", and I think commercial SQLite GUI tools available. There may be a GUI tool with SQLCipher enabled, I am not sure.

For more resources you may want to look through the SQLCipher project pages, web pages, and discussion forum.

You may also want to try using the hexdump tool with the -C option. With a "regular" sqlite file you will see "SQLite format 3" and what looks like a SQL dump in the ASCII character decoding. With a database that is encrypted using SQLCipher you should not see any such information.

jeevithaBA commented 5 years ago

Hi All, Iam using ionic1, iam running my app in xcode simulator, and while login iam getting **close: db name was not open:

screen shot 2018-12-19 at 12 41 18 pm