DisyInformationssysteme / Cordova-spatialite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/Windows Universal(8.1)/Amazon Fire-OS/WP(7/8) with HTML5/Web SQL API
Other
24 stars 17 forks source link

window.sqlitePlugin.openDatabase does not create new database #2

Closed mgiana closed 7 years ago

mgiana commented 7 years ago

Hi,

I tried the following db = window.sqlitePlugin.openDatabase({name: 'file:///storage/emulated/0/Download/zzz.sqlite'}, this.runQuery); but it reports OPEN database: file:///storage/emulated/0/Download/zzz.sqlite failed, aborting any pending transactions It does open if the database exists. Should it not create a new database if it does not exist?

Also how do I refer to an existing database with in the www folder of the cordova android app, I tried db = window.sqlitePlugin.openDatabase({name: 'file:////Roads.sqlite'}, this.runQuery); but again does not connect even though it exists.

Regards

Marco Giana

Cultrarius commented 7 years ago

If you try to open a database that does not exist yet then some plugins will create the database for you, but our plugin does not support that mode of operation. We only use it to open existing databases, so we deactivated the auto-create part for safety reasons. I think you would have to add a new "create" method to the plugin or reactivate the create-on-open functionality. Although it is probably easier to ship an empty database with your app.

Also, you should only open databases with an absolute file path, never a relative one. So to open a database in the www folder, get the absolute path to your app's root folder and append your www/foo/bar/Roads.sqlite path. Additionally, check that your file URL is valid. I think file:///path is valid, but your second example file:////path is not valid.

mgiana commented 7 years ago

Thank You i got it working ☺

On 09/03/2017 8:11 PM, "Michael" notifications@github.com wrote:

If you try to open a database that does not exist yet then some plugins will create the database for you, but our plugin does not support that mode of operation. We only use it to open existing databases, so we deactivated the auto-create part for safety reasons. I think you would have to add a new "create" method to the plugin or reactivate the create-on-open functionality. Although it is probably easier to ship an empty database with your app.

Also, you should only open databases with an absolute file path, never a relative one. So to open a database in the www folder, get the absolute path to your app's root folder and append your 'www/foo/bar/Roads.sqlite' path. Additionally, check that your file URL is valid. I think 'file:///path' is valid, but your second example 'file:////path' is not valid.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DisyInformationssysteme/Cordova-spatialite-storage/issues/2#issuecomment-285295903, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYPtxiJoZKmjfcD4Q_kHdgnQD5OcXCbks5rj8JGgaJpZM4MVCgA .

Cultrarius commented 7 years ago

Great! :)

Alma9170 commented 4 years ago

Thank You i got it working ☺ On 09/03/2017 8:11 PM, "Michael" @.***> wrote: If you try to open a database that does not exist yet then some plugins will create the database for you, but our plugin does not support that mode of operation. We only use it to open existing databases, so we deactivated the auto-create part for safety reasons. I think you would have to add a new "create" method to the plugin or reactivate the create-on-open functionality. Although it is probably easier to ship an empty database with your app. Also, you should only open databases with an absolute file path, never a relative one. So to open a database in the www folder, get the absolute path to your app's root folder and append your 'www/foo/bar/Roads.sqlite' path. Additionally, check that your file URL is valid. I think 'file:///path' is valid, but your second example 'file:////path' is not valid. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYPtxiJoZKmjfcD4Q_kHdgnQD5OcXCbks5rj8JGgaJpZM4MVCgA .

Hello, I am using cordova-spatialite-storage version 2.0.0, and the way I use the database is like this: try { var query = 'SELECT Geometry From '; var args = []; var querySuccess = function (results) { alert(results) } var queryError = function (error) { alert(error.toString()) } var spatialiteURI = "file:///storage/emulated/0/Documents/DB.sqlite"; var db = window.sqlitePlugin.openDatabase({ name: spatialiteURI }); db.transaction(function (tx) { tx.executeSql(query, args, querySuccess, queryError); }); } catch (ex) { alert(ex.message) } But this code is not working and the plugin can't find my database file(no reaction at all). Is my way of defining database name option wrong ?Or is there another way to do this? It is so critical for me to process spatial data in my app. So any help make this plugin work is so appreciated. Thanks in advance.