davibe/Phonegap-SQLitePlugin

Phonegap-SQLitePlugin for Android

ns-1m opened this issue · 23 comments

If you reading this, you must be interested on the Android port for this plugin :-).

I think this plugin can be easily ported with your Java knowledge.

Android guys even manage to port Spatialite (GIS extension for SQLite3) library for Android.

PhoneGap SQLiteplugin is right now for iOS devices only (i.e. Objective-C + Javascript).

Hopefully, some can translate the Objective-C to Java (Android SDK) and use the existing Javascipt (PGSQLitePlugin.js from iOS).

However, there are some JSQLite code already. For instance, this project has the necessary files Java Android SDK for SQLite3/Spatialite.

https://github.com/mrenouf/android-spatialite

Somebody would like to knit pick those functions and assembly a Android PhoneGap SQLite plugin.

https://github.com/mrenouf/android-spatialite/tree/master/src/jsqlite

For sure this one of the files.
https://github.com/mrenouf/android-spatialite/blob/master/src/jsqlite/Database.java

Noli

I would be interested in this kind of port, however I do not have time right now to work on this. Maybe I can work on this sometime in the future. I hope someone will work to make this future-proof by fixing #14 to get this working on Cordova.

Why not use the Plugin that is already provided in the Android repo? It only gets enabled for certain versions of Android that don't properly support window.openDatabase() but all of the necessary code is already there:

https://github.com/apache/incubator-cordova-android/blob/master/framework/src/org/apache/cordova/Storage.java

I am guessing the Android Storage class should emulate the HTML5 Web API in the object returned by window.openDatabase(). I hope we can come up with a solution for #11 to emulate the HTML5 Web API in this plugin for the iOS.

Quite useful if this plugin is available for Android as well

@jawwadfarooq I think it was a very good suggestion by @macdonst to simply use the Plugin that is already provided in the Android repository: https://github.com/apache/incubator-cordova-android/blob/master/framework/src/org/apache/cordova/Storage.java

I think it is better if we can adapt a version of this plugin to follow the same Storage API as has already been made for the Android. Someone has already adapted this plugin for Cordova, and I am about to ask if he can make an adaptation to follow the Android Storage API.

https://github.com/chbrody/Cordova-SQLitePlugin/tree/master/DroidGap copied from [sS]torage.j*, use it at your own risk!

Chris, Brilliant!

Would it be possible to have this index.html for PGSQLplugin iOS as well.

https://github.com/chbrody/Cordova-SQLitePlugin/blob/master/DroidGap/assets/www/index.html

Probably, just rename old index.html to index_lawnchair.html and use
your index.html as default.

Thanks.

Noli

On 4/5/12, Chris Brody
reply@reply.github.com
wrote:

https://github.com/chbrody/Cordova-SQLitePlugin/tree/master/DroidGap copied
from [sS]torage.j*, use it at your own risk!


Reply to this email directly or view it on GitHub:
#20 (comment)

Well the index.html is just copy-pasting an adapted version of the README sample into the template but yes, I can add something like demo-index.html when I get a chance.

I made some more changes in https://github.com/chbrody/Cordova-SQLitePlugin/ for the Android (DroidGap) version including an API improvement and a common Lawnchair adapter. I still want to do a bit of cleanup before submitting a pull request.

I use this plugin when it starts inserting in to the db UI got stuck. Please provide the solution for it.

Can you please specify which version you are using and can you post a sample, as simple as possible, that can demonstrate this behavior?

Thanks for your response Chris Brody. I am using phonegap 1.2.0 and plugin is for ios. I tried to run the db process in background but it crashes the app. While inserting UI got stuck.

It is already in the README if you try to save too much data the UI will be blocked. The two solutions I can think of are to use a worker thread or make a timer mechanism. Both are possible from the application layer.

and this is the sample code for insertion same way i am fetching also.

database.transaction(function(transaction){

    transaction.executeSql(["INSERT INTO TableName(articleId,  priority, sectionId) VALUES(?,?,?)",temp_ArticleId, temp_Priority, temp_SectionId],function(galTemp_Results){});

});

I tried to run the db operation in background thread i replace the code [self respond:callback withString:[resultSet JSONRepresentation] withType:@"success"]; with [self performSelectorOnMainThread:@selector(saveComplite:)
withObject:set waitUntilDone:YES]; but app crashes. I don't know what to do. Please give me solution for it. how to write the code for worker thread? Please paste some code.

@gyanendra-sncet sorry I have never worked with background threads on iOS before so I really cannot help you there. A background thread will only help you if you are doing really large batches, which I believe is not the case for you.

Also this plugin is no longer supported for PG 1.2.0. Please upgrade to 1.5+, preferably 1.7.0 and try again. You can also checkout my fork, which has support for Android and is closer to the HTML5 SQL API.

@chbrody Its ok. I have huge data to save in the sqlite so that is why UI is getting blocked so i though if it runs on background thread then ui will not blocked.

for PG 1.7.0 the sqlite plugin runs on the main thread so t don't think upgrading will solve my problem.

For a huge data record you would have to add the thread to solve the UI blocking and I think this would have to be done in the plugin. I will raise this in an issue in my fork, cannot promise when or even if I will ever make the solution. Also, would it help you to pre-populate the database like (http://gauravstomar.blogspot.com/2011/08/prepopulate-sqlite-in-phonegap.html)?

Thanks Chris Brody. I have serious problem i need to to fix it. Thanks once again...

Pre population of db will not work because i am getting the data from server....

Hi Chris Brody. Any update one adding the thread to solve the UI blocking?