I think with DB = SqlOpenDatabase(fileName,“1.0”,“My Customer Database”)
you have to define fileName somwhere on your device using the PhoneGap FileSystem Plugin. You can’t just get an “outside” (of the webapp) file on your phone or SD card without that plugin.
In Project Properties, open PhoneGap configxml. Change the line for cordova-file-plugin so that it has the version number for the library: <gap:plugin name="cordova-plugin-file" source="npm" version="3.0.0"/>
hmmm… Because it would be nice for my project to read from a db on the external storage I tried what I wrote above. But it didn’t work. It seems that SqlOpenDatabase can not read from external storage by using the PhoneGapFileSystem plugin.
cordova-sqlite-evcore-extbuild-free is what we are looking for!
It supports external storage directory.
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(externalDataDirectoryEntry) {
var db = window.sqlitePlugin.openDatabase({name: 'external.db', androidDatabaseLocation: externalDataDirectoryEntry.toURL()});
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS MyTable (data)');
for reference see:
But my Javascript skills are too less to implement this plugin in NSBasic
alright. phonegap compiles apk with
<gap:plugin name=“cordova-sqlite-evcore-extbuild-free” source=“npm” />
but not with
<gap:plugin name=“cordova-sqlite-ext” source=“npm” />
Anyway. the first one is what I need. The next days I’ll do trial & error until I’ll get this plugin working. My problem is that I know very little javascript and it’s always a hazzle to transfer javascript tutorials into NSBasic.
I don’t need to read necessarily from SD card. But I need to read from public accessible phone storage as the databases the user uses differ from each other and are just to big. so each user installs his apk and put the database(es) into a specific folder on the phone.
YES!!! I got it! I guess I was first too pessimistic. I went to bed to give the “cordova-sqlite-evcore-extbuild-free” a try tomorrow. But I couldn’t sleep. I really wanted to give it a try first. And what to say… it works!!! I can read from an sqlite file on the main directory (root directory - do net get confused with rooting of android devices [my device is also not rooted]).
Just add
<gap:plugin name=“cordova-plugin-file” source=“npm” version=“3.0.0”/>
<gap:plugin name=“cordova-sqlite-evcore-extbuild-free” source=“npm” />
to the config.xml
and put the file ‘extern.db’ into the main directory of your android phone
and and add the file ‘intern.db’ to the manifest - just to see the difference on how to read from inside and how to read from outside the webapp.
And this is the code:
'###### Read prepopulated internal DB
Function btReadInternalDB_onclick()
Dim DB=SqlOpenDatabase("intern.db")
s=Array(["Select * from user WHERE user_level='administrator';", LoadDB_dataHandler])
Sql(DB,s)
End Function
'###### Read prepopulated external DB
Function btReadExternalDB_onclick()
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, gotExtDB, failExtDB)
End Sub
Function failExtDB(error)
Call AddLog("can not open db")
End Function
Function gotExtDB(externalDataDirectoryEntry)
Dim DB = window.sqlitePlugin.openDatabase({name: "extern.db", androidDatabaseLocation: externalDataDirectoryEntry.toURL()})
s=Array(["Select * from user WHERE user_level='administrator';", LoadDB_dataHandler])
Sql(DB,s)
End Function
'###### display records
Sub LoadDB_dataHandler(transaction, result)
Dim DBrecords
DBrecords=result
For i=0 To DBrecords.rows.length-1
record=DBrecords.rows.item(i)
Call AddLog(record["username"])
Next
End Function
'###### log
Sub AddLog(txt)
TextArea1.text = txt & vbCRLF & TextArea1.text
End Sub