Phonegap-SQLitePlugin for Android #20

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

Comments

Projects
None yet
5 participants
@ns-1m

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

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Mar 23, 2012

Contributor

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.

Contributor

brodybits commented Mar 23, 2012

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

This comment has been minimized.

Show comment Hide comment
@macdonst

macdonst Mar 23, 2012

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

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

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Mar 24, 2012

Contributor

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.

Contributor

brodybits commented Mar 24, 2012

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

This comment has been minimized.

Show comment Hide comment
@jawwadfarooq

jawwadfarooq Mar 27, 2012

Quite useful if this plugin is available for Android as well

Quite useful if this plugin is available for Android as well

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Mar 27, 2012

Contributor

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

Contributor

brodybits commented Mar 27, 2012

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

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Apr 4, 2012

Contributor

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

Contributor

brodybits commented Apr 4, 2012

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

@ns-1m

This comment has been minimized.

Show comment Hide comment
@ns-1m

ns-1m 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
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)

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

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Apr 5, 2012

Contributor

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.

Contributor

brodybits commented Apr 5, 2012

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.

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits Apr 9, 2012

Contributor

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.

Contributor

brodybits commented Apr 9, 2012

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

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 May 4, 2012

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

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.

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits May 4, 2012

Contributor

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

Contributor

brodybits commented May 4, 2012

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

This comment has been minimized.

Show comment Hide comment
@gems09

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

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.

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits May 4, 2012

Contributor

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.

Contributor

brodybits commented May 4, 2012

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

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 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 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

This comment has been minimized.

Show comment Hide comment
@gems09

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

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.

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits May 4, 2012

Contributor

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

Contributor

brodybits commented May 4, 2012

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

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits May 4, 2012

Contributor

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.

Contributor

brodybits commented May 4, 2012

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

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 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 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

This comment has been minimized.

Show comment Hide comment
@gems09

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

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.

@brodybits

This comment has been minimized.

Show comment Hide comment
@brodybits

brodybits May 4, 2012

Contributor

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

Contributor

brodybits commented May 4, 2012

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

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 May 4, 2012

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

gems09 commented May 4, 2012

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

@gems09

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 May 4, 2012

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

gems09 commented May 4, 2012

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

@gems09

This comment has been minimized.

Show comment Hide comment
@gems09

gems09 May 18, 2012

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

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