Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phonegap-SQLitePlugin for Android #20

Open
ns-1m opened this issue Mar 23, 2012 · 23 comments
Open

Phonegap-SQLitePlugin for Android #20

ns-1m opened this issue Mar 23, 2012 · 23 comments

Comments

@ns-1m
Copy link

ns-1m commented Mar 23, 2012

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

@brody4hire
Copy link

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.

@macdonst
Copy link

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

@brody4hire
Copy link

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.

@jawwadfarooq
Copy link

Quite useful if this plugin is available for Android as well

@brody4hire
Copy link

@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.

@brody4hire
Copy link

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

@ns-1m
Copy link
Author

ns-1m commented Apr 4, 2012

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
[email protected]
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)

@brody4hire
Copy link

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.

@brody4hire
Copy link

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.

@gems09
Copy link

gems09 commented May 4, 2012

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

@brody4hire
Copy link

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

@gems09
Copy link

gems09 commented May 4, 2012

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.

@brody4hire
Copy link

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.

@gems09
Copy link

gems09 commented May 4, 2012

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){});

});

@gems09
Copy link

gems09 commented May 4, 2012

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.

@brody4hire
Copy link

@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.

@brody4hire
Copy link

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.

@gems09
Copy link

gems09 commented May 4, 2012

@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.

@gems09
Copy link

gems09 commented May 4, 2012

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

@brody4hire
Copy link

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)?

@gems09
Copy link

gems09 commented May 4, 2012

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

@gems09
Copy link

gems09 commented May 4, 2012

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

@gems09
Copy link

gems09 commented May 18, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants